more better block pos

This commit is contained in:
Leijurv 2018-09-22 08:47:02 -07:00
parent 8b307f296a
commit e16bc5eca4
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
14 changed files with 36 additions and 27 deletions

View File

@ -35,6 +35,7 @@ import baritone.utils.BlockStateInterface;
import baritone.utils.Helper; import baritone.utils.Helper;
import baritone.utils.PathRenderer; import baritone.utils.PathRenderer;
import baritone.utils.interfaces.IGoalRenderPos; import baritone.utils.interfaces.IGoalRenderPos;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.EmptyChunk; import net.minecraft.world.chunk.EmptyChunk;
@ -232,7 +233,7 @@ public final class PathingBehavior extends Behavior implements Helper {
} }
public BlockPos pathStart() { public BlockPos pathStart() {
BlockPos feet = playerFeet(); BetterBlockPos feet = playerFeet();
if (BlockStateInterface.get(feet.down()).getBlock().equals(Blocks.AIR) && MovementHelper.canWalkOn(feet.down().down())) { if (BlockStateInterface.get(feet.down()).getBlock().equals(Blocks.AIR) && MovementHelper.canWalkOn(feet.down().down())) {
return feet.down(); return feet.down();
} }

View File

@ -240,7 +240,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.EAST), new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.EAST),
new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.WEST), new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.WEST),
new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.EAST), new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.EAST),
new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.WEST), new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.WEST),
MovementParkour.generate(pos, EnumFacing.EAST, calcContext), MovementParkour.generate(pos, EnumFacing.EAST, calcContext),

View File

@ -55,7 +55,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
private volatile boolean isFinished; private volatile boolean isFinished;
protected volatile boolean cancelRequested; protected boolean cancelRequested;
/** /**
* This is really complicated and hard to explain. I wrote a comment in the old version of MineBot but it was so * This is really complicated and hard to explain. I wrote a comment in the old version of MineBot but it was so

View File

@ -48,12 +48,12 @@ public abstract class Movement implements Helper, MovementHelper {
/** /**
* The positions that need to be broken before this movement can ensue * The positions that need to be broken before this movement can ensue
*/ */
protected final BlockPos[] positionsToBreak; protected final BetterBlockPos[] positionsToBreak;
/** /**
* The position where we need to place a block before this movement can ensue * The position where we need to place a block before this movement can ensue
*/ */
protected final BlockPos positionToPlace; protected final BetterBlockPos positionToPlace;
private boolean didBreakLastTick; private boolean didBreakLastTick;
@ -65,14 +65,14 @@ public abstract class Movement implements Helper, MovementHelper {
private Boolean calculatedWhileLoaded; private Boolean calculatedWhileLoaded;
protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak, BlockPos toPlace) { protected Movement(BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak, BetterBlockPos toPlace) {
this.src = src; this.src = src;
this.dest = dest; this.dest = dest;
this.positionsToBreak = toBreak; this.positionsToBreak = toBreak;
this.positionToPlace = toPlace; this.positionToPlace = toPlace;
} }
protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak) { protected Movement(BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak) {
this(src, dest, toBreak, null); this(src, dest, toBreak, null);
} }

View File

@ -106,8 +106,9 @@ public interface MovementHelper extends ActionCosts, Helper {
if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) {
return false; return false;
} }
return block == Blocks.WATER || block == Blocks.FLOWING_WATER;
} }
return block.isPassable(mc.world, pos); return block.isPassable(mc.world, pos); // only blocks that can get here and actually that use world and pos for this call are snow and trapdoor
} }
/** /**
@ -225,7 +226,7 @@ public interface MovementHelper extends ActionCosts, Helper {
* *
* @return * @return
*/ */
static boolean canWalkOn(BlockPos pos, IBlockState state) { static boolean canWalkOn(BetterBlockPos pos, IBlockState state) {
Block block = state.getBlock(); Block block = state.getBlock();
if (block == Blocks.AIR || block == Blocks.MAGMA) { if (block == Blocks.AIR || block == Blocks.MAGMA) {
return false; return false;
@ -246,8 +247,10 @@ public interface MovementHelper extends ActionCosts, Helper {
return true; return true;
} }
if (BlockStateInterface.isWater(block)) { if (BlockStateInterface.isWater(block)) {
Block up = BlockStateInterface.get(pos.up()).getBlock(); // since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()"
if (up instanceof BlockLilyPad) { // 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(pos.x, pos.y + 1, pos.z).getBlock();
if (up == Blocks.WATERLILY) {
return true; return true;
} }
if (BlockStateInterface.isFlowing(state) || block == Blocks.FLOWING_WATER) { if (BlockStateInterface.isFlowing(state) || block == Blocks.FLOWING_WATER) {
@ -276,7 +279,7 @@ public interface MovementHelper extends ActionCosts, Helper {
return false; return false;
} }
static boolean canWalkOn(BlockPos pos) { static boolean canWalkOn(BetterBlockPos pos) {
return canWalkOn(pos, BlockStateInterface.get(pos)); return canWalkOn(pos, BlockStateInterface.get(pos));
} }

View File

@ -44,7 +44,7 @@ public class MovementAscend extends Movement {
private int ticksWithoutPlacement = 0; private int ticksWithoutPlacement = 0;
public MovementAscend(BetterBlockPos src, BetterBlockPos dest) { public MovementAscend(BetterBlockPos src, BetterBlockPos dest) {
super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down()); super(src, dest, new BetterBlockPos[]{dest, src.up(2), dest.up()}, dest.down());
} }
@Override @Override

View File

@ -34,7 +34,7 @@ public class MovementDescend extends Movement {
private int numTicks = 0; private int numTicks = 0;
public MovementDescend(BetterBlockPos start, BetterBlockPos end) { public MovementDescend(BetterBlockPos start, BetterBlockPos end) {
super(start, end, new BlockPos[]{end.up(2), end.up(), end}, end.down()); super(start, end, new BetterBlockPos[]{end.up(2), end.up(), end}, end.down());
} }
@Override @Override

View File

@ -48,7 +48,7 @@ public class MovementDiagonal extends Movement {
} }
private MovementDiagonal(BetterBlockPos start, BetterBlockPos end, BetterBlockPos dir1, BetterBlockPos dir2) { private MovementDiagonal(BetterBlockPos start, BetterBlockPos end, BetterBlockPos dir1, BetterBlockPos dir2) {
super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}); super(start, end, new BetterBlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()});
} }
@Override @Override
@ -60,7 +60,7 @@ public class MovementDiagonal extends Movement {
if (!MovementHelper.canWalkThrough(positionsToBreak[4]) || !MovementHelper.canWalkThrough(positionsToBreak[5])) { if (!MovementHelper.canWalkThrough(positionsToBreak[4]) || !MovementHelper.canWalkThrough(positionsToBreak[5])) {
return COST_INF; return COST_INF;
} }
BlockPos destDown = dest.down(); BetterBlockPos destDown = dest.down();
IBlockState destWalkOn = BlockStateInterface.get(destDown); IBlockState destWalkOn = BlockStateInterface.get(destDown);
if (!MovementHelper.canWalkOn(destDown, destWalkOn)) { if (!MovementHelper.canWalkOn(destDown, destWalkOn)) {
return COST_INF; return COST_INF;

View File

@ -26,14 +26,13 @@ import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
public class MovementDownward extends Movement { public class MovementDownward extends Movement {
private int numTicks = 0; private int numTicks = 0;
public MovementDownward(BetterBlockPos start, BetterBlockPos end) { public MovementDownward(BetterBlockPos start, BetterBlockPos end) {
super(start, end, new BlockPos[]{end}); super(start, end, new BetterBlockPos[]{end});
} }
@Override @Override

View File

@ -157,14 +157,14 @@ public class MovementFall extends Movement {
return state; return state;
} }
private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) { private static BetterBlockPos[] buildPositionsToBreak(BetterBlockPos src, BetterBlockPos dest) {
BlockPos[] toBreak; BetterBlockPos[] toBreak;
int diffX = src.getX() - dest.getX(); int diffX = src.getX() - dest.getX();
int diffZ = src.getZ() - dest.getZ(); int diffZ = src.getZ() - dest.getZ();
int diffY = src.getY() - dest.getY(); int diffY = src.getY() - dest.getY();
toBreak = new BlockPos[diffY + 2]; toBreak = new BetterBlockPos[diffY + 2];
for (int i = 0; i < toBreak.length; i++) { for (int i = 0; i < toBreak.length; i++) {
toBreak[i] = new BlockPos(src.getX() - diffX, src.getY() + 1 - i, src.getZ() - diffZ); toBreak[i] = new BetterBlockPos(src.getX() - diffX, src.getY() + 1 - i, src.getZ() - diffZ);
} }
return toBreak; return toBreak;
} }

View File

@ -39,12 +39,13 @@ import java.util.Objects;
public class MovementParkour extends Movement { public class MovementParkour extends Movement {
private static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN_SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN}; private static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN_SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN};
private static final BetterBlockPos[] EMPTY = new BetterBlockPos[]{};
private final EnumFacing direction; private final EnumFacing direction;
private final int dist; private final int dist;
private MovementParkour(BetterBlockPos src, int dist, EnumFacing dir) { private MovementParkour(BetterBlockPos src, int dist, EnumFacing dir) {
super(src, src.offset(dir, dist), new BlockPos[]{}); super(src, src.offset(dir, dist), EMPTY);
this.direction = dir; this.direction = dir;
this.dist = dist; this.dist = dist;
super.override(costFromJumpDistance(dist)); super.override(costFromJumpDistance(dist));
@ -59,7 +60,7 @@ public class MovementParkour extends Movement {
if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || MovementHelper.isBottomSlab(standingOn)) { if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || MovementHelper.isBottomSlab(standingOn)) {
return null; return null;
} }
BlockPos adjBlock = src.down().offset(dir); BetterBlockPos adjBlock = src.down().offset(dir);
IBlockState adj = BlockStateInterface.get(adjBlock); IBlockState adj = BlockStateInterface.get(adjBlock);
if (MovementHelper.avoidWalkingInto(adj.getBlock()) && adj.getBlock() != Blocks.WATER && adj.getBlock() != Blocks.FLOWING_WATER) { // magma sucks if (MovementHelper.avoidWalkingInto(adj.getBlock()) && adj.getBlock() != Blocks.WATER && adj.getBlock() != Blocks.FLOWING_WATER) { // magma sucks
return null; return null;
@ -81,7 +82,7 @@ public class MovementParkour extends Movement {
return null; return null;
} }
for (int i = 2; i <= (context.canSprint() ? 4 : 3); i++) { for (int i = 2; i <= (context.canSprint() ? 4 : 3); i++) {
BlockPos dest = src.offset(dir, i); BetterBlockPos dest = src.offset(dir, i);
// TODO perhaps dest.up(3) doesn't need to be fullyPassable, just canWalkThrough, possibly? // TODO perhaps dest.up(3) doesn't need to be fullyPassable, just canWalkThrough, possibly?
for (int y = 0; y < 4; y++) { for (int y = 0; y < 4; y++) {
if (!MovementHelper.fullyPassable(dest.up(y))) { if (!MovementHelper.fullyPassable(dest.up(y))) {

View File

@ -37,7 +37,7 @@ public class MovementPillar extends Movement {
private int numTicks = 0; private int numTicks = 0;
public MovementPillar(BetterBlockPos start, BetterBlockPos end) { public MovementPillar(BetterBlockPos start, BetterBlockPos end) {
super(start, end, new BlockPos[]{start.up(2)}, start); super(start, end, new BetterBlockPos[]{start.up(2)}, start);
} }
@Override @Override

View File

@ -46,7 +46,7 @@ public class MovementTraverse extends Movement {
private boolean wasTheBridgeBlockAlwaysThere = true; private boolean wasTheBridgeBlockAlwaysThere = true;
public MovementTraverse(BetterBlockPos from, BetterBlockPos to) { public MovementTraverse(BetterBlockPos from, BetterBlockPos to) {
super(from, to, new BlockPos[]{to.up(), to}, to.down()); super(from, to, new BetterBlockPos[]{to.up(), to}, to.down());
} }
@Override @Override

View File

@ -213,6 +213,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
logDirect("ok force canceled"); logDirect("ok force canceled");
return; return;
} }
if (msg.equals("gc")) {
System.gc();
event.cancel();
logDirect("Called System.gc();");
return;
}
if (msg.equals("invert")) { if (msg.equals("invert")) {
Goal goal = PathingBehavior.INSTANCE.getGoal(); Goal goal = PathingBehavior.INSTANCE.getGoal();
BlockPos runAwayFrom; BlockPos runAwayFrom;