diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 1e1ea68d..7020aa54 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -136,28 +136,26 @@ public class DisguiseUtilities { // TODO Slimes Entity entity = disguise.getEntity(); if (entity != null) { + DisguiseValues disguiseValues = DisguiseValues.getDisguiseValues(disguise.getType()); + DisguiseValues entityValues = DisguiseValues.getDisguiseValues(DisguiseType.getType(entity.getType())); + FakeBoundingBox entityBox = entityValues.getAdultBox(); + FakeBoundingBox disguiseBox = disguiseValues.getAdultBox(); + if (entityValues.getBabyBox() != null) { + if (entity instanceof Ageable && !(((Ageable) entity).isAdult()) + || (entity instanceof Zombie && ((Zombie) entity).isBaby())) { + entityBox = entityValues.getBabyBox(); + } + } + if (disguiseValues.getBabyBox() != null) { + if (disguise.getWatcher() instanceof AgeableWatcher && (((AgeableWatcher) disguise.getWatcher()).isBaby()) + || (disguise.getWatcher() instanceof ZombieWatcher && ((ZombieWatcher) disguise.getWatcher()).isBaby())) { + disguiseBox = disguiseValues.getBabyBox(); + } + } if (isDisguiseInUse(disguise)) { - DisguiseValues values = DisguiseValues.getDisguiseValues(disguise.getType()); - FakeBoundingBox fakeBox = values.getAdultBox(); - if (values.getBabyBox() != null) { - if (disguise.getWatcher() instanceof AgeableWatcher - && (((AgeableWatcher) disguise.getWatcher()).isBaby()) - || (disguise.getWatcher() instanceof ZombieWatcher && ((ZombieWatcher) disguise.getWatcher()) - .isBaby())) { - fakeBox = values.getBabyBox(); - } - } - ReflectionManager.setBoundingBox(entity, fakeBox.getX(), fakeBox.getY(), fakeBox.getZ()); + ReflectionManager.setBoundingBox(entity, entityBox, disguiseBox); } else { - DisguiseValues values = DisguiseValues.getDisguiseValues(DisguiseType.getType(entity.getType())); - FakeBoundingBox fakeBox = values.getAdultBox(); - if (values.getBabyBox() != null) { - if (entity instanceof Ageable && !(((Ageable) entity).isAdult()) - || (entity instanceof Zombie && ((Zombie) entity).isBaby())) { - fakeBox = values.getBabyBox(); - } - } - ReflectionManager.setBoundingBox(disguise.getEntity(), fakeBox.getX(), fakeBox.getY(), fakeBox.getZ()); + ReflectionManager.setBoundingBox(entity, disguiseBox, entityBox); } } } diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index 6a6b0611..a99e4e64 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -90,7 +90,7 @@ public class ReflectionManager { double x = 0, y = 0, z = 0; int stage = 0; for (Field field : boundingBox.getClass().getFields()) { - if (field.getType().getSimpleName().equals("Double")) { + if (field.getType().getSimpleName().equals("double")) { stage++; switch (stage) { case 1: @@ -114,9 +114,9 @@ public class ReflectionManager { default: throw new Exception("Error while setting the bounding box, more doubles than I thought??"); } - return new FakeBoundingBox(x, y, z); } } + return new FakeBoundingBox(x, y, z); } catch (Exception ex) { ex.printStackTrace(); } @@ -235,32 +235,26 @@ public class ReflectionManager { return after17; } - public static void setBoundingBox(Entity entity, double newX, double newY, double newZ) { + public static void setBoundingBox(Entity entity, FakeBoundingBox oldBox, FakeBoundingBox newBox) { try { Object boundingBox = getNmsClass("Entity").getField("boundingBox").get(getNmsEntity(entity)); - double x = 0, y = 0, z = 0; int stage = 0; for (Field field : boundingBox.getClass().getFields()) { - if (field.getType().getSimpleName().equals("Double")) { + if (field.getType().getSimpleName().equals("double")) { stage++; switch (stage) { case 1: - x = field.getDouble(boundingBox); + field.setDouble(boundingBox, field.getDouble(boundingBox) + (oldBox.getX() - newBox.getX())); break; case 2: - y = field.getDouble(boundingBox); + field.setDouble(boundingBox, field.getDouble(boundingBox) + (oldBox.getY() - newBox.getY())); break; case 3: - z = field.getDouble(boundingBox); + field.setDouble(boundingBox, field.getDouble(boundingBox) + (oldBox.getZ() - newBox.getZ())); break; case 4: - field.setDouble(boundingBox, x); - break; case 5: - field.setDouble(boundingBox, y); - break; case 6: - field.setDouble(boundingBox, z); break; default: throw new Exception("Error while setting the bounding box, more doubles than I thought??");