mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-27 14:13:11 +02:00
ReflectBlock: fix block shape access for 1.11.
This commit is contained in:
parent
12ce099eb1
commit
bf32406435
@ -18,6 +18,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import fr.neatmonster.nocheatplus.compat.cbreflect.reflect.ReflectHelper.ReflectFailureException;
|
import fr.neatmonster.nocheatplus.compat.cbreflect.reflect.ReflectHelper.ReflectFailureException;
|
||||||
|
import fr.neatmonster.nocheatplus.compat.versions.ServerVersion;
|
||||||
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,6 +36,7 @@ public class ReflectBlock implements IReflectBlock {
|
|||||||
private final ReflectBlockPosition reflectBlockPosition;
|
private final ReflectBlockPosition reflectBlockPosition;
|
||||||
private final ReflectAxisAlignedBB reflectAxisAlignedBB;
|
private final ReflectAxisAlignedBB reflectAxisAlignedBB;
|
||||||
private final ReflectIBlockData reflectIBlockData;
|
private final ReflectIBlockData reflectIBlockData;
|
||||||
|
private final ReflectIBlockAccess reflectIBlockAccess;
|
||||||
private final ReflectWorld reflectWorld;
|
private final ReflectWorld reflectWorld;
|
||||||
|
|
||||||
// Static.
|
// Static.
|
||||||
@ -65,7 +67,7 @@ public class ReflectBlock implements IReflectBlock {
|
|||||||
if (reflectWorld.nmsClass == null || reflectWorld.nmsGetType == null) {
|
if (reflectWorld.nmsClass == null || reflectWorld.nmsGetType == null) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
ReflectIBlockAccess reflectIBlockAccess = new ReflectIBlockAccess(base);
|
this.reflectIBlockAccess = new ReflectIBlockAccess(base);
|
||||||
// Block.
|
// Block.
|
||||||
nmsClass = Class.forName(base.nmsPackageName + ".Block");
|
nmsClass = Class.forName(base.nmsPackageName + ".Block");
|
||||||
// byID (static)
|
// byID (static)
|
||||||
@ -78,16 +80,46 @@ public class ReflectBlock implements IReflectBlock {
|
|||||||
if (this.nmsGetBlockData == null) {
|
if (this.nmsGetBlockData == null) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
// TODO: a(IBlockData, IBlockAccess, BlockPosition) is deprecated (why / what else?).
|
this.nmsFetchAABB = determine_fetchAABB();
|
||||||
this.nmsFetchAABB = ReflectionUtil.getMethod(nmsClass, "a",
|
if (this.nmsFetchAABB == null) {
|
||||||
reflectIBlockData.nmsClass, reflectIBlockAccess.nmsClass, reflectBlockPosition.nmsClass);
|
|
||||||
if (nmsFetchAABB == null || nmsFetchAABB.getReturnType() != reflectAxisAlignedBB.nmsClass) {
|
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
if (!nmsFetchAABB.isAnnotationPresent(Deprecated.class)) {
|
}
|
||||||
// The final frontier.
|
|
||||||
fail();
|
/**
|
||||||
|
* Fail-safe (return null if not available).
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Method determine_fetchAABB() {
|
||||||
|
Method nmsFetchAABB = null;
|
||||||
|
|
||||||
|
// At least since 1.11.
|
||||||
|
if (ServerVersion.compareMinecraftVersion("1.11") >= 0) {
|
||||||
|
nmsFetchAABB = ReflectionUtil.getMethod(nmsClass, "b",
|
||||||
|
reflectIBlockData.nmsClass, reflectIBlockAccess.nmsClass, reflectBlockPosition.nmsClass);
|
||||||
|
if (nmsFetchAABB != null
|
||||||
|
&& nmsFetchAABB.getReturnType() == reflectAxisAlignedBB.nmsClass
|
||||||
|
&& nmsFetchAABB.isAnnotationPresent(Deprecated.class) // TODO: Why deprecated?
|
||||||
|
) {
|
||||||
|
return nmsFetchAABB;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Legacy (pre 1.11, possibly even before.)
|
||||||
|
if (nmsFetchAABB == null) {
|
||||||
|
nmsFetchAABB = ReflectionUtil.getMethod(nmsClass, "a",
|
||||||
|
reflectIBlockData.nmsClass, reflectIBlockAccess.nmsClass, reflectBlockPosition.nmsClass);
|
||||||
|
if (nmsFetchAABB != null
|
||||||
|
&& nmsFetchAABB.getReturnType() == reflectAxisAlignedBB.nmsClass
|
||||||
|
&& nmsFetchAABB.isAnnotationPresent(Deprecated.class) // TODO: Why deprecated?
|
||||||
|
) {
|
||||||
|
return nmsFetchAABB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing found.
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,7 +173,6 @@ public class ReflectBlock implements IReflectBlock {
|
|||||||
final int x, final int y, final int z) {
|
final int x, final int y, final int z) {
|
||||||
final Object pos = nmsBlockPosition(x, y, z);
|
final Object pos = nmsBlockPosition(x, y, z);
|
||||||
final Object blockData = reflectWorld.nms_getType(nmsWorld, pos);
|
final Object blockData = reflectWorld.nms_getType(nmsWorld, pos);
|
||||||
// TODO: a(IBlockData, IBlockAccess, BlockPosition) is deprecated (why / what else?).
|
|
||||||
final Object bb = nms_fetchAABB(nmsBlock, blockData, nmsWorld, pos);
|
final Object bb = nms_fetchAABB(nmsBlock, blockData, nmsWorld, pos);
|
||||||
if (bb == null) {
|
if (bb == null) {
|
||||||
return new double[] {0.0, 0.0, 0.0, 1.0, 1.0, 1.0}; // Special case.
|
return new double[] {0.0, 0.0, 0.0, 1.0, 1.0, 1.0}; // Special case.
|
||||||
|
Loading…
Reference in New Issue
Block a user