Fix the bounding box problems. Now just block glitching and suffocation

This commit is contained in:
libraryaddict 2013-12-22 14:30:15 +13:00
parent f6d0994079
commit d00d10f3a8
2 changed files with 25 additions and 33 deletions

View File

@ -136,28 +136,26 @@ public class DisguiseUtilities {
// TODO Slimes
Entity entity = disguise.getEntity();
if (entity != null) {
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());
} else {
DisguiseValues values = DisguiseValues.getDisguiseValues(DisguiseType.getType(entity.getType()));
FakeBoundingBox fakeBox = values.getAdultBox();
if (values.getBabyBox() != 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())) {
fakeBox = values.getBabyBox();
entityBox = entityValues.getBabyBox();
}
}
ReflectionManager.setBoundingBox(disguise.getEntity(), fakeBox.getX(), fakeBox.getY(), fakeBox.getZ());
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)) {
ReflectionManager.setBoundingBox(entity, entityBox, disguiseBox);
} else {
ReflectionManager.setBoundingBox(entity, disguiseBox, entityBox);
}
}
}

View File

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