more better block pos
This commit is contained in:
parent
8b307f296a
commit
e16bc5eca4
@ -35,6 +35,7 @@ import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.PathRenderer;
|
||||
import baritone.utils.interfaces.IGoalRenderPos;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.EmptyChunk;
|
||||
@ -232,7 +233,7 @@ public final class PathingBehavior extends Behavior implements Helper {
|
||||
}
|
||||
|
||||
public BlockPos pathStart() {
|
||||
BlockPos feet = playerFeet();
|
||||
BetterBlockPos feet = playerFeet();
|
||||
if (BlockStateInterface.get(feet.down()).getBlock().equals(Blocks.AIR) && MovementHelper.canWalkOn(feet.down().down())) {
|
||||
return feet.down();
|
||||
}
|
||||
|
@ -240,7 +240,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.EAST),
|
||||
new MovementDiagonal(pos, EnumFacing.NORTH, EnumFacing.WEST),
|
||||
new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.EAST),
|
||||
|
||||
new MovementDiagonal(pos, EnumFacing.SOUTH, EnumFacing.WEST),
|
||||
|
||||
MovementParkour.generate(pos, EnumFacing.EAST, calcContext),
|
||||
|
@ -55,7 +55,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
||||
|
||||
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
|
||||
|
@ -48,12 +48,12 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected final BlockPos positionToPlace;
|
||||
protected final BetterBlockPos positionToPlace;
|
||||
|
||||
private boolean didBreakLastTick;
|
||||
|
||||
@ -65,14 +65,14 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
|
||||
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.dest = dest;
|
||||
this.positionsToBreak = toBreak;
|
||||
this.positionToPlace = toPlace;
|
||||
}
|
||||
|
||||
protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak) {
|
||||
protected Movement(BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak) {
|
||||
this(src, dest, toBreak, null);
|
||||
}
|
||||
|
||||
|
@ -106,8 +106,9 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) {
|
||||
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
|
||||
*/
|
||||
static boolean canWalkOn(BlockPos pos, IBlockState state) {
|
||||
static boolean canWalkOn(BetterBlockPos pos, IBlockState state) {
|
||||
Block block = state.getBlock();
|
||||
if (block == Blocks.AIR || block == Blocks.MAGMA) {
|
||||
return false;
|
||||
@ -246,8 +247,10 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
return true;
|
||||
}
|
||||
if (BlockStateInterface.isWater(block)) {
|
||||
Block up = BlockStateInterface.get(pos.up()).getBlock();
|
||||
if (up instanceof BlockLilyPad) {
|
||||
// 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(pos.x, pos.y + 1, pos.z).getBlock();
|
||||
if (up == Blocks.WATERLILY) {
|
||||
return true;
|
||||
}
|
||||
if (BlockStateInterface.isFlowing(state) || block == Blocks.FLOWING_WATER) {
|
||||
@ -276,7 +279,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean canWalkOn(BlockPos pos) {
|
||||
static boolean canWalkOn(BetterBlockPos pos) {
|
||||
return canWalkOn(pos, BlockStateInterface.get(pos));
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class MovementAscend extends Movement {
|
||||
private int ticksWithoutPlacement = 0;
|
||||
|
||||
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
|
||||
|
@ -34,7 +34,7 @@ public class MovementDescend extends Movement {
|
||||
private int numTicks = 0;
|
||||
|
||||
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
|
||||
|
@ -48,7 +48,7 @@ public class MovementDiagonal extends Movement {
|
||||
}
|
||||
|
||||
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
|
||||
@ -60,7 +60,7 @@ public class MovementDiagonal extends Movement {
|
||||
if (!MovementHelper.canWalkThrough(positionsToBreak[4]) || !MovementHelper.canWalkThrough(positionsToBreak[5])) {
|
||||
return COST_INF;
|
||||
}
|
||||
BlockPos destDown = dest.down();
|
||||
BetterBlockPos destDown = dest.down();
|
||||
IBlockState destWalkOn = BlockStateInterface.get(destDown);
|
||||
if (!MovementHelper.canWalkOn(destDown, destWalkOn)) {
|
||||
return COST_INF;
|
||||
|
@ -26,14 +26,13 @@ import baritone.utils.pathing.BetterBlockPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class MovementDownward extends Movement {
|
||||
|
||||
private int numTicks = 0;
|
||||
|
||||
public MovementDownward(BetterBlockPos start, BetterBlockPos end) {
|
||||
super(start, end, new BlockPos[]{end});
|
||||
super(start, end, new BetterBlockPos[]{end});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -157,14 +157,14 @@ public class MovementFall extends Movement {
|
||||
return state;
|
||||
}
|
||||
|
||||
private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) {
|
||||
BlockPos[] toBreak;
|
||||
private static BetterBlockPos[] buildPositionsToBreak(BetterBlockPos src, BetterBlockPos dest) {
|
||||
BetterBlockPos[] toBreak;
|
||||
int diffX = src.getX() - dest.getX();
|
||||
int diffZ = src.getZ() - dest.getZ();
|
||||
int diffY = src.getY() - dest.getY();
|
||||
toBreak = new BlockPos[diffY + 2];
|
||||
toBreak = new BetterBlockPos[diffY + 2];
|
||||
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;
|
||||
}
|
||||
|
@ -39,12 +39,13 @@ import java.util.Objects;
|
||||
|
||||
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 BetterBlockPos[] EMPTY = new BetterBlockPos[]{};
|
||||
|
||||
private final EnumFacing direction;
|
||||
private final int dist;
|
||||
|
||||
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.dist = 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)) {
|
||||
return null;
|
||||
}
|
||||
BlockPos adjBlock = src.down().offset(dir);
|
||||
BetterBlockPos adjBlock = src.down().offset(dir);
|
||||
IBlockState adj = BlockStateInterface.get(adjBlock);
|
||||
if (MovementHelper.avoidWalkingInto(adj.getBlock()) && adj.getBlock() != Blocks.WATER && adj.getBlock() != Blocks.FLOWING_WATER) { // magma sucks
|
||||
return null;
|
||||
@ -81,7 +82,7 @@ public class MovementParkour extends Movement {
|
||||
return null;
|
||||
}
|
||||
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?
|
||||
for (int y = 0; y < 4; y++) {
|
||||
if (!MovementHelper.fullyPassable(dest.up(y))) {
|
||||
|
@ -37,7 +37,7 @@ public class MovementPillar extends Movement {
|
||||
private int numTicks = 0;
|
||||
|
||||
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
|
||||
|
@ -46,7 +46,7 @@ public class MovementTraverse extends Movement {
|
||||
private boolean wasTheBridgeBlockAlwaysThere = true;
|
||||
|
||||
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
|
||||
|
@ -213,6 +213,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
logDirect("ok force canceled");
|
||||
return;
|
||||
}
|
||||
if (msg.equals("gc")) {
|
||||
System.gc();
|
||||
event.cancel();
|
||||
logDirect("Called System.gc();");
|
||||
return;
|
||||
}
|
||||
if (msg.equals("invert")) {
|
||||
Goal goal = PathingBehavior.INSTANCE.getGoal();
|
||||
BlockPos runAwayFrom;
|
||||
|
Loading…
Reference in New Issue
Block a user