Compare commits

..

10 Commits

Author SHA1 Message Date
Leijurv
65902d556e v1.2.5 2019-03-19 18:22:22 -07:00
Leijurv
aada9731a6 more resiliency to invalid cache files 2019-03-19 18:10:53 -07:00
Leijurv
49658078b9 trapdoors cant be passed vertically in either state, thanks plutie 2019-03-18 22:38:06 -07:00
Leijurv
bcd097c6cb we can cancel calc even if not safe to cancel pathing 2019-03-17 22:40:11 -08:00
Leijurv
cfec67f1f9 wording 2019-03-16 23:23:20 -07:00
Leijurv
aaaf0f8839 hey so what if we didnt do that 2019-03-15 16:40:15 -07:00
Leijurv
ee83471bf6 fix being unable to place or pick up water buckets 2019-03-15 14:26:38 -07:00
Leijurv
610fe6439f fix getting permanently stuck on vines 2019-03-15 14:25:43 -07:00
Leijurv
bd1dcff385 allow ties for closest to explore to 2019-03-14 14:52:51 -07:00
Leijurv
226ede7ba2 crucial 2019-03-13 19:23:28 -07:00
15 changed files with 55 additions and 41 deletions

View File

@@ -16,7 +16,7 @@
*/
group 'baritone'
version '1.2.4'
version '1.2.5'
buildscript {
repositories {

View File

@@ -50,4 +50,6 @@ public interface IPlayerController {
}
EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand);
EnumActionResult processRightClick(EntityPlayerSP player, World world, EnumHand hand);
}

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

@@ -177,7 +177,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

@@ -70,8 +70,6 @@ public final class CachedWorld implements ICachedWorld, Helper {
this.directory = directory.toString();
this.dimension = dimension;
System.out.println("Cached world directory: " + directory);
// Insert an invalid region element
cachedRegions.put(0, null);
Baritone.getExecutor().execute(new PackerThread());
Baritone.getExecutor().execute(() -> {
try {

View File

@@ -90,8 +90,7 @@ public final class ChunkPacker {
IBlockState[] blocks = new IBlockState[256];
for (int z = 0; z < 16; z++) {
https:
//www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
for (int x = 0; x < 16; x++) {
for (int y = 255; y >= 0; y--) {
int index = CachedChunk.getPositionIndex(x, y, z);
@@ -116,7 +115,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 -> Block.getBlockFromName(n.contains(":") ? n : "minecraft:" + n));
}

View File

@@ -72,7 +72,7 @@ public interface MovementHelper extends ActionCosts, Helper {
if (block == Blocks.AIR) { // early return for most common case
return true;
}
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull) {
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull || block instanceof BlockTrapDoor) {
return false;
}
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
@@ -84,9 +84,7 @@ public interface MovementHelper extends ActionCosts, Helper {
if (block == Blocks.CARPET) {
return canWalkOn(bsi, x, y - 1, z);
}
boolean snow = block instanceof BlockSnow;
boolean trapdoor = block instanceof BlockTrapDoor;
if (snow || trapdoor) {
if (block instanceof BlockSnow) {
// 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
@@ -94,19 +92,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.getValue(BlockSnow.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.getValue(BlockSnow.LAYERS) >= 3) {
return false;
}
if (trapdoor) {
return !state.getValue(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable
}
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

@@ -234,7 +234,7 @@ public class MovementTraverse extends Movement {
}
Block low = BlockStateInterface.get(ctx, src).getBlock();
Block high = BlockStateInterface.get(ctx, src.up()).getBlock();
if (!ctx.player().onGround && (low == Blocks.VINE || low == Blocks.LADDER || high == Blocks.VINE || high == Blocks.LADDER)) {
if (ctx.player().posY > src.y + 0.1D && !ctx.player().onGround && (low == Blocks.VINE || low == Blocks.LADDER || high == Blocks.VINE || high == Blocks.LADDER)) {
// hitting W could cause us to climb the ladder instead of going forward
// wait until we're on the ground
return state;

View File

@@ -19,6 +19,8 @@ package baritone.process;
import baritone.Baritone;
import baritone.api.cache.ICachedWorld;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalComposite;
import baritone.api.pathing.goals.GoalXZ;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
@@ -26,6 +28,9 @@ import baritone.cache.CachedWorld;
import baritone.utils.BaritoneProcessHelper;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;
import java.util.List;
public class ExploreProcess extends BaritoneProcessHelper {
private BlockPos explorationOrigin;
@@ -50,23 +55,24 @@ public class ExploreProcess extends BaritoneProcessHelper {
onLostControl();
return null;
}
BlockPos closestUncached = closestUncachedChunk(explorationOrigin);
Goal[] closestUncached = closestUncachedChunks(explorationOrigin);
if (closestUncached == null) {
logDebug("awaiting region load from disk");
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
}
System.out.println("Closest uncached: " + closestUncached);
return new PathingCommand(new GoalXZ(closestUncached.getX(), closestUncached.getZ()), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
return new PathingCommand(new GoalComposite(closestUncached), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
}
private BlockPos closestUncachedChunk(BlockPos pos) {
int chunkX = pos.getX() >> 4;
int chunkZ = pos.getZ() >> 4;
private Goal[] closestUncachedChunks(BlockPos center) {
int chunkX = center.getX() >> 4;
int chunkZ = center.getZ() >> 4;
ICachedWorld cache = baritone.getWorldProvider().getCurrentWorld().getCachedWorld();
for (int dist = 0; ; dist++) {
List<BlockPos> centers = new ArrayList<>();
for (int dx = -dist; dx <= dist; dx++) {
for (int dz = -dist; dz <= dist; dz++) {
int trueDist = Baritone.settings().exploreUsePythagorean.value ? dx * dx + dz + dz : Math.abs(dx) + Math.abs(dz);
int trueDist = Baritone.settings().exploreUsePythagorean.value ? dx * dx + dz * dz : Math.abs(dx) + Math.abs(dz);
if (trueDist != dist) {
continue; // not considering this one just yet in our expanding search
}
@@ -82,9 +88,12 @@ public class ExploreProcess extends BaritoneProcessHelper {
});
return null; // we still need to load regions from disk in order to decide properly
}
return new BlockPos(centerX, 0, centerZ);
centers.add(new BlockPos(centerX, 0, centerZ));
}
}
if (!centers.isEmpty()) {
return centers.stream().map(pos -> new GoalXZ(pos.getX(), pos.getZ())).toArray(Goal[]::new);
}
}
}
@@ -95,6 +104,6 @@ public class ExploreProcess extends BaritoneProcessHelper {
@Override
public String displayName0() {
return "Exploring around " + explorationOrigin + ", currently going to " + closestUncachedChunk(explorationOrigin);
return "Exploring around " + explorationOrigin + ", currently going to " + new GoalComposite(closestUncachedChunks(explorationOrigin));
}
}

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

@@ -302,7 +302,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

@@ -46,6 +46,9 @@ public class BlockPlaceHelper implements Helper {
ctx.player().swingArm(hand);
return;
}
if (!ctx.player().getHeldItem(hand).isEmpty() && ctx.playerController().processRightClick(ctx.player(), ctx.world(), hand) == EnumActionResult.SUCCESS) {
return;
}
}
}
}

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);

View File

@@ -72,4 +72,9 @@ public enum PrimaryPlayerController implements IPlayerController, Helper {
// primaryplayercontroller is always in a WorldClient so this is ok
return mc.playerController.processRightClickBlock(player, (WorldClient) world, pos, direction, vec, hand);
}
@Override
public EnumActionResult processRightClick(EntityPlayerSP player, World world, EnumHand hand) {
return mc.playerController.processRightClick(player, world, hand);
}
}