121000519

I want to make a mod that when the trident is thrown, shoots a beam of particles in minecraft. Before shooting, it must be charged with shift + left click and the particle must be in full red color.

Kodari AI
KodariJun 3 at 7:41 am 25
TridentBeamMod
A Fabric 1.21.11 mod that adds a charged beam mechanic to the trident. Players charge the trident by holding Shift and left-clicking, then throwing the trident shoots a continuous beam of red particles along its trajectory. The charge state is tracked per-item and visualized with particles while active. Simple, focused mechanic with no extra dependencies.
TridentBeamMod
A Fabric 1.21.11 mod that adds a charged particle beam mechanic to the trident. Sneaking and left-clicking while holding a trident charges it with energy. When the charged trident is thrown, it leaves a vivid red particle beam trail along its entire flight path. The charge is stored on the item, persists until thrown, and the beam effect stops once the trident embeds in a surface.

Here’s the plan:

  • Charge: AttackBlockCallback + AttackEntityCallback detect sneak+left-click with trident → writes a flag to CUSTOM_DATA on the stack

  • Transfer: Mixin on TridentItem.onStoppedUsing() at TAIL → if charged flag present, moves the player UUID to a static pending set

  • Beam: Mixin on TridentEntity.tick() → on first tick checks if owner is in pending set (marks entity as charged), then every tick while in-flight spawns red DustParticleEffect particles

How to use:

  1. Hold a Trident in your main hand

  2. Sneak (Shift) + Left-click on any block or entity — actionbar shows “✦ Trident charged!”

  3. Right-click and hold to charge-throw the trident — it blazes a dense red particle beam along its entire flight path

  4. The beam stops the instant the trident hits a surface

121000519

The compilation failed with this error:

code
Compilation failed with 6 error(s):

ERROR in src/main/java/com/tridentbeam/TridentBeamMod.java at line 51: cannot find symbol
        if (existing != null && existing.contains("tridentBeamCharged")) return;
                                        ^
  symbol: method contains(String)
  location: variable existing of type NbtComponent

ERROR in src/main/java/com/tridentbeam/TridentBeamMod.java at line 62: cannot find symbol
        if (comp == null || !comp.contains("tridentBeamCharged")) return false;
                                 ^
  symbol: method contains(String)
  location: variable comp of type NbtComponent

ERROR in src/main/java/com/tridentbeam/mixin/TridentEntityMixin.java at line 38: cannot find symbol
            Vec3d pos = self.getPos();
                            ^
  symbol: method getPos()
  location: variable self of type TridentEntity

ERROR in   src/main/java/com/tridentbeam/TridentBeamMod.java at line 51: cannot find symbol
          if (existing != null && existing.contains("tridentBeamCharged")) return;
                                          ^
  symbol: method contains(String)
  location: variable existing of type NbtComponent

ERROR in   src/main/java/com/tridentbeam/TridentBeamMod.java at line 62: cannot find symbol
          if (comp == null || !comp.contains("tridentBeamCharged")) return false;
                                   ^
  symbol: method contains(String)
  location: variable comp of type NbtComponent

ERROR in   src/main/java/com/tridentbeam/mixin/TridentEntityMixin.java at line 38: cannot find symbol
              Vec3d pos = self.getPos();
                              ^
  symbol: method getPos()
  location: variable self of type TridentEntity


=== COMPILATION ERROR ANALYSIS ===

MISSING METHODS:
  - contains(String)
  - getPos()
ACTION: Check method names and signatures

FILES TO INVESTIGATE:
  - src/main/java/com/tridentbeam/TridentBeamMod.java
  - src/main/java/com/tridentbeam/mixin/TridentEntityMixin.java
  -   src/main/java/com/tridentbeam/TridentBeamMod.java
  -   src/main/java/com/tridentbeam/mixin/TridentEntityMixin.java

Please fix this error by creating a new artifact with the corrected code.

Kodari AI
KodariJun 3 at 7:42 am 7

Two fixes needed:

  1. NbtComponent has no .contains(String) — use .copyNbt().contains(key) instead

  2. TridentEntity (a projectile) has no getPos() — use getX()/getY()/getZ() directly

Both fixes applied:

  • NbtComponent.contains() — NbtComponent has no direct contains method; changed to comp.copyNbt().contains(key) which unpacks the compound first.

  • getPos() — TridentEntity (extends ProjectileEntity) doesn’t expose getPos() via Yarn mappings at this level; replaced with new Vec3d(self.getX(), self.getY(), self.getZ()) which always works on any Entity.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
8 267
src/main/java/com/tridentbeam/TridentBeamMod.java
package com.tridentbeam;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.item.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;

import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public class TridentBeamMod implements ModInitializer {

    public static final String MOD_ID = "tridentbeam";

    // Players whose next trident throw should produce a beam
    public static final Set<UUID> pendingChargedThrows = ConcurrentHashMap.newKeySet();

    // Active TridentEntity UUIDs currently producing a beam
    public static final Set<UUID> activeBreamTridents = ConcurrentHashMap.newKeySet();

    @Override
    public void onInitialize() {
        AttackBlockCallback.EVENT.register((player, world, hand, pos, direction) -> {
            if (!world.isClient() && hand == Hand.MAIN_HAND && player.isSneaking()) {
                tryChargeHeldTrident(player.getMainHandStack(), player);
            }
            return ActionResult.PASS;
        });

        AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
            if (!world.isClient() && hand == Hand.MAIN_HAND && player.isSneaking()) {
                tryChargeHeldTrident(player.getMainHandStack(), player);
            }
            return ActionResult.PASS;
        });
    }

    private static void tryChargeHeldTrident(ItemStack stack, net.minecraft.entity.player.PlayerEntity player) {
        if (!stack.isOf(Items.TRIDENT)) return;

        NbtComponent existing = stack.get(DataComponentTypes.CUSTOM_DATA);
        if (existing != null && existing.copyNbt().contains("tridentBeamCharged")) return;

        NbtCompound nbt = existing != null ? existing.copyNbt() : new NbtCompound();
        nbt.putBoolean("tridentBeamCharged", true);
        stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbt));

        player.sendMessage(Text.literal("✦ Trident charged!").formatted(Formatting.RED), true);
    }

    public static boolean consumeChargeFlag(ItemStack stack) {
        NbtComponent comp = stack.get(DataComponentTypes.CUSTOM_DATA);
        if (comp == null || !comp.copyNbt().contains("tridentBeamCharged")) return false;

        NbtCompound nbt = comp.copyNbt();
        nbt.remove("tridentBeamCharged");
        if (nbt.isEmpty()) {
            stack.remove(DataComponentTypes.CUSTOM_DATA);
        } else {
            stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbt));
        }
        return true;
    }
}