Fix skeleton horse spawning in 1.21.3

This commit is contained in:
fullwall 2024-11-19 01:09:21 +08:00
parent 817df76468
commit 17cd2d742a
3 changed files with 24 additions and 21 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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<EntityDataAccessor<?>> cb) {
EntityDimensions size;
@ -2209,24 +2230,6 @@ public class NMSImpl implements NMSBridge {
throw new IllegalArgumentException();
}
public static <T extends Entity & NPCHolder> 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());