From 17cd2d742aee250616519ba48cb02548b4b8bf14 Mon Sep 17 00:00:00 2001 From: fullwall Date: Tue, 19 Nov 2024 01:09:21 +0800 Subject: [PATCH] Fix skeleton horse spawning in 1.21.3 --- .../nms/v1_21_R2/entity/EntityHumanNPC.java | 2 +- .../entity/HorseSkeletonController.java | 2 +- .../nms/v1_21_R2/util/NMSImpl.java | 41 ++++++++++--------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/entity/EntityHumanNPC.java b/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/entity/EntityHumanNPC.java index 0e6dd7669..2724dca84 100644 --- a/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/entity/EntityHumanNPC.java +++ b/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/entity/EntityHumanNPC.java @@ -149,7 +149,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable onGround = false; } pushEntities(); - NMSImpl.callNPCMoveEvent(this); + NMSImpl.callNPCMoveEvent(npc, this); if (npc.useMinecraftAI()) { foodData.tick(this); } diff --git a/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/entity/HorseSkeletonController.java b/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/entity/HorseSkeletonController.java index 0bfe72733..5b8f6ba5d 100644 --- a/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/entity/HorseSkeletonController.java +++ b/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/entity/HorseSkeletonController.java @@ -40,7 +40,7 @@ import net.minecraft.world.phys.Vec3; public class HorseSkeletonController extends MobEntityController { public HorseSkeletonController() { - super(EntityHorseSkeletonNPC.class, EntityType.SKELETON); + super(EntityHorseSkeletonNPC.class, EntityType.SKELETON_HORSE); } @Override diff --git a/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/util/NMSImpl.java b/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/util/NMSImpl.java index 8c8dde4f8..509dba64b 100644 --- a/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/util/NMSImpl.java +++ b/v1_21_R2/src/main/java/net/citizensnpcs/nms/v1_21_R2/util/NMSImpl.java @@ -18,7 +18,6 @@ import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; -import net.citizensnpcs.api.event.NPCMoveEvent; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -76,6 +75,7 @@ import net.citizensnpcs.api.astar.pathfinder.DoorExaminer; import net.citizensnpcs.api.command.CommandManager; import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.event.DespawnReason; +import net.citizensnpcs.api.event.NPCMoveEvent; import net.citizensnpcs.api.gui.ForwardingInventory; import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; @@ -2135,6 +2135,27 @@ public class NMSImpl implements NMSBridge { } } + public static void callNPCMoveEvent(NPC npc, Entity what) { + if (NPCMoveEvent.getHandlerList().getRegisteredListeners().length == 0) + return; + if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ() || what.yRotO != what.getYRot() + || what.xRotO != what.getXRot()) { + Location from = new Location(what.level().getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO); + Location to = new Location(what.level().getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(), + what.getXRot()); + final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone()); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + final Location eventFrom = event.getFrom(); + what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), + eventFrom.getPitch()); + } else if (!to.equals(event.getTo())) { + what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), + event.getTo().getPitch()); + } + } + } + public static void checkAndUpdateHeight(LivingEntity living, EntityDataAccessor datawatcherobject, Consumer> cb) { EntityDimensions size; @@ -2209,24 +2230,6 @@ public class NMSImpl implements NMSBridge { throw new IllegalArgumentException(); } - public static void callNPCMoveEvent(T what) { - final NPC npc = what.getNPC(); - if (npc != null && NPCMoveEvent.getHandlerList().getRegisteredListeners().length > 0) { - if (what.xo != what.getX() || what.yo != what.getY() || what.zo != what.getZ() || what.yRotO != what.getYRot() || what.xRotO != what.getXRot()) { - Location from = new Location(what.level().getWorld(), what.xo, what.yo, what.zo, what.yRotO, what.xRotO); - Location to = new Location(what.level().getWorld(), what.getX(), what.getY(), what.getZ(), what.getYRot(), what.getXRot()); - final NPCMoveEvent event = new NPCMoveEvent(npc, from, to.clone()); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - final Location eventFrom = event.getFrom(); - what.absMoveTo(eventFrom.getX(), eventFrom.getY(), eventFrom.getZ(), eventFrom.getYaw(), eventFrom.getPitch()); - } else if (!to.equals(event.getTo())) { - what.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch()); - } - } - } - } - public static TreeMap getBehaviorMap(LivingEntity entity) { try { return (TreeMap) AVAILABLE_BEHAVIORS_BY_PRIORITY.invoke(entity.getBrain());