Fix leashes

This commit is contained in:
2025-08-20 20:48:47 +02:00
parent 0e5a830912
commit 4a8c1819a3
2 changed files with 14 additions and 1 deletions

View File

@@ -1,6 +1,12 @@
package com.kasetoatz.fastghast;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.entity.Leashable;
import net.minecraft.entity.passive.HappyGhastEntity;
import net.minecraft.network.packet.s2c.play.PositionFlag;
import java.util.EnumSet;
import static com.kasetoatz.fastghast.config.Config.load;
@@ -10,5 +16,13 @@ public class Fastghast implements ModInitializer
public void onInitialize()
{
load();
ServerTickEvents.END_SERVER_TICK.register((server) -> {
server.getWorlds().forEach(world -> world.iterateEntities().forEach(entity -> {
if (entity instanceof Leashable leashed && leashed.isLeashed() && leashed.getLeashHolder() instanceof HappyGhastEntity ghast && leashed.getDistanceToCenter(ghast) > 8)
{
entity.teleport(world, ghast.getX(), ghast.getY(), ghast.getZ(), EnumSet.noneOf(PositionFlag.class), entity.getYaw(), entity.getPitch(), false);
}
}));
});
}
}

View File

@@ -7,7 +7,6 @@
"authors": [],
"contact": {},
"license": "MIT",
"icon": "assets/fastghast/icon.png",
"environment": "*",
"entrypoints": {
"main": [