Fix for Tunity bounding boxes (#28)

This commit is contained in:
Pierre Maurice Schwang 2021-07-20 00:55:45 +02:00 committed by GitHub
parent a782c6aac3
commit 187e1cbd55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,9 +5,11 @@ import de.gerrygames.viarewind.legacysupport.BukkitPlugin;
import de.gerrygames.viarewind.legacysupport.reflection.ReflectionAPI;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.stream.Stream;
public class BoundingBoxFixer {
@ -67,9 +69,29 @@ public class BoundingBoxFixer {
return;
}
// Tuinity support
if (boundingBox.getClass().getSimpleName().equals("AABBVoxelShape")) {
setAABBVoxelShape(boundingBox, values);
return;
}
throw new IllegalStateException("Unknown bounding box type: " + boundingBox.getClass().getName());
}
private static void setAABBVoxelShape(Object boundingBox, double[] values) throws ReflectiveOperationException {
for (Field field : boundingBox.getClass().getFields()) {
// Set data for internally used AxisAlignedBB
if (field.getType().getSimpleName().equals("AxisAlignedBB")) {
setBoundingBox(field.get(boundingBox), values);
}
// Clear the cache
if (field.getType().getSimpleName().equals("DoubleList")) {
Object doubleList = field.get(boundingBox);
doubleList.getClass().getMethod("clear").invoke(doubleList);
}
}
}
private static void setAxisAlignedBB(Object boundingBox, double[] values) throws ReflectiveOperationException {
Field[] doubleFields = Arrays.stream(boundingBox.getClass().getDeclaredFields())
.filter(f -> f.getType() == double.class)