Skip to content

Commit

Permalink
Revert passable state to last-wins. PassableState priority appears to…
Browse files Browse the repository at this point in the history
… have too much friction, and a custom passable state combining API would run into difficulties with cross-plugin compatibility. One alternative would be to expose some passability bits for ground, water, flying, etc. in the storage to both slightly optimise block lookups and allow safer passability overrides.
  • Loading branch information
fullwall committed Aug 27, 2023
1 parent 555e44d commit 7c80504
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
Expand Up @@ -9,9 +9,5 @@ public enum PassableState {
IGNORE,
PASSABLE,
UNPASSABLE;

public static PassableState fromBoolean(boolean b) {
return b ? PASSABLE : UNPASSABLE;
}
}
}
Expand Up @@ -46,10 +46,10 @@ public PassableState isPassable(BlockSource source, PathPoint point) {
Vector pos = point.getVector();
Block above = source.getBlockAt(pos.clone().add(UP));
Block in = source.getBlockAt(pos);
if (MinecraftBlockExaminer.isLiquid(above.getType(), in.getType())) {
if (MinecraftBlockExaminer.isLiquid(above.getType(), in.getType()))
return PassableState.UNPASSABLE;
}
return PassableState.fromBoolean(MinecraftBlockExaminer.canStandIn(above, in));

return MinecraftBlockExaminer.canStandIn(above, in) ? PassableState.PASSABLE : PassableState.UNPASSABLE;
}

private static final Vector UP = new Vector(0, 1, 0);
Expand Down
Expand Up @@ -73,10 +73,10 @@ public PassableState isPassable(BlockSource source, PathPoint point) {

Vector parentPos = point.getParentPoint().getVector();
if ((parentPos.getX() != pos.getX() || parentPos.getZ() != pos.getZ())
&& pos.clone().subtract(point.getParentPoint().getVector()).getY() == 1) {
&& pos.clone().subtract(point.getParentPoint().getVector()).getY() == 1)
return PassableState.UNPASSABLE;
}
}

return PassableState.PASSABLE;
}

Expand Down
Expand Up @@ -36,12 +36,12 @@ public float getCost(BlockSource source, PathPoint point) {
public PassableState isPassable(BlockSource source, PathPoint point) {
Vector vector = point.getVector();
if (!MinecraftBlockExaminer.isLiquidOrInLiquid(
source.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()))) {
source.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ())))
return PassableState.IGNORE;
}
if (isWaterMob(npc.getEntity())) {

if (isWaterMob(npc.getEntity()))
return PassableState.PASSABLE;
}

Block block = source.getBlockAt(vector.clone().add(UP));
return isSwimmableLiquid(block.getType()) || MinecraftBlockExaminer.canStandIn(block) ? PassableState.PASSABLE
: PassableState.UNPASSABLE;
Expand Down
Expand Up @@ -178,7 +178,7 @@ private boolean isPassable(PathPoint mod) {
PassableState state = examiner.isPassable(info.blockSource, mod);
if (state == PassableState.IGNORE)
continue;
passable &= state == PassableState.PASSABLE ? true : false;
passable = state == PassableState.PASSABLE ? true : false;
}
return passable;
}
Expand Down

0 comments on commit 7c80504

Please sign in to comment.