Run passable ignoring sneaking. Adjust box height for REL.

This commit is contained in:
asofold 2016-08-07 15:18:45 +02:00
parent cec7927850
commit 48a7e9c0e1
3 changed files with 35 additions and 16 deletions

View File

@ -21,14 +21,17 @@ import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.collision.CollisionUtil;
import fr.neatmonster.nocheatplus.utilities.location.TrigUtil;
import fr.neatmonster.nocheatplus.checks.moving.location.LocUtil;
import fr.neatmonster.nocheatplus.utilities.collision.CollideRayVsAABB;
import fr.neatmonster.nocheatplus.utilities.collision.ICollideRayVsAABB;
/**
* The Direction check will find out if a player tried to interact with something that's not in their field of view.
*/
public class Direction extends Check {
private final ICollideRayVsAABB boulder = new CollideRayVsAABB();
/**
* Instantiates a new direction check.
*/
@ -49,15 +52,22 @@ public class Direction extends Check {
boolean cancel = false;
// How far "off" is the player with their aim. We calculate from the players eye location and view direction to
// the center of the target block. If the line of sight is more too far off, "off" will be bigger than 0.
// How far "off" is the player with their aim.
final Vector direction = loc.getDirection();
final double off = CollisionUtil.directionCheck(loc, player.getEyeHeight(), direction, block, TrigUtil.DIRECTION_PRECISION);
// Initialize fully each time.
boulder.setFindNearestPointIfNotCollide(true)
.setRay(loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ(),
direction.getX(), direction.getY(), direction.getZ())
.setAABB(block.getX(), block.getY(), block.getZ(), 0.1)
.loop();
// TODO: if (boulder.collides()) { // Check flying queue.
if (off > 0.1D) {
// Player failed the check. Let's try to guess how far they were from looking directly to the block...
final Vector blockEyes = new Vector(0.5 + block.getX() - loc.getX(), 0.5 + block.getY() - loc.getY() - player.getEyeHeight(), 0.5 + block.getZ() - loc.getZ());
final double distance = blockEyes.crossProduct(direction).length() / direction.length();
if (!boulder.collides()) {
final double distance = Math.sqrt(boulder.getClosestDistanceSquared());
if (data.debug) {
outputDebugFail(player, boulder, distance);
}
// Add the overall violation level of the check.
data.directionVL += distance;
@ -67,10 +77,16 @@ public class Direction extends Check {
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = executeActions(player, data.directionVL, distance, cc.directionActions).willCancel();
} else
} else {
// Player did likely nothing wrong, reduce violation counter to reward them.
data.directionVL *= 0.9D;
}
return cancel;
}
private void outputDebugFail(Player player, ICollideRayVsAABB boulder, double distance) {
debug(player, "Failed: collides: " + boulder.collides() + " , dist: " + distance + " , pos: " + LocUtil.simpleFormat(boulder));
}
}

View File

@ -132,7 +132,7 @@ public class Passable extends Check {
* @param from
*/
private void setNormalMargins(final ICollidePassable rayTracing, final PlayerLocation from) {
rayTracing.setMargins(from.getEyeHeight() * rt_heightFactor, from.getWidth() / 2.0 * rt_xzFactor); // max from/to + resolution ?
rayTracing.setMargins(from.getBoxMarginVertical() * rt_heightFactor, from.getWidth() / 2.0 * rt_xzFactor); // max from/to + resolution ?
}
/**
@ -334,8 +334,8 @@ public class Passable extends Check {
// Keep loc as set-back.
// }
else if (manhattan == 1 && to.isBlockAbove(from)
&& BlockProperties.isPassable(from.getBlockCache(), from.getX(), from.getY() + player.getEyeHeight(), from.getZ(), from.getTypeId(from.getBlockX(), Location.locToBlock(from.getY() + player.getEyeHeight()), from.getBlockZ()))) {
// else if (to.isBlockAbove(from) && BlockProperties.isPassableExact(from.getBlockCache(), from.getX(), from.getY() + player.getEyeHeight(), from.getZ(), from.getTypeId(from.getBlockX(), Location.locToBlock(from.getY() + player.getEyeHeight()), from.getBlockZ()))) {
&& BlockProperties.isPassable(from.getBlockCache(), from.getX(), from.getY() + from.getBoxMarginVertical(), from.getZ(), from.getTypeId(from.getBlockX(), Location.locToBlock(from.getY() + from.getBoxMarginVertical()), from.getBlockZ()))) {
// else if (to.isBlockAbove(from) && BlockProperties.isPassableExact(from.getBlockCache(), from.getX(), from.getY() + from.getBoxMarginVertical(), from.getZ(), from.getTypeId(from.getBlockX(), Location.locToBlock(from.getY() + from.getBoxMarginVertical()), from.getBlockZ()))) {
// Allow the move up if the head is free.
return null;
}

View File

@ -330,7 +330,9 @@ public class RichEntityLocation extends RichBoundsLocation {
}
/**
* Do set.
* Do set.<br>
* For the bounding box height, the maximum of given fullHeight, eyeHeight
* with sneaking ignored and entity height is used.
*
* @param location
* the location
@ -346,8 +348,9 @@ public class RichEntityLocation extends RichBoundsLocation {
protected void doSet(final Location location, final Entity entity, final double fullWidth, double fullHeight, final double yOnGround) {
if (entity instanceof LivingEntity) {
isLiving = true;
eyeHeight = ((LivingEntity) entity).getEyeHeight();
fullHeight = Math.max(fullHeight, eyeHeight);
final LivingEntity living = (LivingEntity) entity;
eyeHeight = living.getEyeHeight();
fullHeight = Math.max(Math.max(fullHeight, eyeHeight), living.getEyeHeight(true));
}
else {
isLiving = false;