Caleb Carter

A god spear that has 4 different tiers that upgrade with kills. For 26.2 minecraft using fabric

Kodari AI
KodariOct 14 at 6:20 am 19
GodSpearTiers
Implements a legendary god spear weapon with four progressive tiers for Minecraft Fabric 26.2. The spear upgrades automatically as players accumulate kills, unlocking enhanced damage, attack speed, visual particle effects, and unique abilities at each tier. Includes custom item registration, kill tracking via entity death events, tier progression logic, configurable stat scaling, and a GUI or chat notification system to inform players of tier advancements. The mod integrates seamlessly with Fabric's API, providing a balanced progression curve that rewards combat engagement while maintaining server performance through efficient event handling and data storage.
  1. Add the Fabric 26.2 project setup and four spear tiers with persistent kill progression.

  2. Make each tier’s attack stats and durability scale, with an upgrade after 10 kills.

  3. Add the Tier I survival recipe, combat-tab entries, names, item assets, and distinct tier textures.

Added the Fabric 26.2 God Spear mod with four visually distinct tiers. Each tier gains attack damage and durability; killing 10 mobs while holding the spear upgrades it to the next tier.

Survival progression: Craft God Spear I with a Nether Star, a Diamond, and a Blaze Rod arranged vertically. Then get 10 kills with each spear to advance through Tiers II, III, and IV. Each upgrade displays a notification and restores the spear’s durability.

Caleb Carter

what does each tier do

Kodari AI
KodariOct 14 at 3:46 pm 1

Each tier increases damage and durability:

Tier
Attack damage
Durability
I
4
800
II
6
1,200
III
8
1,600
IV
11
2,031

Get 10 qualifying kills with the spear in your main hand to awaken the next tier. A qualifying kill is a non-player living mob killed by a player. All tiers also share −2.8 attack speed and the same weapon behavior.

There aren’t any extra powers yet—no lightning, special attacks, or tier-specific effects. Upgrading replaces the spear with a fresh one, so its durability and kill count reset; you’ll see an awakening message.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
19 274
src/main/java/com/kodari/godspear/GodSpearMod.java
package com.kodari.godspear;

import com.mojang.serialization.Codec;
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.DataComponentType;
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.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;
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.ItemStack;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.item.component.Weapon;

public final class GodSpearMod implements ModInitializer {
	public static final String MOD_ID = "godspear";
	private static final int KILLS_PER_TIER = 10;
	private static final String[] TIER_NAMES = {"", "God Spear I", "God Spear II", "God Spear III", "God Spear IV"};

	private static final DataComponentType<Integer> KILL_COUNT = Registry.register(
			BuiltInRegistries.DATA_COMPONENT_TYPE,
			Identifier.fromNamespaceAndPath(MOD_ID, "kill_count"),
			DataComponentType.<Integer>builder().persistent(Codec.INT).build()
	);

	private static final Item GOD_SPEAR_I = registerSpear("god_spear_1", 4.0, 800);
	private static final Item GOD_SPEAR_II = registerSpear("god_spear_2", 6.0, 1200);
	private static final Item GOD_SPEAR_III = registerSpear("god_spear_3", 8.0, 1600);
	private static final Item GOD_SPEAR_IV = registerSpear("god_spear_4", 11.0, 2031);

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

		ServerLivingEntityEvents.AFTER_DEATH.register(this::onLivingEntityDeath);
	}

	private static Item registerSpear(String path, double attackDamage, int durability) {
		ResourceKey<Item> itemKey = ResourceKey.create(
				Registries.ITEM,
				Identifier.fromNamespaceAndPath(MOD_ID, path)
		);
		Item.Properties properties = new Item.Properties()
				.setId(itemKey)
				.durability(durability)
				.attributes(ItemAttributeModifiers.builder()
						.add(Attributes.ATTACK_DAMAGE, new AttributeModifier(
								Identifier.fromNamespaceAndPath(MOD_ID, path + "_attack_damage"),
								attackDamage,
								AttributeModifier.Operation.ADD_VALUE
						), EquipmentSlotGroup.MAINHAND)
						.add(Attributes.ATTACK_SPEED, new AttributeModifier(
								Identifier.fromNamespaceAndPath(MOD_ID, path + "_attack_speed"),
								-2.8,
								AttributeModifier.Operation.ADD_VALUE
						), EquipmentSlotGroup.MAINHAND)
						.build())
				.component(DataComponents.WEAPON, new Weapon(1));

		return Registry.register(BuiltInRegistries.ITEM, itemKey, new Item(properties));
	}

	private void onLivingEntityDeath(LivingEntity victim, DamageSource damageSource) {
		if (victim instanceof Player) {
			return;
		}
		if (!(damageSource.getEntity() instanceof Player killer)) {
			return;
		}

		ItemStack weapon = killer.getMainHandItem();
		int tier = getTier(weapon);
		if (tier == 0 || tier == 4) {
			return;
		}

		Integer previousKills = weapon.get(KILL_COUNT);
		int kills = (previousKills == null ? 0 : previousKills) + 1;
		if (kills < KILLS_PER_TIER) {
			weapon.set(KILL_COUNT, kills);
			return;
		}

		Item nextTier = switch (tier) {
			case 1 -> GOD_SPEAR_II;
			case 2 -> GOD_SPEAR_III;
			default -> GOD_SPEAR_IV;
		};
		killer.setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(nextTier));

		if (killer instanceof ServerPlayer serverPlayer) {
			serverPlayer.sendOverlayMessage(Component.literal(TIER_NAMES[tier + 1] + " awakened!"));
		}
	}

	private static int getTier(ItemStack stack) {
		if (stack.is(GOD_SPEAR_I)) {
			return 1;
		}
		if (stack.is(GOD_SPEAR_II)) {
			return 2;
		}
		if (stack.is(GOD_SPEAR_III)) {
			return 3;
		}
		if (stack.is(GOD_SPEAR_IV)) {
			return 4;
		}
		return 0;
	}
}