Move this to a helper method and add missing cases

This commit is contained in:
ZacSharp 2022-09-30 22:27:32 +02:00
parent 45c0b38156
commit c14be17e53
No known key found for this signature in database
GPG Key ID: 9453647B005083A3
3 changed files with 22 additions and 3 deletions

View File

@ -374,6 +374,26 @@ public interface MovementHelper extends ActionCosts, Helper {
&& ((Integer) state.getValue(BlockLiquid.LEVEL)) == 0; && ((Integer) state.getValue(BlockLiquid.LEVEL)) == 0;
} }
/**
* If movements make us stand/walk on this block, will it have a top to walk on?
*/
static boolean mustBeSolidToWalkOn(CalculationContext context, int x, int y, int z, IBlockState state) {
Block block = state.getBlock();
if (block == Blocks.LADDER || block == Blocks.VINE) {
return false;
}
if (block instanceof BlockLiquid) {
if (context.assumeWalkOnWater) {
return false;
}
Block blockAbove = context.getBlock(x, y+1, z);
if (blockAbove instanceof BlockLiquid) {
return false;
}
}
return true;
}
static boolean canPlaceAgainst(BlockStateInterface bsi, int x, int y, int z) { static boolean canPlaceAgainst(BlockStateInterface bsi, int x, int y, int z) {
return canPlaceAgainst(bsi, x, y, z, bsi.get0(x, y, z)); return canPlaceAgainst(bsi, x, y, z, bsi.get0(x, y, z));
} }

View File

@ -127,7 +127,7 @@ public class MovementDiagonal extends Movement {
destWalkOn = destInto; destWalkOn = destInto;
} else { } else {
destWalkOn = context.get(destX, y - 1, destZ); destWalkOn = context.get(destX, y - 1, destZ);
boolean standingOnABlock = !(context.getBlock(x, y - 1, z) instanceof BlockLiquid) || (!context.assumeWalkOnWater && !(context.getBlock(x, y, z) instanceof BlockLiquid)); boolean standingOnABlock = MovementHelper.mustBeSolidToWalkOn(context, x, y-1, z, context.get(x, y-1, z));
frostWalker = standingOnABlock && MovementHelper.canUseFrostWalker(context, destWalkOn); frostWalker = standingOnABlock && MovementHelper.canUseFrostWalker(context, destWalkOn);
if (!MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destWalkOn) && !frostWalker) { if (!MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destWalkOn) && !frostWalker) {
descend = true; descend = true;

View File

@ -73,8 +73,7 @@ public class MovementTraverse extends Movement {
IBlockState pb1 = context.get(destX, y, destZ); IBlockState pb1 = context.get(destX, y, destZ);
IBlockState destOn = context.get(destX, y - 1, destZ); IBlockState destOn = context.get(destX, y - 1, destZ);
Block srcDown = context.getBlock(x, y - 1, z); Block srcDown = context.getBlock(x, y - 1, z);
// if we are on water but are neither in water nor can stand on water we must have placed a block to get here boolean standingOnABlock = MovementHelper.mustBeSolidToWalkOn(context, x, y-1, z, context.get(x, y-1, z));
boolean standingOnABlock = !(srcDown instanceof BlockLiquid) || (!context.assumeWalkOnWater && !(context.getBlock(x, y, z) instanceof BlockLiquid));
boolean frostWalker = standingOnABlock && MovementHelper.canUseFrostWalker(context, destOn); boolean frostWalker = standingOnABlock && MovementHelper.canUseFrostWalker(context, destOn);
if (MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destOn) || frostWalker) { //this is a walk, not a bridge if (MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destOn) || frostWalker) { //this is a walk, not a bridge
double WC = WALK_ONE_BLOCK_COST; double WC = WALK_ONE_BLOCK_COST;