Merge branch 'master' into 1.13.2

This commit is contained in:
Leijurv
2019-03-19 18:12:26 -07:00
8 changed files with 25 additions and 28 deletions

View File

@@ -325,6 +325,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
public void softCancelIfSafe() {
synchronized (pathPlanLock) {
getInProgress().ifPresent(AbstractNodeCostSearch::cancel); // only cancel ours
if (!isSafeToCancel()) {
return;
}
@@ -332,7 +333,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
next = null;
}
cancelRequested = true;
getInProgress().ifPresent(AbstractNodeCostSearch::cancel); // only cancel ours
// do everything BUT clear keys
}
@@ -340,11 +340,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
public void secretInternalSegmentCancel() {
queuePathEvent(PathEvent.CANCELED);
synchronized (pathPlanLock) {
getInProgress().ifPresent(AbstractNodeCostSearch::cancel);
if (current != null) {
current = null;
next = null;
baritone.getInputOverrideHandler().clearAllKeys();
getInProgress().ifPresent(AbstractNodeCostSearch::cancel);
baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock();
}
}

View File

@@ -212,7 +212,7 @@ public final class CachedChunk {
if (special != null) {
String str = special.get(index);
if (str != null) {
return ChunkPacker.stringToBlock(str).getDefaultState();
return ChunkPacker.stringToBlockRequired(str).getDefaultState();
}
}

View File

@@ -240,7 +240,7 @@ public final class CachedRegion implements ICachedRegion {
for (int z = 0; z < 32; z++) {
if (present[x][z]) {
for (int i = 0; i < 256; i++) {
overview[x][z][i] = ChunkPacker.stringToBlock(in.readUTF()).getDefaultState();
overview[x][z][i] = ChunkPacker.stringToBlockRequired(in.readUTF()).getDefaultState();
}
}
}
@@ -255,6 +255,7 @@ public final class CachedRegion implements ICachedRegion {
int numSpecialBlockTypes = in.readShort() & 0xffff;
for (int i = 0; i < numSpecialBlockTypes; i++) {
String blockName = in.readUTF();
ChunkPacker.stringToBlockRequired(blockName);
List<BlockPos> locs = new ArrayList<>();
location[x][z].put(blockName, locs);
int numLocations = in.readShort() & 0xffff;

View File

@@ -118,7 +118,13 @@ public final class ChunkPacker {
return name;
}
public static Block stringToBlock(String name) {
public static Block stringToBlockRequired(String name) {
Block block = stringToBlockNullable(name);
Objects.requireNonNull(block);
return block;
}
public static Block stringToBlockNullable(String name) {
return resourceCache.computeIfAbsent(name, n -> IRegistry.BLOCK.get(new ResourceLocation(n.contains(":") ? n : "minecraft:" + n)));
}

View File

@@ -79,7 +79,7 @@ public interface MovementHelper extends ActionCosts, Helper {
if (block instanceof BlockAir) { // early return for most common case
return true;
}
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull || block == Blocks.BUBBLE_COLUMN || block instanceof BlockShulkerBox || block instanceof BlockSlab) {
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull || block == Blocks.BUBBLE_COLUMN || block instanceof BlockShulkerBox || block instanceof BlockSlab || block instanceof BlockTrapDoor) {
return false;
}
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
@@ -91,9 +91,7 @@ public interface MovementHelper extends ActionCosts, Helper {
if (block instanceof BlockCarpet) {
return canWalkOn(bsi, x, y - 1, z);
}
boolean snow = block instanceof BlockSnowLayer;
boolean trapdoor = block instanceof BlockTrapDoor;
if (snow || trapdoor) {
if (block instanceof BlockSnowLayer) {
// we've already checked doors and fence gates
// so the only remaining dynamic isPassables are snow and trapdoor
// if they're cached as a top block, we don't know their metadata
@@ -101,20 +99,13 @@ public interface MovementHelper extends ActionCosts, Helper {
if (!bsi.worldContainsLoadedChunk(x, z)) {
return true;
}
if (snow) {
// the check in BlockSnow.isPassable is layers < 5
// while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling
if (state.get(BlockSnowLayer.LAYERS) >= 3) {
return false;
}
// ok, it's low enough we could walk through it, but is it supported?
return canWalkOn(bsi, x, y - 1, z);
// the check in BlockSnow.isPassable is layers < 5
// while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling
if (state.get(BlockSnowLayer.LAYERS) >= 3) {
return false;
}
if (trapdoor) {
return !state.get(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable
}
// The previous condition should always be true, so this exception will never be thrown
throw new IllegalStateException();
// ok, it's low enough we could walk through it, but is it supported?
return canWalkOn(bsi, x, y - 1, z);
}
if (isFlowing(x, y, z, state, bsi)) {
return false; // Don't walk through flowing liquids

View File

@@ -102,7 +102,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
@Override
public String displayName0() {
return "Follow " + cache;
return "Following " + cache;
}
@Override

View File

@@ -303,7 +303,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
@Override
public void mineByName(int quantity, String... blocks) {
mine(quantity, blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlock).toArray(Block[]::new));
mine(quantity, blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlockRequired).toArray(Block[]::new));
}
@Override

View File

@@ -462,14 +462,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
String[] blockTypes = msg.substring(4).trim().split(" ");
try {
int quantity = Integer.parseInt(blockTypes[1]);
Block block = ChunkPacker.stringToBlock(blockTypes[0]);
Objects.requireNonNull(block);
Block block = ChunkPacker.stringToBlockRequired(blockTypes[0]);
baritone.getMineProcess().mine(quantity, block);
logDirect("Will mine " + quantity + " " + blockTypes[0]);
return true;
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {}
for (String s : blockTypes) {
if (ChunkPacker.stringToBlock(s) == null) {
if (ChunkPacker.stringToBlockNullable(s) == null) {
logDirect(s + " isn't a valid block name");
return true;
}
@@ -552,7 +551,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
IWaypoint waypoint;
if (tag == null) {
String mining = waypointType;
Block block = ChunkPacker.stringToBlock(mining);
Block block = ChunkPacker.stringToBlockNullable(mining);
//logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
if (block == null) {
waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null);