This commit is contained in:
Leijurv 2018-08-06 19:31:10 -07:00
commit beb56dca5b
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
8 changed files with 26 additions and 30 deletions

View File

@ -91,7 +91,7 @@ public abstract class Movement implements Helper, MovementHelper {
return true;
for (BlockPos blockPos : positionsToBreak) {
if (!MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) {
if (!MovementHelper.canWalkThrough(blockPos)) {
Optional<Rotation> reachable = LookBehaviorUtils.reachable(blockPos);
if (reachable.isPresent()) {
state.setTarget(new MovementState.MovementTarget(reachable.get())).setInput(Input.CLICK_LEFT, true);
@ -163,7 +163,7 @@ public abstract class Movement implements Helper, MovementHelper {
//^ the above implementation properly deals with falling blocks, TODO integrate
double sum = 0;
for (BlockPos pos : positionsToBreak) {
sum += MovementHelper.getMiningDurationTicks(ts, BlockStateInterface.get(pos), pos);
sum += MovementHelper.getMiningDurationTicks(ts, pos);
if (sum >= COST_INF) {
return COST_INF;
}
@ -196,7 +196,7 @@ public abstract class Movement implements Helper, MovementHelper {
}
ArrayList<BlockPos> result = new ArrayList<>();
for (BlockPos positionToBreak : positionsToBreak) {
if (!MovementHelper.canWalkThrough(positionToBreak, BlockStateInterface.get(positionToBreak))) {
if (!MovementHelper.canWalkThrough(positionToBreak)) {
result.add(positionToBreak);
}
}

View File

@ -34,7 +34,7 @@ public interface MovementHelper extends ActionCosts, Helper {
static boolean avoidBreaking(BlockPos pos) {
Block b = BlockStateInterface.getBlock(pos);
Block below = BlockStateInterface.get(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())).getBlock();
BlockPos below = new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ());
return Blocks.ICE.equals(b) // ice becomes water, and water can mess up the path
|| b instanceof BlockSilverfish
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))//don't break anything touching liquid on any side
@ -51,14 +51,15 @@ public interface MovementHelper extends ActionCosts, Helper {
* @param pos
* @return
*/
static boolean canWalkThrough(BlockPos pos, IBlockState state) {
static boolean canWalkThrough(BlockPos pos) {
IBlockState state = BlockStateInterface.get(pos);
Block block = state.getBlock();
if (block instanceof BlockLilyPad
|| block instanceof BlockFire
|| block instanceof BlockTripWire) {//you can't actually walk through a lilypad from the side, and you shouldn't walk through fire
return false;
}
if (BlockStateInterface.isFlowing(state) || BlockStateInterface.isLiquid(pos.up())) {
if (BlockStateInterface.isFlowing(pos) || BlockStateInterface.isLiquid(pos.up())) {
return false; // Don't walk through flowing liquids
}
return block.isPassable(mc.world, pos);
@ -79,7 +80,8 @@ public interface MovementHelper extends ActionCosts, Helper {
*
* @return
*/
static boolean canWalkOn(BlockPos pos, IBlockState state) {
static boolean canWalkOn(BlockPos pos) {
IBlockState state = BlockStateInterface.get(pos);
Block block = state.getBlock();
if (block instanceof BlockLadder || block instanceof BlockVine) {
return true;
@ -93,18 +95,14 @@ public interface MovementHelper extends ActionCosts, Helper {
return state.isBlockNormalCube() && !BlockStateInterface.isLava(block);
}
static boolean canWalkOn(BlockPos pos) {
return canWalkOn(pos, BlockStateInterface.get(pos));
}
static boolean canFall(BlockPos pos) {
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
}
static double getMiningDurationTicks(ToolSet ts, IBlockState block, BlockPos position) {
if (!block.equals(Blocks.AIR) && !canWalkThrough(position, block)) {
static double getMiningDurationTicks(ToolSet ts, BlockPos position) {
IBlockState state = BlockStateInterface.get(position);
Block block = state.getBlock();
if (!block.equals(Blocks.AIR) && !canWalkThrough(position)) {
if (avoidBreaking(position)) {
return COST_INF;
}
@ -112,7 +110,7 @@ public interface MovementHelper extends ActionCosts, Helper {
// return COST_INF;
//}
double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1;
return m / ts.getStrVsBlock(block, position) + BREAK_ONE_BLOCK_ADD;
return m / ts.getStrVsBlock(state, position) + BREAK_ONE_BLOCK_ADD;
}
return 0;
}

View File

@ -41,7 +41,7 @@ public class MovementAscend extends Movement {
@Override
protected double calculateCost(ToolSet ts) {
if (!MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) {
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
if (!BlockStateInterface.isAir(positionsToPlace[0]) && !BlockStateInterface.isWater(positionsToPlace[0])) {
return COST_INF;
}

View File

@ -19,7 +19,7 @@ public class MovementDescend extends Movement {
@Override
protected double calculateCost(ToolSet ts) {
if (!MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) {
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
return COST_INF;
}
Block tmp1 = BlockStateInterface.get(dest).getBlock();

View File

@ -44,7 +44,7 @@ public class MovementDownward extends Movement {
@Override
protected double calculateCost(ToolSet ts) {
if (!MovementHelper.canWalkOn(dest.down(), BlockStateInterface.get(dest.down()))) {
if (!MovementHelper.canWalkOn(dest.down())) {
return COST_INF;
}
Block td = BlockStateInterface.get(dest).getBlock();

View File

@ -39,7 +39,7 @@ public class MovementFall extends Movement {
@Override
protected double calculateCost(ToolSet ts) {
if (!MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) {
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
return COST_INF;
}
double placeBucketCost = 0.0;

View File

@ -51,8 +51,8 @@ public class MovementTraverse extends Movement {
IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]);
IBlockState pb1 = BlockStateInterface.get(positionsToBreak[1]);
double WC = BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock()) ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST;
if (MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) {//this is a walk, not a bridge
if (MovementHelper.canWalkThrough(positionsToBreak[0], pb0) && MovementHelper.canWalkThrough(positionsToBreak[1], pb1)) {
if (MovementHelper.canWalkOn(positionsToPlace[0])) {//this is a walk, not a bridge
if (MovementHelper.canWalkThrough(positionsToBreak[0]) && MovementHelper.canWalkThrough(positionsToBreak[1])) {
return WC;
}
//double hardness1 = blocksToBreak[0].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[0]);

View File

@ -49,20 +49,18 @@ public class BlockStateInterface {
}
/**
* Returns whether or not the specified block is any sort of liquid.
* Returns whether or not the specified pos has a liquid
*
* @param b The block
* @param p The pos
* @return Whether or not the block is a liquid
*/
public static boolean isLiquid(Block b) {
return b instanceof BlockLiquid;
}
public static boolean isLiquid(BlockPos p) {
return isLiquid(BlockStateInterface.getBlock(p));
return BlockStateInterface.getBlock(p) instanceof BlockLiquid;
}
public static boolean isFlowing(IBlockState state) {
public static boolean isFlowing(BlockPos pos) {
// Will be IFluidState in 1.13
IBlockState state = BlockStateInterface.get(pos);
return state.getBlock() instanceof BlockLiquid
&& state.getPropertyKeys().contains(BlockLiquid.LEVEL)
&& state.getValue(BlockLiquid.LEVEL) != 0;