Complete frostwalker usage

This commit is contained in:
ZacSharp 2022-08-29 16:59:01 +02:00
parent e75a4b95cc
commit da998eb469
No known key found for this signature in database
GPG Key ID: 9453647B005083A3
6 changed files with 24 additions and 10 deletions

View File

@ -116,6 +116,8 @@ public final class Settings {
/**
* Allow Baritone to assume it can walk on still water just like any other block.
* This functionality is assumed to be provided by a separate library that might have imported Baritone.
* <p>
* Note: This will prevent some usage of the frostwalker enchantment, like pillaring up from water.
*/
public final Setting<Boolean> assumeWalkOnWater = new Setting<>(false);

View File

@ -30,6 +30,7 @@ import baritone.utils.ToolSet;
import net.minecraft.block.*;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
@ -366,6 +367,13 @@ public interface MovementHelper extends ActionCosts, Helper {
&& ((Integer) state.getValue(BlockLiquid.LEVEL)) == 0;
}
static boolean canUseFrostWalker(IPlayerContext ctx, BlockPos pos) {
IBlockState state = BlockStateInterface.get(ctx, pos);
return EnchantmentHelper.hasFrostWalkerEnchantment(ctx.player())
&& (state.getBlock() == Blocks.WATER || state.getBlock() == Blocks.FLOWING_WATER)
&& ((Integer) state.getValue(BlockLiquid.LEVEL)) == 0;
}
static boolean canPlaceAgainst(BlockStateInterface bsi, int x, int y, int z) {
return canPlaceAgainst(bsi, x, y, z, bsi.get0(x, y, z));
}

View File

@ -110,7 +110,7 @@ public class MovementDescend extends Movement {
if (destDown.getBlock() == Blocks.LADDER || destDown.getBlock() == Blocks.VINE) {
return;
}
if (MovementHelper.canUseFrostWalker(context, destDown)) {
if (MovementHelper.canUseFrostWalker(context, destDown)) { // no need to check assumeWalkOnWater
return; // the water will freeze when we try to walk into it
}

View File

@ -30,6 +30,7 @@ import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult;
import com.google.common.collect.ImmutableSet;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.init.Blocks;
@ -117,6 +118,7 @@ public class MovementDiagonal extends Movement {
boolean ascend = false;
IBlockState destWalkOn;
boolean descend = false;
boolean frostWalker = false;
if (!MovementHelper.canWalkThrough(context.bsi, destX, y, destZ, destInto)) {
ascend = true;
if (!context.allowDiagonalAscend || !MovementHelper.canWalkThrough(context.bsi, x, y + 2, z) || !MovementHelper.canWalkOn(context.bsi, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi, destX, y + 2, destZ)) {
@ -125,9 +127,8 @@ public class MovementDiagonal extends Movement {
destWalkOn = destInto;
} else {
destWalkOn = context.get(destX, y - 1, destZ);
if (!MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destWalkOn)
&& !MovementHelper.canUseFrostWalker(context, destWalkOn)
) {
frostWalker = MovementHelper.canUseFrostWalker(context, destWalkOn) && !(context.assumeWalkOnWater && context.getBlock(x, y - 1, z) instanceof BlockLiquid);
if (!MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destWalkOn) && !frostWalker) {
descend = true;
if (!context.allowDiagonalDescend || !MovementHelper.canWalkOn(context.bsi, destX, y - 2, destZ) || !MovementHelper.canWalkThrough(context.bsi, destX, y - 1, destZ, destWalkOn)) {
return;
@ -138,8 +139,8 @@ public class MovementDiagonal extends Movement {
// For either possible soul sand, that affects half of our walking
if (destWalkOn.getBlock() == Blocks.SOUL_SAND) {
multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
} else if (!ascend && !descend && MovementHelper.canUseFrostWalker(context, destWalkOn)) {
// frostwalker lets us walk on water without the penalty, but only works if we don't ascend or descend
} else if (frostWalker) {
// frostwalker lets us walk on water without the penalty
} else if (destWalkOn.getBlock() == Blocks.WATER) {
multiplier += context.walkOnWaterOnePenalty * SQRT_2;
}

View File

@ -94,7 +94,8 @@ public class MovementParkour extends Movement {
if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn)) {
return;
}
if (standingOn.getBlock() instanceof BlockLiquid && !MovementHelper.canUseFrostWalker(context, standingOn)) {
// we can't jump from (frozen) water with assumeWalkOnWater because we can't be sure it will be frozen
if (standingOn.getBlock() instanceof BlockLiquid && (!MovementHelper.canUseFrostWalker(context, standingOn) || context.assumeWalkOnWater)) {
return;
}
int maxJump;
@ -138,6 +139,7 @@ public class MovementParkour extends Movement {
// check for flat landing position
IBlockState landingOn = context.bsi.get0(destX, y - 1, destZ);
// farmland needs to be canWalkOn otherwise farm can never work at all, but we want to specifically disallow ending a jump on farmland haha
// frostwalker works here because we can't jump from possibly unfrozen water
if ((landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, landingOn))
|| (Math.min(16, context.frostWalker + 2) >= i && MovementHelper.canUseFrostWalker(context, landingOn))
) {

View File

@ -82,8 +82,9 @@ public class MovementTraverse extends Movement {
} else {
if (destOn.getBlock() == Blocks.SOUL_SAND) {
WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
} else if (destOn.getBlock() == Blocks.WATER && !MovementHelper.canUseFrostWalker(context, destOn)) {
// with frostwalker we can walk on water without the penalty
} else if (MovementHelper.canUseFrostWalker(context, destOn) && !context.assumeWalkOnWater) {
// with frostwalker we can walk on water without the penalty, if we are sure we won't be using jesus
} else if (destOn.getBlock() == Blocks.WATER) {
WC += context.walkOnWaterOnePenalty;
}
if (srcDown == Blocks.SOUL_SAND) {
@ -228,7 +229,7 @@ public class MovementTraverse extends Movement {
}
}
boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(ctx, positionToPlace) || ladder || EnchantmentHelper.hasFrostWalkerEnchantment(ctx.player());
boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(ctx, positionToPlace) || ladder || MovementHelper.canUseFrostWalker(ctx, positionToPlace);
BlockPos feet = ctx.playerFeet();
if (feet.getY() != dest.getY() && !ladder) {
logDebug("Wrong Y coordinate");