Minor performance gains for high frequency checks

Signed-off-by: Jadon Fowler <j@jadon.io>
This commit is contained in:
James H 2019-04-08 19:01:13 -04:00 committed by Jadon Fowler
parent a25dc44501
commit c4e7969c9b
No known key found for this signature in database
GPG Key ID: C7FF05F3C377725C
2 changed files with 13 additions and 4 deletions

View File

@ -464,20 +464,24 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
MovingUtil.ensureChunksLoaded(player, from, to, lastMove, "move", data, cc);
}
// TODO: On pistons pulling the player back: -1.15 yDistance for split move 1 (untracked position > 0.5 yDistance!).
boolean samePos = TrigUtil.isSamePos(from, loc);
boolean samePos2 = TrigUtil.isSamePos(loc, lastMove.from.getX(), lastMove.from.getY(), lastMove.from.getZ());
if (
// Handling split moves has been disabled.
!cc.splitMoves ||
// The usual case: no micro move happened.
TrigUtil.isSamePos(from, loc)
samePos
// Special case / bug? TODO: Which/why, which version of MC/spigot?
|| lastMove.valid && TrigUtil.isSamePos(loc, lastMove.from.getX(), lastMove.from.getY(), lastMove.from.getZ())
|| lastMove.valid && samePos2
// Could also be other envelopes (0.9 velocity upwards), too tedious to research.
//&& data.lastYDist < -SurvivalFly.GRAVITY_MIN && data.lastYDist > -SurvivalFly.GRAVITY_MAX - SurvivalFly.GRAVITY_MIN
) {
// Fire move from -> to
// (Special case: Location has not been updated last moving event.)
moveInfo.set(player, from, to, cc.yOnGround);
checkPlayerMove(player, from, to, 0, moveInfo, data, cc, event);
if(!samePos || !samePos2) { // only perform move checks if we've actually moved
checkPlayerMove(player, from, to, 0, moveInfo, data, cc, event);
}
}
else {
// Split into two moves.

View File

@ -108,8 +108,13 @@ public final class BridgeEnchant {
* Will return 0 if not available.
*/
public static int getDepthStriderLevel(final Player player) {
// Checking item enchantments requires reading NBT which is expensive,
// and since the advantage is minor, we can just give all players the
// benefit of the doubt and assume they have DEPTH_STRIDER 3 at all times
// to negate the performance loss for this check
return 3;
// Cap at three.
return Math.min(3, getMaxLevelArmor(player, DEPTH_STRIDER));
// return Math.min(3, getMaxLevelArmor(player, DEPTH_STRIDER));
}
}