elijah

make the mod in 1.21.1

📎 1 file 2,932 chars
📄
pasted-code-1790997706838.txt
txt 2 lines
▶
Program a fully optimized, network-synchronized Java mod for the official "Lightning Spear" replicating every precise mechanic from Fresh Lols' FreshSMP series, creating a completely thread-safe, robust custom item with infinite durability that utilizes standard vanilla packet registrations and clean execution hooks to ensure total compatibility with the Essential Mod peer-to-peer multiplayer world-hosting network environment; this item must register an active movement event listener that entirely eliminates standard player hunger drain depletion during sprinting, jumping, or lunging with the weapon equipped, dynamically intercept entity damage events to multiply final attack damage directly based on the player’s active horizontal velocity vector length to facilitate high-speed flying one-shot kills, execute an immediate server-side action to spawn a true native lightning bolt entity and bypass defenses by force-disabling enemy shields for exactly 100 ticks upon every successful melee strike, implement a client-and-server synchronized fallback listener providing passive fall-damage immunity that cancels all landing impacts while triggering a terrain-safe 3-block radius knockback explosion whenever hitting the ground from a height greater than 10 blocks, and register a right-click active ability bound to a 20-second cooldown that spawns a 6-second visual aura of circular electric spark particles dealing 3 magic damage points every 20 ticks to all surrounding hostile entities within a 5-block radius; furthermore, you must integrate a persistent PvE mob-hunting quest system that entirely replaces player PvP kills with a 5-tier progression tracker—monitoring milestones where Tier 1 requires 10 Blazes, Tier 2 requires 10 Drowned, Tier 3 requires 5 Endermen, Tier 4 requires 3 Wither Skeletons, and Tier 5 requires 1 Wither Boss—permanently upgrading base attack speed and scaling damage modifiers upon completion while explicitly unlocking the "True Invisibility" attribute feature from Freshlol's "God Leggings" video upon achieving Tier 2, which grants total particle-free character invisibility and completely hides the 3D rendering of all equipped armor pieces from other players' view whenever the spear is held; all of this must be accompanied by coding a dynamic, real-time localized hover tooltip description that automatically modifies its text lines to list every current quest objective, kill count, active ability breakdown, and current tier unlock status directly on the item's graphical user interface profile, and finalize the item by compiling a built-in survival crafting table recipe mapped inside 'src/main/resources/data/modid/recipes/lightning_spear.json' requiring exactly one Netherite Ingot in the top-middle grid space, two Blaze Rods positioned vertically in the middle and bottom-middle slots, and two raw Copper Blocks flanking the central Blaze Rod on the left and right sides.
Kodari AI
KodariOct 3 at 3:55 am 5
LightningSpear
A fully network-synchronized Fabric mod for Minecraft 1.21.1 introducing the Lightning Spear, an infinite-durability custom weapon. It eliminates hunger drain while sprinting, scales damage with horizontal velocity for one-shot kills, spawns native lightning bolts, disables shields for 100 ticks, grants fall-damage immunity with terrain knockback, and offers a 20-second cooldown electric aura ability. Includes a 5-tier PvE quest system (Blazes, Drowned, Endermen, Wither Skeletons, Wither) unlocking attack speed upgrades and True Invisibility at Tier 2, plus a dynamic hover tooltip and survival crafting recipe.
  1. Register the spear and its crafting/item resources for the mounted Fabric 1.21.4 toolchain.

  2. Add server-authoritative melee, hunger, fall, aura, invisibility, cooldown, and mob-quest behavior.

  3. Persist quest progress and expose current progress in the spear tooltip.

Created the mod with the mechanics and recipe from the supplied spec. Quest progress persists in world data, and the tooltip progress syncs through the spear’s item data.

Version note: this project targets Minecraft 1.21.4 with Yarn 1.21.4+build.8, matching the only available source and API toolchain. It is not a 1.21.1 build.

elijah

can you make it run without any other mods installed

Kodari AI
KodariOct 3 at 4:10 am 1

Removed the Fabric API dependency and replaced its event callbacks with vanilla mixins for attacks, damage/death, and player ticks. It now needs only Fabric Loader—no Fabric API or other content mods.

The project is still configured for Minecraft 1.21.4, not 1.21.1.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
15 682
src/main/java/com/kodari/lightningspear/LightningSpearMod.java
package com.kodari.lightningspear;

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

import net.fabricmc.api.ModInitializer;
import net.minecraft.datafixer.DataFixTypes;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.player.HungerManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.PersistentState;
import net.minecraft.world.World;

public final class LightningSpearMod implements ModInitializer {
    public static final String MOD_ID = "lightningspear";
    private static final RegistryKey<Item> SPEAR_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MOD_ID, "lightning_spear"));
    public static final Item LIGHTNING_SPEAR = Registry.register(
            Registries.ITEM,
            SPEAR_KEY,
            new LightningSpearItem(new Item.Settings().registryKey(SPEAR_KEY).maxCount(1))
    );

    private static final PersistentState.Type<QuestState> QUEST_STATE_TYPE = new PersistentState.Type<>(
            QuestState::new,
            QuestState::readNbt,
            DataFixTypes.SAVED_DATA_COMMAND_STORAGE
    );
    private static final Map<UUID, Integer> ATTACK_LOCKS = new ConcurrentHashMap<>();
    private static final Map<UUID, Integer> INVISIBILITY_REFRESH = new ConcurrentHashMap<>();
    private static final Map<UUID, Aura> ACTIVE_AURAS = new ConcurrentHashMap<>();

    @Override
    public void onInitialize() {
    }

    public static boolean handleSpearAttack(ServerPlayerEntity player, Entity target) {
        if (!player.getMainHandStack().isOf(LIGHTNING_SPEAR)) {
            return false;
        }
        if (player.isSpectator()) {
            return true;
        }
        if (!(player.getWorld() instanceof ServerWorld serverWorld)) {
            return true;
        }

        UUID playerId = player.getUuid();
        if (ATTACK_LOCKS.getOrDefault(playerId, 0) > 0) {
            return true;
        }

        Progress progress = progressFor(getQuestState(serverWorld), playerId);
        ATTACK_LOCKS.put(playerId, Math.max(3, 10 - progress.tier()));
        if (target instanceof PlayerEntity defendingPlayer && defendingPlayer.isBlocking()) {
            ItemStack blockingStack = defendingPlayer.getBlockingItem();
            if (blockingStack != null) {
                defendingPlayer.disableShield(blockingStack);
            }
        }

        Vec3d velocity = player.getVelocity();
        float speedMultiplier = 1.0F + (float) velocity.horizontalLength() * 0.65F;
        float tierMultiplier = 1.0F + progress.tier() * 0.2F;
        float damage = 8.0F * speedMultiplier * tierMultiplier;
        boolean damaged = target.damage(serverWorld, player.getDamageSources().playerAttack(player), damage);
        if (damaged) {
            LightningEntity lightning = new LightningEntity(EntityType.LIGHTNING_BOLT, serverWorld);
            lightning.setPosition(target.getX(), target.getY(), target.getZ());
            serverWorld.spawnEntity(lightning);
            player.resetLastAttackedTicks();
        }
        return true;
    }

    public static boolean shouldHideEquipment(PlayerEntity player) {
        if (!player.hasStatusEffect(StatusEffects.INVISIBILITY) || !isHoldingSpear(player)) {
            return false;
        }
        return Math.max(progressFromStack(player.getMainHandStack()).tier(), progressFromStack(player.getOffHandStack()).tier()) >= 2;
    }

    public static boolean shouldCancelFallDamage(LivingEntity entity, DamageSource source) {
        if (!(entity instanceof PlayerEntity player)
                || !source.isOf(DamageTypes.FALL)
                || !isHoldingSpear(player)) {
            return false;
        }
        if (entity.fallDistance > 10.0F && entity.getWorld() instanceof ServerWorld serverWorld) {
            triggerSafeKnockback(player, serverWorld);
        }
        return true;
    }

    public static void recordPlayerKill(LivingEntity entity, DamageSource source) {
        if (entity.getWorld() instanceof ServerWorld serverWorld
                && source.getAttacker() instanceof ServerPlayerEntity player) {
            QuestState state = getQuestState(serverWorld);
            Progress progress = state.recordKill(player.getUuid(), entity.getType());
            syncProgress(player.getInventory(), progress);
        }
    }

    public static void onServerPlayerTick(ServerPlayerEntity player) {
        UUID playerId = player.getUuid();
        ATTACK_LOCKS.computeIfPresent(playerId, (id, ticks) -> ticks <= 1 ? null : ticks - 1);

        boolean holdingSpear = isHoldingSpear(player);
        if (holdingSpear) {
            HungerManager hunger = player.getHungerManager();
            hunger.setFoodLevel(20);
            hunger.setSaturationLevel(20.0F);
        }

        Progress progress = progressFor(getQuestState((ServerWorld) player.getWorld()), playerId);
        syncProgress(player.getInventory(), progress);
        if (holdingSpear && progress.tier() >= 2) {
            refreshInvisibility(player, playerId);
        } else {
            INVISIBILITY_REFRESH.remove(playerId);
        }

        Aura aura = ACTIVE_AURAS.get(playerId);
        if (aura == null) {
            return;
        }
        if (!player.isAlive() || aura.ticksRemaining() <= 0) {
            ACTIVE_AURAS.remove(playerId, aura);
            return;
        }

        ServerWorld world = (ServerWorld) player.getWorld();
        for (int i = 0; i < 16; i++) {
            double angle = Math.PI * 2.0 * i / 16.0;
            world.spawnParticles(
                    ParticleTypes.ELECTRIC_SPARK,
                    player.getX() + Math.cos(angle) * 2.5,
                    player.getY() + 1.0,
                    player.getZ() + Math.sin(angle) * 2.5,
                    1, 0.0, 0.0, 0.0, 0.0
            );
        }
        int elapsed = aura.elapsedTicks() + 1;
        if (elapsed % 20 == 0) {
            for (HostileEntity hostile : world.getEntitiesByClass(
                    HostileEntity.class,
                    new Box(player.getX() - 5.0, player.getY() - 5.0, player.getZ() - 5.0,
                            player.getX() + 5.0, player.getY() + 5.0, player.getZ() + 5.0),
                    entity -> entity.squaredDistanceTo(player) <= 25.0
            )) {
                hostile.damage(world, player.getDamageSources().magic(), 3.0F);
            }
        }
        Aura next = new Aura(aura.ticksRemaining() - 1, elapsed);
        if (next.ticksRemaining() <= 0) {
            ACTIVE_AURAS.remove(playerId, aura);
        } else {
            ACTIVE_AURAS.replace(playerId, aura, next);
        }
    }

    private static void refreshInvisibility(ServerPlayerEntity player, UUID playerId) {
        int elapsed = INVISIBILITY_REFRESH.getOrDefault(playerId, 0);
        if (elapsed == 0 || elapsed >= 20 || !player.hasStatusEffect(StatusEffects.INVISIBILITY)) {
            player.addStatusEffect(new StatusEffectInstance(StatusEffects.INVISIBILITY, 40, 0, false, false, false));
            INVISIBILITY_REFRESH.put(playerId, 1);
        } else {
            INVISIBILITY_REFRESH.put(playerId, elapsed + 1);
        }
    }

    private static void triggerSafeKnockback(PlayerEntity player, ServerWorld world) {