mirror of
https://github.com/ViaVersion/ViaRewind-Legacy-Support.git
synced 2024-09-28 03:57:49 +02:00
Fix for Tunity bounding boxes (#28)
This commit is contained in:
parent
a782c6aac3
commit
187e1cbd55
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user