endxyrn_

i want you to create a fabric Minecraft Mod, where it adds an enchant called "Blood reckoning" its a mod for the weapon sword and its uses is, every 5th hit it steals 3 hearts from the entity its hitting and heal the user with 3 hearts and every 10th hit it summons a sonic boom thats recolour red and bloodliek and the damage is 20 hearts, this mod is a enchantment and it has 3 levels, level 1 every 5th hit it steals 0.5 heart snd heal the smae as it steals, level 2 it steals 1 heart per 5th hit, level 3 it steals 2 hearts per 5th hit and every 10th hit it spawns a sonic boom. that does 20 hearts of damage, its for sword only.

Kodari AI
KodariMon at 10:15 am 2
BloodReckoning
Adds a new sword-only enchantment called "Blood Reckoning" with three levels. On every fifth hit, the enchantment steals health from the target and heals the wielder by the same amount (0.5, 1, or 2 hearts based on level). On every tenth hit, it summons a red, blood-like sonic boom that deals 20 hearts of damage to nearby entities. The enchantment integrates with Fabric's enchantment system and uses custom particle effects and sound for the blood-themed sonic boom.
  1. Register the three-level sword enchantment with vanilla’s 1.21.11 data format.

  2. Add server-side hit tracking, healing/damage triggers, and a blood-red sonic-boom effect.

  3. Create the Fabric project metadata and build files.

Created the Fabric 1.21.11 Blood Reckoning mod. It’s sword-only and has three levels: every fifth hit drains and heals 0.5, 1, or 2 hearts, respectively. At level 3, every tenth hit also deals 20 hearts of damage and creates a blood-red particle burst with the sonic boom sound.

Obtain it by enchanting a sword at an enchanting table. The hit counter is tracked per player while they’re in the session.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
7 175
src/main/java/com/kodari/bloodreckoning/BloodReckoningMod.java
package com.kodari.bloodreckoning;

import java.util.Map;
import java.util.WeakHashMap;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.Registries;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;

public class BloodReckoningMod implements ModInitializer {
    public static final String MOD_ID = "bloodreckoning";
    private static final Map<PlayerEntity, Integer> HIT_COUNTS = new WeakHashMap<>();

    @Override
    public void onInitialize() {
        AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
            if (!(world instanceof ServerWorld serverWorld) || !(entity instanceof LivingEntity target)) {
                return ActionResult.PASS;
            }

            ItemStack weapon = player.getStackInHand(hand);
            var enchantment = serverWorld.getRegistryManager()
                    .getOrThrow(RegistryKeys.ENCHANTMENT)
                    .getEntry(Identifier.of(MOD_ID, "blood_reckoning"))
                    .orElseThrow();
            int level = EnchantmentHelper.getLevel(enchantment, weapon);
            if (level <= 0) {
                return ActionResult.PASS;
            }

            int hitCount = HIT_COUNTS.merge(player, 1, Integer::sum);
            var damageSource = player.getDamageSources().playerAttack(player);

            if (hitCount % 5 == 0) {
                float siphonDamage = switch (level) {
                    case 1 -> 1.0F;
                    case 2 -> 2.0F;
                    default -> 4.0F;
                };
                float healthBefore = target.getHealth();
                target.damage(serverWorld, damageSource, siphonDamage);
                float healthTaken = Math.min(siphonDamage, Math.max(0.0F, healthBefore - target.getHealth()));
                player.heal(healthTaken);
            }

            if (level >= 3 && hitCount % 10 == 0) {
                target.damage(serverWorld, damageSource, 40.0F);
                serverWorld.spawnParticles(
                        new DustParticleEffect(0x8B0000, 1.3F),
                        target.getX(), target.getY() + 1.0, target.getZ(),
                        32, 0.5, 0.7, 0.5, 0.02
                );
                serverWorld.playSound(
                        null,
                        target.getX(), target.getY(), target.getZ(),
                        Registries.SOUND_EVENT.getEntry(SoundEvents.ENTITY_WARDEN_SONIC_BOOM.id()).orElseThrow(),
                        SoundCategory.PLAYERS, 1.0F, 0.85F, 0L
                );
            }

            return ActionResult.PASS;
        });
    }
}