From dda362f082f83402dc08e08256d62ee29a1c5dbd Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 24 Oct 2018 11:09:16 +1300 Subject: [PATCH] Fix bounding boxes --- .../disguise/utilities/DisguiseUtilities.java | 54 +++++++++--------- .../disguise/utilities/ReflectionManager.java | 55 ++++++++++--------- 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 0fdf5ea3..ae0a03a3 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -455,35 +455,37 @@ public class DisguiseUtilities { public static void doBoundingBox(TargetedDisguise disguise) { Entity entity = disguise.getEntity(); - if (entity != null) { - if (isDisguiseInUse(disguise)) { - DisguiseValues disguiseValues = DisguiseValues.getDisguiseValues(disguise.getType()); - FakeBoundingBox disguiseBox = disguiseValues.getAdultBox(); + if (entity == null) { + return; + } - 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 disguiseValues = DisguiseValues.getDisguiseValues(disguise.getType()); + FakeBoundingBox disguiseBox = disguiseValues.getAdultBox(); + + if (disguiseValues.getBabyBox() != null) { + if ((disguise.getWatcher() instanceof AgeableWatcher && + ((AgeableWatcher) disguise.getWatcher()).isBaby()) || + (disguise.getWatcher() instanceof ZombieWatcher && + ((ZombieWatcher) disguise.getWatcher()).isBaby())) { + disguiseBox = disguiseValues.getBabyBox(); } - - ReflectionManager.setBoundingBox(entity, disguiseBox); - } else { - DisguiseValues entityValues = DisguiseValues.getDisguiseValues(DisguiseType.getType(entity.getType())); - - FakeBoundingBox entityBox = entityValues.getAdultBox(); - - if (entityValues.getBabyBox() != null) { - if ((entity instanceof Ageable && !((Ageable) entity).isAdult()) || - (entity instanceof Zombie && ((Zombie) entity).isBaby())) { - entityBox = entityValues.getBabyBox(); - } - } - - ReflectionManager.setBoundingBox(entity, entityBox); } + + ReflectionManager.setBoundingBox(entity, disguiseBox); + } else { + DisguiseValues entityValues = DisguiseValues.getDisguiseValues(DisguiseType.getType(entity.getType())); + + FakeBoundingBox entityBox = entityValues.getAdultBox(); + + if (entityValues.getBabyBox() != null) { + if ((entity instanceof Ageable && !((Ageable) entity).isAdult()) || + (entity instanceof Zombie && ((Zombie) entity).isBaby())) { + entityBox = entityValues.getBabyBox(); + } + } + + ReflectionManager.setBoundingBox(entity, entityBox); } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/ReflectionManager.java index b50d03dc..e246130c 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -187,31 +187,33 @@ public class ReflectionManager { int stage = 0; for (Field field : boundingBox.getClass().getDeclaredFields()) { - if (field.getType().getSimpleName().equals("double")) { - stage++; + if (!field.getType().getSimpleName().equals("double")) { + continue; + } - switch (stage) { - case 1: - x -= field.getDouble(boundingBox); - break; - case 2: - y -= field.getDouble(boundingBox); - break; - case 3: - z -= field.getDouble(boundingBox); - break; - case 4: - x += field.getDouble(boundingBox); - break; - case 5: - y += field.getDouble(boundingBox); - break; - case 6: - z += field.getDouble(boundingBox); - break; - default: - throw new Exception("Error while setting the bounding box, more doubles than I thought??"); - } + stage++; + + switch (stage) { + case 1: + x -= field.getDouble(boundingBox); + break; + case 2: + y -= field.getDouble(boundingBox); + break; + case 3: + z -= field.getDouble(boundingBox); + break; + case 4: + x += field.getDouble(boundingBox); + break; + case 5: + y += field.getDouble(boundingBox); + break; + case 6: + z += field.getDouble(boundingBox); + break; + default: + throw new Exception("Error while setting the bounding box, more doubles than I thought??"); } } @@ -618,8 +620,9 @@ public class ReflectionManager { Location loc = entity.getLocation(); Object boundingBox = boundingBoxConstructor - .newInstance(loc.getX() - newBox.getX(), loc.getY() - newBox.getY(), loc.getZ() - newBox.getZ(), - loc.getX() + newBox.getX(), loc.getY() + newBox.getY(), loc.getZ() + newBox.getZ()); + .newInstance(loc.getX() - (newBox.getX() / 2), loc.getY(), loc.getZ() - (newBox.getZ() / 2), + loc.getX() + (newBox.getX() / 2), loc.getY() + newBox.getY(), + loc.getZ() + (newBox.getZ() / 2)); setBoundingBoxMethod.invoke(getNmsEntity(entity), boundingBox); }