Some working code for apple

This commit is contained in:
libraryaddict 2013-12-22 16:58:49 +13:00
parent aa32f49bbe
commit 0f280da385
3 changed files with 49 additions and 15 deletions

View File

@ -211,7 +211,6 @@ public class LibsDisguises extends JavaPlugin {
} }
// Get the bounding box // Get the bounding box
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity)); disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
if (bukkitEntity instanceof Ageable) { if (bukkitEntity instanceof Ageable) {
((Ageable) bukkitEntity).setBaby(); ((Ageable) bukkitEntity).setBaby();

View File

@ -12,15 +12,15 @@ public class FakeBoundingBox {
} }
public double getX() { public double getX() {
return xMod; return xMod / 2;
} }
public double getY() { public double getY() {
return yMod; return yMod / 2;
} }
public double getZ() { public double getZ() {
return zMod; return zMod / 2;
} }
} }

View File

@ -87,10 +87,38 @@ public class ReflectionManager {
public static FakeBoundingBox getBoundingBox(Entity entity) { public static FakeBoundingBox getBoundingBox(Entity entity) {
try { try {
float length = getNmsClass("Entity").getField("length").getFloat(getNmsEntity(entity)); Object boundingBox = getNmsClass("Entity").getField("boundingBox").get(getNmsEntity(entity));
float width = getNmsClass("Entity").getField("width").getFloat(getNmsEntity(entity)); double x = 0, y = 0, z = 0;
float height = getNmsClass("Entity").getField("height").getFloat(getNmsEntity(entity)); int stage = 0;
return new FakeBoundingBox(length, width, height); for (Field field : boundingBox.getClass().getFields()) {
if (field.getType().getSimpleName().equals("double")) {
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??");
}
}
}
return new FakeBoundingBox(x, y, z);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -213,34 +241,41 @@ public class ReflectionManager {
try { try {
Object boundingBox = getNmsClass("Entity").getField("boundingBox").get(getNmsEntity(entity)); Object boundingBox = getNmsClass("Entity").getField("boundingBox").get(getNmsEntity(entity));
int stage = 0; int stage = 0;
double x = newBox.getX(), y = newBox.getY(), z = newBox.getZ(); double x = 0, y = 0, z = 0;
for (Field field : boundingBox.getClass().getFields()) { for (Field field : boundingBox.getClass().getFields()) {
if (field.getType().getSimpleName().equals("double")) { if (field.getType().getSimpleName().equals("double")) {
stage++; stage++;
switch (stage) { switch (stage) {
case 1: case 1:
x += field.getDouble(boundingBox); x = field.getDouble(boundingBox) + oldBox.getX();
field.setDouble(boundingBox, x - newBox.getX());
break; break;
case 2: case 2:
y += field.getDouble(boundingBox); y = field.getDouble(boundingBox) + oldBox.getY();
field.setDouble(boundingBox, y - newBox.getY());
break; break;
case 3: case 3:
z += field.getDouble(boundingBox); z = field.getDouble(boundingBox) + oldBox.getZ();
field.setDouble(boundingBox, z - newBox.getZ());
break; break;
case 4: case 4:
field.setDouble(boundingBox, x); field.setDouble(boundingBox, x + newBox.getX());
break; break;
case 5: case 5:
field.setDouble(boundingBox, y); field.setDouble(boundingBox, y + newBox.getY());
break; break;
case 6: case 6:
field.setDouble(boundingBox, z); field.setDouble(boundingBox, z + newBox.getZ());
break; break;
default: default:
throw new Exception("Error while setting the bounding box, more doubles than I thought??"); throw new Exception("Error while setting the bounding box, more doubles than I thought??");
} }
} }
} }
if (entity.getType() != EntityType.PLAYER) {
// entity.teleport(entity.getLocation().clone()
// .subtract(oldBox.getX() - newBox.getX(), oldBox.getY() - newBox.getY(), oldBox.getZ() - newBox.getZ()));
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }