Reorder isOnGround, remove unreliable "short-cut".

This commit is contained in:
asofold 2013-03-04 22:24:44 +01:00
parent 078c567e4b
commit 1cc18db8be

View File

@ -431,30 +431,39 @@ public class PlayerLocation {
* @return true, if the player is on ground * @return true, if the player is on ground
*/ */
public boolean isOnGround() { public boolean isOnGround() {
if (onGround == null) { if (onGround != null){
// Check cached values and simplifications. return onGround;
if (notOnGroundMaxY >= yOnGround) onGround = false; }
else if (onGroundMinY <= yOnGround) onGround = true; // Check cached values and simplifications.
else{ if (notOnGroundMaxY >= yOnGround) onGround = false;
if (blockFlags == null || (blockFlags.longValue() & BlockProperties.F_GROUND) != 0){ else if (onGroundMinY <= yOnGround) onGround = true;
final int id = getTypeIdBelow(); else{
if (BlockProperties.isGround(id) && BlockProperties.collidesBlock(blockCache, x, minY - yOnGround, z, x, minY, z, blockX, blockY - 1, blockZ, id)){ if (blockFlags == null || (blockFlags.longValue() & BlockProperties.F_GROUND) != 0){
onGround = true; // // TODO: Consider dropping this shortcut.
} // final int id = getTypeIdBelow();
else{ // final long flags = BlockProperties.getBlockFlags(id);
// Full on-ground check (blocks). // if ((flags & BlockProperties.F_GROUND) != 0 && (flags & BlockProperties.F_VARIABLE) == 0){
// Note: Might check for half-block height too (getTypeId), but that is much more seldom. // final double[] bounds = blockCache.getBounds(blockX, blockY -1, blockZ);
onGround = BlockProperties.isOnGround(blockCache, minX, minY - yOnGround, minZ, maxX, minY, maxZ, 0L); // if (BlockProperties.collidesBlock(blockCache, x, minY - yOnGround, z, x, minY, z, blockX, blockY - 1, blockZ, id, bounds, flags)){
} // // TODO: passable vs maxY ?
} // if (!BlockProperties.isPassableWorkaround(blockCache, blockX, blockY - 1, blockZ, id, minX, minY, minZ, maxX, minY, maxZ)){
else onGround = false; // onGround = true;
// }
// }
// }
// if (onGround == null){
// Full on-ground check (blocks).
// Note: Might check for half-block height too (getTypeId), but that is much more seldom.
onGround = BlockProperties.isOnGround(blockCache, minX, minY - yOnGround, minZ, maxX, minY, maxZ, 0L);
// }
} }
if (!onGround) { else onGround = false;
final double d1 = 0.25D; }
onGround = blockCache.standsOnEntity(player, minX - d1, minY - yOnGround - d1, minZ - d1, maxX + d1, minY + 0.25 + d1, maxZ + d1); if (onGround) onGroundMinY = Math.min(onGroundMinY, yOnGround);
} else{
if (onGround) onGroundMinY = Math.min(onGroundMinY, yOnGround); notOnGroundMaxY = Math.max(notOnGroundMaxY, yOnGround);
else notOnGroundMaxY = Math.max(notOnGroundMaxY, yOnGround); final double d1 = 0.25D;
onGround = blockCache.standsOnEntity(player, minX - d1, minY - yOnGround - d1, minZ - d1, maxX + d1, minY + 0.25 + d1, maxZ + d1);
} }
return onGround; return onGround;
} }
@ -676,7 +685,7 @@ public class PlayerLocation {
* @param player * @param player
* the player * the player
*/ */
public void set(final Location location, final Player player, final double yFreedom) public void set(final Location location, final Player player, final double yOnGround)
{ {
// Entity reference. // Entity reference.
@ -726,10 +735,7 @@ public class PlayerLocation {
notOnGroundMaxY = Double.MIN_VALUE; notOnGroundMaxY = Double.MIN_VALUE;
blockFlags = null; blockFlags = null;
// TODO: Consider blockCache.setAccess? <- currently rather not, because this.yOnGround = yOnGround;
// it might be anything.
this.setyOnGround(yFreedom);
} }
/** /**