Prevent passable from resetting to the "to"- position.

This commit is contained in:
asofold 2012-10-18 16:21:07 +02:00
parent d6d1e319a9
commit d49aacd231
2 changed files with 29 additions and 3 deletions

View File

@ -33,10 +33,14 @@ public class Passable extends Check {
if (blockMiddle.distanceSquared(from.getVector()) < blockMiddle.distanceSquared(to.getVector())) {
// Further check for the players location as possible set back.
loc = player.getLocation();
if (!BlockProperties.isPassable(from.getBlockAccess(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))){
if (to.isSamePos(loc) ){
loc = null;
}
else if (!BlockProperties.isPassable(from.getBlockAccess(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))){
// Allow the move
return null;
}
// else is passable: use the location instead of from.
}
}
}
@ -50,7 +54,7 @@ public class Passable extends Check {
if (!from.isPassable() && loc == null){
// Check if passable.
loc = player.getLocation();
if (!BlockProperties.isPassable(from.getBlockAccess(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(from.getBlockX(), from.getBlockY(), from.getBlockZ()))){
if (to.isSamePos(loc) || !BlockProperties.isPassable(from.getBlockAccess(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(from.getBlockX(), from.getBlockY(), from.getBlockZ()))){
loc = null;
}
}

View File

@ -175,10 +175,32 @@ public class PlayerLocation {
return blockZ;
}
/**
* Compares block coordinates (not the world).
* @param other
* @return
*/
public final boolean isSameBlock(final PlayerLocation other) {
// Maybe make block coordinate fields later.
return blockX == other.getBlockX() && blockZ == other.getBlockZ() && blockY == other.getBlockY();
}
/**
* Compares exact coordinates (not the world).
* @param loc
* @return
*/
public boolean isSamePos(final PlayerLocation loc) {
return x == loc.getX() && z == loc.getZ() && y == loc.getY();
}
/**
* Compares exact coordinates (not the world).
* @param loc
* @return
*/
public boolean isSamePos(final Location loc) {
return x == loc.getX() && z == loc.getZ() && y == loc.getY();
}
/**
* Checks if the player is above stairs.