context specific blockstateinterface lookups. also toxic
This commit is contained in:
@@ -21,7 +21,10 @@ import baritone.Baritone;
|
||||
import baritone.api.pathing.movement.ActionCosts;
|
||||
import baritone.api.utils.*;
|
||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||
import baritone.utils.*;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.ToolSet;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -41,16 +44,16 @@ import net.minecraft.world.chunk.EmptyChunk;
|
||||
*/
|
||||
public interface MovementHelper extends ActionCosts, Helper {
|
||||
|
||||
static boolean avoidBreaking(int x, int y, int z, IBlockState state) {
|
||||
static boolean avoidBreaking(CalculationContext context, int x, int y, int z, IBlockState state) {
|
||||
Block b = state.getBlock();
|
||||
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|
||||
|| b instanceof BlockSilverfish // obvious reasons
|
||||
// call BlockStateInterface.get directly with x,y,z. no need to make 5 new BlockPos for no reason
|
||||
|| BlockStateInterface.get(x, y + 1, z).getBlock() instanceof BlockLiquid//don't break anything touching liquid on any side
|
||||
|| BlockStateInterface.get(x + 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| BlockStateInterface.get(x - 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| BlockStateInterface.get(x, y, z + 1).getBlock() instanceof BlockLiquid
|
||||
|| BlockStateInterface.get(x, y, z - 1).getBlock() instanceof BlockLiquid;
|
||||
// call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason
|
||||
|| context.get(x, y + 1, z).getBlock() instanceof BlockLiquid//don't break anything touching liquid on any side
|
||||
|| context.get(x + 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| context.get(x - 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| context.get(x, y, z + 1).getBlock() instanceof BlockLiquid
|
||||
|| context.get(x, y, z - 1).getBlock() instanceof BlockLiquid;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,14 +63,14 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
* @return
|
||||
*/
|
||||
static boolean canWalkThrough(BetterBlockPos pos) {
|
||||
return canWalkThrough(pos.x, pos.y, pos.z, BlockStateInterface.get(pos));
|
||||
return canWalkThrough(new CalculationContext(), pos.x, pos.y, pos.z, BlockStateInterface.get(pos));
|
||||
}
|
||||
|
||||
static boolean canWalkThrough(int x, int y, int z) {
|
||||
return canWalkThrough(x, y, z, BlockStateInterface.get(x, y, z));
|
||||
static boolean canWalkThrough(CalculationContext context, int x, int y, int z) {
|
||||
return canWalkThrough(context, x, y, z, context.get(x, y, z));
|
||||
}
|
||||
|
||||
static boolean canWalkThrough(int x, int y, int z, IBlockState state) {
|
||||
static boolean canWalkThrough(CalculationContext context, int x, int y, int z, IBlockState state) {
|
||||
Block block = state.getBlock();
|
||||
if (block == Blocks.AIR) { // early return for most common case
|
||||
return true;
|
||||
@@ -108,7 +111,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
if (Baritone.settings().assumeWalkOnWater.get()) {
|
||||
return false;
|
||||
}
|
||||
IBlockState up = BlockStateInterface.get(x, y + 1, z);
|
||||
IBlockState up = context.get(x, y + 1, z);
|
||||
if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) {
|
||||
return false;
|
||||
}
|
||||
@@ -126,8 +129,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static boolean fullyPassable(int x, int y, int z) {
|
||||
return fullyPassable(BlockStateInterface.get(x, y, z));
|
||||
static boolean fullyPassable(CalculationContext context, int x, int y, int z) {
|
||||
return fullyPassable(context.get(x, y, z));
|
||||
}
|
||||
|
||||
static boolean fullyPassable(IBlockState state) {
|
||||
@@ -242,7 +245,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static boolean canWalkOn(int x, int y, int z, IBlockState state) {
|
||||
static boolean canWalkOn(CalculationContext context, int x, int y, int z, IBlockState state) {
|
||||
Block block = state.getBlock();
|
||||
if (block == Blocks.AIR || block == Blocks.MAGMA) {
|
||||
// early return for most common case (air)
|
||||
@@ -264,7 +267,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
if (isWater(block)) {
|
||||
// since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()"
|
||||
// BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think its a decrease in readability
|
||||
Block up = BlockStateInterface.get(x, y + 1, z).getBlock();
|
||||
Block up = context.get(x, y + 1, z).getBlock();
|
||||
if (up == Blocks.WATERLILY) {
|
||||
return true;
|
||||
}
|
||||
@@ -292,19 +295,19 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
}
|
||||
|
||||
static boolean canWalkOn(BetterBlockPos pos, IBlockState state) {
|
||||
return canWalkOn(pos.x, pos.y, pos.z, state);
|
||||
return canWalkOn(new CalculationContext(), pos.x, pos.y, pos.z, state);
|
||||
}
|
||||
|
||||
static boolean canWalkOn(BetterBlockPos pos) {
|
||||
return canWalkOn(pos.x, pos.y, pos.z, BlockStateInterface.get(pos));
|
||||
return canWalkOn(new CalculationContext(), pos.x, pos.y, pos.z, BlockStateInterface.get(pos));
|
||||
}
|
||||
|
||||
static boolean canWalkOn(int x, int y, int z) {
|
||||
return canWalkOn(x, y, z, BlockStateInterface.get(x, y, z));
|
||||
static boolean canWalkOn(CalculationContext context, int x, int y, int z) {
|
||||
return canWalkOn(context, x, y, z, context.get(x, y, z));
|
||||
}
|
||||
|
||||
static boolean canPlaceAgainst(int x, int y, int z) {
|
||||
return canPlaceAgainst(BlockStateInterface.get(x, y, z));
|
||||
static boolean canPlaceAgainst(CalculationContext context, int x, int y, int z) {
|
||||
return canPlaceAgainst(context.get(x, y, z));
|
||||
}
|
||||
|
||||
static boolean canPlaceAgainst(BlockPos pos) {
|
||||
@@ -317,16 +320,16 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
}
|
||||
|
||||
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, boolean includeFalling) {
|
||||
return getMiningDurationTicks(context, x, y, z, BlockStateInterface.get(x, y, z), includeFalling);
|
||||
return getMiningDurationTicks(context, x, y, z, context.get(x, y, z), includeFalling);
|
||||
}
|
||||
|
||||
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
|
||||
Block block = state.getBlock();
|
||||
if (!canWalkThrough(x, y, z, state)) {
|
||||
if (!canWalkThrough(context, x, y, z, state)) {
|
||||
if (!context.canBreakAt(x, y, z)) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (avoidBreaking(x, y, z, state)) {
|
||||
if (avoidBreaking(context, x, y, z, state)) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (block instanceof BlockLiquid) {
|
||||
@@ -341,7 +344,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
double result = m / strVsBlock;
|
||||
result += context.breakBlockAdditionalCost();
|
||||
if (includeFalling) {
|
||||
IBlockState above = BlockStateInterface.get(x, y + 1, z);
|
||||
IBlockState above = context.get(x, y + 1, z);
|
||||
if (above.getBlock() instanceof BlockFalling) {
|
||||
result += getMiningDurationTicks(context, x, y + 1, z, above, true);
|
||||
}
|
||||
@@ -357,10 +360,6 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
&& state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM;
|
||||
}
|
||||
|
||||
static boolean isBottomSlab(BlockPos pos) {
|
||||
return isBottomSlab(BlockStateInterface.get(pos));
|
||||
}
|
||||
|
||||
/**
|
||||
* AutoTool
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user