mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-27 14:13:11 +02:00
The idea of choosing a simple implementation was to skip debugging.
This commit is contained in:
parent
889d21c1d5
commit
cce7e76211
@ -20,6 +20,7 @@ import org.bukkit.block.Block;
|
||||
|
||||
import fr.neatmonster.nocheatplus.components.location.IGetBlockPosition;
|
||||
import fr.neatmonster.nocheatplus.components.location.IGetLocationWithLook;
|
||||
import fr.neatmonster.nocheatplus.components.location.IGetPosition;
|
||||
import fr.neatmonster.nocheatplus.components.location.IGetPositionWithLook;
|
||||
import fr.neatmonster.nocheatplus.components.location.ISetPositionWithLook;
|
||||
import fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation;
|
||||
@ -365,6 +366,16 @@ public class LocUtil {
|
||||
return "x=" + loc.getX() + ",y=" + loc.getY() + ",z=" + loc.getZ() + ",pitch=" + loc.getPitch() + ",yaw=" + loc.getYaw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format like Location.toString, but without extras like the world name.
|
||||
*
|
||||
* @param loc
|
||||
* @return
|
||||
*/
|
||||
public static String simpleFormat(final IGetPosition loc) {
|
||||
return "x=" + loc.getX() + ",y=" + loc.getY() + ",z=" + loc.getZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Just the coordinates, no world/yaw/pitch.
|
||||
* @param loc
|
||||
|
@ -80,6 +80,7 @@ public class CollideRayVsAABB implements ICollideRayVsAABB {
|
||||
final double tMaxX = CollisionUtil.getMaxTimeIncludeEdges(startX, dirX, minX, maxX, tMinX);
|
||||
final double tMaxY = CollisionUtil.getMaxTimeIncludeEdges(startY, dirY, minY, maxY, tMinY);
|
||||
final double tMaxZ = CollisionUtil.getMaxTimeIncludeEdges(startZ, dirZ, minZ, maxZ, tMinZ);
|
||||
//System.out.println("TIMING: " + tMinX + " " + tMinY + " " + tMinZ + " " + tMaxX + " " + tMaxY + " " + tMaxZ);
|
||||
if (tMaxX != Double.NaN && tMaxY != Double.NaN && tMaxZ != Double.NaN) {
|
||||
// (Excludes any tMin value to be Double.MAX_VALUE.)
|
||||
// Determine if there is overlapping intervals.
|
||||
@ -90,6 +91,7 @@ public class CollideRayVsAABB implements ICollideRayVsAABB {
|
||||
closestX = startX + dirX * tMin;
|
||||
closestY = startY + dirY * tMin;
|
||||
closestZ = startZ + dirZ * tMin;
|
||||
closestTime = tMin;
|
||||
}
|
||||
else if (findNearestPointIfNotCollide) {
|
||||
findNearestPoint(tMinX, tMinY, tMinZ, tMaxX, tMaxY, tMaxZ);
|
||||
@ -122,7 +124,7 @@ public class CollideRayVsAABB implements ICollideRayVsAABB {
|
||||
for (int i = 0; i < timeValues.length; i++) {
|
||||
final double time = timeValues[i];
|
||||
if (time == Double.NaN || time == Double.POSITIVE_INFINITY) {
|
||||
// Note that Double.POSITIVE_INFINITY means that we are colliding forever.
|
||||
// Note that Double.POSITIVE_INFINITY could mean that we are either colliding forever, or never.
|
||||
continue;
|
||||
}
|
||||
final double x = startX + dirX * time;
|
||||
|
@ -375,10 +375,10 @@ public class CollisionUtil {
|
||||
return Double.NaN;
|
||||
}
|
||||
else if (dir == 0.0) {
|
||||
return pos < maxPos || pos > maxPos ? Double.NaN : Double.POSITIVE_INFINITY;
|
||||
return (pos < minPos || pos > maxPos) ? Double.NaN : Double.POSITIVE_INFINITY;
|
||||
}
|
||||
else if (dir < 0.0) {
|
||||
return pos < minPos ? Double.NaN : (Math.abs(pos - minPos) / dir);
|
||||
return pos < minPos ? Double.NaN : (Math.abs(pos - minPos) / Math.abs(dir));
|
||||
}
|
||||
else {
|
||||
// dir > 0.0
|
||||
|
@ -127,10 +127,10 @@ public interface ICollideRayVsAABB extends IGetPosition {
|
||||
public boolean collides();
|
||||
|
||||
/**
|
||||
* Get some kind of squared distance for the nearest point, in case of not
|
||||
* colliding and findNearestPointIfNotCollid being set.
|
||||
* Get some kind of squared distance from the nearest point towards the
|
||||
* AABB, in case of not colliding and findNearestPointIfNotCollid being set.
|
||||
*
|
||||
* @return 0.0 if not applicable.
|
||||
* @return 0.0 if colliding.
|
||||
*/
|
||||
public double getClosestDistanceSquared();
|
||||
|
||||
|
@ -0,0 +1,64 @@
|
||||
package fr.neatmonster.nocheatplus;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.moving.location.LocUtil;
|
||||
import fr.neatmonster.nocheatplus.utilities.collision.CollideRayVsAABB;
|
||||
import fr.neatmonster.nocheatplus.utilities.collision.ICollideRayVsAABB;
|
||||
|
||||
public class TestICollideRayVsAABB {
|
||||
|
||||
@Test
|
||||
public void testBlocks() {
|
||||
|
||||
ICollideRayVsAABB boulder = new CollideRayVsAABB();
|
||||
boulder.setFindNearestPointIfNotCollide(true); // Prefer to have the option.
|
||||
|
||||
// Simple x.
|
||||
if (!boulder.setRay(0.5, 1.75, 0.5, 1.0, 0.0, 0.0)
|
||||
.setAABB(3, 1, 0, 0.0)
|
||||
.loop()
|
||||
.collides()) {
|
||||
doFail(boulder);
|
||||
}
|
||||
if (!boulder.setRay(0.5, 1.75, 0.5, -1.0, 0.0, 0.0)
|
||||
.setAABB(-3, 1, 0, 0.0)
|
||||
.loop()
|
||||
.collides()) {
|
||||
doFail(boulder);
|
||||
}
|
||||
// Simple y.
|
||||
if (!boulder.setRay(0.5, 1.75, 0.5, 0.0, 1.0, 0.0)
|
||||
.setAABB(0, 3, 0, 0.0)
|
||||
.loop()
|
||||
.collides()) {
|
||||
doFail(boulder);
|
||||
}
|
||||
if (!boulder.setRay(0.5, 1.75, 0.5, 0.0, -1.0, 0.0)
|
||||
.setAABB(0, -3, 0, 0.0)
|
||||
.loop()
|
||||
.collides()) {
|
||||
doFail(boulder);
|
||||
}
|
||||
// Simple z.
|
||||
if (!boulder.setRay(0.5, 1.75, 0.5, 0.0, 0.0, 1.0)
|
||||
.setAABB(0, 1, 3, 0.0)
|
||||
.loop()
|
||||
.collides()) {
|
||||
doFail(boulder);
|
||||
}
|
||||
if (!boulder.setRay(0.5, 1.75, 0.5, 0.0, 0.0, -1.0)
|
||||
.setAABB(0, 1, -3, 0.0)
|
||||
.loop()
|
||||
.collides()) {
|
||||
doFail(boulder);
|
||||
}
|
||||
}
|
||||
|
||||
private void doFail(ICollideRayVsAABB boulder) {
|
||||
fail("Failed: collides: " + boulder.collides() + " , distSq: " + boulder.getClosestDistanceSquared() + " , pos: " + LocUtil.simpleFormat(boulder));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user