Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 65902d556e | |||
| aada9731a6 | |||
| 49658078b9 | |||
| bcd097c6cb | |||
| cfec67f1f9 | |||
| aaaf0f8839 | |||
| ee83471bf6 | |||
| 610fe6439f | |||
| bd1dcff385 | |||
| 226ede7ba2 |
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
group 'baritone'
|
group 'baritone'
|
||||||
version '1.2.4'
|
version '1.2.5'
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
@@ -50,4 +50,6 @@ public interface IPlayerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand);
|
EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand);
|
||||||
|
|
||||||
|
EnumActionResult processRightClick(EntityPlayerSP player, World world, EnumHand hand);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -325,6 +325,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
|
|
||||||
public void softCancelIfSafe() {
|
public void softCancelIfSafe() {
|
||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
|
getInProgress().ifPresent(AbstractNodeCostSearch::cancel); // only cancel ours
|
||||||
if (!isSafeToCancel()) {
|
if (!isSafeToCancel()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -332,7 +333,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
next = null;
|
next = null;
|
||||||
}
|
}
|
||||||
cancelRequested = true;
|
cancelRequested = true;
|
||||||
getInProgress().ifPresent(AbstractNodeCostSearch::cancel); // only cancel ours
|
|
||||||
// do everything BUT clear keys
|
// do everything BUT clear keys
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,11 +340,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
public void secretInternalSegmentCancel() {
|
public void secretInternalSegmentCancel() {
|
||||||
queuePathEvent(PathEvent.CANCELED);
|
queuePathEvent(PathEvent.CANCELED);
|
||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
|
getInProgress().ifPresent(AbstractNodeCostSearch::cancel);
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
current = null;
|
current = null;
|
||||||
next = null;
|
next = null;
|
||||||
baritone.getInputOverrideHandler().clearAllKeys();
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
getInProgress().ifPresent(AbstractNodeCostSearch::cancel);
|
|
||||||
baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock();
|
baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -177,7 +177,7 @@ public final class CachedChunk {
|
|||||||
if (special != null) {
|
if (special != null) {
|
||||||
String str = special.get(index);
|
String str = special.get(index);
|
||||||
if (str != null) {
|
if (str != null) {
|
||||||
return ChunkPacker.stringToBlock(str).getDefaultState();
|
return ChunkPacker.stringToBlockRequired(str).getDefaultState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -240,7 +240,7 @@ public final class CachedRegion implements ICachedRegion {
|
|||||||
for (int z = 0; z < 32; z++) {
|
for (int z = 0; z < 32; z++) {
|
||||||
if (present[x][z]) {
|
if (present[x][z]) {
|
||||||
for (int i = 0; i < 256; i++) {
|
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;
|
int numSpecialBlockTypes = in.readShort() & 0xffff;
|
||||||
for (int i = 0; i < numSpecialBlockTypes; i++) {
|
for (int i = 0; i < numSpecialBlockTypes; i++) {
|
||||||
String blockName = in.readUTF();
|
String blockName = in.readUTF();
|
||||||
|
ChunkPacker.stringToBlockRequired(blockName);
|
||||||
List<BlockPos> locs = new ArrayList<>();
|
List<BlockPos> locs = new ArrayList<>();
|
||||||
location[x][z].put(blockName, locs);
|
location[x][z].put(blockName, locs);
|
||||||
int numLocations = in.readShort() & 0xffff;
|
int numLocations = in.readShort() & 0xffff;
|
||||||
|
|||||||
@@ -70,8 +70,6 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
this.directory = directory.toString();
|
this.directory = directory.toString();
|
||||||
this.dimension = dimension;
|
this.dimension = dimension;
|
||||||
System.out.println("Cached world directory: " + directory);
|
System.out.println("Cached world directory: " + directory);
|
||||||
// Insert an invalid region element
|
|
||||||
cachedRegions.put(0, null);
|
|
||||||
Baritone.getExecutor().execute(new PackerThread());
|
Baritone.getExecutor().execute(new PackerThread());
|
||||||
Baritone.getExecutor().execute(() -> {
|
Baritone.getExecutor().execute(() -> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
+8
-3
@@ -90,8 +90,7 @@ public final class ChunkPacker {
|
|||||||
IBlockState[] blocks = new IBlockState[256];
|
IBlockState[] blocks = new IBlockState[256];
|
||||||
|
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
https:
|
https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
|
||||||
//www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
|
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
for (int y = 255; y >= 0; y--) {
|
for (int y = 255; y >= 0; y--) {
|
||||||
int index = CachedChunk.getPositionIndex(x, y, z);
|
int index = CachedChunk.getPositionIndex(x, y, z);
|
||||||
@@ -116,7 +115,13 @@ public final class ChunkPacker {
|
|||||||
return name;
|
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));
|
return resourceCache.computeIfAbsent(name, n -> Block.getBlockFromName(n.contains(":") ? n : "minecraft:" + n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
if (block == Blocks.AIR) { // early return for most common case
|
if (block == Blocks.AIR) { // early return for most common case
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
||||||
@@ -84,9 +84,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
if (block == Blocks.CARPET) {
|
if (block == Blocks.CARPET) {
|
||||||
return canWalkOn(bsi, x, y - 1, z);
|
return canWalkOn(bsi, x, y - 1, z);
|
||||||
}
|
}
|
||||||
boolean snow = block instanceof BlockSnow;
|
if (block instanceof BlockSnow) {
|
||||||
boolean trapdoor = block instanceof BlockTrapDoor;
|
|
||||||
if (snow || trapdoor) {
|
|
||||||
// we've already checked doors and fence gates
|
// we've already checked doors and fence gates
|
||||||
// so the only remaining dynamic isPassables are snow and trapdoor
|
// so the only remaining dynamic isPassables are snow and trapdoor
|
||||||
// if they're cached as a top block, we don't know their metadata
|
// 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)) {
|
if (!bsi.worldContainsLoadedChunk(x, z)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (snow) {
|
// the check in BlockSnow.isPassable is layers < 5
|
||||||
// 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
|
||||||
// while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling
|
if (state.getValue(BlockSnow.LAYERS) >= 3) {
|
||||||
if (state.getValue(BlockSnow.LAYERS) >= 3) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// ok, it's low enough we could walk through it, but is it supported?
|
|
||||||
return canWalkOn(bsi, x, y - 1, z);
|
|
||||||
}
|
}
|
||||||
if (trapdoor) {
|
// ok, it's low enough we could walk through it, but is it supported?
|
||||||
return !state.getValue(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable
|
return canWalkOn(bsi, x, y - 1, z);
|
||||||
}
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
}
|
||||||
if (isFlowing(x, y, z, state, bsi)) {
|
if (isFlowing(x, y, z, state, bsi)) {
|
||||||
return false; // Don't walk through flowing liquids
|
return false; // Don't walk through flowing liquids
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ public class MovementTraverse extends Movement {
|
|||||||
}
|
}
|
||||||
Block low = BlockStateInterface.get(ctx, src).getBlock();
|
Block low = BlockStateInterface.get(ctx, src).getBlock();
|
||||||
Block high = BlockStateInterface.get(ctx, src.up()).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
|
// hitting W could cause us to climb the ladder instead of going forward
|
||||||
// wait until we're on the ground
|
// wait until we're on the ground
|
||||||
return state;
|
return state;
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ package baritone.process;
|
|||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.cache.ICachedWorld;
|
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.pathing.goals.GoalXZ;
|
||||||
import baritone.api.process.PathingCommand;
|
import baritone.api.process.PathingCommand;
|
||||||
import baritone.api.process.PathingCommandType;
|
import baritone.api.process.PathingCommandType;
|
||||||
@@ -26,6 +28,9 @@ import baritone.cache.CachedWorld;
|
|||||||
import baritone.utils.BaritoneProcessHelper;
|
import baritone.utils.BaritoneProcessHelper;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ExploreProcess extends BaritoneProcessHelper {
|
public class ExploreProcess extends BaritoneProcessHelper {
|
||||||
|
|
||||||
private BlockPos explorationOrigin;
|
private BlockPos explorationOrigin;
|
||||||
@@ -50,23 +55,24 @@ public class ExploreProcess extends BaritoneProcessHelper {
|
|||||||
onLostControl();
|
onLostControl();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
BlockPos closestUncached = closestUncachedChunk(explorationOrigin);
|
Goal[] closestUncached = closestUncachedChunks(explorationOrigin);
|
||||||
if (closestUncached == null) {
|
if (closestUncached == null) {
|
||||||
logDebug("awaiting region load from disk");
|
logDebug("awaiting region load from disk");
|
||||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
}
|
}
|
||||||
System.out.println("Closest uncached: " + closestUncached);
|
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) {
|
private Goal[] closestUncachedChunks(BlockPos center) {
|
||||||
int chunkX = pos.getX() >> 4;
|
int chunkX = center.getX() >> 4;
|
||||||
int chunkZ = pos.getZ() >> 4;
|
int chunkZ = center.getZ() >> 4;
|
||||||
ICachedWorld cache = baritone.getWorldProvider().getCurrentWorld().getCachedWorld();
|
ICachedWorld cache = baritone.getWorldProvider().getCurrentWorld().getCachedWorld();
|
||||||
for (int dist = 0; ; dist++) {
|
for (int dist = 0; ; dist++) {
|
||||||
|
List<BlockPos> centers = new ArrayList<>();
|
||||||
for (int dx = -dist; dx <= dist; dx++) {
|
for (int dx = -dist; dx <= dist; dx++) {
|
||||||
for (int dz = -dist; dz <= dist; dz++) {
|
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) {
|
if (trueDist != dist) {
|
||||||
continue; // not considering this one just yet in our expanding search
|
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 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
|
@Override
|
||||||
public String displayName0() {
|
public String displayName0() {
|
||||||
return "Exploring around " + explorationOrigin + ", currently going to " + closestUncachedChunk(explorationOrigin);
|
return "Exploring around " + explorationOrigin + ", currently going to " + new GoalComposite(closestUncachedChunks(explorationOrigin));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String displayName0() {
|
public String displayName0() {
|
||||||
return "Follow " + cache;
|
return "Following " + cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mineByName(int quantity, String... blocks) {
|
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
|
@Override
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ public class BlockPlaceHelper implements Helper {
|
|||||||
ctx.player().swingArm(hand);
|
ctx.player().swingArm(hand);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!ctx.player().getHeldItem(hand).isEmpty() && ctx.playerController().processRightClick(ctx.player(), ctx.world(), hand) == EnumActionResult.SUCCESS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -462,14 +462,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
String[] blockTypes = msg.substring(4).trim().split(" ");
|
String[] blockTypes = msg.substring(4).trim().split(" ");
|
||||||
try {
|
try {
|
||||||
int quantity = Integer.parseInt(blockTypes[1]);
|
int quantity = Integer.parseInt(blockTypes[1]);
|
||||||
Block block = ChunkPacker.stringToBlock(blockTypes[0]);
|
Block block = ChunkPacker.stringToBlockRequired(blockTypes[0]);
|
||||||
Objects.requireNonNull(block);
|
|
||||||
baritone.getMineProcess().mine(quantity, block);
|
baritone.getMineProcess().mine(quantity, block);
|
||||||
logDirect("Will mine " + quantity + " " + blockTypes[0]);
|
logDirect("Will mine " + quantity + " " + blockTypes[0]);
|
||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {}
|
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {}
|
||||||
for (String s : blockTypes) {
|
for (String s : blockTypes) {
|
||||||
if (ChunkPacker.stringToBlock(s) == null) {
|
if (ChunkPacker.stringToBlockNullable(s) == null) {
|
||||||
logDirect(s + " isn't a valid block name");
|
logDirect(s + " isn't a valid block name");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -552,7 +551,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
IWaypoint waypoint;
|
IWaypoint waypoint;
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
String mining = waypointType;
|
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());
|
//logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null);
|
waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null);
|
||||||
|
|||||||
@@ -72,4 +72,9 @@ public enum PrimaryPlayerController implements IPlayerController, Helper {
|
|||||||
// primaryplayercontroller is always in a WorldClient so this is ok
|
// primaryplayercontroller is always in a WorldClient so this is ok
|
||||||
return mc.playerController.processRightClickBlock(player, (WorldClient) world, pos, direction, vec, hand);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user