Leathon Esau
📎 1 file 1,341 chars
📄
pasted-code-1791795597265.txt
txt 1 lines
▶
create a mod that uses a magic system for battle, spells are cast through rmb only when in attack mode, attack mode is entered when the player holds a book in their off hand, the book also is used to equiped certain pells there is one slot for attack(will be activated when pressed by rmb), defense(will be activated when holding v while presing rmb), attack spells have 2 catagorys quick and low cost and long charge and high reward, some attacks have fit in both catagories like zoltrak, wich is a direct bolt of ligthing casted from the players hand, the barrier is a one way distorted mirrior that is a defensive spell, you can see through it from behind but its a bit blurry and yu can cast spells from behind, if the spells path go through the barrier from behind it instantly breaks and let the spell through, howerver if a spell is cast against it from the front it will absorbe and tank it, subtracting its lifespan from the attack damage and lettig it pass through, it has a lifespan of 100 seconds, the stronger the player the stronger the barrier, the barrier gets a 2x boost if player has more than 50xp, xp maultiplies mana per xp the player have, when the player dies they hold 10% of their maximum ever mana, if player have a flying spell that can be found by a spawned libraria that hasnt been traded with, then they can fly
Kodari AI
KodariOct 12 at 9:39 am 11
ManaMagicCombat
A Fabric mod introducing a mana-based magic combat system. Spells are cast via right-click while in attack mode, activated by holding a spellbook in the off-hand. The book equips spells into attack and defense slots, with defense triggered by holding V while right-clicking. Attack spells are categorized as quick/low-cost or charged/high-reward, including Zoltrak, a direct lightning bolt. The defensive Barrier is a one-way distorted mirror with 100-second lifespan, absorbing frontal attacks while letting friendly spells pass through from behind. Barrier strength scales with player XP, doubling above 50 XP. Mana multiplies per XP, and players retain 10% of maximum mana on death. A flying spell is obtainable from an untraded librarian.
  1. Establish the Fabric 1.20.4 event, networking, registration, and trade APIs.

  2. Implement the spellbook, mana/attack/defense loop, and librarian flight tome.

  3. Add the mod metadata, survival acquisition assets, and English names.

Created the Aetherbound Fabric 1.20.4 mod with mana that scales with XP, two attack spells, and a one-way barrier. The barrier shimmers with portal particles; it does not apply a screen-blur shader.

  • Equip the Spellbook in your offhand to enter attack mode. Right-click casts the selected spell; Sneak + right-click switches between Zoltrak and Aether Lance. Aether Lance charges for two seconds before firing.

  • Hold V while right-clicking to cast the Barrier. V + Sneak + right-click toggles the defensive slot.

  • Mana regenerates and increases with XP. On death, mana returns to 10% of the highest capacity recorded during that session.

  • Survival access: craft the Spellbook with 2 books, 2 amethyst shards, and 1 lapis lazuli. A novice librarian offers the one-use Tome of Flight for 32 emeralds; using it unlocks flight.

  • Added item textures, models, names, and a creative-tab listing.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
12 584
src/main/java/com/kodari/aetherbound/AetherboundMod.java
package com.kodari.aetherbound;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.village.TradeOffer;
import net.minecraft.village.VillagerProfession;
import net.minecraft.world.World;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public final class AetherboundMod implements ModInitializer {
    public static final String MOD_ID = "aetherbound";

    public static final Item SPELLBOOK = registerItem("spellbook", new Item(new Item.Settings().maxCount(1)));
    public static final Item FLIGHT_TOME = registerItem("flight_tome", new Item(new Item.Settings().maxCount(1)));

    private static final Identifier DEFENSE_KEY_PACKET = new Identifier(MOD_ID, "defense_key");
    private static final RegistryKey<ItemGroup> INGREDIENTS_GROUP = RegistryKey.of(
            RegistryKeys.ITEM_GROUP,
            new Identifier("minecraft", "ingredients")
    );
    private static final Map<UUID, MageState> MAGES = new HashMap<>();
    private static final Set<UUID> DEFENSE_HELD = new HashSet<>();

    @Override
    public void onInitialize() {
        UseItemCallback.EVENT.register(AetherboundMod::onUseItem);
        ServerTickEvents.END_SERVER_TICK.register(AetherboundMod::tickServer);
        ServerLivingEntityEvents.AFTER_DEATH.register((entity, damageSource) -> {
            if (entity instanceof ServerPlayerEntity player) {
                MageState state = stateFor(player);
                state.mana = state.maximumEverMana * 0.1;
                state.barrierTicks = 0;
                state.barrierStrength = 0.0f;
                state.chargeTicksRemaining = 0;
            }
        });
        ServerPlayNetworking.registerGlobalReceiver(DEFENSE_KEY_PACKET, (server, player, handler, buffer, responseSender) -> {
            boolean held = buffer.readBoolean();
            server.execute(() -> {
                if (held) {
                    DEFENSE_HELD.add(player.getUuid());
                } else {
                    DEFENSE_HELD.remove(player.getUuid());
                }
            });
        });
        TradeOfferHelper.registerVillagerOffers(VillagerProfession.LIBRARIAN, 1, factories -> factories.add(
                (entity, random) -> new TradeOffer(
                        new ItemStack(Items.EMERALD, 32),
                        new ItemStack(FLIGHT_TOME),
                        1,
                        20,
                        0.2f
                )
        ));
        ItemGroupEvents.modifyEntriesEvent(INGREDIENTS_GROUP).register(entries -> {
            entries.add(SPELLBOOK);
            entries.add(FLIGHT_TOME);
        });
    }

    private static Item registerItem(String name, Item item) {
        return Registry.register(Registries.ITEM, new Identifier(MOD_ID, name), item);
    }

    private static TypedActionResult<ItemStack> onUseItem(PlayerEntity player, World world, Hand hand) {
        ItemStack heldStack = player.getStackInHand(hand);
        if (!(player instanceof ServerPlayerEntity serverPlayer)) {
            return TypedActionResult.pass(heldStack);
        }

        ServerWorld serverWorld = (ServerWorld) world;
        if (heldStack.isOf(FLIGHT_TOME)) {
            if (serverPlayer.getAbilities().allowFlying) {
                return TypedActionResult.pass(heldStack);
            }
            serverPlayer.getAbilities().allowFlying = true;
            serverPlayer.getAbilities().flying = false;
            serverPlayer.sendAbilitiesUpdate();
            if (!serverPlayer.isCreative()) {
                heldStack.decrement(1);
            }
            serverWorld.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_LIGHTNING_BOLT_IMPACT, SoundCategory.PLAYERS, 0.8f, 1.6f);
            return TypedActionResult.success(heldStack);
        }

        if (!serverPlayer.getOffHandStack().isOf(SPELLBOOK)) {
            return TypedActionResult.pass(heldStack);
        }

        MageState state = stateFor(serverPlayer);
        UUID playerId = serverPlayer.getUuid();
        boolean defenseHeld = DEFENSE_HELD.contains(playerId);

        if (serverPlayer.isSneaking()) {
            if (defenseHeld) {
                state.defenseEquipped = !state.defenseEquipped;
                showStatus(serverPlayer, state, state.defenseEquipped ? "Barrier equipped" : "Defense slot empty");
            } else {
                state.attackSlot = (state.attackSlot + 1) % 2;
                showStatus(serverPlayer, state, "Attack spell equipped");
            }
            return TypedActionResult.success(heldStack);
        }

        if (defenseHeld) {
            if (state.defenseEquipped) {
                castBarrier(serverWorld, serverPlayer, state);
            } else {
                showStatus(serverPlayer, state, "Defense slot empty");
            }
            return TypedActionResult.success(heldStack);
        }

        if (state.attackSlot == 0) {
            if (spendMana(state, 12.0)) {
                castLightning(serverWorld, serverPlayer, 10.0f);
                showStatus(serverPlayer, state, "Zoltrak");
            } else {
                showStatus(serverPlayer, state, "Not enough mana");
            }
        } else if (state.chargeTicksRemaining == 0) {
            if (spendMana(state, 40.0)) {
                state.chargeTicksRemaining = 40;
                state.chargedDamage = 26.0f;
                showStatus(serverPlayer, state, "Charging Aether Lance");
            } else {
                showStatus(serverPlayer, state, "Not enough mana");
            }
        }
        return TypedActionResult.success(heldStack);
    }

    private static void tickServer(MinecraftServer server) {
        Set<UUID> onlinePlayers = new HashSet<>();
        for (ServerWorld world : server.getWorlds()) {
            for (ServerPlayerEntity player : world.getPlayers()) {
                onlinePlayers.add(player.getUuid());
                MageState state = stateFor(player);
                state.maximumEverMana = Math.max(state.maximumEverMana, manaCapacity(player));
                state.mana = Math.min(state.maximumEverMana, state.mana + 0.02 + Math.max(0, player.experienceLevel) * 0.002);

                if (state.barrierTicks > 0) {
                    state.barrierTicks--;
                    if (state.barrierTicks == 0 || state.barrierStrength <= 0.0f) {
                        state.barrierTicks = 0;
                        state.barrierStrength = 0.0f;
                    } else if (state.barrierTicks % 4 == 0) {
                        renderBarrier(world, player);
                    }
                }

                if (state.chargeTicksRemaining > 0) {
                    if (!player.getOffHandStack().isOf(SPELLBOOK)) {
                        state.chargeTicksRemaining = 0;
                    } else if (--state.chargeTicksRemaining == 0) {
                        castLightning(world, player, state.chargedDamage);
                        showStatus(player, state, "Aether Lance released");
                    } else if (state.chargeTicksRemaining % 5 == 0) {
                        Vec3d eye = player.getEyePos();
                        world.spawnParticles(ParticleTypes.PORTAL, eye.x, eye.y, eye.z, 3, 0.2, 0.2, 0.2, 0.01);
                    }
                }

                if (player.getOffHandStack().isOf(SPELLBOOK)) {