Nathan kim

start with mace and spear and each kill upgrade (Fabric and for 26.2)

Kodari AI
KodariNov 14 at 12:44 pm 11
WeaponEvolution
A Fabric mod for Minecraft 26.2 that introduces a weapon progression system. Players start with a mace and spear, and each kill upgrades their held weapon to the next tier. The mod tracks kill counts per weapon type, automatically enhances weapon stats (damage, durability, and enchantment levels) as kills accumulate. Features include visual weapon tier indicators, configurable upgrade thresholds, and support for both melee weapons. The system integrates seamlessly with vanilla combat, providing a rewarding progression loop that encourages continued combat engagement.
  1. Add custom mace and spear items with per-kill permanent damage upgrades and a visible kill counter.

  2. Register them in a vanilla creative tab and provide survival recipes.

  3. Add the Fabric 26.2 project metadata, item models, and dedicated textures.

Added the Killbound Mace and Killbound Spear for Fabric 26.2. Each kill made while holding one adds +1 attack damage, persists on the weapon, and updates its kill counter. The mace keeps vanilla smash behavior; the spear uses vanilla spear properties.

Both are in the Combat creative tab and have custom textures. In survival, craft the mace with 1 heavy core and 2 breeze rods, or the spear with 1 iron ingot and 2 sticks. The mace repairs with breeze rods; the spear uses its iron repair material.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
14 252
src/main/java/dev/kodari/killbound/KillboundMod.java
package dev.kodari.killbound;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.creativetab.v1.CreativeModeTabEvents;
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
import net.minecraft.core.Registry;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.MaceItem;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.item.component.Weapon;
import net.minecraft.world.item.ItemStack;

public final class KillboundMod implements ModInitializer {
    public static final String MOD_ID = "killbound";
    private static final String KILL_COUNT_KEY = "killbound:kills";

    private static final Identifier MACE_ID = Identifier.fromNamespaceAndPath(MOD_ID, "killbound_mace");
    private static final ResourceKey<Item> MACE_KEY = ResourceKey.create(Registries.ITEM, MACE_ID);
    private static final Identifier SPEAR_ID = Identifier.fromNamespaceAndPath(MOD_ID, "killbound_spear");
    private static final ResourceKey<Item> SPEAR_KEY = ResourceKey.create(Registries.ITEM, SPEAR_ID);

    public static final Item MACE = Registry.register(
        BuiltInRegistries.ITEM,
        MACE_ID,
        new MaceItem(new Item.Properties()
            .setId(MACE_KEY)
            .rarity(Rarity.EPIC)
            .durability(500)
            .component(DataComponents.TOOL, MaceItem.createToolProperties())
            .repairable(Items.BREEZE_ROD)
            .attributes(MaceItem.createAttributes())
            .enchantable(15)
            .component(DataComponents.WEAPON, new Weapon(1)))
    );

    public static final Item SPEAR = Registry.register(
        BuiltInRegistries.ITEM,
        SPEAR_ID,
        new Item(new Item.Properties()
            .spear(ToolMaterial.IRON, 0.95F, 0.95F, 0.6F, 2.5F, 11.0F, 6.75F, 5.1F, 11.25F, 4.6F)
            .setId(SPEAR_KEY))
    );

    private static final Identifier MACE_UPGRADE_ID = Identifier.fromNamespaceAndPath(MOD_ID, "mace_kill_damage");
    private static final Identifier SPEAR_UPGRADE_ID = Identifier.fromNamespaceAndPath(MOD_ID, "spear_kill_damage");

    @Override
    public void onInitialize() {
        ResourceKey<CreativeModeTab> combatTab = ResourceKey.create(
            Registries.CREATIVE_MODE_TAB,
            Identifier.fromNamespaceAndPath("minecraft", "combat")
        );
        CreativeModeTabEvents.modifyOutputEvent(combatTab).register(output -> {
            output.accept(MACE);
            output.accept(SPEAR);
        });

        ServerLivingEntityEvents.AFTER_DEATH.register((entity, damageSource) -> upgradeWeapon(damageSource));
    }

    private static void upgradeWeapon(DamageSource damageSource) {
        if (!(damageSource.getEntity() instanceof Player player)) {
            return;
        }

        ItemStack stack = player.getMainHandItem();
        Item item = stack.getItem();
        if (item != MACE && item != SPEAR) {
            return;
        }

        int kills = getKillCount(stack) + 1;
        CustomData.update(DataComponents.CUSTOM_DATA, stack, tag -> tag.putInt(KILL_COUNT_KEY, kills));

        Identifier modifierId = item == MACE ? MACE_UPGRADE_ID : SPEAR_UPGRADE_ID;
        ItemAttributeModifiers modifiers = stack.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
        stack.set(DataComponents.ATTRIBUTE_MODIFIERS, modifiers.withModifierAdded(
            Attributes.ATTACK_DAMAGE,
            new AttributeModifier(modifierId, kills, AttributeModifier.Operation.ADD_VALUE),
            EquipmentSlotGroup.MAINHAND
        ));

        String nameKey = item == MACE ? "item.killbound.killbound_mace" : "item.killbound.killbound_spear";
        stack.set(DataComponents.CUSTOM_NAME, Component.translatable(nameKey).append(" [Kills: " + kills + "]"));
    }

    private static int getKillCount(ItemStack stack) {
        CustomData data = stack.get(DataComponents.CUSTOM_DATA);
        return data == null ? 0 : data.copyTag().getIntOr(KILL_COUNT_KEY, 0);
    }
}