Fix bounding boxes

This commit is contained in:
libraryaddict 2018-10-24 11:09:16 +13:00
parent 1c04576ae3
commit dda362f082
2 changed files with 57 additions and 52 deletions

View File

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

View File

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