holdy_yt

can you make me a minecraft plugin that makes a config and ideal speed for turtle eggs to hatch for 1.21.11 paper

Kodari AI
KodariOct 24 at 6:27 pm 1
EggHatchTimer
A Paper 1.21.1 Minecraft plugin that introduces configurable hatching speeds for turtle eggs. Administrators can set a custom hatch duration in seconds via a config.yml file, overriding the vanilla hatching time. The plugin listens to block placement events for turtle eggs, tracks their age using a scheduled task, and automatically hatches them when the configured time elapses. Includes per-egg tracking, config reload command, and proper cleanup on block break. Ideal for servers wanting faster or slower turtle breeding mechanics.
  1. Create the Paper plugin entry point and default config.

  2. Track player-placed and turtle-laid eggs, then accelerate their hatch stages using configurable timing and vanilla-like night/sand conditions.

  3. Scan loaded chunks so existing eggs are included.

Created TurtleHatch with a configurable config.yml. Eggs advance one hatch stage every 5 minutes by default, only at night and on sand or red sand; completed eggs hatch into baby turtles. Existing eggs in loaded chunks and newly placed or turtle-laid eggs are tracked.

Adjust seconds-per-stage, only-at-night, and require-sand-below in src/main/resources/config.yml.

holdy_yt

and can you make it where you can customize how long it takes for turtles to grow up

Kodari AI
KodariOct 24 at 6:36 pm 1
  1. Add a turtle-growth-seconds setting to config.yml, defaulting to 20 minutes.

  2. Use it to set the age of turtles hatched by the plugin; 0 makes them adults immediately.

Added turtle-growth-seconds to config.yml, defaulting to 1200 seconds (20 minutes) for turtles hatched by the plugin. Set it to 0 for instant adulthood.

holdy_yt

can you change the name to turtlechanger

Kodari AI
KodariOct 24 at 6:37 pm 1
  1. Rename the plugin’s displayed name to TurtleChanger.

  2. Keep its existing main class and settings unchanged.

Renamed the plugin to TurtleChanger in plugin.yml. The main class and config settings remain unchanged.

Kodari can make mistakes. Review important code before using.
Files
src
Code
3 212
src/main/java/com/kodari/turtlehatch/TurtleHatchPlugin.java
package com.kodari.turtlehatch;

import com.cryptomorin.xseries.XMaterial;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.TurtleEgg;
import org.bukkit.entity.Turtle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public final class TurtleHatchPlugin extends JavaPlugin implements Listener {
    private final Map<Block, EggProgress> trackedEggs = new HashMap<>();
    private Material turtleEggMaterial;
    private Material airMaterial;
    private Material sandMaterial;
    private Material redSandMaterial;
    private int secondsPerStage;
    private int turtleGrowthSeconds;
    private boolean onlyAtNight;
    private boolean requireSandBelow;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        turtleEggMaterial = material("TURTLE_EGG");
        airMaterial = material("AIR");
        sandMaterial = material("SAND");
        redSandMaterial = material("RED_SAND");
        secondsPerStage = Math.max(1, getConfig().getInt("seconds-per-stage", 300));
        turtleGrowthSeconds = Math.max(0, Math.min(Integer.MAX_VALUE / 20, getConfig().getInt("turtle-growth-seconds", 1200)));
        onlyAtNight = getConfig().getBoolean("only-at-night", true);
        requireSandBelow = getConfig().getBoolean("require-sand-below", true);

        getServer().getPluginManager().registerEvents(this, this);
        for (World world : Bukkit.getWorlds()) {
            for (Chunk chunk : world.getLoadedChunks()) {
                scanChunk(chunk);
            }
        }
        Bukkit.getScheduler().runTaskTimer(this, this::advanceEggs, 20L, 20L);
    }

    @EventHandler(ignoreCancelled = true)
    public void onBlockPlace(BlockPlaceEvent event) {
        trackEgg(event.getBlockPlaced());
    }

    @EventHandler(ignoreCancelled = true)
    public void onBlockForm(BlockFormEvent event) {
        if (event.getNewState().getType() == turtleEggMaterial) {
            trackEgg(event.getBlock());
        }
    }

    @EventHandler
    public void onChunkLoad(ChunkLoadEvent event) {
        scanChunk(event.getChunk());
    }

    private Material material(String name) {
        return XMaterial.matchXMaterial(name)
                .map(XMaterial::parseMaterial)
                .orElseThrow(() -> new IllegalStateException("Required material is unavailable: " + name));
    }

    private void scanChunk(Chunk chunk) {
        World world = chunk.getWorld();
        for (int x = 0; x < 16; x++) {
            for (int z = 0; z < 16; z++) {
                for (int y = world.getMinHeight(); y < world.getMaxHeight(); y++) {
                    Block block = chunk.getBlock(x, y, z);
                    if (block.getType() == turtleEggMaterial) {
                        trackEgg(block);
                    }
                }
            }
        }
    }

    private void trackEgg(Block block) {
        if (block.getType() != turtleEggMaterial) {
            return;
        }

        BlockData data = block.getBlockData();
        if (data instanceof TurtleEgg eggData) {
            trackedEggs.putIfAbsent(block, new EggProgress(eggData.getHatch()));
        }
    }

    private void advanceEggs() {
        Iterator<Map.Entry<Block, EggProgress>> iterator = trackedEggs.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<Block, EggProgress> entry = iterator.next();
            Block block = entry.getKey();
            World world = block.getWorld();
            if (!world.isChunkLoaded(block.getX() >> 4, block.getZ() >> 4)) {
                continue;
            }
            if (block.getType() != turtleEggMaterial) {
                iterator.remove();
                continue;
            }

            BlockData data = block.getBlockData();
            if (!(data instanceof TurtleEgg eggData)) {
                iterator.remove();
                continue;
            }

            int stage = eggData.getHatch();
            EggProgress progress = entry.getValue();
            if (stage != progress.getStage()) {
                progress.setStage(stage);
                progress.setElapsedSeconds(0);
            }
            if ((onlyAtNight && !isNight(world)) || (requireSandBelow && !isOnSand(block))) {
                continue;
            }

            int elapsed = progress.getElapsedSeconds() + 1;
            if (elapsed < secondsPerStage) {
                progress.setElapsedSeconds(elapsed);
                continue;
            }

            if (stage < 2) {
                eggData.setHatch(stage + 1);
                block.setBlockData(eggData);
                progress.setStage(stage + 1);
                progress.setElapsedSeconds(0);
                continue;
            }

            hatchOne(block, eggData, iterator);
        }
    }

    private boolean isNight(World world) {
        long time = world.getTime();
        return time >= 13000L && time < 23000L;
    }

    private boolean isOnSand(Block egg) {
        Material below = egg.getRelative(0, -1, 0).getType();
        return below == sandMaterial || below == redSandMaterial;
    }

    private void hatchOne(Block block, TurtleEgg eggData, Iterator<Map.Entry<Block, EggProgress>> iterator) {
        Location spawnLocation = block.getLocation().add(0.5, 0.1, 0.5);
        Turtle baby = block.getWorld().spawn(spawnLocation, Turtle.class);
        baby.setAge(-turtleGrowthSeconds * 20);

        int eggsRemaining = eggData.getEggs() - 1;
        if (eggsRemaining > 0) {
            eggData.setEggs(eggsRemaining);
            eggData.setHatch(0);
            block.setBlockData(eggData);
            EggProgress progress = trackedEggs.get(block);
            if (progress != null) {
                progress.setStage(0);
                progress.setElapsedSeconds(0);
            }
        } else {
            block.setType(airMaterial, false);
            iterator.remove();
        }
    }

    @Getter
    @Setter
    private static final class EggProgress {
        private int stage;
        private int elapsedSeconds;

        private EggProgress(int stage) {
            this.stage = stage;
        }
    }
}