mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-14 06:14:52 +00:00
Nudge npcs out of blocks they grow into when the hitbox changes
This commit is contained in:
1 parent
e3d1c9b1a7
commit
9ff4b8ae16
6 files changed
+17
-15
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user