mumulikely522

Make me a Fabric version 1.21.11 mod featuring a long blood red katana with a bright brimming aura around the blade. The sword will have an ability to unleash multiple blood slashes with a cooldown of 20 seconds after use.

Kodari AI
KodariOct 6 at 1:45 am 7
BloodKatanaAura
A Fabric 1.21.11 mod introducing a long blood-red katana with a bright, glowing aura surrounding the blade. The sword features a unique active ability that unleashes multiple powerful blood slashes in a forward arc, dealing heavy damage to all enemies hit. The ability has a 20-second cooldown, indicated by a visual and audio cue when ready. The katana is craftable with a custom recipe and has enhanced base stats, including high attack speed and damage. The aura effect is rendered with custom particle effects and a dynamic glow that intensifies when the ability is charged.
  1. Add a survival-craftable blood-red katana with its own glowing texture and item assets.

  2. Make its ability unleash five blood slashes, deal damage, and apply a 20-second cooldown.

  3. Create the Fabric 1.21.11 project metadata and register the item.

Added the Blood Katana Fabric 1.21.11 mod with a custom glowing blood-red texture, diamond-tier sword stats, and a five-slash crimson ability that damages targets in its path. The ability has a 20-second cooldown.

Survival: Craft it with 2 diamonds, 1 redstone dust, and 1 stick. It uses diamond repair material and appears in the Combat creative tab.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
10 243
src/main/java/com/kodari/bloodkatana/BloodKatanaMod.java
package com.kodari.bloodkatana;

import java.util.List;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ToolMaterial;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
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.World;

public class BloodKatanaMod implements ModInitializer {
    public static final String MOD_ID = "bloodkatana";
    private static final RegistryKey<Item> BLOOD_KATANA_KEY = RegistryKey.of(
            RegistryKeys.ITEM,
            Identifier.of(MOD_ID, "blood_katana")
    );
    public static final Item BLOOD_KATANA = Registry.register(
            Registries.ITEM,
            BLOOD_KATANA_KEY,
            new BloodKatanaItem(new Item.Settings()
                    .registryKey(BLOOD_KATANA_KEY)
                    .sword(ToolMaterial.DIAMOND, 3.0F, -2.4F))
    );
    private static final RegistryKey<net.minecraft.item.ItemGroup> COMBAT_GROUP = RegistryKey.of(
            RegistryKeys.ITEM_GROUP,
            Identifier.of("minecraft", "combat")
    );

    @Override
    public void onInitialize() {
        ItemGroupEvents.modifyEntriesEvent(COMBAT_GROUP).register(entries -> entries.add(BLOOD_KATANA));
    }

    private static final class BloodKatanaItem extends Item {
        private static final DustParticleEffect BLOOD_SLASH = new DustParticleEffect(0xF20D2F, 1.15F);

        private BloodKatanaItem(Settings settings) {
            super(settings);
        }

        @Override
        public ActionResult use(World world, PlayerEntity user, Hand hand) {
            ItemStack stack = user.getStackInHand(hand);
            if (user.getItemCooldownManager().isCoolingDown(stack)) {
                return ActionResult.FAIL;
            }

            user.getItemCooldownManager().set(stack, 400);
            if (world instanceof ServerWorld serverWorld) {
                unleashBloodSlashes(serverWorld, user);
            }
            return ActionResult.SUCCESS;
        }

        private void unleashBloodSlashes(ServerWorld world, PlayerEntity user) {
            Vec3d direction = user.getRotationVec(1.0F);
            double horizontalLength = Math.max(1.0E-4, Math.sqrt(direction.x * direction.x + direction.z * direction.z));
            double sideX = -direction.z / horizontalLength;
            double sideZ = direction.x / horizontalLength;
            double startX = user.getX();
            double startY = user.getY() + 1.0;
            double startZ = user.getZ();

            for (int slash = 0; slash < 5; slash++) {
                double offset = (slash - 2) * 0.65;
                for (int step = 0; step <= 8; step++) {
                    double distance = 1.0 + step;
                    double x = startX + direction.x * distance + sideX * offset;
                    double y = startY + direction.y * distance + Math.sin(distance + slash) * 0.08;
                    double z = startZ + direction.z * distance + sideZ * offset;
                    world.spawnParticles(BLOOD_SLASH, x, y, z, 2, 0.035, 0.035, 0.035, 0.0);
                }
            }

            Box searchArea = new Box(startX - 10, startY - 3, startZ - 10, startX + 10, startY + 10, startZ + 10);
            List<Entity> targets = world.getOtherEntities(user, searchArea,
                    entity -> entity instanceof LivingEntity living && living.isAlive());
            DamageSource damageSource = world.getDamageSources().playerAttack(user);

            for (Entity target : targets) {
                if (!(target instanceof LivingEntity living)) {
                    continue;
                }

                double targetX = living.getX() - startX;
                double targetY = living.getY() + living.getHeight() * 0.5 - startY;
                double targetZ = living.getZ() - startZ;
                double along = targetX * direction.x + targetY * direction.y + targetZ * direction.z;
                if (along < 0.5 || along > 9.0) {
                    continue;
                }

                double lateral = targetX * sideX + targetZ * sideZ;
                double slashHeight = startY + direction.y * along;
                if (Math.abs(living.getY() + living.getHeight() * 0.5 - slashHeight) > 1.4) {
                    continue;
                }

                for (int slash = 0; slash < 5; slash++) {
                    double offset = (slash - 2) * 0.65;
                    if (Math.abs(lateral - offset) <= 0.7) {
                        living.damage(world, damageSource, 5.0F);
                        break;
                    }
                }
            }
        }
    }
}