X

Make me A PearlCatching Mod Where if i press Z It throws a pearl first after pearl Windcharge like mace pvp things

Kodari AI
KodariJun 13 at 12:03 pm 20
PearlCatcher
A PVP-focused mod that enables a classic pearl-catch combo. Press Z to throw an Ender Pearl — upon landing and teleporting, a Wind Charge is automatically launched forward, enabling the mace-style aerial PVP combo. Includes client-side keybind registration, server-side pearl teleport detection, and smooth Wind Charge follow-up throw. Designed for 1.21.4 Fabric with full client/server support.

Plan:

  1. Build files (gradle.properties, build.gradle, settings.gradle)

  2. fabric.mod.json + mixin config

  3. ThrowPearlPayload — C2S packet (keybind → server)

  4. PearlCatcher — main init, receive packet, throw pearl, track pending wind charge

  5. EnderPearlMixin — inject after pearl teleport → spawn wind charge

  6. PearlCatcherClient — register Z keybind, send packet on press

  7. Lang file


Here’s what was built and how it works:

Flow:

  1. Press Z → PearlCatcherClient detects the keybind and sends ThrowPearlPayload to the server

  2. Server receives packet → checks for an ender pearl in inventory, consumes one, marks the player UUID in PENDING_WIND_CHARGE, then spawns an EnderPearlEntity aimed in the player’s look direction

  3. Pearl lands → EnderPearlMixin injects at the end of onCollision (after the teleport already happened), removes the player from PENDING_WIND_CHARGE, then spawns a WindChargeEntity at the player’s new position aimed in their current look direction

  4. Wind charge flies forward → launches you up / explodes for the mace follow-up hit

Key details:

  • Only works in survival (creative/spectator skipped, pearl must exist in inventory)

  • Normal right-click pearls are unaffected — wind charge only fires for Z-thrown pearls

  • Thread-safe UUID tracking with ConcurrentHashMap-backed set

  • Wind charge speed is 1.5f — adjust in EnderPearlMixin to taste (2.0f for more aggressive)

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
10 244
src/main/java/com/pearlcatcher/PearlCatcher.java
package com.pearlcatcher;

import com.pearlcatcher.network.ThrowPearlPayload;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public class PearlCatcher implements ModInitializer {

    public static final String MOD_ID = "pearlcatcher";
    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

    /**
     * Players whose next pearl teleport should trigger a wind charge.
     * Populated when the keybind packet is received; consumed in EnderPearlMixin.
     */
    public static final Set<UUID> PENDING_WIND_CHARGE =
            Collections.newSetFromMap(new ConcurrentHashMap<>());

    @Override
    public void onInitialize() {
        PayloadTypeRegistry.playC2S().register(ThrowPearlPayload.ID, ThrowPearlPayload.CODEC);

        ServerPlayNetworking.registerGlobalReceiver(ThrowPearlPayload.ID, (payload, context) -> {
            ServerPlayerEntity player = context.player();
            ServerWorld world = player.getServerWorld();

            if (player.isSpectator() || player.isCreative()) return;

            // Consume one pearl from inventory (survival check)
            boolean foundPearl = false;
            for (int i = 0; i < player.getInventory().size(); i++) {
                ItemStack stack = player.getInventory().getStack(i);
                if (stack.isOf(Items.ENDER_PEARL)) {
                    stack.decrement(1);
                    foundPearl = true;
                    break;
                }
            }
            if (!foundPearl) return;

            // Mark this player for wind-charge follow-up when the pearl lands
            PENDING_WIND_CHARGE.add(player.getUuid());

            // Throw the pearl
            EnderPearlEntity pearl = new EnderPearlEntity(world, player, new ItemStack(Items.ENDER_PEARL));
            pearl.setVelocity(player, player.getPitch(), player.getYaw(), 0.0f, 2.5f, 1.0f);
            world.spawnEntity(pearl);
        });
    }
}