merge
This commit is contained in:
commit
beb56dca5b
@ -91,7 +91,7 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
for (BlockPos blockPos : positionsToBreak) {
|
for (BlockPos blockPos : positionsToBreak) {
|
||||||
if (!MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) {
|
if (!MovementHelper.canWalkThrough(blockPos)) {
|
||||||
Optional<Rotation> reachable = LookBehaviorUtils.reachable(blockPos);
|
Optional<Rotation> reachable = LookBehaviorUtils.reachable(blockPos);
|
||||||
if (reachable.isPresent()) {
|
if (reachable.isPresent()) {
|
||||||
state.setTarget(new MovementState.MovementTarget(reachable.get())).setInput(Input.CLICK_LEFT, true);
|
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
|
//^ the above implementation properly deals with falling blocks, TODO integrate
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (BlockPos pos : positionsToBreak) {
|
for (BlockPos pos : positionsToBreak) {
|
||||||
sum += MovementHelper.getMiningDurationTicks(ts, BlockStateInterface.get(pos), pos);
|
sum += MovementHelper.getMiningDurationTicks(ts, pos);
|
||||||
if (sum >= COST_INF) {
|
if (sum >= COST_INF) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
}
|
}
|
||||||
ArrayList<BlockPos> result = new ArrayList<>();
|
ArrayList<BlockPos> result = new ArrayList<>();
|
||||||
for (BlockPos positionToBreak : positionsToBreak) {
|
for (BlockPos positionToBreak : positionsToBreak) {
|
||||||
if (!MovementHelper.canWalkThrough(positionToBreak, BlockStateInterface.get(positionToBreak))) {
|
if (!MovementHelper.canWalkThrough(positionToBreak)) {
|
||||||
result.add(positionToBreak);
|
result.add(positionToBreak);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
|
|
||||||
static boolean avoidBreaking(BlockPos pos) {
|
static boolean avoidBreaking(BlockPos pos) {
|
||||||
Block b = BlockStateInterface.getBlock(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
|
return Blocks.ICE.equals(b) // ice becomes water, and water can mess up the path
|
||||||
|| b instanceof BlockSilverfish
|
|| b instanceof BlockSilverfish
|
||||||
|| BlockStateInterface.isLiquid(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))//don't break anything touching liquid on any side
|
|| 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
|
* @param pos
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static boolean canWalkThrough(BlockPos pos, IBlockState state) {
|
static boolean canWalkThrough(BlockPos pos) {
|
||||||
|
IBlockState state = BlockStateInterface.get(pos);
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (block instanceof BlockLilyPad
|
if (block instanceof BlockLilyPad
|
||||||
|| block instanceof BlockFire
|
|| block instanceof BlockFire
|
||||||
|| block instanceof BlockTripWire) {//you can't actually walk through a lilypad from the side, and you shouldn't walk through fire
|
|| block instanceof BlockTripWire) {//you can't actually walk through a lilypad from the side, and you shouldn't walk through fire
|
||||||
return false;
|
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 false; // Don't walk through flowing liquids
|
||||||
}
|
}
|
||||||
return block.isPassable(mc.world, pos);
|
return block.isPassable(mc.world, pos);
|
||||||
@ -79,7 +80,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static boolean canWalkOn(BlockPos pos, IBlockState state) {
|
static boolean canWalkOn(BlockPos pos) {
|
||||||
|
IBlockState state = BlockStateInterface.get(pos);
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (block instanceof BlockLadder || block instanceof BlockVine) {
|
if (block instanceof BlockLadder || block instanceof BlockVine) {
|
||||||
return true;
|
return true;
|
||||||
@ -93,18 +95,14 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return state.isBlockNormalCube() && !BlockStateInterface.isLava(block);
|
return state.isBlockNormalCube() && !BlockStateInterface.isLava(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static boolean canWalkOn(BlockPos pos) {
|
|
||||||
return canWalkOn(pos, BlockStateInterface.get(pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static boolean canFall(BlockPos pos) {
|
static boolean canFall(BlockPos pos) {
|
||||||
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
||||||
}
|
}
|
||||||
|
|
||||||
static double getMiningDurationTicks(ToolSet ts, IBlockState block, BlockPos position) {
|
static double getMiningDurationTicks(ToolSet ts, BlockPos position) {
|
||||||
if (!block.equals(Blocks.AIR) && !canWalkThrough(position, block)) {
|
IBlockState state = BlockStateInterface.get(position);
|
||||||
|
Block block = state.getBlock();
|
||||||
|
if (!block.equals(Blocks.AIR) && !canWalkThrough(position)) {
|
||||||
if (avoidBreaking(position)) {
|
if (avoidBreaking(position)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
@ -112,7 +110,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
// return COST_INF;
|
// return COST_INF;
|
||||||
//}
|
//}
|
||||||
double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class MovementAscend extends Movement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateCost(ToolSet ts) {
|
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])) {
|
if (!BlockStateInterface.isAir(positionsToPlace[0]) && !BlockStateInterface.isWater(positionsToPlace[0])) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ public class MovementDescend extends Movement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateCost(ToolSet ts) {
|
protected double calculateCost(ToolSet ts) {
|
||||||
if (!MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) {
|
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
Block tmp1 = BlockStateInterface.get(dest).getBlock();
|
Block tmp1 = BlockStateInterface.get(dest).getBlock();
|
||||||
|
@ -44,7 +44,7 @@ public class MovementDownward extends Movement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateCost(ToolSet ts) {
|
protected double calculateCost(ToolSet ts) {
|
||||||
if (!MovementHelper.canWalkOn(dest.down(), BlockStateInterface.get(dest.down()))) {
|
if (!MovementHelper.canWalkOn(dest.down())) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
Block td = BlockStateInterface.get(dest).getBlock();
|
Block td = BlockStateInterface.get(dest).getBlock();
|
||||||
|
@ -39,7 +39,7 @@ public class MovementFall extends Movement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateCost(ToolSet ts) {
|
protected double calculateCost(ToolSet ts) {
|
||||||
if (!MovementHelper.canWalkOn(positionsToPlace[0], BlockStateInterface.get(positionsToPlace[0]))) {
|
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
double placeBucketCost = 0.0;
|
double placeBucketCost = 0.0;
|
||||||
|
@ -51,8 +51,8 @@ public class MovementTraverse extends Movement {
|
|||||||
IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]);
|
IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]);
|
||||||
IBlockState pb1 = BlockStateInterface.get(positionsToBreak[1]);
|
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;
|
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.canWalkOn(positionsToPlace[0])) {//this is a walk, not a bridge
|
||||||
if (MovementHelper.canWalkThrough(positionsToBreak[0], pb0) && MovementHelper.canWalkThrough(positionsToBreak[1], pb1)) {
|
if (MovementHelper.canWalkThrough(positionsToBreak[0]) && MovementHelper.canWalkThrough(positionsToBreak[1])) {
|
||||||
return WC;
|
return WC;
|
||||||
}
|
}
|
||||||
//double hardness1 = blocksToBreak[0].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[0]);
|
//double hardness1 = blocksToBreak[0].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[0]);
|
||||||
|
@ -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
|
* @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) {
|
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
|
return state.getBlock() instanceof BlockLiquid
|
||||||
&& state.getPropertyKeys().contains(BlockLiquid.LEVEL)
|
&& state.getPropertyKeys().contains(BlockLiquid.LEVEL)
|
||||||
&& state.getValue(BlockLiquid.LEVEL) != 0;
|
&& state.getValue(BlockLiquid.LEVEL) != 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user