A

i want you to make a mod where when you throw a pearl a windcharge get thrown and hit the pearl. The windcharge need to get thrown a little bit after the pearl but it should still hit the pearl. this is called pearl catching

Kodari AI
KodariJun 23 at 10:11 pm 16
PearlCatcher
A Fabric 1.21.11 mod that adds "pearl catching" mechanic. When a player throws an Ender Pearl, a Wind Charge is automatically launched shortly after with a calculated trajectory to intercept and hit the pearl mid-air. The Wind Charge tracks the pearl's position and velocity, launching at the right angle and speed to collide with it, creating a satisfying mid-air interception effect.
PearlCatcher
A Fabric 1.21.11 mod that adds a "pearl catching" mechanic. When a player throws an Ender Pearl, a Wind Charge is automatically launched a short delay later with a calculated trajectory to intercept and collide with the pearl mid-flight. The Wind Charge velocity is solved using geometric series drag compensation to precisely hit the predicted pearl position, creating a satisfying mid-air interception visual effect.

Now I’ll build the mod. Plan:

  • gradle.properties + build.gradle — standard 1.21.11 setup

  • fabric.mod.json — main entrypoint only (no client code needed)

  • PearlCatcher.java — detect pearl throw via ENTITY_LOAD, schedule wind charge via START_SERVER_TICK, solve intercept trajectory with drag compensation

The mod works like this:

  1. Pearl detection — ServerEntityEvents.ENTITY_LOAD fires the moment any EnderPearlEntity enters the world. It stores the pearl + owner in a tracker list with a countdown of 5 ticks.

  2. Delayed launch — START_SERVER_TICK counts down each tracker. At 0, launchWindCharge fires.

  3. Intercept trajectory — The pearl’s current position and velocity are used to simulate its physics 18 ticks forward (drag × 0.99 / tick, gravity − 0.03 / tick) to find where it’ll be.

  4. Drag-compensated velocity — The wind charge’s required initial velocity is solved analytically using a geometric series: v₀ = Δx · (1 − drag) / (1 − dragᴺ), which gives the exact starting velocity that covers the displacement in N ticks under drag. Wind charges have no gravity so no extra correction is needed.

  5. Spawn — The wind charge is spawned 0.5 blocks in front of the player’s eyes, owned by the player, and launched with the calculated velocity toward the pearl’s predicted position.

A

The compilation failed with this error:

code
Compilation failed with 8 error(s):

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 8: cannot find symbol
import net.minecraft.entity.projectile.EnderPearlEntity;
                                      ^
  symbol: class EnderPearlEntity
  location: package net.minecraft.entity.projectile

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 34: cannot find symbol
    private record PearlTracker(EnderPearlEntity pearl, PlayerEntity thrower, int ticksRemaining) {}
                                ^
  symbol: class EnderPearlEntity
  location: class PearlTracker

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 68: cannot find symbol
    private void launchWindCharge(EnderPearlEntity pearl, PlayerEntity thrower) {
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 41: cannot find symbol
            if (entity instanceof EnderPearlEntity pearl
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 8: cannot find symbol
  import net.minecraft.entity.projectile.EnderPearlEntity;
                                        ^
  symbol: class EnderPearlEntity
  location: package net.minecraft.entity.projectile

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 34: cannot find symbol
      private record PearlTracker(EnderPearlEntity pearl, PlayerEntity thrower, int ticksRemaining) {}
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlTracker

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 68: cannot find symbol
      private void launchWindCharge(EnderPearlEntity pearl, PlayerEntity thrower) {
                                    ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 41: cannot find symbol
              if (entity instanceof EnderPearlEntity pearl
                                    ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher


=== COMPILATION ERROR ANALYSIS ===

MISSING CLASSES:
  - EnderPearlEntity
ACTION: Create these classes or check imports

FILES TO INVESTIGATE:
  - src/main/java/com/pearlcatcher/PearlCatcher.java
  -   src/main/java/com/pearlcatcher/PearlCatcher.java

Please fix this error by creating a new artifact with the corrected code.

A

The compilation failed with this error:

code
Compilation failed with 8 error(s):

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 8: cannot find symbol
import net.minecraft.entity.projectile.EnderPearlEntity;
                                      ^
  symbol: class EnderPearlEntity
  location: package net.minecraft.entity.projectile

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 34: cannot find symbol
    private record PearlTracker(EnderPearlEntity pearl, PlayerEntity thrower, int ticksRemaining) {}
                                ^
  symbol: class EnderPearlEntity
  location: class PearlTracker

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 68: cannot find symbol
    private void launchWindCharge(EnderPearlEntity pearl, PlayerEntity thrower) {
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 41: cannot find symbol
            if (entity instanceof EnderPearlEntity pearl
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 8: cannot find symbol
  import net.minecraft.entity.projectile.EnderPearlEntity;
                                        ^
  symbol: class EnderPearlEntity
  location: package net.minecraft.entity.projectile

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 34: cannot find symbol
      private record PearlTracker(EnderPearlEntity pearl, PlayerEntity thrower, int ticksRemaining) {}
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlTracker

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 68: cannot find symbol
      private void launchWindCharge(EnderPearlEntity pearl, PlayerEntity thrower) {
                                    ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 41: cannot find symbol
              if (entity instanceof EnderPearlEntity pearl
                                    ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher


=== COMPILATION ERROR ANALYSIS ===

MISSING CLASSES:
  - EnderPearlEntity
ACTION: Create these classes or check imports

FILES TO INVESTIGATE:
  - src/main/java/com/pearlcatcher/PearlCatcher.java
  -   src/main/java/com/pearlcatcher/PearlCatcher.java

Please fix this error by creating a new artifact with the corrected code.

A

The compilation failed with this error:

code
Compilation failed with 8 error(s):

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 8: cannot find symbol
import net.minecraft.entity.projectile.EnderPearlEntity;
                                      ^
  symbol: class EnderPearlEntity
  location: package net.minecraft.entity.projectile

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 34: cannot find symbol
    private record PearlTracker(EnderPearlEntity pearl, PlayerEntity thrower, int ticksRemaining) {}
                                ^
  symbol: class EnderPearlEntity
  location: class PearlTracker

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 68: cannot find symbol
    private void launchWindCharge(EnderPearlEntity pearl, PlayerEntity thrower) {
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 41: cannot find symbol
            if (entity instanceof EnderPearlEntity pearl
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 8: cannot find symbol
  import net.minecraft.entity.projectile.EnderPearlEntity;
                                        ^
  symbol: class EnderPearlEntity
  location: package net.minecraft.entity.projectile

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 34: cannot find symbol
      private record PearlTracker(EnderPearlEntity pearl, PlayerEntity thrower, int ticksRemaining) {}
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlTracker

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 68: cannot find symbol
      private void launchWindCharge(EnderPearlEntity pearl, PlayerEntity thrower) {
                                    ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 41: cannot find symbol
              if (entity instanceof EnderPearlEntity pearl
                                    ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher


=== COMPILATION ERROR ANALYSIS ===

MISSING CLASSES:
  - EnderPearlEntity
ACTION: Create these classes or check imports

FILES TO INVESTIGATE:
  - src/main/java/com/pearlcatcher/PearlCatcher.java
  -   src/main/java/com/pearlcatcher/PearlCatcher.java

Please fix this error by creating a new artifact with the corrected code.

A

The compilation failed with this error:

code
Compilation failed with 8 error(s):

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 8: cannot find symbol
import net.minecraft.entity.projectile.EnderPearlEntity;
                                      ^
  symbol: class EnderPearlEntity
  location: package net.minecraft.entity.projectile

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 34: cannot find symbol
    private record PearlTracker(EnderPearlEntity pearl, PlayerEntity thrower, int ticksRemaining) {}
                                ^
  symbol: class EnderPearlEntity
  location: class PearlTracker

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 68: cannot find symbol
    private void launchWindCharge(EnderPearlEntity pearl, PlayerEntity thrower) {
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in src/main/java/com/pearlcatcher/PearlCatcher.java at line 41: cannot find symbol
            if (entity instanceof EnderPearlEntity pearl
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 8: cannot find symbol
  import net.minecraft.entity.projectile.EnderPearlEntity;
                                        ^
  symbol: class EnderPearlEntity
  location: package net.minecraft.entity.projectile

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 34: cannot find symbol
      private record PearlTracker(EnderPearlEntity pearl, PlayerEntity thrower, int ticksRemaining) {}
                                  ^
  symbol: class EnderPearlEntity
  location: class PearlTracker

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 68: cannot find symbol
      private void launchWindCharge(EnderPearlEntity pearl, PlayerEntity thrower) {
                                    ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher

ERROR in   src/main/java/com/pearlcatcher/PearlCatcher.java at line 41: cannot find symbol
              if (entity instanceof EnderPearlEntity pearl
                                    ^
  symbol: class EnderPearlEntity
  location: class PearlCatcher


=== COMPILATION ERROR ANALYSIS ===

MISSING CLASSES:
  - EnderPearlEntity
ACTION: Create these classes or check imports

FILES TO INVESTIGATE:
  - src/main/java/com/pearlcatcher/PearlCatcher.java
  -   src/main/java/com/pearlcatcher/PearlCatcher.java

Please fix this error by creating a new artifact with the corrected code.

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

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.EnderPearlEntity;
import net.minecraft.entity.projectile.WindChargeEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

import java.util.ArrayList;
import java.util.List;

public class PearlCatcher implements ModInitializer {

    public static final String MOD_ID = "pearlcatcher";

    // Ticks after the pearl is thrown before the wind charge launches.
    private static final int LAUNCH_DELAY_TICKS = 5;

    // How many ticks ahead to predict the pearl position for the intercept point.
    private static final int INTERCEPT_LEAD_TICKS = 18;

    // Ender pearl physics constants (per-tick).
    private static final double PEARL_DRAG = 0.99;
    private static final double PEARL_GRAVITY = 0.03;

    // Wind charge has no gravity but does have drag (same coefficient as pearl).
    private static final double WIND_CHARGE_DRAG = 0.99;

    private record PearlTracker(EnderPearlEntity pearl, PlayerEntity thrower, int ticksRemaining) {}

    private final List<PearlTracker> trackers = new ArrayList<>();

    @Override
    public void onInitialize() {
        ServerEntityEvents.ENTITY_LOAD.register((entity, world) -> {
            if (entity instanceof EnderPearlEntity pearl
                    && pearl.getOwner() instanceof PlayerEntity player) {
                trackers.add(new PearlTracker(pearl, player, LAUNCH_DELAY_TICKS));
            }
        });

        ServerTickEvents.START_SERVER_TICK.register(server -> {
            List<PearlTracker> toRemove = new ArrayList<>();
            List<PearlTracker> toAdd = new ArrayList<>();

            for (PearlTracker tracker : trackers) {
                toRemove.add(tracker);
                if (tracker.pearl().isRemoved()) {
                    continue;
                }
                if (tracker.ticksRemaining() <= 0) {
                    launchWindCharge(tracker.pearl(), tracker.thrower());
                } else {
                    toAdd.add(new PearlTracker(tracker.pearl(), tracker.thrower(), tracker.ticksRemaining() - 1));
                }
            }

            trackers.removeAll(toRemove);
            trackers.addAll(toAdd);
        });
    }

    private void launchWindCharge(EnderPearlEntity pearl, PlayerEntity thrower) {
        World world = pearl.getEntityWorld();
        if (!(world instanceof ServerWorld serverWorld)) return;
        if (pearl.isRemoved()) return;

        // Simulate the pearl's trajectory INTERCEPT_LEAD_TICKS steps forward,
        // accounting for per-tick drag and gravity, to find a good intercept point.
        Vec3d pearlPos = pearl.getPos();
        Vec3d pearlVel = pearl.getVelocity();
        Vec3d simPos = pearlPos;
        Vec3d simVel = pearlVel;
        for (int i = 0; i < INTERCEPT_LEAD_TICKS; i++) {
            simVel = new Vec3d(
                simVel.x * PEARL_DRAG,
                simVel.y * PEARL_DRAG - PEARL_GRAVITY,
                simVel.z * PEARL_DRAG
            );
            simPos = simPos.add(simVel);
        }
        Vec3d targetPos = simPos;

        // Spawn the wind charge just in front of the player's eyes.
        Vec3d spawnPos = thrower.getEyePos().add(thrower.getRotationVector().multiply(0.5));
        Vec3d displacement = targetPos.subtract(spawnPos);

        // Solve the initial velocity needed to cover `displacement` in exactly
        // INTERCEPT_LEAD_TICKS ticks under geometric drag:
        //   total displacement = v0 * sum_{n=0}^{N-1} drag^n  =  v0 * (1 - drag^N) / (1 - drag)
        //   => v0 = displacement * (1 - drag) / (1 - drag^N)
        double dragPowN = Math.pow(WIND_CHARGE_DRAG, INTERCEPT_LEAD_TICKS);
        double scale = (1.0 - WIND_CHARGE_DRAG) / (1.0 - dragPowN);
        Vec3d windChargeVelocity = displacement.multiply(scale);

        WindChargeEntity windCharge = new WindChargeEntity(EntityType.WIND_CHARGE, serverWorld);
        windCharge.setOwner(thrower);
        windCharge.setPosition(spawnPos);
        windCharge.setVelocity(windChargeVelocity);
        serverWorld.spawnEntity(windCharge);
    }
}