Skip to content

Commit

Permalink
Fix block collisions not working on Paper
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Apr 3, 2024
1 parent a155098 commit 3cc472e
Showing 1 changed file with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.viaversion.viarewind.legacysupport.feature;

import com.viaversion.viarewind.legacysupport.BukkitPlugin;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -77,23 +78,19 @@ public static void fixLadder(final Logger logger, final ProtocolVersion serverVe
}

private static void setBoundingBox(Object boundingBox, double... values) throws ReflectiveOperationException {
if (boundingBox.getClass().getSimpleName().equals("VoxelShapeArray")) {
setVoxelShapeArray(boundingBox, values);
return;
}

if (boundingBox.getClass().getSimpleName().equals("AxisAlignedBB")) {
setAxisAlignedBB(boundingBox, values);
return;
}

// Tuinity support
if (boundingBox.getClass().getSimpleName().equals("AABBVoxelShape")) {
setAABBVoxelShape(boundingBox, values);
return;
switch (boundingBox.getClass().getSimpleName()) {
case "AxisAlignedBB": // Legacy NMS
setAxisAlignedBB(boundingBox, values);
break;
case "VoxelShapeArray": // Paper
setVoxelShapeArray(boundingBox, values);
break;
case "AABBVoxelShape": // Tuinity
setAABBVoxelShape(boundingBox, values);
break;
default:
throw new IllegalStateException("Unknown bounding box type: " + boundingBox.getClass().getName());
}

throw new IllegalStateException("Unknown bounding box type: " + boundingBox.getClass().getName());
}

private static void setAABBVoxelShape(Object boundingBox, double[] values) throws ReflectiveOperationException {
Expand Down Expand Up @@ -143,5 +140,21 @@ private static void setVoxelShapeArray(final Object voxelShapeArray, final doubl
field.setAccessible(true);
field.set(voxelShapeArray, wrapMethod.invoke(null, (Object) array));
}

// Handle Paper voxel shape caching by clearing the cache
final Class<?> voxelShape = voxelShapeArray.getClass().getSuperclass();

final Field shape = getFieldAccessible(voxelShape, "a");
final Field cachedShapeData = getFieldAccessible(shape.getType(), "cachedShapeData");
if (cachedShapeData == null) { // No Paper or too old version
return;
}
cachedShapeData.set(shape.get(voxelShapeArray), null);

final Field isEmpty = getFieldAccessible(voxelShape, "isEmpty");
isEmpty.setBoolean(voxelShapeArray, true);

final Method initCache = voxelShape.getDeclaredMethod("initCache");
initCache.invoke(voxelShapeArray);
}
}

0 comments on commit 3cc472e

Please sign in to comment.