Muhammed Anshad

package net.example.necromancymod.item;

import net.minecraft.entity.EntityType; import net.minecraft.entity.mob.ZombieEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World;

public class StaffOfNecromancyItem extends Item { public StaffOfNecromancyItem(Settings settings) { super(settings); }

@Override public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { ItemStack stack = user.getStackInHand(hand);

// Only execute logic on the server side if (!world.isClient) { // Check if the player has Soul Sand in their inventory to use as fuel if (user.getInventory().contains(new ItemStack(Items.SOUL_SAND)) || user.isCreative()) {

// Find the block position right in front of the player BlockPos spawnPos = user.getBlockPos().offset(user.getHorizontalFacing(), 2);

// Summon a loyal Zombie Minion ZombieEntity minion = EntityType.ZOMBIE.create(world); if (minion != null) { minion.refreshPositionAndAngles(spawnPos.getX() + 0.5, spawnPos.getY(), spawnPos.getZ() + 0.5, 0, 0);

// Customise minion behavior: Custom name tag minion.setCustomName(Text.literal(user.getName().getString() + "'s Thrall")); minion.setCustomNameVisible(true);

// Prevent the minion from burning in the sunlight minion.setPersistent();

world.spawnEntity(minion);

// Play a spooky summoning sound world.playSound(null, user.getX(), user.getY(), user.getZ(), SoundEvents.ENTITY_WITHER_SPAWN, SoundCategory.PLAYERS, 1.0f, 0.5f);

// Consume one Soul Sand if not in Creative mode if (!user.isCreative()) { user.getInventory().remove(itemStack -> itemStack.isOf(Items.SOUL_SAND), 1, user.getInventoryState()); }

// Damage the staff durability stack.damage(1, user, PlayerEntity.getSlotForHand(hand));

return TypedActionResult.success(stack); } } else { // Warn the player if they don't have fuel user.sendMessage(Text.literal("§cYou require Soul Sand to harvest thralls!§r"), true); } } return TypedActionResult.pass(stack); } }

Kodari AI
KodariNov 10 at 2:49 pm 7
NecromancyStaff
A Fabric mod for Minecraft 1.21.1 that adds a Staff of Necromancy item. Players can use the staff to summon loyal zombie minions that fight for them. The staff requires Soul Sand as fuel, consumes durability with each use, and creates a spooky wither spawn sound effect when summoning. Minions receive custom names based on the player and are protected from sunlight burning, making them persistent allies.
  • Register a craftable, repairable staff with its own texture.

  • Summon a named zombie using soul sand, with durability and sound feedback.

Created the Staff of Necromancy. Craft it with two sticks and soul sand; each summon consumes one soul sand.

Limitation: The named zombie is still a normal hostile zombie: it can attack its summoner and burn in daylight. setPersistent() prevents despawning, not sunlight damage.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
11 168
src/main/java/net/example/necromancymod/NecromancyMod.java
package net.example.necromancymod;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.example.necromancymod.item.StaffOfNecromancyItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;

public class NecromancyMod implements ModInitializer {
    private static final RegistryKey<Item> STAFF_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of("necromancymod", "staff_of_necromancy"));
    public static final Item STAFF = Registry.register(Registries.ITEM, STAFF_KEY,
            new StaffOfNecromancyItem(new Item.Settings().registryKey(STAFF_KEY).maxDamage(256).repairable(Items.SOUL_SAND)));

    @Override
    public void onInitialize() {
        RegistryKey<ItemGroup> tools = RegistryKey.of(RegistryKeys.ITEM_GROUP, Identifier.of("minecraft", "tools_and_utilities"));
        ItemGroupEvents.modifyEntriesEvent(tools).register(entries -> entries.add(STAFF));
    }
}