Creighton Roy
๐Ÿ“Ž 1 file 3,030 chars
๐Ÿ“„
pasted-code-1794336818387.txt
txt 55 lines
โ–ถ
# Minecraft Fabric Mod โ€“ Ender Pearl Effects (1.21.11)

Create a lightweight Minecraft Fabric mod for **Minecraft 1.21.11** that enhances the visual and audio effects of throwing and landing with Ender Pearls.

The mod must be **100% client-side**, meaning it must not require installation on a server and must not modify server-side mechanics, networking, or gameplay behavior.

## 1. Ender Pearl Throwing Effects
- Add a satisfying, custom sound effect when the player throws an Ender Pearl.
- Create a visually appealing animation when the pearl is thrown.
- Add a short burst of particles around the player's hand when the pearl launches.
- Make the throwing animation feel smooth, responsive, and polished.

## 2. Ender Pearl Flight Effects
- Give flying Ender Pearls a beautiful, customizable-looking particle trail.
- The trail should follow the pearl's actual movement smoothly.
- Use subtle glowing particles, magical sparkles, or small wisps of energy.
- Add occasional particle bursts or twinkles to make the trail more interesting.
- Avoid excessive particles that could cause performance issues.
- Make the trail visually appealing without obstructing the player's view.

## 3. Teleportation / Landing Effects
When the player successfully teleports using an Ender Pearl:
- Play a satisfying custom teleportation sound.
- Create a visually impressive particle burst at the destination.
- Add a short-lived magical shockwave or expanding ring effect.
- Optionally add a brief visual effect around the player's character.
- Make the teleport feel impactful and rewarding.

## 4. Performance and Compatibility
- The mod must be entirely client-side.
- Do not require server installation.
- Do not change Ender Pearl damage, velocity, cooldowns, teleportation behavior, or other vanilla mechanics.
- Keep the mod lightweight and optimized.
- Avoid unnecessary mixins and expensive rendering operations.
- Ensure compatibility with Minecraft Fabric 1.21.11.
- Use appropriate client-side events and rendering hooks.

## 5. Code Quality
- Use clean, organized, maintainable Java code.
- Follow modern Fabric API conventions for Minecraft 1.21.11.
- Include all necessary Gradle configuration, dependencies, resources, and mod metadata.
- Ensure sounds and particle effects are properly registered and loaded.
- Avoid outdated Minecraft or Fabric API methods.
- Make sure the project compiles and runs.

## 6. Final Deliverable
Provide a complete, working Fabric mod project, including:
- All Java source files.
- Fabric mod configuration and metadata.
- Gradle build files.
- Custom sound assets, if needed.
- Any required resource files.
- Clear instructions for building the mod into a `.jar` file.

**Overall vision:** Make Ender Pearls feel much more satisfying and magical to use. Throwing should feel powerful, the pearl should leave a beautiful trail while flying, and teleporting should have a smooth, flashy visual and audio payoff. Keep everything lightweight, polished, and faithful to vanilla Minecraft gameplay.
Kodari AI
KodariNov 10 at 6:56 pm 4
EnderPearlEnhance
Client-side Fabric mod for Minecraft 1.21.11 that enhances Ender Pearl usage with custom sounds, particle trails, and teleportation effects. Adds a throwing sound with hand particle burst, a glowing particle trail following the pearl's flight path with occasional twinkles, and a landing effect featuring a teleportation sound, particle burst, and expanding shockwave ring. Uses client-side events and rendering hooks only, with no server requirements or vanilla mechanic changes. Optimized for performance with controlled particle counts and lightweight rendering operations.
  • Add client-only launch, trail, and landing effects without changing pearl mechanics.

  • Use layered vanilla sounds for the audio cues and correlate landing effects with tracked pearls.

Created the client-side Ender Pearl effects mod. It adds a launch burst, a pearl trail, and a landing burst with an expanding ring. Audio cues layer vanilla sounds; no custom sound files are included.

Landing detection correlates position corrections with nearby tracked pearls, so it is best-effort rather than guaranteed.

To build the JAR, click Compile in the top bar, then Compile in the window. When it succeeds, click Download. On phone, use โ‹ฎ โ†’ Compile Project.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
8 251
src/client/java/com/kodari/pearleffects/PearlEffectsClient.java
package com.kodari.pearleffects;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public final class PearlEffectsClient implements ClientModInitializer {
    private static final Random RANDOM = new Random();
    private static final Map<Integer, PearlPosition> PEARLS = new HashMap<>();
    private static ClientWorld activeWorld;
    private static int tick;
    private static int ringTicks;
    private static double ringX, ringY, ringZ;

    private record PearlPosition(double x, double y, double z, int tick) { }

    @Override
    public void onInitializeClient() {
        ClientTickEvents.END_CLIENT_TICK.register(PearlEffectsClient::tick);
    }

    public static void onThrow(World world, PlayerEntity player, Hand hand) {
        MinecraftClient client = MinecraftClient.getInstance();
        if (!(world instanceof ClientWorld clientWorld) || player != client.player) return;
        Vec3d direction = player.getRotationVec(1.0F);
        double side = hand == Hand.MAIN_HAND ? 0.24 : -0.24;
        double x = player.getX() + direction.x * 0.45 - direction.z * side;
        double y = player.getEyeY() - 0.25 + direction.y * 0.45;
        double z = player.getZ() + direction.z * 0.45 + direction.x * side;
        clientWorld.playSoundClient(x, y, z, SoundEvents.BLOCK_AMETHYST_BLOCK_CHIME, SoundCategory.PLAYERS, 0.55F, 1.45F, false);
        for (int i = 0; i < 12; i++) {
            double vx = direction.x * 0.07 + (RANDOM.nextDouble() - 0.5) * 0.1;
            double vy = direction.y * 0.07 + (RANDOM.nextDouble() - 0.5) * 0.1;
            double vz = direction.z * 0.07 + (RANDOM.nextDouble() - 0.5) * 0.1;
            clientWorld.addParticleClient(i % 3 == 0 ? ParticleTypes.END_ROD : ParticleTypes.REVERSE_PORTAL, x, y, z, vx, vy, vz);
        }
    }

    private static void tick(MinecraftClient client) {
        ClientWorld world = client.world;
        if (world != activeWorld) {
            activeWorld = world;
            PEARLS.clear();
            ringTicks = 0;
            tick = 0;
        }
        if (world == null || client.player == null) return;
        tick++;
        for (Entity entity : world.getEntities()) {
            if (!(entity instanceof EnderPearlEntity pearl)) continue;
            if (pearl.getOwner() == client.player) {
                PEARLS.put(pearl.getId(), new PearlPosition(pearl.getX(), pearl.getY(), pearl.getZ(), tick));
            }
            double dx = pearl.getX() - pearl.lastX;
            double dy = pearl.getY() - pearl.lastY;
            double dz = pearl.getZ() - pearl.lastZ;
            for (int i = 0; i < 3; i++) {
                double t = (i + 0.5) / 3.0;
                double x = pearl.lastX + dx * t + (RANDOM.nextDouble() - 0.5) * 0.08;
                double y = pearl.lastY + dy * t + (RANDOM.nextDouble() - 0.5) * 0.08;
                double z = pearl.lastZ + dz * t + (RANDOM.nextDouble() - 0.5) * 0.08;
                world.addParticleClient(ParticleTypes.REVERSE_PORTAL, x, y, z, 0, 0.005, 0);
            }
            if (tick % 5 == 0) {
                world.addParticleClient(ParticleTypes.END_ROD, pearl.getX(), pearl.getY(), pearl.getZ(), 0, 0.01, 0);
            }
        }
        PEARLS.values().removeIf(position -> tick - position.tick() > 20);
        if (ringTicks > 0) {
            double radius = 0.3 + (7 - ringTicks) * 0.27;
            for (int i = 0; i < 18; i++) {
                double angle = 2 * Math.PI * i / 18;
                world.addParticleClient(ParticleTypes.END_ROD, ringX + Math.cos(angle) * radius, ringY + 0.08, ringZ + Math.sin(angle) * radius, 0, 0.005, 0);
            }
            ringTicks--;
        }
    }

    public static void onPositionCorrection() {
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.world == null || client.player == null || client.world != activeWorld) return;
        double x = client.player.getX(), y = client.player.getY(), z = client.player.getZ();
        Iterator<PearlPosition> positions = PEARLS.values().iterator();
        while (positions.hasNext()) {
            PearlPosition position = positions.next();
            double dx = position.x() - x, dy = position.y() - y, dz = position.z() - z;
            if (tick - position.tick() <= 20 && dx * dx + dy * dy + dz * dz < 36) {
                positions.remove();
                landing(client.world, x, y, z);
                return;
            }
        }
    }

    private static void landing(ClientWorld world, double x, double y, double z) {
        world.playSoundClient(x, y, z, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.PLAYERS, 0.65F, 1.25F, false);
        world.playSoundClient(x, y, z, SoundEvents.BLOCK_AMETHYST_BLOCK_CHIME, SoundCategory.PLAYERS, 0.7F, 0.8F, false);
        for (int i = 0; i < 32; i++) {
            double angle = RANDOM.nextDouble() * Math.PI * 2;
            double speed = 0.03 + RANDOM.nextDouble() * 0.12;
            world.addParticleClient(i % 4 == 0 ? ParticleTypes.END_ROD : ParticleTypes.REVERSE_PORTAL,
                    x, y + 0.8, z, Math.cos(angle) * speed, (RANDOM.nextDouble() - 0.25) * 0.16, Math.sin(angle) * speed);
        }
        ringX = x;
        ringY = y;
        ringZ = z;
        ringTicks = 6;
    }
}