These should be all the suggested changes for the caching of can walk through block states

This commit is contained in:
scorbett123 2022-07-14 17:18:02 +01:00
parent fdcdcbb85f
commit 6b0fb1721b
4 changed files with 15 additions and 7 deletions

View File

@ -30,6 +30,7 @@ import baritone.utils.ToolSet;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -98,10 +99,12 @@ public interface MovementHelper extends ActionCosts, Helper {
return context.precomputedData.canWalkThrough(context.bsi, x, y, z, context.get(x, y, z)); return context.precomputedData.canWalkThrough(context.bsi, x, y, z, context.get(x, y, z));
} }
static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
Optional<Boolean> canWalkOn = canWalkThroughBlockState(state); Optional<Boolean> canWalkThrough = canWalkThroughBlockState(state);
return canWalkOn.orElseGet(() -> canWalkThroughPosition(bsi, x, y, z, state)); if (canWalkThrough.isPresent()) {
return canWalkThrough.get();
}
return canWalkThroughPosition(bsi, x, y, z, state);
} }
static Optional<Boolean> canWalkThroughBlockState(IBlockState state) { static Optional<Boolean> canWalkThroughBlockState(IBlockState state) {
@ -342,7 +345,10 @@ public interface MovementHelper extends ActionCosts, Helper {
*/ */
static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
Optional<Boolean> canWalkOn = canWalkOnBlockState(state); Optional<Boolean> canWalkOn = canWalkOnBlockState(state);
return canWalkOn.orElseGet(() -> canWalkOnPosition(bsi, x, y, z, state)); if (canWalkOn.isPresent()) {
return canWalkOn.get();
}
return canWalkOnPosition(bsi, x, y, z, state);
} }
static Optional<Boolean> canWalkOnBlockState(IBlockState state) { static Optional<Boolean> canWalkOnBlockState(IBlockState state) {
@ -463,7 +469,7 @@ public interface MovementHelper extends ActionCosts, Helper {
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) { static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
Block block = state.getBlock(); Block block = state.getBlock();
if (!canWalkThrough(context.bsi, x, y, z, state)) { if (!canWalkThrough(context, x, y, z, state)) {
if (block instanceof BlockLiquid) { if (block instanceof BlockLiquid) {
return COST_INF; return COST_INF;
} }

View File

@ -120,7 +120,7 @@ public class MovementPillar extends Movement {
} }
} }
// this is commented because it may have had a purpose, but it's very unclear what it was. it's from the minebot era. // this is commented because it may have had a purpose, but it's very unclear what it was. it's from the minebot era.
//if (!context.precomputedData.canWalkOn(chkPos, check) || context.precomputedData.canWalkThrough(chkPos, check)) {//if the block above where we want to break is not a full block, don't do it //if (!MovementHelper.canWalkOn(context, chkPos, check) || MovementHelper.canWalkThrough(context, chkPos, check)) {//if the block above where we want to break is not a full block, don't do it
// TODO why does canWalkThrough mean this action is COST_INF? // TODO why does canWalkThrough mean this action is COST_INF?
// BlockFalling makes sense, and !canWalkOn deals with weird cases like if it were lava // BlockFalling makes sense, and !canWalkOn deals with weird cases like if it were lava
// but I don't understand why canWalkThrough makes it impossible // but I don't understand why canWalkThrough makes it impossible

View File

@ -24,6 +24,7 @@ import baritone.pathing.movement.MovementHelper;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;

View File

@ -28,6 +28,7 @@ import baritone.cache.CachedChunk;
import baritone.cache.WorldScanner; import baritone.cache.WorldScanner;
import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementHelper;
import baritone.pathing.precompute.PrecomputedData;
import baritone.utils.BaritoneProcessHelper; import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -111,7 +112,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value;
List<BlockPos> curr = new ArrayList<>(knownOreLocations); List<BlockPos> curr = new ArrayList<>(knownOreLocations);
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
CalculationContext context = new CalculationContext(baritone, true, null); // Precomputed data should never be used on this calculation context CalculationContext context = new CalculationContext(baritone, true, new PrecomputedData());
Baritone.getExecutor().execute(() -> rescan(curr, context)); Baritone.getExecutor().execute(() -> rescan(curr, context));
} }
if (Baritone.settings().legitMine.value) { if (Baritone.settings().legitMine.value) {