From 9ff4b8ae165389b7cbc52ac3522cba721d419bd8 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 12:53:08 -0400 Subject: [PATCH] Nudge npcs out of blocks they grow into when the hitbox changes --- .../java/noppes/npcs/entity/EntityCustomNpc.java | 4 +--- src/main/java/noppes/npcs/entity/EntityNPCGolem.java | 4 +--- .../java/noppes/npcs/entity/EntityNPCInterface.java | 12 ++++++++++++ .../java/noppes/npcs/entity/EntityNpcDragon.java | 4 +--- src/main/java/noppes/npcs/entity/EntityNpcSlime.java | 4 +--- .../noppes/npcs/entity/old/EntityNPCEnderman.java | 4 +--- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/noppes/npcs/entity/EntityCustomNpc.java b/src/main/java/noppes/npcs/entity/EntityCustomNpc.java index 336f778ce..638898fd6 100644 --- a/src/main/java/noppes/npcs/entity/EntityCustomNpc.java +++ b/src/main/java/noppes/npcs/entity/EntityCustomNpc.java @@ -86,9 +86,7 @@ public class EntityCustomNpc extends EntityNPCFlying { worldObj.MAX_ENTITY_RADIUS = newWidth / 2; } - this.width = newWidth; - this.height = newHeight; - this.setPosition(posX, posY, posZ); + applyHitbox(newWidth, newHeight); } } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCGolem.java b/src/main/java/noppes/npcs/entity/EntityNPCGolem.java index 5eb111e4d..918dce813 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCGolem.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCGolem.java @@ -37,9 +37,7 @@ public class EntityNPCGolem extends EntityNPCInterface { newWidth = 1.4f; newHeight = 2.5f; } - this.width = newWidth; - this.height = newHeight; - this.setPosition(posX, posY, posZ); + applyHitbox(newWidth, newHeight); if (width / 2 > World.MAX_ENTITY_RADIUS) { World.MAX_ENTITY_RADIUS = width / 2; } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 1c106d7f6..db956f5fe 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -1324,9 +1324,21 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti World.MAX_ENTITY_RADIUS = newWidth / 2; } + applyHitbox(newWidth, newHeight); + } + + /** + * Applies a new hitbox size. Mirrors vanilla setSize by nudging the npc out of whatever it grew + * into -- an overlapped block stops resolving downward collision, so the npc drops through it. + */ + protected void applyHitbox(float newWidth, float newHeight) { + float oldWidth = this.width; this.width = newWidth; this.height = newHeight; this.setPosition(posX, posY, posZ); + + if (newWidth > oldWidth && !this.firstUpdate && !this.worldObj.isRemote) + this.moveEntity(oldWidth - newWidth, 0.0D, oldWidth - newWidth); } @Override diff --git a/src/main/java/noppes/npcs/entity/EntityNpcDragon.java b/src/main/java/noppes/npcs/entity/EntityNpcDragon.java index c5952fa3c..a2d87c69b 100644 --- a/src/main/java/noppes/npcs/entity/EntityNpcDragon.java +++ b/src/main/java/noppes/npcs/entity/EntityNpcDragon.java @@ -115,9 +115,7 @@ public class EntityNpcDragon extends EntityNPCInterface { // } @Override public void updateHitbox() { - this.width = 1.8f; - this.height = 1.4f; - this.setPosition(posX, posY, posZ); + applyHitbox(1.8f, 1.4f); if (width / 2 > World.MAX_ENTITY_RADIUS) { World.MAX_ENTITY_RADIUS = width / 2; } diff --git a/src/main/java/noppes/npcs/entity/EntityNpcSlime.java b/src/main/java/noppes/npcs/entity/EntityNpcSlime.java index 93bdc5a7d..928cba1bb 100644 --- a/src/main/java/noppes/npcs/entity/EntityNpcSlime.java +++ b/src/main/java/noppes/npcs/entity/EntityNpcSlime.java @@ -17,9 +17,7 @@ public class EntityNpcSlime extends EntityNPCInterface { @Override public void updateHitbox() { - this.width = 0.8f; - this.height = 0.8f; - this.setPosition(posX, posY, posZ); + applyHitbox(0.8f, 0.8f); if (width / 2 > World.MAX_ENTITY_RADIUS) { World.MAX_ENTITY_RADIUS = width / 2; } diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java b/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java index 6479f90c7..174c7b195 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java @@ -40,9 +40,7 @@ public class EntityNPCEnderman extends EntityNpcEnderchibi { newHeight = (newHeight / 5f) * display.modelSize; newWidth = Math.max(newWidth, 0.00001f); newHeight = Math.max(newHeight, 0.00001f); - this.width = newWidth; - this.height = newHeight; - this.setPosition(posX, posY, posZ); + applyHitbox(newWidth, newHeight); if (width / 2 > World.MAX_ENTITY_RADIUS) { World.MAX_ENTITY_RADIUS = width / 2; }