thedutchpianoman_

Develop a projectile optimizer plugin for Minecraft version 1.21.11 - 26.3 that specifically enhances the performance of ender pearl throws. The plugin should minimize network lag by optimizing entity tracking and movement prediction, ensuring smooth travel with adjustable settings for distance and speed. Additionally, include a configuration option for players to enable or disable the optimization feature as needed.

Kodari AI
KodariOct 6 at 4:54 pm 2
PearlFlightOptimizer
Enhances ender pearl throw performance in Minecraft 1.21.11 by optimizing entity tracking and movement prediction to minimize network lag. Features adjustable distance and speed settings for smooth projectile travel, plus a configurable toggle allowing players to enable or disable the optimization feature. Improves overall gameplay responsiveness during pearl throws with customizable parameters.
  1. Add a Fabric 1.21.11 mod that throttles ender-pearl position updates without changing server-side pearl physics.

  2. Add saved distance/speed settings and a per-player /pearloptimizer toggle.

  3. Package the mod metadata, mixin config, and default settings. 1.21.11 is the project target; 26.3 would require a separate port.I’ll implement the optimization as selective position-packet throttling; pearl physics and velocity synchronization will remain unchanged.

Created a server-side Fabric 1.21.11 mod. It throttles ender-pearl position packets beyond the configured distance, while preserving velocity updates, server-side physics, and the tracker’s last-sent position so skipped updates accumulate rather than being lost. It relies on vanilla client interpolation.

Use /pearloptimizer toggle to enable or disable optimization for your pearls; it is enabled by default. The mod creates config/pearloptimizer.properties on first start. Set distance in blocks and speed to the position-update interval in ticks (1 disables throttling; higher values send fewer updates). Restart the server after changing the file.

This project targets 1.21.11 only; Minecraft 26.3 needs a separate port.

thedutchpianoman_

yeah so there is still a delay when i throw an ender pearl. there is like a 200 ms delay when i throw the pearl. also, make the mod compatible with mod menu. so that i can tweak the settings.

Kodari AI
KodariOct 6 at 5:20 pm 6
  1. Fix the pearl throw delay at its source without weakening normal tracking.

  2. Add Mod Menu integration and an in-game settings screen for the optimization options.

  1. Throw delay: Added client-side pearl prediction so the pearl appears moving immediately while the server processes the throw. The server still controls the real pearl and its teleport, so prediction masks visual latency; it can’t remove the underlying network round trip.

  2. Mod Menu settings: Added a settings screen for the enable toggle, tracking distance, and position-update interval. Changes sync to your per-player server settings when connected.

Install the mod on both the client and server for prediction and server-side settings sync. Mod Menu and YACL are included as dependencies.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
11 600
src/client/java/com/kodari/pearloptimizer/PearlOptimizerClient.java
package com.kodari.pearloptimizer;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.ActionResult;

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

public class PearlOptimizerClient implements ClientModInitializer {
    private static final List<Prediction> PREDICTIONS = new ArrayList<>();
    private static int nextPredictionId = Integer.MIN_VALUE;
    private static ClientPlayNetworkHandler lastNetworkHandler;
    private static boolean settingsDirty;
    private static int syncDelay;

    @Override
    public void onInitializeClient() {
        UseItemCallback.EVENT.register((player, world, hand) -> {
            if (!world.isClient() || !PearlOptimizerConfig.isClientOptimizationEnabled()
                    || !(player instanceof ClientPlayerEntity clientPlayer) || clientPlayer.isSpectator()) {
                return ActionResult.PASS;
            }

            ItemStack stack = clientPlayer.getStackInHand(hand);
            if (!stack.isOf(Items.ENDER_PEARL) || clientPlayer.getItemCooldownManager().isCoolingDown(stack)) {
                return ActionResult.PASS;
            }

            ClientWorld clientWorld = (ClientWorld) world;
            EnderPearlEntity prediction = new EnderPearlEntity(clientWorld, clientPlayer, stack);
            prediction.setVelocity(clientPlayer, clientPlayer.getPitch(), clientPlayer.getYaw(), 0.0F, 1.5F, 1.0F);
            while (clientWorld.getEntityById(nextPredictionId) != null) {
                nextPredictionId++;
            }
            prediction.setId(nextPredictionId++);
            PREDICTIONS.add(new Prediction(clientWorld, prediction));
            clientWorld.addEntity(prediction);
            return ActionResult.PASS;
        });

        ClientEntityEvents.ENTITY_LOAD.register(PearlOptimizerClient::onEntityLoad);
        ClientTickEvents.END_CLIENT_TICK.register(PearlOptimizerClient::cleanupPredictions);
    }

    public static void settingsChanged() {
        settingsDirty = true;
        syncDelay = 5;
    }

    private static void onEntityLoad(Entity entity, ClientWorld world) {
        MinecraftClient client = MinecraftClient.getInstance();
        if (!(entity instanceof EnderPearlEntity authoritativePearl)
                || authoritativePearl.getOwner() != client.player) {
            return;
        }

        Prediction match = null;
        double closestDistance = 4.0;
        for (Prediction prediction : PREDICTIONS) {
            if (prediction.world != world || prediction.pearl == authoritativePearl || prediction.removeNextTick) {
                continue;
            }

            double distance = authoritativePearl.squaredDistanceTo(
                    prediction.startX, prediction.startY, prediction.startZ);
            if (distance <= closestDistance) {
                closestDistance = distance;
                match = prediction;
            }
        }

        if (match != null) {
            authoritativePearl.setPosition(match.pearl.getX(), match.pearl.getY(), match.pearl.getZ());
            authoritativePearl.setVelocity(match.pearl.getVelocity());
            match.removeNextTick = true;
        }
    }

    private static void cleanupPredictions(MinecraftClient client) {
        Iterator<Prediction> iterator = PREDICTIONS.iterator();
        while (iterator.hasNext()) {
            Prediction prediction = iterator.next();
            if (prediction.removeNextTick || prediction.pearl.isRemoved() || prediction.pearl.age >= 40
                    || prediction.world != client.world) {
                if (!prediction.pearl.isRemoved() && prediction.world == client.world) {
                    prediction.pearl.discard();
                }
                iterator.remove();
            }
        }

        ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
        if (networkHandler == null) {
            lastNetworkHandler = null;
            return;
        }
        if (networkHandler != lastNetworkHandler) {
            lastNetworkHandler = networkHandler;
            if (PearlOptimizerConfig.hasClientSettings()) {
                settingsDirty = true;
                syncDelay = 0;
            }
        }
        if (!settingsDirty) {
            return;
        }
        if (syncDelay > 0) {
            syncDelay--;
            return;
        }

        networkHandler.sendChatCommand("pearloptimizer set "
                + PearlOptimizerConfig.isClientOptimizationEnabled() + " "
                + PearlOptimizerConfig.getDistance() + " " + PearlOptimizerConfig.getSpeed());
        settingsDirty = false;
    }

    private static final class Prediction {
        private final ClientWorld world;
        private final EnderPearlEntity pearl;
        private final double startX;
        private final double startY;
        private final double startZ;
        private boolean removeNextTick;

        private Prediction(ClientWorld world, EnderPearlEntity pearl) {
            this.world = world;
            this.pearl = pearl;
            this.startX = pearl.getX();
            this.startY = pearl.getY();
            this.startZ = pearl.getZ();
        }
    }
}