From bd345ae041d789673f01986baa90e657cbc3d70d Mon Sep 17 00:00:00 2001 From: Xennex <55858288+Xephorix@users.noreply.github.com> Date: Mon, 7 Oct 2019 09:50:10 -0600 Subject: [PATCH 001/133] Update USAGE.md added a few commands to the list of "fun / interesting / important ones that you might want to look at" --- USAGE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/USAGE.md b/USAGE.md index 25fef11e..76da07cb 100644 --- a/USAGE.md +++ b/USAGE.md @@ -65,6 +65,8 @@ There are about a hundred settings, but here are some fun / interesting / import - `worldExploringChunkOffset` - `acceptableThrowawayItems` - `blocksToAvoidBreaking` +- `mineScanDroppedItems` +- `allowDiagonalAscend` From e65c854e6a0822dbc2559620e602beb6920b561d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 15 Oct 2019 11:25:35 -0700 Subject: [PATCH 002/133] Update USAGE.md --- USAGE.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/USAGE.md b/USAGE.md index 45dfab57..11810499 100644 --- a/USAGE.md +++ b/USAGE.md @@ -14,11 +14,17 @@ Lots of the commands have changed, BUT `#help` is improved vastly (its clickable Try `#help` I promise it won't just send you back here =) +"wtf where is cleararea" -> look at `#help sel` + +"wtf where is goto death, goto waypoint" -> look at `#help wp` + +just look at `#help` lmao + # Commands **All** of these commands may need a prefix before them, as above ^. -`help` for (rudimentary) help. You can see what it says [here](https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/utils/ExampleBaritoneControl.java#L47). +`help` To toggle a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `primaryTimeoutMS 250`). It's case insensitive. To reset a setting to its default value, say `acceptableThrowawayItems reset`. To reset all settings, say `reset`. To see all settings that have been modified from their default values, say `modified`. From 66ffd1e0d9acb68b5b3b13a112522cd88b6d76db Mon Sep 17 00:00:00 2001 From: 0x22 <0x22@futureclient.net> Date: Thu, 17 Oct 2019 14:35:28 -0400 Subject: [PATCH 003/133] Disable harmful mob spawning in Travis auto test. --- .../java/baritone/utils/BaritoneAutoTest.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/baritone/utils/BaritoneAutoTest.java b/src/main/java/baritone/utils/BaritoneAutoTest.java index a723ebc5..7fe913ac 100644 --- a/src/main/java/baritone/utils/BaritoneAutoTest.java +++ b/src/main/java/baritone/utils/BaritoneAutoTest.java @@ -29,9 +29,7 @@ import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.settings.GameSettings; import net.minecraft.client.tutorial.TutorialSteps; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.GameType; -import net.minecraft.world.WorldSettings; -import net.minecraft.world.WorldType; +import net.minecraft.world.*; /** * Responsible for automatically testing Baritone's pathing algorithm by automatically creating a world with a specific @@ -85,15 +83,21 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper { if (mc.currentScreen instanceof GuiMainMenu) { System.out.println("Beginning Baritone automatic test routine"); mc.displayGuiScreen(null); - WorldSettings worldsettings = new WorldSettings(TEST_SEED, GameType.getByName("survival"), true, false, WorldType.DEFAULT); + WorldSettings worldsettings = new WorldSettings(TEST_SEED, GameType.SURVIVAL, true, false, WorldType.DEFAULT); mc.launchIntegratedServer("BaritoneAutoTest", "BaritoneAutoTest", worldsettings); } - // If the integrated server is launched and the world has initialized, set the spawn point - // to our defined starting position - if (mc.getIntegratedServer() != null && mc.getIntegratedServer().worlds[0] != null) { - mc.getIntegratedServer().worlds[0].setSpawnPoint(STARTING_POSITION); - mc.getIntegratedServer().worlds[0].getGameRules().setOrCreateGameRule("spawnRadius", "0"); + // If the integrated server is running, set the difficulty to peaceful + if (mc.getIntegratedServer() != null) { + mc.getIntegratedServer().setDifficultyForAllWorlds(EnumDifficulty.PEACEFUL); + + for (final WorldServer world : mc.getIntegratedServer().worlds) { + // If the world has initialized, set the spawn point to our defined starting position + if (world != null) { + world.setSpawnPoint(STARTING_POSITION); + world.getGameRules().setOrCreateGameRule("spawnRadius", "0"); + } + } } if (event.getType() == TickEvent.Type.IN) { // If we're in-game @@ -101,7 +105,7 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper { // Force the integrated server to share the world to LAN so that // the ingame pause menu gui doesn't actually pause our game if (mc.isSingleplayer() && !mc.getIntegratedServer().getPublic()) { - mc.getIntegratedServer().shareToLAN(GameType.getByName("survival"), false); + mc.getIntegratedServer().shareToLAN(GameType.SURVIVAL, false); } // For the first 200 ticks, wait for the world to generate From 43ab4f7d3b114748aec18be299f78e7404c76c64 Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 22 Oct 2019 15:58:10 -0500 Subject: [PATCH 004/133] Fix isPassable crash --- .../pathing/movement/MovementHelper.java | 27 ++++++++++--------- .../movement/movements/MovementParkour.java | 16 +++++------ .../baritone/pathing/path/PathExecutor.java | 6 ++--- .../baritone/utils/BlockStateInterface.java | 5 ++++ 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 725a0876..9fd1c75f 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -35,6 +35,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.IBlockAccess; import java.util.Optional; @@ -132,27 +133,29 @@ public interface MovementHelper extends ActionCosts, Helper { } return block == Blocks.WATER || block == Blocks.FLOWING_WATER; } - // every block that overrides isPassable with anything more complicated than a "return true;" or "return false;" - // has already been accounted for above - // therefore it's safe to not construct a blockpos from our x, y, z ints and instead just pass null - return block.isPassable(null, BlockPos.ORIGIN); + + return block.isPassable(bsi.world, bsi.isPassableBlockPos.setPos(x, y, z)); } /** * canWalkThrough but also won't impede movement at all. so not including doors or fence gates (we'd have to right click), * not including water, and not including ladders or vines or cobwebs (they slow us down) * - * @param context Calculation context to provide block state lookup - * @param x The block's x position - * @param y The block's y position - * @param z The block's z position + * @param bsi Block State Interface to provide block state lookup + * @param x The block's x position + * @param y The block's y position + * @param z The block's z position * @return Whether or not the block at the specified position */ - static boolean fullyPassable(CalculationContext context, int x, int y, int z) { - return fullyPassable(context.get(x, y, z)); + static boolean fullyPassable(BlockStateInterface bsi, int x, int y, int z) { + return fullyPassable(bsi.world, bsi.isPassableBlockPos.setPos(x, y, z), bsi.get0(x, y, z)); } - static boolean fullyPassable(IBlockState state) { + static boolean fullyPassable(IPlayerContext ctx, BlockPos pos) { + return fullyPassable(ctx.world(), pos, ctx.world().getBlockState(pos)); + } + + static boolean fullyPassable(IBlockAccess world, BlockPos pos, IBlockState state) { Block block = state.getBlock(); if (block == Blocks.AIR) { // early return for most common case return true; @@ -174,7 +177,7 @@ public interface MovementHelper extends ActionCosts, Helper { return false; } // door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters - return block.isPassable(null, null); + return block.isPassable(world, pos); } static boolean isReplaceable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index eb032210..7475182c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -69,7 +69,7 @@ public class MovementParkour extends Movement { int xDiff = dir.getXOffset(); int zDiff = dir.getZOffset(); - if (!MovementHelper.fullyPassable(context, x + xDiff, y, z + zDiff)) { + if (!MovementHelper.fullyPassable(context.bsi, x + xDiff, y, z + zDiff)) { // most common case at the top -- the adjacent block isn't air return; } @@ -81,13 +81,13 @@ public class MovementParkour extends Movement { if (MovementHelper.avoidWalkingInto(adj.getBlock()) && adj.getBlock() != Blocks.WATER && adj.getBlock() != Blocks.FLOWING_WATER) { // magma sucks return; } - if (!MovementHelper.fullyPassable(context, x + xDiff, y + 1, z + zDiff)) { + if (!MovementHelper.fullyPassable(context.bsi, x + xDiff, y + 1, z + zDiff)) { return; } - if (!MovementHelper.fullyPassable(context, x + xDiff, y + 2, z + zDiff)) { + if (!MovementHelper.fullyPassable(context.bsi, x + xDiff, y + 2, z + zDiff)) { return; } - if (!MovementHelper.fullyPassable(context, x, y + 2, z)) { + if (!MovementHelper.fullyPassable(context.bsi, x, y + 2, z)) { return; } IBlockState standingOn = context.get(x, y - 1, z); @@ -107,14 +107,14 @@ public class MovementParkour extends Movement { for (int i = 2; i <= maxJump; i++) { int destX = x + xDiff * i; int destZ = z + zDiff * i; - if (!MovementHelper.fullyPassable(context, destX, y + 1, destZ)) { + if (!MovementHelper.fullyPassable(context.bsi, destX, y + 1, destZ)) { return; } - if (!MovementHelper.fullyPassable(context, destX, y + 2, destZ)) { + if (!MovementHelper.fullyPassable(context.bsi, destX, y + 2, destZ)) { return; } IBlockState destInto = context.bsi.get0(destX, y, destZ); - if (!MovementHelper.fullyPassable(destInto)) { + if (!MovementHelper.fullyPassable(context.bsi.world, context.bsi.isPassableBlockPos.setPos(destX, y, destZ), destInto)) { if (i <= 3 && context.allowParkourAscend && context.canSprint && MovementHelper.canWalkOn(context.bsi, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) { res.x = destX; res.y = y + 1; @@ -134,7 +134,7 @@ public class MovementParkour extends Movement { } return; } - if (!MovementHelper.fullyPassable(context, destX, y + 3, destZ)) { + if (!MovementHelper.fullyPassable(context.bsi, destX, y + 3, destZ)) { return; } } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 97bee424..7e4f76a3 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -466,7 +466,7 @@ public class PathExecutor implements IPathExecutor, Helper { } for (int y = next.getDest().y; y <= movement.getSrc().y + 1; y++) { BlockPos chk = new BlockPos(next.getDest().x, y, next.getDest().z); - if (!MovementHelper.fullyPassable(ctx.world().getBlockState(chk))) { + if (!MovementHelper.fullyPassable(ctx, chk)) { break outer; } } @@ -491,7 +491,7 @@ public class PathExecutor implements IPathExecutor, Helper { } // we are centered BlockPos headBonk = current.getSrc().subtract(current.getDirection()).up(2); - if (MovementHelper.fullyPassable(ctx.world().getBlockState(headBonk))) { + if (MovementHelper.fullyPassable(ctx, headBonk)) { return true; } // wait 0.3 @@ -524,7 +524,7 @@ public class PathExecutor implements IPathExecutor, Helper { if (x == 1) { chk = chk.add(current.getDirection()); } - if (!MovementHelper.fullyPassable(ctx.world().getBlockState(chk))) { + if (!MovementHelper.fullyPassable(ctx, chk)) { return false; } } diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 84bdce5f..bbe5a17e 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -30,6 +30,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; @@ -42,6 +43,8 @@ public class BlockStateInterface { private final Long2ObjectMap loadedChunks; private final WorldData worldData; + public final IBlockAccess world; + public final BlockPos.MutableBlockPos isPassableBlockPos; private Chunk prev = null; private CachedRegion prevCached = null; @@ -59,6 +62,7 @@ public class BlockStateInterface { } public BlockStateInterface(World world, WorldData worldData, boolean copyLoadedChunks) { + this.world = world; this.worldData = worldData; Long2ObjectMap worldLoaded = ((IChunkProviderClient) world.getChunkProvider()).loadedChunks(); if (copyLoadedChunks) { @@ -70,6 +74,7 @@ public class BlockStateInterface { if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) { throw new IllegalStateException(); } + this.isPassableBlockPos = new BlockPos.MutableBlockPos(); } public boolean worldContainsLoadedChunk(int blockX, int blockZ) { From f02c33d95a7563a497b04195f661d754babc82db Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 23 Oct 2019 17:47:20 -0500 Subject: [PATCH 005/133] Fix improper tick count incrementation --- .../baritone/api/event/events/TickEvent.java | 18 ++++++++++-------- .../baritone/launch/mixins/MixinMinecraft.java | 10 +++++++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/api/java/baritone/api/event/events/TickEvent.java b/src/api/java/baritone/api/event/events/TickEvent.java index da8f8878..5c484ae4 100644 --- a/src/api/java/baritone/api/event/events/TickEvent.java +++ b/src/api/java/baritone/api/event/events/TickEvent.java @@ -19,22 +19,20 @@ package baritone.api.event.events; import baritone.api.event.events.type.EventState; +import java.util.function.BiFunction; + public final class TickEvent { + private static int overallTickCount; + private final EventState state; private final Type type; private final int count; - private static int overallTickCount; - - public TickEvent(EventState state, Type type) { + public TickEvent(EventState state, Type type, int count) { this.state = state; this.type = type; - this.count = incrementCount(); - } - - private static synchronized int incrementCount() { - return overallTickCount++; + this.count = count; } public int getCount() { @@ -49,6 +47,10 @@ public final class TickEvent { return state; } + public static synchronized BiFunction createNextProvider() { + final int count = overallTickCount++; + return (state, type) -> new TickEvent(state, type, count); + } public enum Type { /** diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java index 9dc835cd..3de4a0f5 100644 --- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -41,6 +41,8 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import java.util.function.BiFunction; + /** * @author Brady * @since 7/31/2018 @@ -84,13 +86,15 @@ public class MixinMinecraft { ) ) private void runTick(CallbackInfo ci) { - for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { + final BiFunction tickProvider = TickEvent.createNextProvider(); - TickEvent.Type type = ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().world() != null + for (IBaritone baritone : BaritoneAPI.getProvider().getAllBaritones()) { + + TickEvent.Type type = baritone.getPlayerContext().player() != null && baritone.getPlayerContext().world() != null ? TickEvent.Type.IN : TickEvent.Type.OUT; - ibaritone.getGameEventHandler().onTick(new TickEvent(EventState.PRE, type)); + baritone.getGameEventHandler().onTick(tickProvider.apply(EventState.PRE, type)); } } From 5201d39adf1ef1709ed35f3d61245b6364f7cf6f Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 24 Oct 2019 15:20:23 -0500 Subject: [PATCH 006/133] Retain old method signature --- .../pathing/movement/MovementHelper.java | 16 ++++++++++------ .../movement/movements/MovementParkour.java | 14 +++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 9fd1c75f..62a96a18 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -141,14 +141,18 @@ public interface MovementHelper extends ActionCosts, Helper { * canWalkThrough but also won't impede movement at all. so not including doors or fence gates (we'd have to right click), * not including water, and not including ladders or vines or cobwebs (they slow us down) * - * @param bsi Block State Interface to provide block state lookup - * @param x The block's x position - * @param y The block's y position - * @param z The block's z position + * @param context Calculation context to provide block state lookup + * @param x The block's x position + * @param y The block's y position + * @param z The block's z position * @return Whether or not the block at the specified position */ - static boolean fullyPassable(BlockStateInterface bsi, int x, int y, int z) { - return fullyPassable(bsi.world, bsi.isPassableBlockPos.setPos(x, y, z), bsi.get0(x, y, z)); + static boolean fullyPassable(CalculationContext context, int x, int y, int z) { + return fullyPassable( + context.bsi.world, + context.bsi.isPassableBlockPos.setPos(x, y, z), + context.bsi.get0(x, y, z) + ); } static boolean fullyPassable(IPlayerContext ctx, BlockPos pos) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 7475182c..0477c85c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -69,7 +69,7 @@ public class MovementParkour extends Movement { int xDiff = dir.getXOffset(); int zDiff = dir.getZOffset(); - if (!MovementHelper.fullyPassable(context.bsi, x + xDiff, y, z + zDiff)) { + if (!MovementHelper.fullyPassable(context, x + xDiff, y, z + zDiff)) { // most common case at the top -- the adjacent block isn't air return; } @@ -81,13 +81,13 @@ public class MovementParkour extends Movement { if (MovementHelper.avoidWalkingInto(adj.getBlock()) && adj.getBlock() != Blocks.WATER && adj.getBlock() != Blocks.FLOWING_WATER) { // magma sucks return; } - if (!MovementHelper.fullyPassable(context.bsi, x + xDiff, y + 1, z + zDiff)) { + if (!MovementHelper.fullyPassable(context, x + xDiff, y + 1, z + zDiff)) { return; } - if (!MovementHelper.fullyPassable(context.bsi, x + xDiff, y + 2, z + zDiff)) { + if (!MovementHelper.fullyPassable(context, x + xDiff, y + 2, z + zDiff)) { return; } - if (!MovementHelper.fullyPassable(context.bsi, x, y + 2, z)) { + if (!MovementHelper.fullyPassable(context, x, y + 2, z)) { return; } IBlockState standingOn = context.get(x, y - 1, z); @@ -107,10 +107,10 @@ public class MovementParkour extends Movement { for (int i = 2; i <= maxJump; i++) { int destX = x + xDiff * i; int destZ = z + zDiff * i; - if (!MovementHelper.fullyPassable(context.bsi, destX, y + 1, destZ)) { + if (!MovementHelper.fullyPassable(context, destX, y + 1, destZ)) { return; } - if (!MovementHelper.fullyPassable(context.bsi, destX, y + 2, destZ)) { + if (!MovementHelper.fullyPassable(context, destX, y + 2, destZ)) { return; } IBlockState destInto = context.bsi.get0(destX, y, destZ); @@ -134,7 +134,7 @@ public class MovementParkour extends Movement { } return; } - if (!MovementHelper.fullyPassable(context.bsi, destX, y + 3, destZ)) { + if (!MovementHelper.fullyPassable(context, destX, y + 3, destZ)) { return; } } From 82d520d8081a0189fddd31be9329b2910defc77a Mon Sep 17 00:00:00 2001 From: Greg Depoire--Ferrer Date: Fri, 25 Oct 2019 14:42:36 +0200 Subject: [PATCH 007/133] Don't print invalid type error to stderr --- .../CommandErrorMessageException.java | 4 ++++ .../command/exception/CommandException.java | 4 ++++ .../CommandInvalidArgumentException.java | 21 +++++++++++++------ .../CommandInvalidTypeException.java | 4 ++-- .../command/argument/ArgConsumer.java | 5 ++--- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/api/java/baritone/api/command/exception/CommandErrorMessageException.java b/src/api/java/baritone/api/command/exception/CommandErrorMessageException.java index 4a21bede..b3161516 100644 --- a/src/api/java/baritone/api/command/exception/CommandErrorMessageException.java +++ b/src/api/java/baritone/api/command/exception/CommandErrorMessageException.java @@ -22,4 +22,8 @@ public abstract class CommandErrorMessageException extends CommandException { protected CommandErrorMessageException(String reason) { super(reason); } + + protected CommandErrorMessageException(String reason, Throwable cause) { + super(reason, cause); + } } diff --git a/src/api/java/baritone/api/command/exception/CommandException.java b/src/api/java/baritone/api/command/exception/CommandException.java index b8962c15..53b8e602 100644 --- a/src/api/java/baritone/api/command/exception/CommandException.java +++ b/src/api/java/baritone/api/command/exception/CommandException.java @@ -22,4 +22,8 @@ public abstract class CommandException extends Exception implements ICommandExce protected CommandException(String reason) { super(reason); } + + protected CommandException(String reason, Throwable cause) { + super(reason, cause); + } } diff --git a/src/api/java/baritone/api/command/exception/CommandInvalidArgumentException.java b/src/api/java/baritone/api/command/exception/CommandInvalidArgumentException.java index 1902d735..6997d6d6 100644 --- a/src/api/java/baritone/api/command/exception/CommandInvalidArgumentException.java +++ b/src/api/java/baritone/api/command/exception/CommandInvalidArgumentException.java @@ -23,12 +23,21 @@ public abstract class CommandInvalidArgumentException extends CommandErrorMessag public final ICommandArgument arg; - protected CommandInvalidArgumentException(ICommandArgument arg, String reason) { - super(String.format( - "Error at argument #%s: %s", - arg.getIndex() == -1 ? "" : Integer.toString(arg.getIndex() + 1), - reason - )); + protected CommandInvalidArgumentException(ICommandArgument arg, String message) { + super(formatMessage(arg, message)); this.arg = arg; } + + protected CommandInvalidArgumentException(ICommandArgument arg, String message, Throwable cause) { + super(formatMessage(arg, message), cause); + this.arg = arg; + } + + private static String formatMessage(ICommandArgument arg, String message) { + return String.format( + "Error at argument #%s: %s", + arg.getIndex() == -1 ? "" : Integer.toString(arg.getIndex() + 1), + message + ); + } } diff --git a/src/api/java/baritone/api/command/exception/CommandInvalidTypeException.java b/src/api/java/baritone/api/command/exception/CommandInvalidTypeException.java index 516fd308..06658c3a 100644 --- a/src/api/java/baritone/api/command/exception/CommandInvalidTypeException.java +++ b/src/api/java/baritone/api/command/exception/CommandInvalidTypeException.java @@ -26,7 +26,7 @@ public class CommandInvalidTypeException extends CommandInvalidArgumentException } public CommandInvalidTypeException(ICommandArgument arg, String expected, Throwable cause) { - super(arg, String.format("Expected %s.\nMore details: %s", expected, cause.getMessage())); + super(arg, String.format("Expected %s", expected), cause); } public CommandInvalidTypeException(ICommandArgument arg, String expected, String got) { @@ -34,6 +34,6 @@ public class CommandInvalidTypeException extends CommandInvalidArgumentException } public CommandInvalidTypeException(ICommandArgument arg, String expected, String got, Throwable cause) { - super(arg, String.format("Expected %s, but got %s instead.\nMore details: %s", expected, got, cause.getMessage())); + super(arg, String.format("Expected %s, but got %s instead", expected, got), cause); } } diff --git a/src/main/java/baritone/command/argument/ArgConsumer.java b/src/main/java/baritone/command/argument/ArgConsumer.java index 651ca50b..f4e7dd52 100644 --- a/src/main/java/baritone/command/argument/ArgConsumer.java +++ b/src/main/java/baritone/command/argument/ArgConsumer.java @@ -316,8 +316,7 @@ public class ArgConsumer implements IArgConsumer { try { return datatype.apply(this.context, original); } catch (Exception e) { - e.printStackTrace(); - throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName()); + throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e); } } @@ -346,7 +345,7 @@ public class ArgConsumer implements IArgConsumer { try { return datatype.get(this.context); } catch (Exception e) { - throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName()); + throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e); } } From 0db4b193e14b5df0990b5c65c512a72399da534c Mon Sep 17 00:00:00 2001 From: Greg Depoire--Ferrer Date: Fri, 25 Oct 2019 14:48:53 +0200 Subject: [PATCH 008/133] Remove hack, add comment, don't use default when arg is required --- .../api/command/datatypes/RelativeGoal.java | 42 +++++++------------ .../command/defaults/GotoCommand.java | 8 +++- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/api/java/baritone/api/command/datatypes/RelativeGoal.java b/src/api/java/baritone/api/command/datatypes/RelativeGoal.java index cda0ad66..19312907 100644 --- a/src/api/java/baritone/api/command/datatypes/RelativeGoal.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeGoal.java @@ -38,38 +38,26 @@ public enum RelativeGoal implements IDatatypePost { if (origin == null) { origin = BetterBlockPos.ORIGIN; } + final IArgConsumer consumer = ctx.getConsumer(); - List> coords = new ArrayList<>(); - final IArgConsumer copy = consumer.copy(); // This is a hack and should be fixed in the future probably - for (int i = 0; i < 3; i++) { - if (copy.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { - coords.add(o -> consumer.getDatatypePost(RelativeCoordinate.INSTANCE, o)); - copy.get(); // Consume so we actually decrement the remaining arguments - } + GoalBlock goalBlock = consumer.peekDatatypePostOrNull(RelativeGoalBlock.INSTANCE, origin); + if (goalBlock != null) { + return goalBlock; } - switch (coords.size()) { - case 0: - return new GoalBlock(origin); - case 1: - return new GoalYLevel( - MathHelper.floor(coords.get(0).apply((double) origin.y)) - ); - case 2: - return new GoalXZ( - MathHelper.floor(coords.get(0).apply((double) origin.x)), - MathHelper.floor(coords.get(1).apply((double) origin.z)) - ); - case 3: - return new GoalBlock( - MathHelper.floor(coords.get(0).apply((double) origin.x)), - MathHelper.floor(coords.get(1).apply((double) origin.y)), - MathHelper.floor(coords.get(2).apply((double) origin.z)) - ); - default: - throw new IllegalStateException("Unexpected coords size: " + coords.size()); + GoalXZ goalXZ = consumer.peekDatatypePostOrNull(RelativeGoalXZ.INSTANCE, origin); + if (goalXZ != null) { + return goalXZ; } + + GoalYLevel goalYLevel = consumer.peekDatatypePostOrNull(RelativeGoalYLevel.INSTANCE, origin); + if (goalYLevel != null) { + return goalYLevel; + } + + // when the user doesn't input anything, default to the origin + return new GoalBlock(origin); } @Override diff --git a/src/main/java/baritone/command/defaults/GotoCommand.java b/src/main/java/baritone/command/defaults/GotoCommand.java index 427e67b2..28e76829 100644 --- a/src/main/java/baritone/command/defaults/GotoCommand.java +++ b/src/main/java/baritone/command/defaults/GotoCommand.java @@ -41,9 +41,13 @@ public class GotoCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { - if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { // if we have a numeric first argument... + // If we have a numeric first argument, then parse arguments as coordinates. + // Note: There is no reason to want to go where you're already at so there + // is no need to handle the case of empty arguments. + if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { + args.requireMax(3); BetterBlockPos origin = baritone.getPlayerContext().playerFeet(); - Goal goal = args.getDatatypePostOrNull(RelativeGoal.INSTANCE, origin); + Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin); logDirect(String.format("Going to: %s", goal.toString())); baritone.getCustomGoalProcess().setGoalAndPath(goal); return; From 23fc6c8b494cc523a6278696da6d34c2156c49be Mon Sep 17 00:00:00 2001 From: Greg Depoire--Ferrer Date: Fri, 25 Oct 2019 14:49:49 +0200 Subject: [PATCH 009/133] Add a space between sentences in error message --- .../api/command/exception/CommandUnhandledException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/command/exception/CommandUnhandledException.java b/src/api/java/baritone/api/command/exception/CommandUnhandledException.java index fe0b09fa..02987d4e 100644 --- a/src/api/java/baritone/api/command/exception/CommandUnhandledException.java +++ b/src/api/java/baritone/api/command/exception/CommandUnhandledException.java @@ -37,7 +37,7 @@ public class CommandUnhandledException extends RuntimeException implements IComm @Override public void handle(ICommand command, List args) { - HELPER.logDirect("An unhandled exception occurred." + + HELPER.logDirect("An unhandled exception occurred. " + "The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues", TextFormatting.RED); From 2ae16d8bb1cd6bed87fe2a4858ac2e5458911079 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 26 Oct 2019 16:01:08 -0700 Subject: [PATCH 010/133] configurable block reach distance --- src/api/java/baritone/api/Settings.java | 5 +++++ src/api/java/baritone/api/utils/IPlayerController.java | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 776d8e61..3ca6dd9a 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -248,6 +248,11 @@ public final class Settings { */ public final Setting rightClickSpeed = new Setting<>(4); + /** + * Block reach distance + */ + public final Setting blockReachDistance = new Setting<>(4.5f); + /** * How many degrees to randomize the pitch and yaw every tick. Set to 0 to disable */ diff --git a/src/api/java/baritone/api/utils/IPlayerController.java b/src/api/java/baritone/api/utils/IPlayerController.java index 05199fca..d6fa1837 100644 --- a/src/api/java/baritone/api/utils/IPlayerController.java +++ b/src/api/java/baritone/api/utils/IPlayerController.java @@ -17,6 +17,7 @@ package baritone.api.utils; +import baritone.api.BaritoneAPI; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ClickType; @@ -56,6 +57,6 @@ public interface IPlayerController { void setHittingBlock(boolean hittingBlock); default double getBlockReachDistance() { - return this.getGameType().isCreative() ? 5.0F : 4.5F; + return this.getGameType().isCreative() ? 5.0F : BaritoneAPI.getSettings().blockReachDistance.value; } } From 45ea776090cf5d17aa660bcfe1a81116f3a64453 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 28 Oct 2019 10:47:20 -0700 Subject: [PATCH 011/133] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 90173889..043aed08 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ ![Lines of Code](https://tokei.rs/b1/github/cabaletta/baritone?category=code) [![GitHub contributors](https://img.shields.io/github/contributors/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/graphs/contributors/) [![GitHub commits](https://img.shields.io/github/commits-since/cabaletta/baritone/v1.0.0.svg)](https://github.com/cabaletta/baritone/commit/) -[![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.10%20/%20v1.3.5%20/%20v1.4.2-brightgreen.svg)](https://impactclient.net/) +[![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.10%20/%20v1.3.5%20/%20v1.4.3-brightgreen.svg)](https://impactclient.net/) [![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/) [![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api) [![WWE integration](https://img.shields.io/badge/WWE%20%22integration%22-master%3F-green.svg)](https://wweclient.com/) From 152285043d89a49931a1ea9db7563d7e96c56908 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 5 Nov 2019 11:50:27 -0800 Subject: [PATCH 012/133] Update USAGE.md --- USAGE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USAGE.md b/USAGE.md index 11810499..0f911efa 100644 --- a/USAGE.md +++ b/USAGE.md @@ -16,7 +16,7 @@ Try `#help` I promise it won't just send you back here =) "wtf where is cleararea" -> look at `#help sel` -"wtf where is goto death, goto waypoint" -> look at `#help wp` +"wtf where is goto death, goto waypoint" -> look at `#help wp` (a "tag" is like "home" (created automatically on right clicking a bed) or "death" (created automatically on death) or "user" (has to be created manually)). So you might want `#wp save user coolbiome` then, to set the goal `#wp goal coolbiome` then `#path` to path to it. For death, `#wp goal death` (remember stuff is clickable!). just look at `#help` lmao From 7e3a2d3c0a676ef955c1b345b1a789d51e8c6834 Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 5 Nov 2019 18:17:10 -0600 Subject: [PATCH 013/133] Create a BlockStateInterface specialized IBlockAccess wrapper --- .../pathing/movement/MovementHelper.java | 8 +- .../movement/movements/MovementParkour.java | 2 +- .../baritone/utils/BlockStateInterface.java | 4 +- .../BlockStateInterfaceAccessWrapper.java | 80 +++++++++++++++++++ 4 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 62a96a18..31a1de7a 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -134,7 +134,7 @@ public interface MovementHelper extends ActionCosts, Helper { return block == Blocks.WATER || block == Blocks.FLOWING_WATER; } - return block.isPassable(bsi.world, bsi.isPassableBlockPos.setPos(x, y, z)); + return block.isPassable(bsi.access, bsi.isPassableBlockPos.setPos(x, y, z)); } /** @@ -149,7 +149,7 @@ public interface MovementHelper extends ActionCosts, Helper { */ static boolean fullyPassable(CalculationContext context, int x, int y, int z) { return fullyPassable( - context.bsi.world, + context.bsi.access, context.bsi.isPassableBlockPos.setPos(x, y, z), context.bsi.get0(x, y, z) ); @@ -159,7 +159,7 @@ public interface MovementHelper extends ActionCosts, Helper { return fullyPassable(ctx.world(), pos, ctx.world().getBlockState(pos)); } - static boolean fullyPassable(IBlockAccess world, BlockPos pos, IBlockState state) { + static boolean fullyPassable(IBlockAccess access, BlockPos pos, IBlockState state) { Block block = state.getBlock(); if (block == Blocks.AIR) { // early return for most common case return true; @@ -181,7 +181,7 @@ public interface MovementHelper extends ActionCosts, Helper { return false; } // door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters - return block.isPassable(world, pos); + return block.isPassable(access, pos); } static boolean isReplaceable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 0477c85c..3d3426da 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -114,7 +114,7 @@ public class MovementParkour extends Movement { return; } IBlockState destInto = context.bsi.get0(destX, y, destZ); - if (!MovementHelper.fullyPassable(context.bsi.world, context.bsi.isPassableBlockPos.setPos(destX, y, destZ), destInto)) { + if (!MovementHelper.fullyPassable(context.bsi.access, context.bsi.isPassableBlockPos.setPos(destX, y, destZ), destInto)) { if (i <= 3 && context.allowParkourAscend && context.canSprint && MovementHelper.canWalkOn(context.bsi, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) { res.x = destX; res.y = y + 1; diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index bbe5a17e..4f5f2689 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -43,8 +43,9 @@ public class BlockStateInterface { private final Long2ObjectMap loadedChunks; private final WorldData worldData; - public final IBlockAccess world; + protected final IBlockAccess world; public final BlockPos.MutableBlockPos isPassableBlockPos; + public final IBlockAccess access; private Chunk prev = null; private CachedRegion prevCached = null; @@ -75,6 +76,7 @@ public class BlockStateInterface { throw new IllegalStateException(); } this.isPassableBlockPos = new BlockPos.MutableBlockPos(); + this.access = new BlockStateInterfaceAccessWrapper(this); } public boolean worldContainsLoadedChunk(int blockX, int blockZ) { diff --git a/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java b/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java new file mode 100644 index 00000000..6ce70193 --- /dev/null +++ b/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java @@ -0,0 +1,80 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils; + +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.WorldType; +import net.minecraft.world.biome.Biome; + +import javax.annotation.Nullable; + +/** + * @author Brady + * @since 11/5/2019 + */ +@SuppressWarnings("NullableProblems") +public final class BlockStateInterfaceAccessWrapper implements IBlockAccess { + + private final BlockStateInterface bsi; + + BlockStateInterfaceAccessWrapper(BlockStateInterface bsi) { + this.bsi = bsi; + } + + @Nullable + @Override + public TileEntity getTileEntity(BlockPos pos) { + throw new UnsupportedOperationException("getTileEntity not supported by BlockStateInterfaceAccessWrapper"); + } + + @Override + public int getCombinedLight(BlockPos pos, int lightValue) { + throw new UnsupportedOperationException("getCombinedLight not supported by BlockStateInterfaceAccessWrapper"); + } + + @Override + public IBlockState getBlockState(BlockPos pos) { + // BlockStateInterface#get0(BlockPos) btfo! + return this.bsi.get0(pos.getX(), pos.getY(), pos.getZ()); + } + + @Override + public boolean isAirBlock(BlockPos pos) { + return this.bsi.get0(pos.getX(), pos.getY(), pos.getZ()).getMaterial() == Material.AIR; + } + + @Override + public Biome getBiome(BlockPos pos) { + throw new UnsupportedOperationException("getBiome not supported by BlockStateInterfaceAccessWrapper"); + } + + @Override + public int getStrongPower(BlockPos pos, EnumFacing direction) { + throw new UnsupportedOperationException("getStrongPower not supported by BlockStateInterfaceAccessWrapper"); + } + + @Override + public WorldType getWorldType() { + return this.bsi.world.getWorldType(); + } +} From ed144e995bc51430f0d665924a7d3193a78b2466 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 10 Nov 2019 14:04:27 -0800 Subject: [PATCH 014/133] apparently this usage of > was an invalid javadoc command lol --- src/api/java/baritone/api/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 3ca6dd9a..22b5d187 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -234,7 +234,7 @@ public final class Settings { /** * If we overshoot a traverse and end up one block beyond the destination, mark it as successful anyway. *

- * This helps with speed at >=20m/s + * This helps with speed exceeding 20m/s */ public final Setting overshootTraverse = new Setting<>(true); From 0fba32853b61891ee9608bad4553c0dad9c6ec03 Mon Sep 17 00:00:00 2001 From: Conner Vercellino Date: Wed, 20 Nov 2019 12:26:37 -0800 Subject: [PATCH 015/133] Create .gitmessage --- .gitmessage | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .gitmessage diff --git a/.gitmessage b/.gitmessage new file mode 100644 index 00000000..259d0702 --- /dev/null +++ b/.gitmessage @@ -0,0 +1,31 @@ + (<ticket>) + +# πŸ“ Update README.md (WD-1234) +# βœ… Add unit test for inputs (WD-1234) + +# <emoji> can be: +# 🎨 :art: when improving structure of the code +# ⚑️ :zap: when improving performance +# πŸ”₯ :fire: when removing code or files +# ✨ :sparkles: when introducing new features +# 🚧 :construction: when work in progress +# πŸ”¨ :hammer: when refactoring code +# πŸ“ :memo: when writing docs +# πŸ’„ :lipstick: when updating the UI and style files +# πŸ“ˆ :chart_with_upwards_trend: when adding analytics or tracking code +# 🌐 :globe_with_meridians: when adding internationalization and localization +# ✏️ :pencil2: when fixing typos +# 🚚 :truck: when moving or renaming files +# βœ… :white_check_mark: when adding tests + +# πŸ‘Œ :ok_hand: when updating code due to code review changes +# πŸ› :bug: when fixing a bug +# πŸš‘ :ambulance: when doing a critical hotfix +# 🚨 :rotating_light: when removing linter warnings + +# πŸ”€ :twisted_rightwards_arrows: when merging branches +# ⬆️ :arrow_up: when upgrading dependencies +# ⬇️ :arrow_down: when downgrading dependencies +# πŸ”§ :wrench: when changing configuration files +# πŸ”– :bookmark: when releasing / version tagging +# πŸ’š :green_heart: when fixing the CI build From ddc681fe772a4a8a3550d4f34a963bc1cc163b61 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sun, 24 Nov 2019 11:11:21 -0800 Subject: [PATCH 016/133] build repeat count --- src/api/java/baritone/api/Settings.java | 5 +++++ src/main/java/baritone/process/BuilderProcess.java | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 22b5d187..14a13183 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -743,6 +743,11 @@ public final class Settings { */ public final Setting<Vec3i> buildRepeat = new Setting<>(new Vec3i(0, 0, 0)); + /** + * How many times to buildrepeat. -1 for infinite. + */ + public final Setting<Integer> buildRepeatCount = new Setting<>(-1); + /** * Allow standing above a block while mining it, in BuilderProcess * <p> diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 4300ce53..17cbe110 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -26,7 +26,10 @@ import baritone.api.process.IBuilderProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.api.schematic.ISchematic; -import baritone.api.utils.*; +import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.RayTraceUtils; +import baritone.api.utils.Rotation; +import baritone.api.utils.RotationUtils; import baritone.api.utils.input.Input; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; @@ -69,6 +72,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil private int ticks; private boolean paused; private int layer; + private int numRepeats; private List<IBlockState> approxPlaceable; public BuilderProcess(Baritone baritone) { @@ -95,6 +99,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil this.origin = new Vec3i(x, y, z); this.paused = false; this.layer = 0; + this.numRepeats = 0; this.observedCompleted = new LongOpenHashSet(); } @@ -391,7 +396,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil return onTick(calcFailed, isSafeToCancel); } Vec3i repeat = Baritone.settings().buildRepeat.value; - if (repeat.equals(new Vec3i(0, 0, 0))) { + int max = Baritone.settings().buildRepeatCount.value; + numRepeats++; + if (repeat.equals(new Vec3i(0, 0, 0)) || (max != -1 && numRepeats >= max)) { logDirect("Done building"); onLostControl(); return null; @@ -731,6 +738,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil schematic = null; realSchematic = null; layer = 0; + numRepeats = 0; paused = false; observedCompleted = null; } From 2c3e1f42321fd65c2d3d1e7fd41e936adde94aae Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Fri, 13 Dec 2019 20:09:04 -0800 Subject: [PATCH 017/133] builder stuff, fixes #1059 --- src/api/java/baritone/api/Settings.java | 14 ++++++++++++++ src/main/java/baritone/process/BuilderProcess.java | 11 ++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 14a13183..dac1ae55 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -184,6 +184,20 @@ public final class Settings { Blocks.WALL_SIGN ))); + /** + * A list of blocks to be treated as if they're air. + * <p> + * If a schematic asks for air at a certain position, and that position currently contains a block on this list, it will be treated as correct. + */ + public final Setting<List<Block>> buildIgnoreBlocks = new Setting<>(new ArrayList<>(Arrays.asList( + + ))); + + /** + * If this is true, the builder will treat all non-air blocks as correct. It will only place new blocks. + */ + public final Setting<Boolean> buildIgnoreExisting = new Setting<>(true); + /** * If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block. * <p> diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 17cbe110..4d66a764 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -764,11 +764,20 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } private boolean valid(IBlockState current, IBlockState desired) { + if (desired == null) { + return true; + } // TODO more complicated comparison logic I guess if (current.getBlock() instanceof BlockLiquid && Baritone.settings().okIfWater.value) { return true; } - return desired == null || current.equals(desired); + if (desired.getBlock() instanceof BlockAir && Baritone.settings().buildIgnoreBlocks.value.contains(current.getBlock())) { + return true; + } + if (!(current.getBlock() instanceof BlockAir) && Baritone.settings().buildIgnoreExisting.value) { + return true; + } + return current.equals(desired); } public class BuilderCalculationContext extends CalculationContext { From 937d4cc8847a2cbd59ecc0e1f1d7f5f354c09107 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Fri, 13 Dec 2019 20:46:12 -0800 Subject: [PATCH 018/133] whoops --- src/api/java/baritone/api/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index dac1ae55..bf077f1a 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -196,7 +196,7 @@ public final class Settings { /** * If this is true, the builder will treat all non-air blocks as correct. It will only place new blocks. */ - public final Setting<Boolean> buildIgnoreExisting = new Setting<>(true); + public final Setting<Boolean> buildIgnoreExisting = new Setting<>(false); /** * If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block. From 5c9f02810347ec8e5bc0c98d0938eefbbd1f4330 Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Wed, 18 Dec 2019 10:24:43 -0600 Subject: [PATCH 019/133] Initial sponge support --- .../api/schematic/AbstractSchematic.java | 4 + .../baritone/api/utils/BlockOptionalMeta.java | 8 +- .../java/baritone/process/BuilderProcess.java | 31 ++- .../utils/schematic/MapArtSchematic.java | 42 +++- .../baritone/utils/schematic/Schematic.java | 92 -------- .../schematic/format/SchematicFormat.java | 70 ++++++ .../schematic/parse/ISchematicParser.java | 32 +++ .../utils/schematic/parse/MCEditParser.java | 94 ++++++++ .../utils/schematic/parse/SpongeParser.java | 202 ++++++++++++++++++ 9 files changed, 456 insertions(+), 119 deletions(-) delete mode 100644 src/main/java/baritone/utils/schematic/Schematic.java create mode 100644 src/main/java/baritone/utils/schematic/format/SchematicFormat.java create mode 100644 src/main/java/baritone/utils/schematic/parse/ISchematicParser.java create mode 100644 src/main/java/baritone/utils/schematic/parse/MCEditParser.java create mode 100644 src/main/java/baritone/utils/schematic/parse/SpongeParser.java diff --git a/src/api/java/baritone/api/schematic/AbstractSchematic.java b/src/api/java/baritone/api/schematic/AbstractSchematic.java index 3cd14747..cca6bc96 100644 --- a/src/api/java/baritone/api/schematic/AbstractSchematic.java +++ b/src/api/java/baritone/api/schematic/AbstractSchematic.java @@ -23,6 +23,10 @@ public abstract class AbstractSchematic implements ISchematic { protected int y; protected int z; + public AbstractSchematic() { + this(0, 0, 0); + } + public AbstractSchematic(int x, int y, int z) { this.x = x; this.y = y; diff --git a/src/api/java/baritone/api/utils/BlockOptionalMeta.java b/src/api/java/baritone/api/utils/BlockOptionalMeta.java index 3ab76dd2..451d95eb 100644 --- a/src/api/java/baritone/api/utils/BlockOptionalMeta.java +++ b/src/api/java/baritone/api/utils/BlockOptionalMeta.java @@ -178,12 +178,12 @@ public final class BlockOptionalMeta { normalizations = Collections.unmodifiableMap(_normalizations); } - private static <C extends Comparable<C>, P extends IProperty<C>> P castToIProperty(Object value) { + public static <C extends Comparable<C>, P extends IProperty<C>> P castToIProperty(Object value) { //noinspection unchecked return (P) value; } - private static <C extends Comparable<C>, P extends IProperty<C>> C castToIPropertyValue(P iproperty, Object value) { + public static <C extends Comparable<C>, P extends IProperty<C>> C castToIPropertyValue(P iproperty, Object value) { //noinspection unchecked return (C) value; } @@ -191,6 +191,10 @@ public final class BlockOptionalMeta { public static IBlockState normalize(IBlockState state) { IBlockState newState = state; + // TODO: Can the state not be normalized by simply doing...? + // return state.getBlock().getDefaultState(); + // ??? + for (IProperty<?> property : state.getProperties().keySet()) { Class<?> valueClass = property.getValueClass(); if (normalizations.containsKey(property)) { diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 4d66a764..1dfd6c82 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -39,7 +39,7 @@ import baritone.utils.BlockStateInterface; import baritone.utils.PathingCommandContext; import baritone.utils.schematic.FillSchematic; import baritone.utils.schematic.MapArtSchematic; -import baritone.utils.schematic.Schematic; +import baritone.utils.schematic.format.SchematicFormat; import baritone.utils.schematic.schematica.SchematicaHelper; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import net.minecraft.block.BlockAir; @@ -48,15 +48,12 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.Tuple; import net.minecraft.util.math.*; import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.util.*; import static baritone.api.pathing.movement.ActionCosts.COST_INF; @@ -118,18 +115,24 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public boolean build(String name, File schematic, Vec3i origin) { - NBTTagCompound tag; - try (FileInputStream fileIn = new FileInputStream(schematic)) { - tag = CompressedStreamTools.readCompressed(fileIn); - } catch (IOException e) { + Optional<SchematicFormat> format = SchematicFormat.getByFile(schematic); + if (!format.isPresent()) { + return false; + } + + ISchematic parsed; + try { + parsed = format.get().getParser().parse(new FileInputStream(schematic)); + } catch (Exception e) { e.printStackTrace(); return false; } - //noinspection ConstantConditions - if (tag == null) { - return false; + + if (Baritone.settings().mapArtMode.value) { + parsed = new MapArtSchematic(parsed); } - build(name, parse(tag), origin); + + build(name, parsed, origin); return true; } @@ -160,10 +163,6 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil return new ArrayList<>(approxPlaceable); } - private static ISchematic parse(NBTTagCompound schematic) { - return Baritone.settings().mapArtMode.value ? new MapArtSchematic(schematic) : new Schematic(schematic); - } - @Override public boolean isActive() { return schematic != null; diff --git a/src/main/java/baritone/utils/schematic/MapArtSchematic.java b/src/main/java/baritone/utils/schematic/MapArtSchematic.java index 32b3292c..33ec3a15 100644 --- a/src/main/java/baritone/utils/schematic/MapArtSchematic.java +++ b/src/main/java/baritone/utils/schematic/MapArtSchematic.java @@ -17,24 +17,29 @@ package baritone.utils.schematic; +import baritone.api.schematic.AbstractSchematic; +import baritone.api.schematic.ISchematic; import net.minecraft.block.BlockAir; import net.minecraft.block.state.IBlockState; -import net.minecraft.nbt.NBTTagCompound; +import java.util.List; import java.util.OptionalInt; import java.util.function.Predicate; -public class MapArtSchematic extends Schematic { +public class MapArtSchematic extends AbstractSchematic { + private final ISchematic child; private final int[][] heightMap; - public MapArtSchematic(NBTTagCompound schematic) { - super(schematic); - heightMap = new int[widthX][lengthZ]; + public MapArtSchematic(ISchematic schematic) { + super(schematic.widthX(), schematic.heightY(), schematic.lengthZ()); + this.child = schematic; - for (int x = 0; x < widthX; x++) { - for (int z = 0; z < lengthZ; z++) { - IBlockState[] column = states[x][z]; + heightMap = new int[schematic.widthX()][schematic.lengthZ()]; + + for (int x = 0; x < schematic.widthX(); x++) { + for (int z = 0; z < schematic.lengthZ(); z++) { + IBlockState[] column = /*states[x][z]*/null; OptionalInt lowestBlockY = lastIndexMatching(column, state -> !(state.getBlock() instanceof BlockAir)); if (lowestBlockY.isPresent()) { @@ -44,7 +49,6 @@ public class MapArtSchematic extends Schematic { System.out.println("Letting it be whatever"); heightMap[x][z] = 256; } - } } } @@ -63,4 +67,24 @@ public class MapArtSchematic extends Schematic { // in map art, we only care about coordinates in or above the art return super.inSchematic(x, y, z, currentState) && y >= heightMap[x][z]; } + + @Override + public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { + return this.child.desiredState(x, y, z, current, approxPlaceable); + } + + @Override + public int widthX() { + return this.child.widthX(); + } + + @Override + public int heightY() { + return this.child.heightY(); + } + + @Override + public int lengthZ() { + return this.child.lengthZ(); + } } diff --git a/src/main/java/baritone/utils/schematic/Schematic.java b/src/main/java/baritone/utils/schematic/Schematic.java deleted file mode 100644 index 1169578a..00000000 --- a/src/main/java/baritone/utils/schematic/Schematic.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see <https://www.gnu.org/licenses/>. - */ - -package baritone.utils.schematic; - -import baritone.api.schematic.ISchematic; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.nbt.NBTTagCompound; - -import java.util.List; - -public class Schematic implements ISchematic { - - public final int widthX; - public final int heightY; - public final int lengthZ; - protected final IBlockState[][][] states; - - public Schematic(NBTTagCompound schematic) { - String type = schematic.getString("Materials"); - if (!type.equals("Alpha")) { - throw new IllegalStateException("bad schematic " + type); - } - widthX = schematic.getInteger("Width"); - heightY = schematic.getInteger("Height"); - lengthZ = schematic.getInteger("Length"); - byte[] blocks = schematic.getByteArray("Blocks"); - byte[] metadata = schematic.getByteArray("Data"); - - byte[] additional = null; - if (schematic.hasKey("AddBlocks")) { - byte[] addBlocks = schematic.getByteArray("AddBlocks"); - additional = new byte[addBlocks.length * 2]; - for (int i = 0; i < addBlocks.length; i++) { - additional[i * 2 + 0] = (byte) ((addBlocks[i] >> 4) & 0xF); // lower nibble - additional[i * 2 + 1] = (byte) ((addBlocks[i] >> 0) & 0xF); // upper nibble - } - } - states = new IBlockState[widthX][lengthZ][heightY]; - for (int y = 0; y < heightY; y++) { - for (int z = 0; z < lengthZ; z++) { - for (int x = 0; x < widthX; x++) { - int blockInd = (y * lengthZ + z) * widthX + x; - - int blockID = blocks[blockInd] & 0xFF; - if (additional != null) { - // additional is 0 through 15 inclusive since it's & 0xF above - blockID |= additional[blockInd] << 8; - } - Block block = Block.REGISTRY.getObjectById(blockID); - int meta = metadata[blockInd] & 0xFF; - states[x][z][y] = block.getStateFromMeta(meta); - } - } - } - } - - @Override - public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { - return states[x][z][y]; - } - - @Override - public int widthX() { - return widthX; - } - - @Override - public int heightY() { - return heightY; - } - - @Override - public int lengthZ() { - return lengthZ; - } -} diff --git a/src/main/java/baritone/utils/schematic/format/SchematicFormat.java b/src/main/java/baritone/utils/schematic/format/SchematicFormat.java new file mode 100644 index 00000000..5f103d9a --- /dev/null +++ b/src/main/java/baritone/utils/schematic/format/SchematicFormat.java @@ -0,0 +1,70 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.utils.schematic.format; + +import baritone.utils.schematic.parse.ISchematicParser; +import baritone.utils.schematic.parse.MCEditParser; +import baritone.utils.schematic.parse.SpongeParser; +import org.apache.commons.io.FilenameUtils; + +import java.io.File; +import java.util.Optional; +import java.util.stream.Stream; + +/** + * @author Brady + * @since 12/13/2019 + */ +public enum SchematicFormat { + + /** + * The MCEdit schematic specification. Commonly denoted by the ".schematic" file extension. + */ + MCEDIT("schematic", MCEditParser.INSTANCE), + + /** + * The SpongePowered Schematic Specification. Commonly denoted by the ".schem" file extension. + * + * @see <a href="https://github.com/SpongePowered/Schematic-Specification">Sponge Schematic Specification</a> + */ + SPONGE("schem", SpongeParser.INSTANCE); + + private final String extension; + private final ISchematicParser parser; + + SchematicFormat(String extension, ISchematicParser parser) { + this.extension = extension; + this.parser = parser; + } + + public final ISchematicParser getParser() { + return this.parser; + } + + public static Optional<SchematicFormat> getByFile(File schematic) { + // TODO: Better identification + // Maybe peek file contents and make a safe determination? + return getByExtension(FilenameUtils.getExtension(schematic.getAbsolutePath())); + } + + public static Optional<SchematicFormat> getByExtension(String extension) { + return extension == null || extension.isEmpty() + ? Optional.empty() + : Stream.of(values()).filter(format -> format.extension.equals(extension)).findFirst(); + } +} diff --git a/src/main/java/baritone/utils/schematic/parse/ISchematicParser.java b/src/main/java/baritone/utils/schematic/parse/ISchematicParser.java new file mode 100644 index 00000000..040addc1 --- /dev/null +++ b/src/main/java/baritone/utils/schematic/parse/ISchematicParser.java @@ -0,0 +1,32 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.utils.schematic.parse; + +import baritone.api.schematic.ISchematic; + +import java.io.IOException; +import java.io.InputStream; + +/** + * @author Brady + * @since 12/13/2019 + */ +public interface ISchematicParser { + + ISchematic parse(InputStream input) throws IOException; +} diff --git a/src/main/java/baritone/utils/schematic/parse/MCEditParser.java b/src/main/java/baritone/utils/schematic/parse/MCEditParser.java new file mode 100644 index 00000000..dce2c856 --- /dev/null +++ b/src/main/java/baritone/utils/schematic/parse/MCEditParser.java @@ -0,0 +1,94 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.utils.schematic.parse; + +import baritone.api.schematic.AbstractSchematic; +import baritone.api.schematic.ISchematic; +import baritone.utils.schematic.format.SchematicFormat; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +/** + * An implementation of {@link ISchematicParser} for {@link SchematicFormat#MCEDIT} + * + * @author Brady + * @since 12/16/2019 + */ +public enum MCEditParser implements ISchematicParser { + INSTANCE; + + @Override + public ISchematic parse(InputStream input) throws IOException { + return new MCEditSchematic(CompressedStreamTools.readCompressed(input)); + } + + private static final class MCEditSchematic extends AbstractSchematic { + + private final IBlockState[][][] states; + + MCEditSchematic(NBTTagCompound schematic) { + String type = schematic.getString("Materials"); + if (!type.equals("Alpha")) { + throw new IllegalStateException("bad schematic " + type); + } + this.x = schematic.getInteger("Width"); + this.y = schematic.getInteger("Height"); + this.z = schematic.getInteger("Length"); + byte[] blocks = schematic.getByteArray("Blocks"); + byte[] metadata = schematic.getByteArray("Data"); + + byte[] additional = null; + if (schematic.hasKey("AddBlocks")) { + byte[] addBlocks = schematic.getByteArray("AddBlocks"); + additional = new byte[addBlocks.length * 2]; + for (int i = 0; i < addBlocks.length; i++) { + additional[i * 2 + 0] = (byte) ((addBlocks[i] >> 4) & 0xF); // lower nibble + additional[i * 2 + 1] = (byte) ((addBlocks[i] >> 0) & 0xF); // upper nibble + } + } + this.states = new IBlockState[this.x][this.z][this.y]; + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + int blockInd = (y * this.z + z) * this.x + x; + + int blockID = blocks[blockInd] & 0xFF; + if (additional != null) { + // additional is 0 through 15 inclusive since it's & 0xF above + blockID |= additional[blockInd] << 8; + } + Block block = Block.REGISTRY.getObjectById(blockID); + int meta = metadata[blockInd] & 0xFF; + this.states[x][z][y] = block.getStateFromMeta(meta); + } + } + } + } + + @Override + public final IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { + return this.states[x][z][y]; + } + } +} diff --git a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java new file mode 100644 index 00000000..71984f91 --- /dev/null +++ b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java @@ -0,0 +1,202 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.utils.schematic.parse; + +import baritone.api.schematic.AbstractSchematic; +import baritone.api.schematic.ISchematic; +import baritone.api.utils.BlockOptionalMeta; +import baritone.utils.schematic.format.SchematicFormat; +import io.netty.buffer.Unpooled; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import net.minecraft.block.Block; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.IBlockState; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.ResourceLocation; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * An implementation of {@link ISchematicParser} for {@link SchematicFormat#SPONGE} + * + * @author Brady + * @since 12/16/2019 + */ +public enum SpongeParser implements ISchematicParser { + INSTANCE; + + @Override + public ISchematic parse(InputStream input) throws IOException { + NBTTagCompound nbt = CompressedStreamTools.readCompressed(input); + int version = nbt.getInteger("Version"); + switch (version) { + case 1: + case 2: + return new SpongeSchematic(nbt); + default: + throw new UnsupportedOperationException("Unsupported Version of the a Sponge Schematic"); + } + } + + /** + * Implementation of the Sponge Schematic Format supporting both V1 and V2. (For the current + * use case, there is no difference between reading a V1 and V2 schematic). + */ + private static final class SpongeSchematic extends AbstractSchematic { + + /** + * Block states for this schematic stored in [x, z, y] indexing order + */ + private IBlockState[][][] states; + + SpongeSchematic(NBTTagCompound nbt) { + this.x = nbt.getInteger("Width"); + this.y = nbt.getInteger("Height"); + this.z = nbt.getInteger("Length"); + this.states = new IBlockState[this.x][this.z][this.y]; + + Int2ObjectArrayMap<IBlockState> palette = new Int2ObjectArrayMap<>(); + NBTTagCompound paletteTag = nbt.getCompoundTag("Palette"); + for (String tag : paletteTag.getKeySet()) { + int index = paletteTag.getInteger(tag); + + SerializedBlockState serializedState = SerializedBlockState.getFromString(tag); + if (serializedState == null) { + throw new IllegalArgumentException("Unable to parse palette tag"); + } + + IBlockState state = serializedState.deserialize(); + if (state == null) { + throw new IllegalArgumentException("Unable to deserialize palette tag"); + } + + palette.put(index, state); + } + + // BlockData is stored as an NBT byte[], however, the actual data that is represented is a varint[]. + // This is kind of a hacky approach but it works /shrug + byte[] rawBlockData = nbt.getByteArray("BlockData"); + int[] blockData = new int[this.x * this.y * this.z]; + PacketBuffer buffer = new PacketBuffer(Unpooled.wrappedBuffer(rawBlockData)); + for (int i = 0; i < blockData.length; i++) { + if (buffer.readableBytes() > 0) { + blockData[i] = buffer.readVarInt(); + } else { + throw new IllegalArgumentException("Not enough"); + } + } + + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + int index = (y * this.z + z) * this.x + x; + this.states[x][z][y] = palette.get(blockData[index]); + } + } + } + } + + @Override + public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { + return this.states[x][z][y]; + } + } + + private static final class SerializedBlockState { + + private static final Pattern REGEX = Pattern.compile("(?<location>(\\w+:)?\\w+)(\\[(?<properties>(\\w+=\\w+,?)+)])?"); + + private final ResourceLocation resourceLocation; + private final Map<String, String> properties; + private IBlockState blockState; + + private SerializedBlockState(ResourceLocation resourceLocation, Map<String, String> properties) { + this.resourceLocation = resourceLocation; + this.properties = properties; + } + + ResourceLocation getResourceLocation() { + return this.resourceLocation; + } + + Map<String, String> getProperties() { + return this.properties; + } + + IBlockState deserialize() { + if (this.blockState == null) { + // Get the base state for the block specified + this.blockState = Block.REGISTRY.getObject(this.resourceLocation).getDefaultState(); + + // AFAIK it is best to order the property keys so that Minecraft caches the Block States ideally + this.properties.keySet().stream().sorted(String::compareTo).forEachOrdered(key -> { + // getProperty(String) when lol + IProperty<?> property = this.blockState.getPropertyKeys().stream() + .filter(p -> p.getName().equals(key)) + .findFirst().orElseThrow(IllegalArgumentException::new); + + Optional<?> value = property.parseValue(this.properties.get(key)).toJavaUtil(); + if (value.isPresent()) { + this.blockState = this.blockState.withProperty( + BlockOptionalMeta.castToIProperty(property), + BlockOptionalMeta.castToIPropertyValue(property, value) + ); + } else { + throw new IllegalArgumentException(); + } + }); + } + return this.blockState; + } + + static SerializedBlockState getFromString(String s) { + Matcher m = REGEX.matcher(s); + if (!m.matches()) { + return null; + } + + try { + String location = m.group("location"); + String properties = m.group("properties"); + + ResourceLocation resourceLocation = new ResourceLocation(location); + Map<String, String> propertiesMap = new HashMap<>(); + if (properties != null) { + for (String property : properties.split(",")) { + String[] split = property.split("="); + propertiesMap.put(split[0], split[1]); + } + } + + return new SerializedBlockState(resourceLocation, propertiesMap); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + } +} From b4ddf381162aca4122fc7969c613e2aa6bf772f6 Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Wed, 18 Dec 2019 10:27:34 -0600 Subject: [PATCH 020/133] Check if state is null --- .../baritone/utils/schematic/parse/SpongeParser.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java index 71984f91..1b6cb5e0 100644 --- a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java +++ b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java @@ -106,7 +106,7 @@ public enum SpongeParser implements ISchematicParser { if (buffer.readableBytes() > 0) { blockData[i] = buffer.readVarInt(); } else { - throw new IllegalArgumentException("Not enough"); + throw new IllegalArgumentException("Buffer has no remaining bytes"); } } @@ -114,7 +114,12 @@ public enum SpongeParser implements ISchematicParser { for (int z = 0; z < this.z; z++) { for (int x = 0; x < this.x; x++) { int index = (y * this.z + z) * this.x + x; - this.states[x][z][y] = palette.get(blockData[index]); + IBlockState state = palette.get(blockData[index]); + if (state == null) { + throw new IllegalArgumentException("Invalid Palette Index " + index); + } + + this.states[x][z][y] = state; } } } From ea8d7fb3b9bfbe93e0c7415a4fdc1f37d26f5dc0 Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Wed, 18 Dec 2019 15:19:58 -0600 Subject: [PATCH 021/133] Improve file extension fallback mechanism --- src/api/java/baritone/api/Settings.java | 6 ++++++ src/main/java/baritone/command/defaults/BuildCommand.java | 7 ++++--- .../baritone/utils/schematic/format/SchematicFormat.java | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index bf077f1a..69bcabcb 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -811,6 +811,12 @@ public final class Settings { */ public final Setting<Boolean> schematicOrientationZ = new Setting<>(false); + /** + * The fallback used by the build command when no extension is specified. This may be useful if schematics of a + * particular format are used often, and the user does not wish to have to specify the extension with every usage. + */ + public final Setting<String> schematicFallbackExtension = new Setting<>("schematic"); + /** * Distance to scan every tick for updates. Expanding this beyond player reach distance (i.e. setting it to 6 or above) * is only necessary in very large schematics where rescanning the whole thing is costly. diff --git a/src/main/java/baritone/command/defaults/BuildCommand.java b/src/main/java/baritone/command/defaults/BuildCommand.java index 39bf0d3f..3d549587 100644 --- a/src/main/java/baritone/command/defaults/BuildCommand.java +++ b/src/main/java/baritone/command/defaults/BuildCommand.java @@ -17,6 +17,7 @@ package baritone.command.defaults; +import baritone.Baritone; import baritone.api.IBaritone; import baritone.api.utils.BetterBlockPos; import baritone.api.command.Command; @@ -26,11 +27,11 @@ import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandInvalidStateException; import baritone.api.command.argument.IArgConsumer; import net.minecraft.client.Minecraft; +import org.apache.commons.io.FilenameUtils; import java.io.File; import java.util.Arrays; import java.util.List; -import java.util.Locale; import java.util.stream.Stream; public class BuildCommand extends Command { @@ -44,8 +45,8 @@ public class BuildCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile(); - if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) { - file = new File(file.getAbsolutePath() + ".schematic"); + if (FilenameUtils.getExtension(file.getAbsolutePath()).isEmpty()) { + file = new File(file.getAbsolutePath() + "." + Baritone.settings().schematicFallbackExtension); } BetterBlockPos origin = ctx.playerFeet(); BetterBlockPos buildOrigin; diff --git a/src/main/java/baritone/utils/schematic/format/SchematicFormat.java b/src/main/java/baritone/utils/schematic/format/SchematicFormat.java index 5f103d9a..6c84273e 100644 --- a/src/main/java/baritone/utils/schematic/format/SchematicFormat.java +++ b/src/main/java/baritone/utils/schematic/format/SchematicFormat.java @@ -65,6 +65,6 @@ public enum SchematicFormat { public static Optional<SchematicFormat> getByExtension(String extension) { return extension == null || extension.isEmpty() ? Optional.empty() - : Stream.of(values()).filter(format -> format.extension.equals(extension)).findFirst(); + : Stream.of(values()).filter(format -> format.extension.equalsIgnoreCase(extension)).findFirst(); } } From aa3bd80ab2066dc30452cc68de4265924ac18d9a Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Thu, 19 Dec 2019 11:40:38 -0600 Subject: [PATCH 022/133] Clean ups --- .../utils/schematic/MapArtSchematic.java | 2 +- .../utils/schematic/parse/SpongeParser.java | 59 +++++------- src/main/java/baritone/utils/type/VarInt.java | 94 +++++++++++++++++++ 3 files changed, 120 insertions(+), 35 deletions(-) create mode 100644 src/main/java/baritone/utils/type/VarInt.java diff --git a/src/main/java/baritone/utils/schematic/MapArtSchematic.java b/src/main/java/baritone/utils/schematic/MapArtSchematic.java index 33ec3a15..ec477b57 100644 --- a/src/main/java/baritone/utils/schematic/MapArtSchematic.java +++ b/src/main/java/baritone/utils/schematic/MapArtSchematic.java @@ -65,7 +65,7 @@ public class MapArtSchematic extends AbstractSchematic { @Override public boolean inSchematic(int x, int y, int z, IBlockState currentState) { // in map art, we only care about coordinates in or above the art - return super.inSchematic(x, y, z, currentState) && y >= heightMap[x][z]; + return this.child.inSchematic(x, y, z, currentState) && y >= heightMap[x][z]; } @Override diff --git a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java index 1b6cb5e0..6219f148 100644 --- a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java +++ b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java @@ -19,16 +19,14 @@ package baritone.utils.schematic.parse; import baritone.api.schematic.AbstractSchematic; import baritone.api.schematic.ISchematic; -import baritone.api.utils.BlockOptionalMeta; import baritone.utils.schematic.format.SchematicFormat; -import io.netty.buffer.Unpooled; +import baritone.utils.type.VarInt; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.PacketBuffer; import net.minecraft.util.ResourceLocation; import java.io.IOException; @@ -97,17 +95,18 @@ public enum SpongeParser implements ISchematicParser { palette.put(index, state); } - // BlockData is stored as an NBT byte[], however, the actual data that is represented is a varint[]. - // This is kind of a hacky approach but it works /shrug + // BlockData is stored as an NBT byte[], however, the actual data that is represented is a varint[] byte[] rawBlockData = nbt.getByteArray("BlockData"); int[] blockData = new int[this.x * this.y * this.z]; - PacketBuffer buffer = new PacketBuffer(Unpooled.wrappedBuffer(rawBlockData)); + int offset = 0; for (int i = 0; i < blockData.length; i++) { - if (buffer.readableBytes() > 0) { - blockData[i] = buffer.readVarInt(); - } else { - throw new IllegalArgumentException("Buffer has no remaining bytes"); + if (offset >= blockData.length) { + throw new IllegalArgumentException("No remaining bytes in BlockData for complete schematic"); } + + VarInt varInt = VarInt.read(rawBlockData, offset); + blockData[i] = varInt.getValue(); + offset += varInt.getSize(); } for (int y = 0; y < this.y; y++) { @@ -144,35 +143,18 @@ public enum SpongeParser implements ISchematicParser { this.properties = properties; } - ResourceLocation getResourceLocation() { - return this.resourceLocation; - } - - Map<String, String> getProperties() { - return this.properties; - } - IBlockState deserialize() { if (this.blockState == null) { - // Get the base state for the block specified - this.blockState = Block.REGISTRY.getObject(this.resourceLocation).getDefaultState(); + Block block = Block.REGISTRY.getObject(this.resourceLocation); + this.blockState = block.getDefaultState(); - // AFAIK it is best to order the property keys so that Minecraft caches the Block States ideally this.properties.keySet().stream().sorted(String::compareTo).forEachOrdered(key -> { - // getProperty(String) when lol - IProperty<?> property = this.blockState.getPropertyKeys().stream() - .filter(p -> p.getName().equals(key)) - .findFirst().orElseThrow(IllegalArgumentException::new); - - Optional<?> value = property.parseValue(this.properties.get(key)).toJavaUtil(); - if (value.isPresent()) { - this.blockState = this.blockState.withProperty( - BlockOptionalMeta.castToIProperty(property), - BlockOptionalMeta.castToIPropertyValue(property, value) - ); - } else { - throw new IllegalArgumentException(); + IProperty<?> property = block.getBlockState().getProperty(key); + if (property == null) { + throw new IllegalArgumentException("Invalid property"); } + + this.blockState = setPropertyValue(this.blockState, property, this.properties.get(key)); }); } return this.blockState; @@ -203,5 +185,14 @@ public enum SpongeParser implements ISchematicParser { return null; } } + + private static <T extends Comparable<T>> IBlockState setPropertyValue(IBlockState state, IProperty<T> property, String value) { + Optional<T> parsed = property.parseValue(value).toJavaUtil(); + if (parsed.isPresent()) { + return state.withProperty(property, parsed.get()); + } else { + throw new IllegalArgumentException("Invalid value for property " + property); + } + } } } diff --git a/src/main/java/baritone/utils/type/VarInt.java b/src/main/java/baritone/utils/type/VarInt.java new file mode 100644 index 00000000..8eb31e7f --- /dev/null +++ b/src/main/java/baritone/utils/type/VarInt.java @@ -0,0 +1,94 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.utils.type; + +import it.unimi.dsi.fastutil.bytes.ByteArrayList; +import it.unimi.dsi.fastutil.bytes.ByteList; + +/** + * @author Brady + * @since 12/19/2019 + */ +public final class VarInt { + + private final int value; + private final byte[] serialized; + private final int size; + + public VarInt(int value) { + this.value = value; + this.serialized = serialize0(this.value); + this.size = this.serialized.length; + } + + /** + * @return The integer value that is represented by this {@link VarInt}. + */ + public final int getValue() { + return this.value; + } + + /** + * @return The size of this {@link VarInt}, in bytes, once serialized. + */ + public final int getSize() { + return this.size; + } + + public final byte[] serialize() { + return this.serialized; + } + + private static byte[] serialize0(int value) { + ByteList bytes = new ByteArrayList(); + + while ((value & 0xFF) != 0) { + bytes.add((byte) (value & 0x7F | 0x80)); + value >>>= 7; + } + bytes.add((byte) (value & 0xFF)); + + return bytes.toByteArray(); + } + + public static VarInt read(byte[] bytes) { + return read(bytes, 0); + } + + public static VarInt read(byte[] bytes, int start) { + int value = 0; + int size = 0; + int index = start; + + while (true) { + byte b = bytes[index++]; + value |= (b & 0x7F) << size++ * 7; + + if (size > 5) { + throw new IllegalArgumentException("VarInt size cannot exceed 5 bytes"); + } + + // Most significant bit denotes another byte is to be read. + if ((b & 0x80) != 0x80) { + break; + } + } + + return new VarInt(value); + } +} From 6759917a2fbab523edd4532ebbd1f575ffcac24b Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Thu, 19 Dec 2019 11:58:47 -0600 Subject: [PATCH 023/133] Additional clean up --- .../baritone/api/schematic/FillSchematic.java | 3 ++ .../utils/schematic/FillSchematic.java | 26 ++------------ .../utils/schematic/MapArtSchematic.java | 34 +++---------------- 3 files changed, 11 insertions(+), 52 deletions(-) diff --git a/src/api/java/baritone/api/schematic/FillSchematic.java b/src/api/java/baritone/api/schematic/FillSchematic.java index aaaeb5dd..fbf16fb4 100644 --- a/src/api/java/baritone/api/schematic/FillSchematic.java +++ b/src/api/java/baritone/api/schematic/FillSchematic.java @@ -38,6 +38,9 @@ public class FillSchematic extends AbstractSchematic { @Override public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { + // TODO: is this even necessary??? + // Builder will already handle logic that requires breaking blocks before replacing them, and non-api Fill Schematic + // is used for clear area and doesn't have any issues. if (bom.matches(current)) { return current; } else if (current.getBlock() != Blocks.AIR) { diff --git a/src/main/java/baritone/utils/schematic/FillSchematic.java b/src/main/java/baritone/utils/schematic/FillSchematic.java index 2e67b121..67e5c734 100644 --- a/src/main/java/baritone/utils/schematic/FillSchematic.java +++ b/src/main/java/baritone/utils/schematic/FillSchematic.java @@ -17,22 +17,17 @@ package baritone.utils.schematic; -import baritone.api.schematic.ISchematic; +import baritone.api.schematic.AbstractSchematic; import net.minecraft.block.state.IBlockState; import java.util.List; -public class FillSchematic implements ISchematic { +public class FillSchematic extends AbstractSchematic { - private final int widthX; - private final int heightY; - private final int lengthZ; private final IBlockState state; public FillSchematic(int widthX, int heightY, int lengthZ, IBlockState state) { - this.widthX = widthX; - this.heightY = heightY; - this.lengthZ = lengthZ; + super(widthX, heightY, lengthZ); this.state = state; } @@ -40,19 +35,4 @@ public class FillSchematic implements ISchematic { public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { return state; } - - @Override - public int widthX() { - return widthX; - } - - @Override - public int heightY() { - return heightY; - } - - @Override - public int lengthZ() { - return lengthZ; - } } diff --git a/src/main/java/baritone/utils/schematic/MapArtSchematic.java b/src/main/java/baritone/utils/schematic/MapArtSchematic.java index ec477b57..a6bd2021 100644 --- a/src/main/java/baritone/utils/schematic/MapArtSchematic.java +++ b/src/main/java/baritone/utils/schematic/MapArtSchematic.java @@ -17,23 +17,20 @@ package baritone.utils.schematic; -import baritone.api.schematic.AbstractSchematic; import baritone.api.schematic.ISchematic; +import baritone.api.schematic.MaskSchematic; import net.minecraft.block.BlockAir; import net.minecraft.block.state.IBlockState; -import java.util.List; import java.util.OptionalInt; import java.util.function.Predicate; -public class MapArtSchematic extends AbstractSchematic { +public class MapArtSchematic extends MaskSchematic { - private final ISchematic child; private final int[][] heightMap; public MapArtSchematic(ISchematic schematic) { - super(schematic.widthX(), schematic.heightY(), schematic.lengthZ()); - this.child = schematic; + super(schematic); heightMap = new int[schematic.widthX()][schematic.lengthZ()]; @@ -63,28 +60,7 @@ public class MapArtSchematic extends AbstractSchematic { } @Override - public boolean inSchematic(int x, int y, int z, IBlockState currentState) { - // in map art, we only care about coordinates in or above the art - return this.child.inSchematic(x, y, z, currentState) && y >= heightMap[x][z]; - } - - @Override - public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { - return this.child.desiredState(x, y, z, current, approxPlaceable); - } - - @Override - public int widthX() { - return this.child.widthX(); - } - - @Override - public int heightY() { - return this.child.heightY(); - } - - @Override - public int lengthZ() { - return this.child.lengthZ(); + protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { + return y >= heightMap[x][z]; } } From eea5b69b6cd8090afdb736d858a6dd16d8ecc28b Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Thu, 19 Dec 2019 12:03:02 -0600 Subject: [PATCH 024/133] Utilize new FillSchematic --- .../baritone/api/schematic/FillSchematic.java | 7 ++-- .../java/baritone/process/BuilderProcess.java | 2 +- .../utils/schematic/FillSchematic.java | 38 ------------------- 3 files changed, 5 insertions(+), 42 deletions(-) delete mode 100644 src/main/java/baritone/utils/schematic/FillSchematic.java diff --git a/src/api/java/baritone/api/schematic/FillSchematic.java b/src/api/java/baritone/api/schematic/FillSchematic.java index fbf16fb4..de9ccf97 100644 --- a/src/api/java/baritone/api/schematic/FillSchematic.java +++ b/src/api/java/baritone/api/schematic/FillSchematic.java @@ -32,15 +32,16 @@ public class FillSchematic extends AbstractSchematic { this.bom = bom; } + public FillSchematic(int x, int y, int z, IBlockState state) { + this(x, y, z, new BlockOptionalMeta(state.getBlock(), state.getBlock().getMetaFromState(state))); + } + public BlockOptionalMeta getBom() { return bom; } @Override public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { - // TODO: is this even necessary??? - // Builder will already handle logic that requires breaking blocks before replacing them, and non-api Fill Schematic - // is used for clear area and doesn't have any issues. if (bom.matches(current)) { return current; } else if (current.getBlock() != Blocks.AIR) { diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 1dfd6c82..88338a01 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -25,6 +25,7 @@ import baritone.api.pathing.goals.GoalGetToBlock; import baritone.api.process.IBuilderProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; +import baritone.api.schematic.FillSchematic; import baritone.api.schematic.ISchematic; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.RayTraceUtils; @@ -37,7 +38,6 @@ import baritone.pathing.movement.MovementHelper; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import baritone.utils.PathingCommandContext; -import baritone.utils.schematic.FillSchematic; import baritone.utils.schematic.MapArtSchematic; import baritone.utils.schematic.format.SchematicFormat; import baritone.utils.schematic.schematica.SchematicaHelper; diff --git a/src/main/java/baritone/utils/schematic/FillSchematic.java b/src/main/java/baritone/utils/schematic/FillSchematic.java deleted file mode 100644 index 67e5c734..00000000 --- a/src/main/java/baritone/utils/schematic/FillSchematic.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see <https://www.gnu.org/licenses/>. - */ - -package baritone.utils.schematic; - -import baritone.api.schematic.AbstractSchematic; -import net.minecraft.block.state.IBlockState; - -import java.util.List; - -public class FillSchematic extends AbstractSchematic { - - private final IBlockState state; - - public FillSchematic(int widthX, int heightY, int lengthZ, IBlockState state) { - super(widthX, heightY, lengthZ); - this.state = state; - } - - @Override - public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { - return state; - } -} From 0a858c040c981337ae1fd82eeda6befe62622c24 Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Thu, 19 Dec 2019 22:15:14 -0600 Subject: [PATCH 025/133] Working --- .../java/baritone/utils/schematic/parse/SpongeParser.java | 8 +++----- src/main/java/baritone/utils/type/VarInt.java | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java index 6219f148..190c6d48 100644 --- a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java +++ b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java @@ -100,7 +100,7 @@ public enum SpongeParser implements ISchematicParser { int[] blockData = new int[this.x * this.y * this.z]; int offset = 0; for (int i = 0; i < blockData.length; i++) { - if (offset >= blockData.length) { + if (offset >= rawBlockData.length) { throw new IllegalArgumentException("No remaining bytes in BlockData for complete schematic"); } @@ -150,11 +150,9 @@ public enum SpongeParser implements ISchematicParser { this.properties.keySet().stream().sorted(String::compareTo).forEachOrdered(key -> { IProperty<?> property = block.getBlockState().getProperty(key); - if (property == null) { - throw new IllegalArgumentException("Invalid property"); + if (property != null) { + this.blockState = setPropertyValue(this.blockState, property, this.properties.get(key)); } - - this.blockState = setPropertyValue(this.blockState, property, this.properties.get(key)); }); } return this.blockState; diff --git a/src/main/java/baritone/utils/type/VarInt.java b/src/main/java/baritone/utils/type/VarInt.java index 8eb31e7f..45f83dda 100644 --- a/src/main/java/baritone/utils/type/VarInt.java +++ b/src/main/java/baritone/utils/type/VarInt.java @@ -57,7 +57,7 @@ public final class VarInt { private static byte[] serialize0(int value) { ByteList bytes = new ByteArrayList(); - while ((value & 0xFF) != 0) { + while ((value & 0x80) != 0) { bytes.add((byte) (value & 0x7F | 0x80)); value >>>= 7; } From 77bdf6e444d338d993f80efeae6e9a0e3cd3a3fb Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Mon, 23 Dec 2019 18:05:50 -0600 Subject: [PATCH 026/133] Fix MapSchematic --- .../java/baritone/process/BuilderProcess.java | 3 +- .../utils/schematic/MapArtSchematic.java | 34 +------ .../utils/schematic/StaticSchematic.java | 88 +++++++++++++++++++ .../schematic/parse/ISchematicParser.java | 4 +- .../utils/schematic/parse/MCEditParser.java | 15 +--- .../utils/schematic/parse/SpongeParser.java | 19 +--- 6 files changed, 101 insertions(+), 62 deletions(-) create mode 100644 src/main/java/baritone/utils/schematic/StaticSchematic.java diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 88338a01..a7a17160 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -39,6 +39,7 @@ import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import baritone.utils.PathingCommandContext; import baritone.utils.schematic.MapArtSchematic; +import baritone.utils.schematic.StaticSchematic; import baritone.utils.schematic.format.SchematicFormat; import baritone.utils.schematic.schematica.SchematicaHelper; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; @@ -129,7 +130,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } if (Baritone.settings().mapArtMode.value) { - parsed = new MapArtSchematic(parsed); + parsed = new MapArtSchematic((StaticSchematic) parsed); } build(name, parsed, origin); diff --git a/src/main/java/baritone/utils/schematic/MapArtSchematic.java b/src/main/java/baritone/utils/schematic/MapArtSchematic.java index a6bd2021..dc2edf2c 100644 --- a/src/main/java/baritone/utils/schematic/MapArtSchematic.java +++ b/src/main/java/baritone/utils/schematic/MapArtSchematic.java @@ -17,46 +17,16 @@ package baritone.utils.schematic; -import baritone.api.schematic.ISchematic; import baritone.api.schematic.MaskSchematic; -import net.minecraft.block.BlockAir; import net.minecraft.block.state.IBlockState; -import java.util.OptionalInt; -import java.util.function.Predicate; - public class MapArtSchematic extends MaskSchematic { private final int[][] heightMap; - public MapArtSchematic(ISchematic schematic) { + public MapArtSchematic(StaticSchematic schematic) { super(schematic); - - heightMap = new int[schematic.widthX()][schematic.lengthZ()]; - - for (int x = 0; x < schematic.widthX(); x++) { - for (int z = 0; z < schematic.lengthZ(); z++) { - IBlockState[] column = /*states[x][z]*/null; - - OptionalInt lowestBlockY = lastIndexMatching(column, state -> !(state.getBlock() instanceof BlockAir)); - if (lowestBlockY.isPresent()) { - heightMap[x][z] = lowestBlockY.getAsInt(); - } else { - System.out.println("Column " + x + "," + z + " has no blocks, but it's apparently map art? wtf"); - System.out.println("Letting it be whatever"); - heightMap[x][z] = 256; - } - } - } - } - - private static <T> OptionalInt lastIndexMatching(T[] arr, Predicate<? super T> predicate) { - for (int y = arr.length - 1; y >= 0; y--) { - if (predicate.test(arr[y])) { - return OptionalInt.of(y); - } - } - return OptionalInt.empty(); + this.heightMap = schematic.getHeightMap(); } @Override diff --git a/src/main/java/baritone/utils/schematic/StaticSchematic.java b/src/main/java/baritone/utils/schematic/StaticSchematic.java new file mode 100644 index 00000000..97fc91cd --- /dev/null +++ b/src/main/java/baritone/utils/schematic/StaticSchematic.java @@ -0,0 +1,88 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.utils.schematic; + +import baritone.api.schematic.AbstractSchematic; +import net.minecraft.block.BlockAir; +import net.minecraft.block.state.IBlockState; + +import java.util.List; +import java.util.OptionalInt; +import java.util.function.Predicate; + +/** + * @author Brady + * @since 12/23/2019 + */ +public abstract class StaticSchematic extends AbstractSchematic { + + /** + * Block states for this schematic stored in [x, z, y] indexing order + */ + protected IBlockState[][][] states; + + /** + * The maximum height of a given block in this schematic, indexed as [x, z]. + * This is lazily initialized by {@link #getHeightMap()}. + */ + protected int[][] heightMap; + + public StaticSchematic() { + super(); + } + + public StaticSchematic(int x, int y, int z) { + super(x, y, z); + } + + @Override + public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { + return this.states[x][z][y]; + } + + public final int[][] getHeightMap() { + if (this.heightMap == null) { + this.heightMap = new int[this.x][this.z]; + + for (int x = 0; x < this.x; x++) { + for (int z = 0; z < this.z; z++) { + IBlockState[] column = states[x][z]; + + OptionalInt lowestBlockY = lastIndexMatching(column, state -> !(state.getBlock() instanceof BlockAir)); + if (lowestBlockY.isPresent()) { + this.heightMap[x][z] = lowestBlockY.getAsInt(); + } else { + System.out.println("Column " + x + "," + z + " has no blocks, but it's apparently map art? wtf"); + System.out.println("Letting it be whatever"); + this.heightMap[x][z] = 256; + } + } + } + } + return this.heightMap; + } + + private static <T> OptionalInt lastIndexMatching(T[] arr, Predicate<? super T> predicate) { + for (int y = arr.length - 1; y >= 0; y--) { + if (predicate.test(arr[y])) { + return OptionalInt.of(y); + } + } + return OptionalInt.empty(); + } +} diff --git a/src/main/java/baritone/utils/schematic/parse/ISchematicParser.java b/src/main/java/baritone/utils/schematic/parse/ISchematicParser.java index 040addc1..8bc716f1 100644 --- a/src/main/java/baritone/utils/schematic/parse/ISchematicParser.java +++ b/src/main/java/baritone/utils/schematic/parse/ISchematicParser.java @@ -17,7 +17,7 @@ package baritone.utils.schematic.parse; -import baritone.api.schematic.ISchematic; +import baritone.utils.schematic.StaticSchematic; import java.io.IOException; import java.io.InputStream; @@ -28,5 +28,5 @@ import java.io.InputStream; */ public interface ISchematicParser { - ISchematic parse(InputStream input) throws IOException; + StaticSchematic parse(InputStream input) throws IOException; } diff --git a/src/main/java/baritone/utils/schematic/parse/MCEditParser.java b/src/main/java/baritone/utils/schematic/parse/MCEditParser.java index dce2c856..54d78201 100644 --- a/src/main/java/baritone/utils/schematic/parse/MCEditParser.java +++ b/src/main/java/baritone/utils/schematic/parse/MCEditParser.java @@ -17,8 +17,7 @@ package baritone.utils.schematic.parse; -import baritone.api.schematic.AbstractSchematic; -import baritone.api.schematic.ISchematic; +import baritone.utils.schematic.StaticSchematic; import baritone.utils.schematic.format.SchematicFormat; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -27,7 +26,6 @@ import net.minecraft.nbt.NBTTagCompound; import java.io.IOException; import java.io.InputStream; -import java.util.List; /** * An implementation of {@link ISchematicParser} for {@link SchematicFormat#MCEDIT} @@ -39,13 +37,11 @@ public enum MCEditParser implements ISchematicParser { INSTANCE; @Override - public ISchematic parse(InputStream input) throws IOException { + public StaticSchematic parse(InputStream input) throws IOException { return new MCEditSchematic(CompressedStreamTools.readCompressed(input)); } - private static final class MCEditSchematic extends AbstractSchematic { - - private final IBlockState[][][] states; + private static final class MCEditSchematic extends StaticSchematic { MCEditSchematic(NBTTagCompound schematic) { String type = schematic.getString("Materials"); @@ -85,10 +81,5 @@ public enum MCEditParser implements ISchematicParser { } } } - - @Override - public final IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { - return this.states[x][z][y]; - } } } diff --git a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java index 190c6d48..48cc60aa 100644 --- a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java +++ b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java @@ -17,8 +17,7 @@ package baritone.utils.schematic.parse; -import baritone.api.schematic.AbstractSchematic; -import baritone.api.schematic.ISchematic; +import baritone.utils.schematic.StaticSchematic; import baritone.utils.schematic.format.SchematicFormat; import baritone.utils.type.VarInt; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; @@ -32,7 +31,6 @@ import net.minecraft.util.ResourceLocation; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Optional; import java.util.regex.Matcher; @@ -48,7 +46,7 @@ public enum SpongeParser implements ISchematicParser { INSTANCE; @Override - public ISchematic parse(InputStream input) throws IOException { + public StaticSchematic parse(InputStream input) throws IOException { NBTTagCompound nbt = CompressedStreamTools.readCompressed(input); int version = nbt.getInteger("Version"); switch (version) { @@ -56,7 +54,7 @@ public enum SpongeParser implements ISchematicParser { case 2: return new SpongeSchematic(nbt); default: - throw new UnsupportedOperationException("Unsupported Version of the a Sponge Schematic"); + throw new UnsupportedOperationException("Unsupported Version of a Sponge Schematic"); } } @@ -64,12 +62,8 @@ public enum SpongeParser implements ISchematicParser { * Implementation of the Sponge Schematic Format supporting both V1 and V2. (For the current * use case, there is no difference between reading a V1 and V2 schematic). */ - private static final class SpongeSchematic extends AbstractSchematic { + private static final class SpongeSchematic extends StaticSchematic { - /** - * Block states for this schematic stored in [x, z, y] indexing order - */ - private IBlockState[][][] states; SpongeSchematic(NBTTagCompound nbt) { this.x = nbt.getInteger("Width"); @@ -123,11 +117,6 @@ public enum SpongeParser implements ISchematicParser { } } } - - @Override - public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { - return this.states[x][z][y]; - } } private static final class SerializedBlockState { From eee705b371d27bf7f797ffa3d578c797cf046395 Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Tue, 24 Dec 2019 17:20:00 -0600 Subject: [PATCH 027/133] Schematic Format API support --- .../java/baritone/api/IBaritoneProvider.java | 6 ++ .../api/schematic/ISchematicSystem.java | 44 ++++++++++++++ .../api/schematic/IStaticSchematic.java | 60 +++++++++++++++++++ .../schematic/format/ISchematicFormat.java | 43 +++++++++++++ .../schematic/parse/ISchematicParser.java | 6 +- src/main/java/baritone/BaritoneProvider.java | 7 +++ .../java/baritone/process/BuilderProcess.java | 9 +-- .../utils/schematic/MapArtSchematic.java | 40 ++++++++++++- .../utils/schematic/SchematicSystem.java | 51 ++++++++++++++++ .../utils/schematic/StaticSchematic.java | 58 ++++-------------- ...rmat.java => DefaultSchematicFormats.java} | 25 ++++---- .../utils/schematic/parse/MCEditParser.java | 5 +- .../utils/schematic/parse/SpongeParser.java | 5 +- 13 files changed, 282 insertions(+), 77 deletions(-) create mode 100644 src/api/java/baritone/api/schematic/ISchematicSystem.java create mode 100644 src/api/java/baritone/api/schematic/IStaticSchematic.java create mode 100644 src/api/java/baritone/api/schematic/format/ISchematicFormat.java rename src/{main/java/baritone/utils => api/java/baritone/api}/schematic/parse/ISchematicParser.java (84%) create mode 100644 src/main/java/baritone/utils/schematic/SchematicSystem.java rename src/main/java/baritone/utils/schematic/format/{SchematicFormat.java => DefaultSchematicFormats.java} (68%) diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java index b7228e33..84a8abbb 100644 --- a/src/api/java/baritone/api/IBaritoneProvider.java +++ b/src/api/java/baritone/api/IBaritoneProvider.java @@ -20,6 +20,7 @@ package baritone.api; import baritone.api.cache.IWorldScanner; import baritone.api.command.ICommand; import baritone.api.command.ICommandSystem; +import baritone.api.schematic.ISchematicSystem; import net.minecraft.client.entity.EntityPlayerSP; import java.util.List; @@ -82,4 +83,9 @@ public interface IBaritoneProvider { * @return The {@link ICommandSystem} instance. */ ICommandSystem getCommandSystem(); + + /** + * @return The {@link ISchematicSystem} instance. + */ + ISchematicSystem getSchematicSystem(); } diff --git a/src/api/java/baritone/api/schematic/ISchematicSystem.java b/src/api/java/baritone/api/schematic/ISchematicSystem.java new file mode 100644 index 00000000..c8f03907 --- /dev/null +++ b/src/api/java/baritone/api/schematic/ISchematicSystem.java @@ -0,0 +1,44 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.api.schematic; + +import baritone.api.command.registry.Registry; +import baritone.api.schematic.format.ISchematicFormat; + +import java.io.File; +import java.util.Optional; + +/** + * @author Brady + * @since 12/23/2019 + */ +public interface ISchematicSystem { + + /** + * @return The registry of supported schematic formats + */ + Registry<ISchematicFormat> getRegistry(); + + /** + * Attempts to find an {@link ISchematicFormat} that supports the specified schematic file. + * + * @param file A schematic file + * @return The corresponding format for the file, {@link Optional#empty()} if no candidates were found. + */ + Optional<ISchematicFormat> getByFile(File file); +} diff --git a/src/api/java/baritone/api/schematic/IStaticSchematic.java b/src/api/java/baritone/api/schematic/IStaticSchematic.java new file mode 100644 index 00000000..268b1b1f --- /dev/null +++ b/src/api/java/baritone/api/schematic/IStaticSchematic.java @@ -0,0 +1,60 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.api.schematic; + +import net.minecraft.block.state.IBlockState; + +/** + * A static schematic is capable of providing the desired state at a given position without + * additional context. Schematics of this type are expected to have non-varying contents. + * + * @see #getDirect(int, int, int) + * + * @author Brady + * @since 12/24/2019 + */ +public interface IStaticSchematic extends ISchematic { + + /** + * Gets the {@link IBlockState} for a given position in this schematic. It should be guaranteed + * that the return value of this method will not change given that the parameters are the same. + * + * @param x The X block position + * @param y The Y block position + * @param z The Z block position + * @return The desired state at the specified position. + */ + IBlockState getDirect(int x, int y, int z); + + /** + * Returns an {@link IBlockState} array of size {@link #heightY()} which contains all + * desired block states in the specified vertical column. The index of {@link IBlockState}s + * in the array are equivalent to their Y position in the schematic. + * + * @param x The X column position + * @param z The Z column position + * @return An {@link IBlockState} array + */ + default IBlockState[] getColumn(int x, int z) { + IBlockState[] column = new IBlockState[this.heightY()]; + for (int i = 0; i < this.heightY(); i++) { + column[i] = getDirect(x, i, z); + } + return column; + } +} diff --git a/src/api/java/baritone/api/schematic/format/ISchematicFormat.java b/src/api/java/baritone/api/schematic/format/ISchematicFormat.java new file mode 100644 index 00000000..260ab453 --- /dev/null +++ b/src/api/java/baritone/api/schematic/format/ISchematicFormat.java @@ -0,0 +1,43 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.api.schematic.format; + +import baritone.api.schematic.ISchematic; +import baritone.api.schematic.parse.ISchematicParser; + +import java.io.File; + +/** + * The base of a {@link ISchematic} file format + * + * @author Brady + * @since 12/23/2019 + */ +public interface ISchematicFormat { + + /** + * @return The parser for creating schematics of this format + */ + ISchematicParser getParser(); + + /** + * @param file The file to check against + * @return Whether or not the specified file matches this schematic format + */ + boolean isFileType(File file); +} diff --git a/src/main/java/baritone/utils/schematic/parse/ISchematicParser.java b/src/api/java/baritone/api/schematic/parse/ISchematicParser.java similarity index 84% rename from src/main/java/baritone/utils/schematic/parse/ISchematicParser.java rename to src/api/java/baritone/api/schematic/parse/ISchematicParser.java index 8bc716f1..ab0f12f4 100644 --- a/src/main/java/baritone/utils/schematic/parse/ISchematicParser.java +++ b/src/api/java/baritone/api/schematic/parse/ISchematicParser.java @@ -15,9 +15,9 @@ * along with Baritone. If not, see <https://www.gnu.org/licenses/>. */ -package baritone.utils.schematic.parse; +package baritone.api.schematic.parse; -import baritone.utils.schematic.StaticSchematic; +import baritone.api.schematic.IStaticSchematic; import java.io.IOException; import java.io.InputStream; @@ -28,5 +28,5 @@ import java.io.InputStream; */ public interface ISchematicParser { - StaticSchematic parse(InputStream input) throws IOException; + IStaticSchematic parse(InputStream input) throws IOException; } diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java index cb24dfe2..84034ef3 100644 --- a/src/main/java/baritone/BaritoneProvider.java +++ b/src/main/java/baritone/BaritoneProvider.java @@ -21,9 +21,11 @@ import baritone.api.IBaritone; import baritone.api.IBaritoneProvider; import baritone.api.cache.IWorldScanner; import baritone.api.command.ICommandSystem; +import baritone.api.schematic.ISchematicSystem; import baritone.command.BaritoneChatControl; import baritone.cache.WorldScanner; import baritone.command.CommandSystem; +import baritone.utils.schematic.SchematicSystem; import java.util.Collections; import java.util.List; @@ -64,4 +66,9 @@ public final class BaritoneProvider implements IBaritoneProvider { public ICommandSystem getCommandSystem() { return CommandSystem.INSTANCE; } + + @Override + public ISchematicSystem getSchematicSystem() { + return SchematicSystem.INSTANCE; + } } diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index a7a17160..55361602 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -27,6 +27,8 @@ import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.api.schematic.FillSchematic; import baritone.api.schematic.ISchematic; +import baritone.api.schematic.IStaticSchematic; +import baritone.api.schematic.format.ISchematicFormat; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.RayTraceUtils; import baritone.api.utils.Rotation; @@ -39,8 +41,7 @@ import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import baritone.utils.PathingCommandContext; import baritone.utils.schematic.MapArtSchematic; -import baritone.utils.schematic.StaticSchematic; -import baritone.utils.schematic.format.SchematicFormat; +import baritone.utils.schematic.SchematicSystem; import baritone.utils.schematic.schematica.SchematicaHelper; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import net.minecraft.block.BlockAir; @@ -116,7 +117,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public boolean build(String name, File schematic, Vec3i origin) { - Optional<SchematicFormat> format = SchematicFormat.getByFile(schematic); + Optional<ISchematicFormat> format = SchematicSystem.INSTANCE.getByFile(schematic); if (!format.isPresent()) { return false; } @@ -130,7 +131,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } if (Baritone.settings().mapArtMode.value) { - parsed = new MapArtSchematic((StaticSchematic) parsed); + parsed = new MapArtSchematic((IStaticSchematic) parsed); } build(name, parsed, origin); diff --git a/src/main/java/baritone/utils/schematic/MapArtSchematic.java b/src/main/java/baritone/utils/schematic/MapArtSchematic.java index dc2edf2c..31442261 100644 --- a/src/main/java/baritone/utils/schematic/MapArtSchematic.java +++ b/src/main/java/baritone/utils/schematic/MapArtSchematic.java @@ -17,20 +17,54 @@ package baritone.utils.schematic; +import baritone.api.schematic.IStaticSchematic; import baritone.api.schematic.MaskSchematic; +import net.minecraft.block.BlockAir; import net.minecraft.block.state.IBlockState; +import java.util.OptionalInt; +import java.util.function.Predicate; + public class MapArtSchematic extends MaskSchematic { private final int[][] heightMap; - public MapArtSchematic(StaticSchematic schematic) { + public MapArtSchematic(IStaticSchematic schematic) { super(schematic); - this.heightMap = schematic.getHeightMap(); + this.heightMap = generateHeightMap(schematic); } @Override protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { - return y >= heightMap[x][z]; + return y >= this.heightMap[x][z]; + } + + private static int[][] generateHeightMap(IStaticSchematic schematic) { + int[][] heightMap = new int[schematic.widthX()][schematic.lengthZ()]; + + for (int x = 0; x < schematic.widthX(); x++) { + for (int z = 0; z < schematic.lengthZ(); z++) { + IBlockState[] column = schematic.getColumn(x, z); + + OptionalInt lowestBlockY = lastIndexMatching(column, state -> !(state.getBlock() instanceof BlockAir)); + if (lowestBlockY.isPresent()) { + heightMap[x][z] = lowestBlockY.getAsInt(); + } else { + System.out.println("Column " + x + "," + z + " has no blocks, but it's apparently map art? wtf"); + System.out.println("Letting it be whatever"); + heightMap[x][z] = 256; + } + } + } + return heightMap; + } + + private static <T> OptionalInt lastIndexMatching(T[] arr, Predicate<? super T> predicate) { + for (int y = arr.length - 1; y >= 0; y--) { + if (predicate.test(arr[y])) { + return OptionalInt.of(y); + } + } + return OptionalInt.empty(); } } diff --git a/src/main/java/baritone/utils/schematic/SchematicSystem.java b/src/main/java/baritone/utils/schematic/SchematicSystem.java new file mode 100644 index 00000000..8afafa8c --- /dev/null +++ b/src/main/java/baritone/utils/schematic/SchematicSystem.java @@ -0,0 +1,51 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.utils.schematic; + +import baritone.api.command.registry.Registry; +import baritone.api.schematic.ISchematicSystem; +import baritone.api.schematic.format.ISchematicFormat; +import baritone.utils.schematic.format.DefaultSchematicFormats; + +import java.io.File; +import java.util.Arrays; +import java.util.Optional; + +/** + * @author Brady + * @since 12/24/2019 + */ +public enum SchematicSystem implements ISchematicSystem { + INSTANCE; + + private final Registry<ISchematicFormat> registry = new Registry<>(); + + SchematicSystem() { + Arrays.stream(DefaultSchematicFormats.values()).forEach(this.registry::register); + } + + @Override + public Registry<ISchematicFormat> getRegistry() { + return this.registry; + } + + @Override + public Optional<ISchematicFormat> getByFile(File file) { + return this.registry.stream().filter(format -> format.isFileType(file)).findFirst(); + } +} diff --git a/src/main/java/baritone/utils/schematic/StaticSchematic.java b/src/main/java/baritone/utils/schematic/StaticSchematic.java index 97fc91cd..2251450a 100644 --- a/src/main/java/baritone/utils/schematic/StaticSchematic.java +++ b/src/main/java/baritone/utils/schematic/StaticSchematic.java @@ -18,71 +18,33 @@ package baritone.utils.schematic; import baritone.api.schematic.AbstractSchematic; -import net.minecraft.block.BlockAir; +import baritone.api.schematic.IStaticSchematic; import net.minecraft.block.state.IBlockState; import java.util.List; -import java.util.OptionalInt; -import java.util.function.Predicate; /** + * Default implementation of {@link IStaticSchematic} + * * @author Brady * @since 12/23/2019 */ -public abstract class StaticSchematic extends AbstractSchematic { +public class StaticSchematic extends AbstractSchematic implements IStaticSchematic { - /** - * Block states for this schematic stored in [x, z, y] indexing order - */ protected IBlockState[][][] states; - /** - * The maximum height of a given block in this schematic, indexed as [x, z]. - * This is lazily initialized by {@link #getHeightMap()}. - */ - protected int[][] heightMap; - - public StaticSchematic() { - super(); - } - - public StaticSchematic(int x, int y, int z) { - super(x, y, z); - } - @Override public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { return this.states[x][z][y]; } - public final int[][] getHeightMap() { - if (this.heightMap == null) { - this.heightMap = new int[this.x][this.z]; - - for (int x = 0; x < this.x; x++) { - for (int z = 0; z < this.z; z++) { - IBlockState[] column = states[x][z]; - - OptionalInt lowestBlockY = lastIndexMatching(column, state -> !(state.getBlock() instanceof BlockAir)); - if (lowestBlockY.isPresent()) { - this.heightMap[x][z] = lowestBlockY.getAsInt(); - } else { - System.out.println("Column " + x + "," + z + " has no blocks, but it's apparently map art? wtf"); - System.out.println("Letting it be whatever"); - this.heightMap[x][z] = 256; - } - } - } - } - return this.heightMap; + @Override + public IBlockState getDirect(int x, int y, int z) { + return this.states[x][z][y]; } - private static <T> OptionalInt lastIndexMatching(T[] arr, Predicate<? super T> predicate) { - for (int y = arr.length - 1; y >= 0; y--) { - if (predicate.test(arr[y])) { - return OptionalInt.of(y); - } - } - return OptionalInt.empty(); + @Override + public IBlockState[] getColumn(int x, int z) { + return this.states[x][z]; } } diff --git a/src/main/java/baritone/utils/schematic/format/SchematicFormat.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java similarity index 68% rename from src/main/java/baritone/utils/schematic/format/SchematicFormat.java rename to src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index 6c84273e..494d6ec8 100644 --- a/src/main/java/baritone/utils/schematic/format/SchematicFormat.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -17,20 +17,21 @@ package baritone.utils.schematic.format; -import baritone.utils.schematic.parse.ISchematicParser; +import baritone.api.schematic.format.ISchematicFormat; +import baritone.api.schematic.parse.ISchematicParser; import baritone.utils.schematic.parse.MCEditParser; import baritone.utils.schematic.parse.SpongeParser; import org.apache.commons.io.FilenameUtils; import java.io.File; -import java.util.Optional; -import java.util.stream.Stream; /** + * Default implementations of {@link ISchematicFormat} + * * @author Brady * @since 12/13/2019 */ -public enum SchematicFormat { +public enum DefaultSchematicFormats implements ISchematicFormat { /** * The MCEdit schematic specification. Commonly denoted by the ".schematic" file extension. @@ -47,24 +48,18 @@ public enum SchematicFormat { private final String extension; private final ISchematicParser parser; - SchematicFormat(String extension, ISchematicParser parser) { + DefaultSchematicFormats(String extension, ISchematicParser parser) { this.extension = extension; this.parser = parser; } + @Override public final ISchematicParser getParser() { return this.parser; } - public static Optional<SchematicFormat> getByFile(File schematic) { - // TODO: Better identification - // Maybe peek file contents and make a safe determination? - return getByExtension(FilenameUtils.getExtension(schematic.getAbsolutePath())); - } - - public static Optional<SchematicFormat> getByExtension(String extension) { - return extension == null || extension.isEmpty() - ? Optional.empty() - : Stream.of(values()).filter(format -> format.extension.equalsIgnoreCase(extension)).findFirst(); + @Override + public boolean isFileType(File file) { + return this.extension.equalsIgnoreCase(FilenameUtils.getExtension(file.getAbsolutePath())); } } diff --git a/src/main/java/baritone/utils/schematic/parse/MCEditParser.java b/src/main/java/baritone/utils/schematic/parse/MCEditParser.java index 54d78201..3599b824 100644 --- a/src/main/java/baritone/utils/schematic/parse/MCEditParser.java +++ b/src/main/java/baritone/utils/schematic/parse/MCEditParser.java @@ -17,8 +17,9 @@ package baritone.utils.schematic.parse; +import baritone.api.schematic.parse.ISchematicParser; import baritone.utils.schematic.StaticSchematic; -import baritone.utils.schematic.format.SchematicFormat; +import baritone.utils.schematic.format.DefaultSchematicFormats; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.CompressedStreamTools; @@ -28,7 +29,7 @@ import java.io.IOException; import java.io.InputStream; /** - * An implementation of {@link ISchematicParser} for {@link SchematicFormat#MCEDIT} + * An implementation of {@link ISchematicParser} for {@link DefaultSchematicFormats#MCEDIT} * * @author Brady * @since 12/16/2019 diff --git a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java index 48cc60aa..255916d1 100644 --- a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java +++ b/src/main/java/baritone/utils/schematic/parse/SpongeParser.java @@ -17,8 +17,9 @@ package baritone.utils.schematic.parse; +import baritone.api.schematic.parse.ISchematicParser; import baritone.utils.schematic.StaticSchematic; -import baritone.utils.schematic.format.SchematicFormat; +import baritone.utils.schematic.format.DefaultSchematicFormats; import baritone.utils.type.VarInt; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import net.minecraft.block.Block; @@ -37,7 +38,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * An implementation of {@link ISchematicParser} for {@link SchematicFormat#SPONGE} + * An implementation of {@link ISchematicParser} for {@link DefaultSchematicFormats#SPONGE} * * @author Brady * @since 12/16/2019 From d712839c259a3be2df801e366140e0ae25ba73f0 Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Wed, 25 Dec 2019 01:35:10 -0600 Subject: [PATCH 028/133] Make Schematica respect mapArtMode setting --- src/main/java/baritone/process/BuilderProcess.java | 9 +++++++-- .../utils/schematic/schematica/SchematicAdapter.java | 11 ++++++++--- .../utils/schematic/schematica/SchematicaHelper.java | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 55361602..5cbc3da7 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -141,9 +141,14 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public void buildOpenSchematic() { if (SchematicaHelper.isSchematicaPresent()) { - Optional<Tuple<ISchematic, BlockPos>> schematic = SchematicaHelper.getOpenSchematic(); + Optional<Tuple<IStaticSchematic, BlockPos>> schematic = SchematicaHelper.getOpenSchematic(); if (schematic.isPresent()) { - this.build(schematic.get().getFirst().toString(), schematic.get().getFirst(), schematic.get().getSecond()); + IStaticSchematic s = schematic.get().getFirst(); + this.build( + schematic.get().getFirst().toString(), + Baritone.settings().mapArtMode.value ? new MapArtSchematic(s) : s, + schematic.get().getSecond() + ); } else { logDirect("No schematic currently open"); } diff --git a/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java b/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java index cd1e789f..0ae3edab 100644 --- a/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java +++ b/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java @@ -17,14 +17,14 @@ package baritone.utils.schematic.schematica; -import baritone.api.schematic.ISchematic; +import baritone.api.schematic.IStaticSchematic; import com.github.lunatrius.schematica.client.world.SchematicWorld; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import java.util.List; -public final class SchematicAdapter implements ISchematic { +public final class SchematicAdapter implements IStaticSchematic { private final SchematicWorld schematic; @@ -34,7 +34,12 @@ public final class SchematicAdapter implements ISchematic { @Override public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) { - return schematic.getSchematic().getBlockState(new BlockPos(x, y, z)); + return this.getDirect(x, y, z); + } + + @Override + public IBlockState getDirect(int x, int y, int z) { + return this.schematic.getSchematic().getBlockState(new BlockPos(x, y, z)); } @Override diff --git a/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java b/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java index 85b3967f..fab68845 100644 --- a/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java @@ -17,7 +17,7 @@ package baritone.utils.schematic.schematica; -import baritone.api.schematic.ISchematic; +import baritone.api.schematic.IStaticSchematic; import com.github.lunatrius.schematica.Schematica; import com.github.lunatrius.schematica.proxy.ClientProxy; import net.minecraft.util.Tuple; @@ -37,7 +37,7 @@ public enum SchematicaHelper { } } - public static Optional<Tuple<ISchematic, BlockPos>> getOpenSchematic() { + public static Optional<Tuple<IStaticSchematic, BlockPos>> getOpenSchematic() { return Optional.ofNullable(ClientProxy.schematic) .map(world -> new Tuple<>(new SchematicAdapter(world), world.position)); } From 812bc0d8c40ebe56cd637280e0d412190d1f4f7d Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Fri, 27 Dec 2019 01:14:31 -0600 Subject: [PATCH 029/133] Remove redundant parser layer --- .../schematic/format/ISchematicFormat.java | 6 +- .../api/schematic/parse/ISchematicParser.java | 32 ----- .../java/baritone/process/BuilderProcess.java | 2 +- .../format/DefaultSchematicFormats.java | 43 +++++-- .../format/defaults/MCEditSchematic.java | 69 ++++++++++ .../defaults/SpongeSchematic.java} | 119 +++++++----------- .../utils/schematic/parse/MCEditParser.java | 86 ------------- 7 files changed, 149 insertions(+), 208 deletions(-) delete mode 100644 src/api/java/baritone/api/schematic/parse/ISchematicParser.java create mode 100644 src/main/java/baritone/utils/schematic/format/defaults/MCEditSchematic.java rename src/main/java/baritone/utils/schematic/{parse/SpongeParser.java => format/defaults/SpongeSchematic.java} (53%) delete mode 100644 src/main/java/baritone/utils/schematic/parse/MCEditParser.java diff --git a/src/api/java/baritone/api/schematic/format/ISchematicFormat.java b/src/api/java/baritone/api/schematic/format/ISchematicFormat.java index 260ab453..3fe045bc 100644 --- a/src/api/java/baritone/api/schematic/format/ISchematicFormat.java +++ b/src/api/java/baritone/api/schematic/format/ISchematicFormat.java @@ -18,9 +18,11 @@ package baritone.api.schematic.format; import baritone.api.schematic.ISchematic; -import baritone.api.schematic.parse.ISchematicParser; +import baritone.api.schematic.IStaticSchematic; import java.io.File; +import java.io.IOException; +import java.io.InputStream; /** * The base of a {@link ISchematic} file format @@ -33,7 +35,7 @@ public interface ISchematicFormat { /** * @return The parser for creating schematics of this format */ - ISchematicParser getParser(); + IStaticSchematic parse(InputStream input) throws IOException; /** * @param file The file to check against diff --git a/src/api/java/baritone/api/schematic/parse/ISchematicParser.java b/src/api/java/baritone/api/schematic/parse/ISchematicParser.java deleted file mode 100644 index ab0f12f4..00000000 --- a/src/api/java/baritone/api/schematic/parse/ISchematicParser.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see <https://www.gnu.org/licenses/>. - */ - -package baritone.api.schematic.parse; - -import baritone.api.schematic.IStaticSchematic; - -import java.io.IOException; -import java.io.InputStream; - -/** - * @author Brady - * @since 12/13/2019 - */ -public interface ISchematicParser { - - IStaticSchematic parse(InputStream input) throws IOException; -} diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 5cbc3da7..4efa2c95 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -124,7 +124,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil ISchematic parsed; try { - parsed = format.get().getParser().parse(new FileInputStream(schematic)); + parsed = format.get().parse(new FileInputStream(schematic)); } catch (Exception e) { e.printStackTrace(); return false; diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index 494d6ec8..942bd72a 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -17,13 +17,17 @@ package baritone.utils.schematic.format; +import baritone.api.schematic.IStaticSchematic; import baritone.api.schematic.format.ISchematicFormat; -import baritone.api.schematic.parse.ISchematicParser; -import baritone.utils.schematic.parse.MCEditParser; -import baritone.utils.schematic.parse.SpongeParser; +import baritone.utils.schematic.format.defaults.MCEditSchematic; +import baritone.utils.schematic.format.defaults.SpongeSchematic; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; import org.apache.commons.io.FilenameUtils; import java.io.File; +import java.io.IOException; +import java.io.InputStream; /** * Default implementations of {@link ISchematicFormat} @@ -36,26 +40,39 @@ public enum DefaultSchematicFormats implements ISchematicFormat { /** * The MCEdit schematic specification. Commonly denoted by the ".schematic" file extension. */ - MCEDIT("schematic", MCEditParser.INSTANCE), + MCEDIT("schematic") { + + @Override + public IStaticSchematic parse(InputStream input) throws IOException { + return new MCEditSchematic(CompressedStreamTools.readCompressed(input)); + } + }, /** * The SpongePowered Schematic Specification. Commonly denoted by the ".schem" file extension. * * @see <a href="https://github.com/SpongePowered/Schematic-Specification">Sponge Schematic Specification</a> */ - SPONGE("schem", SpongeParser.INSTANCE); + SPONGE("schem") { + + @Override + public IStaticSchematic parse(InputStream input) throws IOException { + NBTTagCompound nbt = CompressedStreamTools.readCompressed(input); + int version = nbt.getInteger("Version"); + switch (version) { + case 1: + case 2: + return new SpongeSchematic(nbt); + default: + throw new UnsupportedOperationException("Unsupported Version of a Sponge Schematic"); + } + } + }; private final String extension; - private final ISchematicParser parser; - DefaultSchematicFormats(String extension, ISchematicParser parser) { + DefaultSchematicFormats(String extension) { this.extension = extension; - this.parser = parser; - } - - @Override - public final ISchematicParser getParser() { - return this.parser; } @Override diff --git a/src/main/java/baritone/utils/schematic/format/defaults/MCEditSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/MCEditSchematic.java new file mode 100644 index 00000000..08e571c9 --- /dev/null +++ b/src/main/java/baritone/utils/schematic/format/defaults/MCEditSchematic.java @@ -0,0 +1,69 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.utils.schematic.format.defaults; + +import baritone.utils.schematic.StaticSchematic; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.nbt.NBTTagCompound; + +/** + * @author Brady + * @since 12/27/2019 + */ +public final class MCEditSchematic extends StaticSchematic { + + public MCEditSchematic(NBTTagCompound schematic) { + String type = schematic.getString("Materials"); + if (!type.equals("Alpha")) { + throw new IllegalStateException("bad schematic " + type); + } + this.x = schematic.getInteger("Width"); + this.y = schematic.getInteger("Height"); + this.z = schematic.getInteger("Length"); + byte[] blocks = schematic.getByteArray("Blocks"); + byte[] metadata = schematic.getByteArray("Data"); + + byte[] additional = null; + if (schematic.hasKey("AddBlocks")) { + byte[] addBlocks = schematic.getByteArray("AddBlocks"); + additional = new byte[addBlocks.length * 2]; + for (int i = 0; i < addBlocks.length; i++) { + additional[i * 2 + 0] = (byte) ((addBlocks[i] >> 4) & 0xF); // lower nibble + additional[i * 2 + 1] = (byte) ((addBlocks[i] >> 0) & 0xF); // upper nibble + } + } + this.states = new IBlockState[this.x][this.z][this.y]; + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + int blockInd = (y * this.z + z) * this.x + x; + + int blockID = blocks[blockInd] & 0xFF; + if (additional != null) { + // additional is 0 through 15 inclusive since it's & 0xF above + blockID |= additional[blockInd] << 8; + } + Block block = Block.REGISTRY.getObjectById(blockID); + int meta = metadata[blockInd] & 0xFF; + this.states[x][z][y] = block.getStateFromMeta(meta); + } + } + } + } +} diff --git a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java b/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java similarity index 53% rename from src/main/java/baritone/utils/schematic/parse/SpongeParser.java rename to src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java index 255916d1..0d03e5d8 100644 --- a/src/main/java/baritone/utils/schematic/parse/SpongeParser.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java @@ -15,22 +15,17 @@ * along with Baritone. If not, see <https://www.gnu.org/licenses/>. */ -package baritone.utils.schematic.parse; +package baritone.utils.schematic.format.defaults; -import baritone.api.schematic.parse.ISchematicParser; import baritone.utils.schematic.StaticSchematic; -import baritone.utils.schematic.format.DefaultSchematicFormats; import baritone.utils.type.VarInt; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; -import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; -import java.io.IOException; -import java.io.InputStream; import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -38,83 +33,59 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * An implementation of {@link ISchematicParser} for {@link DefaultSchematicFormats#SPONGE} - * * @author Brady - * @since 12/16/2019 + * @since 12/27/2019 */ -public enum SpongeParser implements ISchematicParser { - INSTANCE; +public final class SpongeSchematic extends StaticSchematic { - @Override - public StaticSchematic parse(InputStream input) throws IOException { - NBTTagCompound nbt = CompressedStreamTools.readCompressed(input); - int version = nbt.getInteger("Version"); - switch (version) { - case 1: - case 2: - return new SpongeSchematic(nbt); - default: - throw new UnsupportedOperationException("Unsupported Version of a Sponge Schematic"); + public SpongeSchematic(NBTTagCompound nbt) { + this.x = nbt.getInteger("Width"); + this.y = nbt.getInteger("Height"); + this.z = nbt.getInteger("Length"); + this.states = new IBlockState[this.x][this.z][this.y]; + + Int2ObjectArrayMap<IBlockState> palette = new Int2ObjectArrayMap<>(); + NBTTagCompound paletteTag = nbt.getCompoundTag("Palette"); + for (String tag : paletteTag.getKeySet()) { + int index = paletteTag.getInteger(tag); + + SerializedBlockState serializedState = SerializedBlockState.getFromString(tag); + if (serializedState == null) { + throw new IllegalArgumentException("Unable to parse palette tag"); + } + + IBlockState state = serializedState.deserialize(); + if (state == null) { + throw new IllegalArgumentException("Unable to deserialize palette tag"); + } + + palette.put(index, state); } - } - /** - * Implementation of the Sponge Schematic Format supporting both V1 and V2. (For the current - * use case, there is no difference between reading a V1 and V2 schematic). - */ - private static final class SpongeSchematic extends StaticSchematic { - - - SpongeSchematic(NBTTagCompound nbt) { - this.x = nbt.getInteger("Width"); - this.y = nbt.getInteger("Height"); - this.z = nbt.getInteger("Length"); - this.states = new IBlockState[this.x][this.z][this.y]; - - Int2ObjectArrayMap<IBlockState> palette = new Int2ObjectArrayMap<>(); - NBTTagCompound paletteTag = nbt.getCompoundTag("Palette"); - for (String tag : paletteTag.getKeySet()) { - int index = paletteTag.getInteger(tag); - - SerializedBlockState serializedState = SerializedBlockState.getFromString(tag); - if (serializedState == null) { - throw new IllegalArgumentException("Unable to parse palette tag"); - } - - IBlockState state = serializedState.deserialize(); - if (state == null) { - throw new IllegalArgumentException("Unable to deserialize palette tag"); - } - - palette.put(index, state); + // BlockData is stored as an NBT byte[], however, the actual data that is represented is a varint[] + byte[] rawBlockData = nbt.getByteArray("BlockData"); + int[] blockData = new int[this.x * this.y * this.z]; + int offset = 0; + for (int i = 0; i < blockData.length; i++) { + if (offset >= rawBlockData.length) { + throw new IllegalArgumentException("No remaining bytes in BlockData for complete schematic"); } - // BlockData is stored as an NBT byte[], however, the actual data that is represented is a varint[] - byte[] rawBlockData = nbt.getByteArray("BlockData"); - int[] blockData = new int[this.x * this.y * this.z]; - int offset = 0; - for (int i = 0; i < blockData.length; i++) { - if (offset >= rawBlockData.length) { - throw new IllegalArgumentException("No remaining bytes in BlockData for complete schematic"); - } + VarInt varInt = VarInt.read(rawBlockData, offset); + blockData[i] = varInt.getValue(); + offset += varInt.getSize(); + } - VarInt varInt = VarInt.read(rawBlockData, offset); - blockData[i] = varInt.getValue(); - offset += varInt.getSize(); - } - - for (int y = 0; y < this.y; y++) { - for (int z = 0; z < this.z; z++) { - for (int x = 0; x < this.x; x++) { - int index = (y * this.z + z) * this.x + x; - IBlockState state = palette.get(blockData[index]); - if (state == null) { - throw new IllegalArgumentException("Invalid Palette Index " + index); - } - - this.states[x][z][y] = state; + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + int index = (y * this.z + z) * this.x + x; + IBlockState state = palette.get(blockData[index]); + if (state == null) { + throw new IllegalArgumentException("Invalid Palette Index " + index); } + + this.states[x][z][y] = state; } } } diff --git a/src/main/java/baritone/utils/schematic/parse/MCEditParser.java b/src/main/java/baritone/utils/schematic/parse/MCEditParser.java deleted file mode 100644 index 3599b824..00000000 --- a/src/main/java/baritone/utils/schematic/parse/MCEditParser.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see <https://www.gnu.org/licenses/>. - */ - -package baritone.utils.schematic.parse; - -import baritone.api.schematic.parse.ISchematicParser; -import baritone.utils.schematic.StaticSchematic; -import baritone.utils.schematic.format.DefaultSchematicFormats; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; - -import java.io.IOException; -import java.io.InputStream; - -/** - * An implementation of {@link ISchematicParser} for {@link DefaultSchematicFormats#MCEDIT} - * - * @author Brady - * @since 12/16/2019 - */ -public enum MCEditParser implements ISchematicParser { - INSTANCE; - - @Override - public StaticSchematic parse(InputStream input) throws IOException { - return new MCEditSchematic(CompressedStreamTools.readCompressed(input)); - } - - private static final class MCEditSchematic extends StaticSchematic { - - MCEditSchematic(NBTTagCompound schematic) { - String type = schematic.getString("Materials"); - if (!type.equals("Alpha")) { - throw new IllegalStateException("bad schematic " + type); - } - this.x = schematic.getInteger("Width"); - this.y = schematic.getInteger("Height"); - this.z = schematic.getInteger("Length"); - byte[] blocks = schematic.getByteArray("Blocks"); - byte[] metadata = schematic.getByteArray("Data"); - - byte[] additional = null; - if (schematic.hasKey("AddBlocks")) { - byte[] addBlocks = schematic.getByteArray("AddBlocks"); - additional = new byte[addBlocks.length * 2]; - for (int i = 0; i < addBlocks.length; i++) { - additional[i * 2 + 0] = (byte) ((addBlocks[i] >> 4) & 0xF); // lower nibble - additional[i * 2 + 1] = (byte) ((addBlocks[i] >> 0) & 0xF); // upper nibble - } - } - this.states = new IBlockState[this.x][this.z][this.y]; - for (int y = 0; y < this.y; y++) { - for (int z = 0; z < this.z; z++) { - for (int x = 0; x < this.x; x++) { - int blockInd = (y * this.z + z) * this.x + x; - - int blockID = blocks[blockInd] & 0xFF; - if (additional != null) { - // additional is 0 through 15 inclusive since it's & 0xF above - blockID |= additional[blockInd] << 8; - } - Block block = Block.REGISTRY.getObjectById(blockID); - int meta = metadata[blockInd] & 0xFF; - this.states[x][z][y] = block.getStateFromMeta(meta); - } - } - } - } - } -} From 220ee30d35c8a5f9851903e7b4d791ae5253ffc3 Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Fri, 27 Dec 2019 21:28:05 -0600 Subject: [PATCH 030/133] Appease Codacy --- .../utils/schematic/format/defaults/SpongeSchematic.java | 4 ++-- src/main/java/baritone/utils/type/VarInt.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java index 0d03e5d8..8de038f5 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/SpongeSchematic.java @@ -104,7 +104,7 @@ public final class SpongeSchematic extends StaticSchematic { this.properties = properties; } - IBlockState deserialize() { + private IBlockState deserialize() { if (this.blockState == null) { Block block = Block.REGISTRY.getObject(this.resourceLocation); this.blockState = block.getDefaultState(); @@ -119,7 +119,7 @@ public final class SpongeSchematic extends StaticSchematic { return this.blockState; } - static SerializedBlockState getFromString(String s) { + private static SerializedBlockState getFromString(String s) { Matcher m = REGEX.matcher(s); if (!m.matches()) { return null; diff --git a/src/main/java/baritone/utils/type/VarInt.java b/src/main/java/baritone/utils/type/VarInt.java index 45f83dda..93b3e425 100644 --- a/src/main/java/baritone/utils/type/VarInt.java +++ b/src/main/java/baritone/utils/type/VarInt.java @@ -54,9 +54,10 @@ public final class VarInt { return this.serialized; } - private static byte[] serialize0(int value) { + private static byte[] serialize0(int valueIn) { ByteList bytes = new ByteArrayList(); + int value = valueIn; while ((value & 0x80) != 0) { bytes.add((byte) (value & 0x7F | 0x80)); value >>>= 7; From fcfa022232f28627b9aebc78a8b3ddac63ea76aa Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Mon, 30 Dec 2019 02:27:20 -0600 Subject: [PATCH 031/133] Clean up BlockOptionalMeta comment and add behavioral clarification --- .../baritone/api/utils/BlockOptionalMeta.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/utils/BlockOptionalMeta.java b/src/api/java/baritone/api/utils/BlockOptionalMeta.java index 451d95eb..020df814 100644 --- a/src/api/java/baritone/api/utils/BlockOptionalMeta.java +++ b/src/api/java/baritone/api/utils/BlockOptionalMeta.java @@ -188,13 +188,20 @@ public final class BlockOptionalMeta { return (C) value; } + /** + * Normalizes the specified blockstate by setting meta-affecting properties which + * are not being targeted by the meta parameter to their default values. + * <p> + * For example, block variant/color is the primary target for the meta value, so properties + * such as rotation/facing direction will be set to default values in order to nullify + * the effect that they have on the state's meta value. + * + * @param state The state to normalize + * @return The normalized block state + */ public static IBlockState normalize(IBlockState state) { IBlockState newState = state; - // TODO: Can the state not be normalized by simply doing...? - // return state.getBlock().getDefaultState(); - // ??? - for (IProperty<?> property : state.getProperties().keySet()) { Class<?> valueClass = property.getValueClass(); if (normalizations.containsKey(property)) { @@ -224,6 +231,15 @@ public final class BlockOptionalMeta { return newState; } + /** + * Evaluate the target meta value for the specified state. The target meta value is + * most often that which is influenced by the variant/color property of the block state. + * + * @see #normalize(IBlockState) + * + * @param state The state to check + * @return The target meta of the state + */ public static int stateMeta(IBlockState state) { return state.getBlock().getMetaFromState(normalize(state)); } From bbb25acff3b8c118ae9853ab5ac35ebd5a29ed77 Mon Sep 17 00:00:00 2001 From: FTC55 <francescoiera55@gmail.com> Date: Tue, 31 Dec 2019 19:16:31 +0100 Subject: [PATCH 032/133] Fixed the bug, merged CancelCommand into ExecutionControlCommands --- .../command/defaults/CancelCommand.java | 61 ------------------- ...nds.java => ExecutionControlCommands.java} | 32 ++++++++++ 2 files changed, 32 insertions(+), 61 deletions(-) delete mode 100644 src/main/java/baritone/command/defaults/CancelCommand.java rename src/main/java/baritone/command/defaults/{PauseResumeCommands.java => ExecutionControlCommands.java} (84%) diff --git a/src/main/java/baritone/command/defaults/CancelCommand.java b/src/main/java/baritone/command/defaults/CancelCommand.java deleted file mode 100644 index 3b4c6367..00000000 --- a/src/main/java/baritone/command/defaults/CancelCommand.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see <https://www.gnu.org/licenses/>. - */ - -package baritone.command.defaults; - -import baritone.api.IBaritone; -import baritone.api.command.Command; -import baritone.api.command.exception.CommandException; -import baritone.api.command.argument.IArgConsumer; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Stream; - -public class CancelCommand extends Command { - - public CancelCommand(IBaritone baritone) { - super(baritone, "cancel", "stop"); - } - - @Override - public void execute(String label, IArgConsumer args) throws CommandException { - args.requireMax(0); - baritone.getPathingBehavior().cancelEverything(); - logDirect("ok canceled"); - } - - @Override - public Stream<String> tabComplete(String label, IArgConsumer args) { - return Stream.empty(); - } - - @Override - public String getShortDesc() { - return "Cancel what Baritone is currently doing"; - } - - @Override - public List<String> getLongDesc() { - return Arrays.asList( - "The cancel command tells Baritone to stop whatever it's currently doing.", - "", - "Usage:", - "> cancel" - ); - } -} diff --git a/src/main/java/baritone/command/defaults/PauseResumeCommands.java b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java similarity index 84% rename from src/main/java/baritone/command/defaults/PauseResumeCommands.java rename to src/main/java/baritone/command/defaults/ExecutionControlCommands.java index 54718e9b..376b8f43 100644 --- a/src/main/java/baritone/command/defaults/PauseResumeCommands.java +++ b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java @@ -42,6 +42,7 @@ public class PauseResumeCommands { Command pauseCommand; Command resumeCommand; Command pausedCommand; + Command cancelCommand; public PauseResumeCommands(IBaritone baritone) { // array for mutability, non-field so reflection can't touch it @@ -169,5 +170,36 @@ public class PauseResumeCommands { ); } }; + cancelCommand = new Command(baritone, "cancel", "stop") { + @Override + public void execute(String label, IArgConsumer args) throws CommandException { + args.requireMax(0); + if (paused[0]) { + paused[0] = false; + } + baritone.getPathingBehavior().cancelEverything(); + logDirect("ok canceled"); + } + + @Override + public Stream<String> tabComplete(String label, IArgConsumer args) { + return Stream.empty(); + } + + @Override + public String getShortDesc() { + return "Cancel what Baritone is currently doing"; + } + + @Override + public List<String> getLongDesc() { + return Arrays.asList( + "The cancel command tells Baritone to stop whatever it's currently doing.", + "", + "Usage:", + "> cancel" + ); + } + }; } } From 4b10904b97ea5cc0c36f4d33559f93db2ffa13b3 Mon Sep 17 00:00:00 2001 From: FTC55 <francescoiera55@gmail.com> Date: Tue, 31 Dec 2019 19:43:54 +0100 Subject: [PATCH 033/133] Git missed some changes. Autoreformatted files. --- .../command/defaults/DefaultCommands.java | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/src/main/java/baritone/command/defaults/DefaultCommands.java b/src/main/java/baritone/command/defaults/DefaultCommands.java index c48644e3..67555ed5 100644 --- a/src/main/java/baritone/command/defaults/DefaultCommands.java +++ b/src/main/java/baritone/command/defaults/DefaultCommands.java @@ -24,52 +24,53 @@ import java.util.*; public final class DefaultCommands { - private DefaultCommands() {} + private DefaultCommands() { + } public static List<ICommand> createAll(IBaritone baritone) { Objects.requireNonNull(baritone); List<ICommand> commands = new ArrayList<>(Arrays.asList( - new HelpCommand(baritone), - new SetCommand(baritone), - new CommandAlias(baritone, Arrays.asList("modified", "mod", "baritone", "modifiedsettings"), "List modified settings", "set modified"), - new CommandAlias(baritone, "reset", "Reset all settings or just one", "set reset"), - new GoalCommand(baritone), - new GotoCommand(baritone), - new PathCommand(baritone), - new ProcCommand(baritone), - new VersionCommand(baritone), - new RepackCommand(baritone), - new BuildCommand(baritone), - new SchematicaCommand(baritone), - new ComeCommand(baritone), - new AxisCommand(baritone), - new CancelCommand(baritone), - new ForceCancelCommand(baritone), - new GcCommand(baritone), - new InvertCommand(baritone), - new TunnelCommand(baritone), - new RenderCommand(baritone), - new FarmCommand(baritone), - new ChestsCommand(baritone), - new FollowCommand(baritone), - new ExploreFilterCommand(baritone), - new ReloadAllCommand(baritone), - new SaveAllCommand(baritone), - new ExploreCommand(baritone), - new BlacklistCommand(baritone), - new FindCommand(baritone), - new MineCommand(baritone), - new ClickCommand(baritone), - new ThisWayCommand(baritone), - new WaypointsCommand(baritone), - new CommandAlias(baritone, "sethome", "Sets your home waypoint", "waypoints save home"), - new CommandAlias(baritone, "home", "Set goal to your home waypoint", "waypoints goal home"), - new SelCommand(baritone) + new HelpCommand(baritone), + new SetCommand(baritone), + new CommandAlias(baritone, Arrays.asList("modified", "mod", "baritone", "modifiedsettings"), "List modified settings", "set modified"), + new CommandAlias(baritone, "reset", "Reset all settings or just one", "set reset"), + new GoalCommand(baritone), + new GotoCommand(baritone), + new PathCommand(baritone), + new ProcCommand(baritone), + new VersionCommand(baritone), + new RepackCommand(baritone), + new BuildCommand(baritone), + new SchematicaCommand(baritone), + new ComeCommand(baritone), + new AxisCommand(baritone), + new ForceCancelCommand(baritone), + new GcCommand(baritone), + new InvertCommand(baritone), + new TunnelCommand(baritone), + new RenderCommand(baritone), + new FarmCommand(baritone), + new ChestsCommand(baritone), + new FollowCommand(baritone), + new ExploreFilterCommand(baritone), + new ReloadAllCommand(baritone), + new SaveAllCommand(baritone), + new ExploreCommand(baritone), + new BlacklistCommand(baritone), + new FindCommand(baritone), + new MineCommand(baritone), + new ClickCommand(baritone), + new ThisWayCommand(baritone), + new WaypointsCommand(baritone), + new CommandAlias(baritone, "sethome", "Sets your home waypoint", "waypoints save home"), + new CommandAlias(baritone, "home", "Set goal to your home waypoint", "waypoints goal home"), + new SelCommand(baritone) )); - PauseResumeCommands prc = new PauseResumeCommands(baritone); + ExecutionControlCommands prc = new ExecutionControlCommands(baritone); commands.add(prc.pauseCommand); commands.add(prc.resumeCommand); commands.add(prc.pausedCommand); + commands.add(prc.cancelCommand); return Collections.unmodifiableList(commands); } } From 04190af34049495bbaef5f9230d0cf3f9f5c7a05 Mon Sep 17 00:00:00 2001 From: FTC55 <francescoiera55@gmail.com> Date: Tue, 31 Dec 2019 19:45:08 +0100 Subject: [PATCH 034/133] ...more than I thought. Autoreformatted file x2 --- .../defaults/ExecutionControlCommands.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java index 376b8f43..4a04b9e0 100644 --- a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java +++ b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java @@ -18,13 +18,13 @@ package baritone.command.defaults; import baritone.api.IBaritone; +import baritone.api.command.Command; +import baritone.api.command.argument.IArgConsumer; +import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidStateException; import baritone.api.process.IBaritoneProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; -import baritone.api.command.Command; -import baritone.api.command.exception.CommandException; -import baritone.api.command.exception.CommandInvalidStateException; -import baritone.api.command.argument.IArgConsumer; import java.util.Arrays; import java.util.List; @@ -37,14 +37,14 @@ import java.util.stream.Stream; * TO USE THIS to pause and resume Baritone. Make your own process that returns {@link PathingCommandType#REQUEST_PAUSE * REQUEST_PAUSE} as needed. */ -public class PauseResumeCommands { +public class ExecutionControlCommands { Command pauseCommand; Command resumeCommand; Command pausedCommand; Command cancelCommand; - public PauseResumeCommands(IBaritone baritone) { + public ExecutionControlCommands(IBaritone baritone) { // array for mutability, non-field so reflection can't touch it final boolean[] paused = {false}; baritone.getPathingControlManager().registerProcess( @@ -65,7 +65,8 @@ public class PauseResumeCommands { } @Override - public void onLostControl() {} + public void onLostControl() { + } @Override public double priority() { From 4a05837b01cb04e28a73b114f6c035033d218454 Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Tue, 31 Dec 2019 17:44:20 -0600 Subject: [PATCH 035/133] Requested changes --- src/main/java/baritone/utils/type/VarInt.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/type/VarInt.java b/src/main/java/baritone/utils/type/VarInt.java index 93b3e425..7cc005bd 100644 --- a/src/main/java/baritone/utils/type/VarInt.java +++ b/src/main/java/baritone/utils/type/VarInt.java @@ -85,7 +85,7 @@ public final class VarInt { } // Most significant bit denotes another byte is to be read. - if ((b & 0x80) != 0x80) { + if ((b & 0x80) == 0) { break; } } From fb22cf05ebe539cb6f8510e12bc58c3597cb8199 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 4 Jan 2020 21:57:16 -0800 Subject: [PATCH 036/133] v1.2.11 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 117f1d63..9912a92a 100755 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ */ group 'baritone' -version '1.2.10' +version '1.2.11' buildscript { repositories { From 710170ef2d2c8909e3fbdd67108f5b57f447d25f Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Fri, 10 Jan 2020 20:10:16 -0600 Subject: [PATCH 037/133] Fix RelativeGoalXZ coordinate mix-up Basically for many months now RelativeGoalXZ produced (~X, ~Y), not (~X, ~Z). --- src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java b/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java index cd3977b6..c50aab01 100644 --- a/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java @@ -37,7 +37,7 @@ public enum RelativeGoalXZ implements IDatatypePost<GoalXZ, BetterBlockPos> { final IArgConsumer consumer = ctx.getConsumer(); return new GoalXZ( MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.x)), - MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.y)) + MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.z)) ); } From 539b8ef973537e633eb954a0008a370582f24721 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 25 Jan 2020 22:34:55 -0800 Subject: [PATCH 038/133] fix oversight in coordinate censorship --- src/main/java/baritone/cache/CachedWorld.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index e7405390..23d7ca8c 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -184,7 +184,9 @@ public final class CachedWorld implements ICachedWorld, Helper { int distZ = ((region.getZ() << 9) + 256) - pruneCenter.getZ(); double dist = Math.sqrt(distX * distX + distZ * distZ); if (dist > 1024) { - logDebug("Deleting cached region " + region.getX() + "," + region.getZ() + " from ram"); + if (!Baritone.settings().censorCoordinates.value) { + logDebug("Deleting cached region " + region.getX() + "," + region.getZ() + " from ram"); + } cachedRegions.remove(getRegionID(region.getX(), region.getZ())); } } From b3de840e04568f5c21a3e0a80b490f326e5ea9b9 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sun, 26 Jan 2020 12:41:15 -0800 Subject: [PATCH 039/133] no reason for this now that impact is 1.14.4 for all --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 043aed08..87d35d2f 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,6 @@ Baritone is the pathfinding system used in [Impact](https://impactclient.net/) s The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. -For 1.14.4, [click here](https://www.dropbox.com/s/rkml3hjokd3qv0m/1.14.4-Baritone.zip?dl=1). Or [with optifine](https://github.com/cabaletta/baritone/issues/797). - This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 and 1.13.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). From 17a06621f5149c1f76e52a7b946e7774ccf0cc95 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 1 Feb 2020 16:42:14 -0800 Subject: [PATCH 040/133] rootnet shill --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 87d35d2f..6067610b 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ [![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.10%20/%20v1.3.5%20/%20v1.4.3-brightgreen.svg)](https://impactclient.net/) [![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/) [![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api) +[![rootNET integration](https://img.shields.io/badge/rootNET%20integration-v1.2.11-green.svg)](https://rootnet.dev/) [![WWE integration](https://img.shields.io/badge/WWE%20%22integration%22-master%3F-green.svg)](https://wweclient.com/) [![Future integration](https://img.shields.io/badge/Future%20integration-Soonβ„’%3F%3F%3F-red.svg)](https://futureclient.net/) [![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](http://forthebadge.com/) From de89da20b23a616ae889d10967f011643ea2a0a5 Mon Sep 17 00:00:00 2001 From: Bella Who <bella.who.two@gmail.com> Date: Sun, 9 Feb 2020 17:44:50 -0500 Subject: [PATCH 041/133] Update bug.md --- .github/ISSUE_TEMPLATE/bug.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index 55e5ad06..ced6b51e 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -20,6 +20,7 @@ You can find your logs in `%appdata%/.minecraft/logs/` (Windows) or `/Library/Ap Add your steps to reproduce the issue/bug experienced here. ## Final checklist +- [x] I know how to properly use check boxes - [ ] I have included the version of Minecraft I'm running, baritone's version and forge mods (if used). - [ ] I have included logs, exceptions and / or steps to reproduce the issue. -- [ ] I have not used any OwO's or UwU's in this issue. \ No newline at end of file +- [ ] I have not used any OwO's or UwU's in this issue. From de68e6630eb4c7e6d3b5d627dac317ca73df211b Mon Sep 17 00:00:00 2001 From: Bella Who <bella.who.two@gmail.com> Date: Sun, 9 Feb 2020 17:45:09 -0500 Subject: [PATCH 042/133] Update question.md --- .github/ISSUE_TEMPLATE/question.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md index 2482fd4c..b5de2dfd 100644 --- a/.github/ISSUE_TEMPLATE/question.md +++ b/.github/ISSUE_TEMPLATE/question.md @@ -10,4 +10,5 @@ assignees: '' With as much detail as possible, describe your question and what you may need help with. ## Final checklist -- [ ] I have not used any OwO's or UwU's in this issue. \ No newline at end of file +- [x] I know how to properly use check boxes +- [ ] I have not used any OwO's or UwU's in this issue. From 7cdbc4acca78f8737ceb28dca32a6265861b8c55 Mon Sep 17 00:00:00 2001 From: Bella Who <bella.who.two@gmail.com> Date: Sun, 9 Feb 2020 17:45:28 -0500 Subject: [PATCH 043/133] Update suggestion.md --- .github/ISSUE_TEMPLATE/suggestion.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/suggestion.md b/.github/ISSUE_TEMPLATE/suggestion.md index da61c638..9f7a30bf 100644 --- a/.github/ISSUE_TEMPLATE/suggestion.md +++ b/.github/ISSUE_TEMPLATE/suggestion.md @@ -16,4 +16,5 @@ If applicable, what settings/customizability should be offered to tweak the func Describe how your suggestion would improve Baritone, or the reason behind it being added. ## Final checklist -- [ ] I have not used any OwO's or UwU's in this issue. \ No newline at end of file +- [x] I know how to properly use check boxes +- [ ] I have not used any OwO's or UwU's in this issue. From 656dd910040e13ce2653c416b772693eff13d678 Mon Sep 17 00:00:00 2001 From: Bella Who <bella.who.two@gmail.com> Date: Sun, 9 Feb 2020 19:12:40 -0500 Subject: [PATCH 044/133] Update bug.md --- .github/ISSUE_TEMPLATE/bug.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index ced6b51e..dc6eb226 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -14,7 +14,13 @@ Baritone version: Forge mods (if used): ## Exception, error or logs -You can find your logs in `%appdata%/.minecraft/logs/` (Windows) or `/Library/Application\ Support/minecraft/logs` (Mac). +Please find your `latest.log` or `debug.log` in this folder and attach it to the issue + +Linux: `~/.minecraft/logs/` + +Windows: `%appdata%/.minecraft/logs/` + +Mac:`/Library/Application\ Support/minecraft/logs/` ## How to reproduce Add your steps to reproduce the issue/bug experienced here. From e66d8616ceeb520009bc5ef1ac0b578f8f1dcdb2 Mon Sep 17 00:00:00 2001 From: Bella Who <bella.who.two@gmail.com> Date: Sun, 9 Feb 2020 19:28:19 -0500 Subject: [PATCH 045/133] fixed space --- .github/ISSUE_TEMPLATE/bug.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index dc6eb226..e2b8874c 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -20,7 +20,7 @@ Linux: `~/.minecraft/logs/` Windows: `%appdata%/.minecraft/logs/` -Mac:`/Library/Application\ Support/minecraft/logs/` +Mac: `/Library/Application\ Support/minecraft/logs/` ## How to reproduce Add your steps to reproduce the issue/bug experienced here. From e0985d3b68ee10e1cbb0560fac5fdb293b2d8305 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Fri, 14 Feb 2020 13:49:15 -0800 Subject: [PATCH 046/133] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6067610b..4d9900b5 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ Baritone is the pathfinding system used in [Impact](https://impactclient.net/) s The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. +For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. + This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 and 1.13.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). From 01ba712d339f6dc5d48c15bdc5cbc5cb8fca1e38 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Fri, 14 Feb 2020 13:49:53 -0800 Subject: [PATCH 047/133] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d9900b5..7de14beb 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ [![Minecraft](https://img.shields.io/badge/MC-1.12.2-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/master/) [![Minecraft](https://img.shields.io/badge/MC-1.13.2-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/1.13.2/) [![Minecraft](https://img.shields.io/badge/MC-1.14.4-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/1.14.4/) +[![Minecraft](https://img.shields.io/badge/MC-1.15.2-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/1.15.2/) [![Code of Conduct](https://img.shields.io/badge/%E2%9D%A4-code%20of%20conduct-blue.svg?style=flat)](https://github.com/cabaletta/baritone/blob/master/CODE_OF_CONDUCT.md) [![Known Vulnerabilities](https://snyk.io/test/github/cabaletta/baritone/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/cabaletta/baritone?targetFile=build.gradle) [![Contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues/) @@ -37,7 +38,7 @@ The easiest way to install Baritone is to install [Impact](https://impactclient. For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/), -the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 and 1.13.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). +the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 through 1.15.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). Have committed at least once a day from Aug 1 2018 to Aug 1 2019. From 80955cad8bd381e9d658f75f6780c3d2fa36aa8b Mon Sep 17 00:00:00 2001 From: Bella Who <bella.who.two@gmail.com> Date: Mon, 17 Feb 2020 17:42:05 -0500 Subject: [PATCH 048/133] Make setup instructions more clear --- SETUP.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/SETUP.md b/SETUP.md index 1fcaf1d2..7efab34f 100644 --- a/SETUP.md +++ b/SETUP.md @@ -47,6 +47,8 @@ You can verify whether or not it worked by running `.b version` in chat (only va ## Command Line On Mac OSX and Linux, use `./gradlew` instead of `gradlew`. +If you have errors with a package missing please make sure you have setup your environment, and are using Oracle JDK 8. + Setting up the Environment: ``` @@ -54,6 +56,12 @@ $ gradlew setupDecompWorkspace $ gradlew --refresh-dependencies ``` +Building Baritone: + +``` +$ gradlew build +``` + Running Baritone: ``` @@ -87,16 +95,6 @@ For information on how to build baritone, see [Building Baritone](#building-bari ![Image](https://i.imgur.com/hrLhG9u.png) -# Building - -Make sure that you have properly [setup](#setup) the environment before trying to build it. - -## Command Line - -``` -$ gradlew build -``` - ## IntelliJ - Navigate to the gradle tasks on the right tab as follows From 85d63c9d7fe484bfc501f02ae4421a08bcad9e1a Mon Sep 17 00:00:00 2001 From: Babbaj <babbaj45@gmail.com> Date: Thu, 20 Feb 2020 20:29:36 -0500 Subject: [PATCH 049/133] Exceptions are side effects --- scripts/proguard.pro | 48 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 4ac0f723..52b843dd 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -181,19 +181,19 @@ -assumenosideeffects public class java.lang.* extends java.lang.Number { public static java.lang.String toString(byte); public static java.lang.Byte valueOf(byte); - public static byte parseByte(java.lang.String); - public static byte parseByte(java.lang.String,int); - public static java.lang.Byte valueOf(java.lang.String,int); - public static java.lang.Byte valueOf(java.lang.String); - public static java.lang.Byte decode(java.lang.String); +# public static byte parseByte(java.lang.String); +# public static byte parseByte(java.lang.String,int); +# public static java.lang.Byte valueOf(java.lang.String,int); +# public static java.lang.Byte valueOf(java.lang.String); +# public static java.lang.Byte decode(java.lang.String); public int compareTo(java.lang.Byte); public static java.lang.String toString(short); - public static short parseShort(java.lang.String); - public static short parseShort(java.lang.String,int); - public static java.lang.Short valueOf(java.lang.String,int); - public static java.lang.Short valueOf(java.lang.String); +# public static short parseShort(java.lang.String); +# public static short parseShort(java.lang.String,int); +# public static java.lang.Short valueOf(java.lang.String,int); +# public static java.lang.Short valueOf(java.lang.String); public static java.lang.Short valueOf(short); - public static java.lang.Short decode(java.lang.String); +# public static java.lang.Short decode(java.lang.String); public static short reverseBytes(short); public int compareTo(java.lang.Short); public static java.lang.String toString(int,int); @@ -201,10 +201,10 @@ public static java.lang.String toOctalString(int); public static java.lang.String toBinaryString(int); public static java.lang.String toString(int); - public static int parseInt(java.lang.String,int); - public static int parseInt(java.lang.String); - public static java.lang.Integer valueOf(java.lang.String,int); - public static java.lang.Integer valueOf(java.lang.String); +# public static int parseInt(java.lang.String,int); +# public static int parseInt(java.lang.String); +# public static java.lang.Integer valueOf(java.lang.String,int); +# public static java.lang.Integer valueOf(java.lang.String); public static java.lang.Integer valueOf(int); public static java.lang.Integer getInteger(java.lang.String); public static java.lang.Integer getInteger(java.lang.String,int); @@ -226,12 +226,12 @@ public static java.lang.String toOctalString(long); public static java.lang.String toBinaryString(long); public static java.lang.String toString(long); - public static long parseLong(java.lang.String,int); - public static long parseLong(java.lang.String); - public static java.lang.Long valueOf(java.lang.String,int); - public static java.lang.Long valueOf(java.lang.String); +# public static long parseLong(java.lang.String,int); +# public static long parseLong(java.lang.String); +# public static java.lang.Long valueOf(java.lang.String,int); +# public static java.lang.Long valueOf(java.lang.String); public static java.lang.Long valueOf(long); - public static java.lang.Long decode(java.lang.String); +# public static java.lang.Long decode(java.lang.String); public static java.lang.Long getLong(java.lang.String); public static java.lang.Long getLong(java.lang.String,long); public static java.lang.Long getLong(java.lang.String,java.lang.Long); @@ -248,9 +248,9 @@ public int compareTo(java.lang.Long); public static java.lang.String toString(float); public static java.lang.String toHexString(float); - public static java.lang.Float valueOf(java.lang.String); +# public static java.lang.Float valueOf(java.lang.String); public static java.lang.Float valueOf(float); - public static float parseFloat(java.lang.String); +# public static float parseFloat(java.lang.String); public static boolean isNaN(float); public static boolean isInfinite(float); public static int floatToIntBits(float); @@ -262,9 +262,9 @@ public int compareTo(java.lang.Float); public static java.lang.String toString(double); public static java.lang.String toHexString(double); - public static java.lang.Double valueOf(java.lang.String); - public static java.lang.Double valueOf(double); - public static double parseDouble(java.lang.String); +# public static java.lang.Double valueOf(java.lang.String); +# public static java.lang.Double valueOf(double); +# public static double parseDouble(java.lang.String); public static boolean isNaN(double); public static boolean isInfinite(double); public static long doubleToLongBits(double); From 2d2571cff5aa30d2142b5d809f74cf85c267a0e9 Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Sat, 22 Feb 2020 18:31:41 -0500 Subject: [PATCH 050/133] Desktop Notification System --- src/api/java/baritone/api/Settings.java | 4 ++ .../pathing/calc/AbstractNodeCostSearch.java | 3 + .../baritone/utils/NotificationHelper.java | 72 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/main/java/baritone/utils/NotificationHelper.java diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 69bcabcb..1bbde3b2 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -1046,6 +1046,10 @@ public final class Settings { */ public final Setting<Boolean> renderSelectionCorners = new Setting<>(true); + /** + * Desktop Notifications + */ + public final Setting<Boolean> desktopNotifications = new Setting<>(false); /** * A map of lowercase setting field names to their respective setting diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index a67384ac..baaeed8b 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -26,6 +26,7 @@ import baritone.api.utils.Helper; import baritone.api.utils.PathCalculationResult; import baritone.pathing.movement.CalculationContext; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; +import baritone.utils.NotificationHelper; import java.util.Optional; @@ -216,6 +217,8 @@ public abstract class AbstractNodeCostSearch implements IPathFinder, Helper { if (logInfo) { logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks"); logDebug("No path found =("); + if (Baritone.settings().desktopNotifications.value) + NotificationHelper.notify("No path found =(", true); } return Optional.empty(); } diff --git a/src/main/java/baritone/utils/NotificationHelper.java b/src/main/java/baritone/utils/NotificationHelper.java new file mode 100644 index 00000000..927befb0 --- /dev/null +++ b/src/main/java/baritone/utils/NotificationHelper.java @@ -0,0 +1,72 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone.utils; + +import java.awt.*; +import java.io.IOException; + +public class NotificationHelper { + public static void notify(String text, boolean error) { + if (System.getProperty("os.name").contains("Linux")) + linux(text); + else + notification(text, error); + } + + public static void notification(String text, boolean error) { + if (SystemTray.isSupported()) { + try { + SystemTray tray = SystemTray.getSystemTray(); + Image image = Toolkit.getDefaultToolkit().createImage(""); + // Replace with some logo + + TrayIcon trayIcon = new TrayIcon(image, "Baritone"); + trayIcon.setImageAutoSize(true); + trayIcon.setToolTip("Baritone"); + tray.add(trayIcon); + + if(error) + trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.ERROR); + else + trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.INFO); + } + catch (Exception e) { + e.printStackTrace(); + } + } + else { + System.out.println("SystemTray is not supported"); + } + } + + /* + * The only way to display notifications on linux is to use the java-gnome library, or send notify-send to shell with a ProcessBuilder + * Unfortunately the java-gnome library is licenced under the GPL, see: (https://en.wikipedia.org/wiki/Java-gnome) + */ + + public static void linux(String text) { + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.command("notify-send", "-a", "Baritone", text); + try { + processBuilder.start(); + } catch (IOException e) { + e.printStackTrace(); + } + + } +} From 0dcb9d4b6968584f9cf3c15f1089bfcff055034e Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Sat, 22 Feb 2020 20:12:43 -0500 Subject: [PATCH 051/133] Formatting --- .../pathing/calc/AbstractNodeCostSearch.java | 3 +- .../baritone/utils/NotificationHelper.java | 30 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index baaeed8b..eea23905 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -217,8 +217,9 @@ public abstract class AbstractNodeCostSearch implements IPathFinder, Helper { if (logInfo) { logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks"); logDebug("No path found =("); - if (Baritone.settings().desktopNotifications.value) + if (Baritone.settings().desktopNotifications.value) { NotificationHelper.notify("No path found =(", true); + } } return Optional.empty(); } diff --git a/src/main/java/baritone/utils/NotificationHelper.java b/src/main/java/baritone/utils/NotificationHelper.java index 927befb0..9ab0b545 100644 --- a/src/main/java/baritone/utils/NotificationHelper.java +++ b/src/main/java/baritone/utils/NotificationHelper.java @@ -20,12 +20,20 @@ package baritone.utils; import java.awt.*; import java.io.IOException; +/** + * This class is not called from the main game thread. + * Do not refer to any Minecraft classes, it wouldn't be thread safe. + * + * @author aUniqueUser + */ public class NotificationHelper { + public static void notify(String text, boolean error) { - if (System.getProperty("os.name").contains("Linux")) + if (System.getProperty("os.name").contains("Linux")) { linux(text); - else + } else { notification(text, error); + } } public static void notification(String text, boolean error) { @@ -33,30 +41,29 @@ public class NotificationHelper { try { SystemTray tray = SystemTray.getSystemTray(); Image image = Toolkit.getDefaultToolkit().createImage(""); - // Replace with some logo TrayIcon trayIcon = new TrayIcon(image, "Baritone"); trayIcon.setImageAutoSize(true); trayIcon.setToolTip("Baritone"); tray.add(trayIcon); - if(error) + if (error) { trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.ERROR); - else + } else { trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.INFO); - } - catch (Exception e) { + } + } catch (Exception e) { e.printStackTrace(); } - } - else { + } else { System.out.println("SystemTray is not supported"); } } /* - * The only way to display notifications on linux is to use the java-gnome library, or send notify-send to shell with a ProcessBuilder - * Unfortunately the java-gnome library is licenced under the GPL, see: (https://en.wikipedia.org/wiki/Java-gnome) + * The only way to display notifications on linux is to use the java-gnome library, + * or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome + * library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome) */ public static void linux(String text) { @@ -67,6 +74,5 @@ public class NotificationHelper { } catch (IOException e) { e.printStackTrace(); } - } } From cf691118b90c3b13de13f851cc28ef55cfa11bc3 Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Sat, 22 Feb 2020 20:19:25 -0500 Subject: [PATCH 052/133] comment fixed --- src/main/java/baritone/utils/NotificationHelper.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/utils/NotificationHelper.java b/src/main/java/baritone/utils/NotificationHelper.java index 9ab0b545..76cd5b1c 100644 --- a/src/main/java/baritone/utils/NotificationHelper.java +++ b/src/main/java/baritone/utils/NotificationHelper.java @@ -60,12 +60,9 @@ public class NotificationHelper { } } - /* - * The only way to display notifications on linux is to use the java-gnome library, - * or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome - * library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome) - */ - + // The only way to display notifications on linux is to use the java-gnome library, + // or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome + // library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome) public static void linux(String text) { ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.command("notify-send", "-a", "Baritone", text); From 25b85f17a30bf71133fdcefebc2b693576d528f1 Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Sat, 22 Feb 2020 20:41:06 -0500 Subject: [PATCH 053/133] mfw --- src/main/java/baritone/utils/NotificationHelper.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/utils/NotificationHelper.java b/src/main/java/baritone/utils/NotificationHelper.java index 76cd5b1c..3e7b22ae 100644 --- a/src/main/java/baritone/utils/NotificationHelper.java +++ b/src/main/java/baritone/utils/NotificationHelper.java @@ -60,9 +60,11 @@ public class NotificationHelper { } } - // The only way to display notifications on linux is to use the java-gnome library, - // or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome - // library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome) + /* + * The only way to display notifications on linux is to use the java-gnome library, + * or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome + * library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome) + */ public static void linux(String text) { ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.command("notify-send", "-a", "Baritone", text); From a8645afbdb8c8d376ff3ca510771c84c4d43cd8a Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Sat, 22 Feb 2020 21:09:36 -0500 Subject: [PATCH 054/133] Revert "mfw" This reverts commit 25b85f17a30bf71133fdcefebc2b693576d528f1. --- src/main/java/baritone/utils/NotificationHelper.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/utils/NotificationHelper.java b/src/main/java/baritone/utils/NotificationHelper.java index 3e7b22ae..76cd5b1c 100644 --- a/src/main/java/baritone/utils/NotificationHelper.java +++ b/src/main/java/baritone/utils/NotificationHelper.java @@ -60,11 +60,9 @@ public class NotificationHelper { } } - /* - * The only way to display notifications on linux is to use the java-gnome library, - * or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome - * library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome) - */ + // The only way to display notifications on linux is to use the java-gnome library, + // or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome + // library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome) public static void linux(String text) { ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.command("notify-send", "-a", "Baritone", text); From 042b1ed6d7e706c8f228d13de84519090196a41a Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 22 Feb 2020 18:37:10 -0800 Subject: [PATCH 055/133] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7de14beb..26c70025 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ A Minecraft pathfinder bot. -Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://www.youtube.com/watch?v=yI8hgW_m6dQ) made by @Adovin#3153 on Baritone's integration into Impact. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a video I made showing off what it can do. +Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a video I made showing off what it can do. The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. From b1f5429db98b1c6ab711671627ea0541ac6bd832 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 22 Feb 2020 18:37:29 -0800 Subject: [PATCH 056/133] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 26c70025..c07add8f 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ A Minecraft pathfinder bot. -Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a video I made showing off what it can do. +Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do. The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. From 27440fc1478aa7029e470f90ddda06a2418a5fe1 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 22 Feb 2020 22:42:22 -0800 Subject: [PATCH 057/133] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c07add8f..9bc29c66 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,10 @@ Here are some links to help to get started: - [Usage (chat control)](USAGE.md) +## Stars over time + +[![Stargazers over time](https://starchart.cc/cabaletta/baritone.svg)](https://starchart.cc/cabaletta/baritone) + # API The API is heavily documented, you can find the Javadocs for the latest release [here](https://baritone.leijurv.com/). From c578d5c1a3a01cdc83a60d7ed502ce40bc18eca0 Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Sun, 23 Feb 2020 12:51:14 -0600 Subject: [PATCH 058/133] Fix additional TrayIcon creation and support Mac notifs --- .../baritone/utils/NotificationHelper.java | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/main/java/baritone/utils/NotificationHelper.java b/src/main/java/baritone/utils/NotificationHelper.java index 76cd5b1c..54abbf87 100644 --- a/src/main/java/baritone/utils/NotificationHelper.java +++ b/src/main/java/baritone/utils/NotificationHelper.java @@ -17,6 +17,8 @@ package baritone.utils; +import org.apache.commons.lang3.SystemUtils; + import java.awt.*; import java.io.IOException; @@ -28,30 +30,32 @@ import java.io.IOException; */ public class NotificationHelper { + private static TrayIcon trayIcon; + public static void notify(String text, boolean error) { - if (System.getProperty("os.name").contains("Linux")) { + if (SystemUtils.IS_OS_WINDOWS) { + windows(text, error); + } else if (SystemUtils.IS_OS_MAC_OSX) { + mac(text); + } else if (SystemUtils.IS_OS_LINUX) { linux(text); - } else { - notification(text, error); } } - public static void notification(String text, boolean error) { + private static void windows(String text, boolean error) { if (SystemTray.isSupported()) { try { - SystemTray tray = SystemTray.getSystemTray(); - Image image = Toolkit.getDefaultToolkit().createImage(""); + if (trayIcon == null) { + SystemTray tray = SystemTray.getSystemTray(); + Image image = Toolkit.getDefaultToolkit().createImage(""); - TrayIcon trayIcon = new TrayIcon(image, "Baritone"); - trayIcon.setImageAutoSize(true); - trayIcon.setToolTip("Baritone"); - tray.add(trayIcon); - - if (error) { - trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.ERROR); - } else { - trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.INFO); + trayIcon = new TrayIcon(image, "Baritone"); + trayIcon.setImageAutoSize(true); + trayIcon.setToolTip("Baritone"); + tray.add(trayIcon); } + + trayIcon.displayMessage("Baritone", text, error ? TrayIcon.MessageType.ERROR : TrayIcon.MessageType.INFO); } catch (Exception e) { e.printStackTrace(); } @@ -60,10 +64,20 @@ public class NotificationHelper { } } + private static void mac(String text) { + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.command("osascript", "-e", "display notification \"" + text + "\" with title \"Baritone\""); + try { + processBuilder.start(); + } catch (IOException e) { + e.printStackTrace(); + } + } + // The only way to display notifications on linux is to use the java-gnome library, // or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome // library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome) - public static void linux(String text) { + private static void linux(String text) { ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.command("notify-send", "-a", "Baritone", text); try { From 07c406aa1615cf08e0e0e74cba284c4e47a3e2d7 Mon Sep 17 00:00:00 2001 From: Babbaj <babbaj45@gmail.com> Date: Sun, 23 Feb 2020 21:48:15 -0500 Subject: [PATCH 059/133] baritoe --- src/api/java/baritone/api/utils/Helper.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/utils/Helper.java b/src/api/java/baritone/api/utils/Helper.java index 994d8c7b..2f821a39 100755 --- a/src/api/java/baritone/api/utils/Helper.java +++ b/src/api/java/baritone/api/utils/Helper.java @@ -24,6 +24,7 @@ import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; import java.util.Arrays; +import java.util.Calendar; import java.util.stream.Stream; /** @@ -47,7 +48,9 @@ public interface Helper { static ITextComponent getPrefix() { // Inner text component - ITextComponent baritone = new TextComponentString(BaritoneAPI.getSettings().shortBaritonePrefix.value ? "B" : "Baritone"); + final Calendar now = Calendar.getInstance(); + final boolean xd = now.get(Calendar.MONTH) == Calendar.APRIL && now.get(Calendar.DAY_OF_MONTH) == 1; + ITextComponent baritone = new TextComponentString(BaritoneAPI.getSettings().shortBaritonePrefix.value ? "B" : (xd ? "Baritoe" : "Baritone")); baritone.getStyle().setColor(TextFormatting.LIGHT_PURPLE); // Outer brackets From ee33666b38eb2207f1f739dc30a9307603740643 Mon Sep 17 00:00:00 2001 From: Babbaj <babbaj45@gmail.com> Date: Sun, 23 Feb 2020 21:54:18 -0500 Subject: [PATCH 060/133] 3 days --- src/api/java/baritone/api/utils/Helper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/utils/Helper.java b/src/api/java/baritone/api/utils/Helper.java index 2f821a39..7e85725f 100755 --- a/src/api/java/baritone/api/utils/Helper.java +++ b/src/api/java/baritone/api/utils/Helper.java @@ -49,7 +49,7 @@ public interface Helper { static ITextComponent getPrefix() { // Inner text component final Calendar now = Calendar.getInstance(); - final boolean xd = now.get(Calendar.MONTH) == Calendar.APRIL && now.get(Calendar.DAY_OF_MONTH) == 1; + final boolean xd = now.get(Calendar.MONTH) == Calendar.APRIL && now.get(Calendar.DAY_OF_MONTH) <= 3; ITextComponent baritone = new TextComponentString(BaritoneAPI.getSettings().shortBaritonePrefix.value ? "B" : (xd ? "Baritoe" : "Baritone")); baritone.getStyle().setColor(TextFormatting.LIGHT_PURPLE); From 888b2723e0f2bd887f9496e06abd3ecb38295a3a Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Sun, 23 Feb 2020 21:13:51 -0600 Subject: [PATCH 061/133] Fix critical prefix tag bug --- src/api/java/baritone/api/utils/Helper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/utils/Helper.java b/src/api/java/baritone/api/utils/Helper.java index 7e85725f..3cda1834 100755 --- a/src/api/java/baritone/api/utils/Helper.java +++ b/src/api/java/baritone/api/utils/Helper.java @@ -50,7 +50,7 @@ public interface Helper { // Inner text component final Calendar now = Calendar.getInstance(); final boolean xd = now.get(Calendar.MONTH) == Calendar.APRIL && now.get(Calendar.DAY_OF_MONTH) <= 3; - ITextComponent baritone = new TextComponentString(BaritoneAPI.getSettings().shortBaritonePrefix.value ? "B" : (xd ? "Baritoe" : "Baritone")); + ITextComponent baritone = new TextComponentString(xd ? "Baritoe" : BaritoneAPI.getSettings().shortBaritonePrefix.value ? "B" : "Baritone"); baritone.getStyle().setColor(TextFormatting.LIGHT_PURPLE); // Outer brackets From 393a3a87b6ee6fa282446fe5b0ae7ae055939215 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Mon, 24 Feb 2020 12:20:13 -0800 Subject: [PATCH 062/133] Update USAGE.md --- USAGE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/USAGE.md b/USAGE.md index 0f911efa..5a63c05e 100644 --- a/USAGE.md +++ b/USAGE.md @@ -20,6 +20,8 @@ Try `#help` I promise it won't just send you back here =) just look at `#help` lmao +Watch this [showcase video](https://youtu.be/CZkLXWo4Fg4)! + # Commands **All** of these commands may need a prefix before them, as above ^. From e854bf59f83b92bc548a18efb12cf072c415abb5 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Mon, 24 Feb 2020 18:31:42 -0800 Subject: [PATCH 063/133] fix sneaking based issues --- .../baritone/api/utils/IPlayerContext.java | 4 +++ .../baritone/api/utils/RayTraceUtils.java | 15 +++++++- .../baritone/api/utils/RotationUtils.java | 34 ++++++++++++++----- .../baritone/pathing/movement/Movement.java | 2 +- .../pathing/movement/MovementHelper.java | 12 +++++-- .../movement/movements/MovementAscend.java | 2 +- .../movement/movements/MovementDescend.java | 2 +- .../movement/movements/MovementParkour.java | 2 +- .../movement/movements/MovementPillar.java | 2 +- .../movement/movements/MovementTraverse.java | 2 +- .../baritone/process/BackfillProcess.java | 2 +- .../java/baritone/process/FarmProcess.java | 2 +- 12 files changed, 61 insertions(+), 20 deletions(-) diff --git a/src/api/java/baritone/api/utils/IPlayerContext.java b/src/api/java/baritone/api/utils/IPlayerContext.java index b461c389..8ce3271b 100644 --- a/src/api/java/baritone/api/utils/IPlayerContext.java +++ b/src/api/java/baritone/api/utils/IPlayerContext.java @@ -77,6 +77,10 @@ public interface IPlayerContext { return new Rotation(player().rotationYaw, player().rotationPitch); } + static double eyeHeight(boolean ifSneaking) { + return ifSneaking ? 1.54 : 1.62; + } + /** * Returns the block that the crosshair is currently placed over. Updated once per tick. * diff --git a/src/api/java/baritone/api/utils/RayTraceUtils.java b/src/api/java/baritone/api/utils/RayTraceUtils.java index 0fd1e4e0..4f763e39 100644 --- a/src/api/java/baritone/api/utils/RayTraceUtils.java +++ b/src/api/java/baritone/api/utils/RayTraceUtils.java @@ -40,7 +40,16 @@ public final class RayTraceUtils { * @return The calculated raytrace result */ public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance) { - Vec3d start = entity.getPositionEyes(1.0F); + return rayTraceTowards(entity, rotation, blockReachDistance, false); + } + + public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance, boolean wouldSneak) { + Vec3d start; + if (wouldSneak) { + start = inferSneakingEyePosition(entity); + } else { + start = entity.getPositionEyes(1.0F); // do whatever is correct + } Vec3d direction = RotationUtils.calcVec3dFromRotation(rotation); Vec3d end = start.add( direction.x * blockReachDistance, @@ -49,4 +58,8 @@ public final class RayTraceUtils { ); return entity.world.rayTraceBlocks(start, end, false, false, true); } + + public static Vec3d inferSneakingEyePosition(Entity entity) { + return new Vec3d(entity.posX, entity.posY + IPlayerContext.eyeHeight(true), entity.posZ); + } } diff --git a/src/api/java/baritone/api/utils/RotationUtils.java b/src/api/java/baritone/api/utils/RotationUtils.java index e19f531d..39e68fd4 100644 --- a/src/api/java/baritone/api/utils/RotationUtils.java +++ b/src/api/java/baritone/api/utils/RotationUtils.java @@ -140,6 +140,10 @@ public final class RotationUtils { return reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); } + public static Optional<Rotation> reachable(IPlayerContext ctx, BlockPos pos, boolean wouldSneak) { + return reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance(), wouldSneak); + } + /** * Determines if the specified entity is able to reach the center of any of the sides * of the specified block. It first checks if the block center is reachable, and if so, @@ -153,6 +157,10 @@ public final class RotationUtils { * @return The optional rotation */ public static Optional<Rotation> reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) { + return reachable(entity, pos, blockReachDistance, false); + } + + public static Optional<Rotation> reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) { IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity); if (baritone.getPlayerContext().isLookingAt(pos)) { /* @@ -165,9 +173,18 @@ public final class RotationUtils { * * or if you're a normal person literally all this does it ensure that we don't nudge the pitch to a normal level */ - return Optional.of(new Rotation(entity.rotationYaw, entity.rotationPitch + 0.0001F)); + Rotation hypothetical = new Rotation(entity.rotationYaw, entity.rotationPitch + 0.0001F); + if (wouldSneak) { + // the concern here is: what if we're looking at it now, but as soon as we start sneaking we no longer are + RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, hypothetical, blockReachDistance, true); + if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK && result.getBlockPos().equals(pos)) { + return Optional.of(hypothetical); // yes, if we sneaked we would still be looking at the block + } + } else { + return Optional.of(hypothetical); + } } - Optional<Rotation> possibleRotation = reachableCenter(entity, pos, blockReachDistance); + Optional<Rotation> possibleRotation = reachableCenter(entity, pos, blockReachDistance, wouldSneak); //System.out.println("center: " + possibleRotation); if (possibleRotation.isPresent()) { return possibleRotation; @@ -179,7 +196,7 @@ public final class RotationUtils { double xDiff = aabb.minX * sideOffset.x + aabb.maxX * (1 - sideOffset.x); double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y); double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z); - possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance); + possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance, wouldSneak); if (possibleRotation.isPresent()) { return possibleRotation; } @@ -198,9 +215,10 @@ public final class RotationUtils { * @param blockReachDistance The block reach distance of the entity * @return The optional rotation */ - public static Optional<Rotation> reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance) { - Rotation rotation = calcRotationFromVec3d(entity.getPositionEyes(1.0F), offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch)); - RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance); + public static Optional<Rotation> reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance, boolean wouldSneak) { + Vec3d eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(entity) : entity.getPositionEyes(1.0F); + Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch)); + RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance, wouldSneak); //System.out.println(result); if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { if (result.getBlockPos().equals(pos)) { @@ -222,7 +240,7 @@ public final class RotationUtils { * @param blockReachDistance The block reach distance of the entity * @return The optional rotation */ - public static Optional<Rotation> reachableCenter(Entity entity, BlockPos pos, double blockReachDistance) { - return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(entity.world, pos), blockReachDistance); + public static Optional<Rotation> reachableCenter(Entity entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) { + return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(entity.world, pos), blockReachDistance, wouldSneak); } } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index ca4abe9e..c46b24de 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -177,7 +177,7 @@ public abstract class Movement implements IMovement, MovementHelper { //i'm doing it anyway //i dont care if theres snow in the way!!!!!!! //you dont own me!!!! - state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.player().getPositionEyes(1.0F), + state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(blockPos), ctx.playerRotations()), true) ); // don't check selectedblock on this one, this is a fallback when we can't see any face directly, it's intended to be breaking the "incorrect" block diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 31a1de7a..7e1c567a 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -502,9 +502,9 @@ public interface MovementHelper extends ActionCosts, Helper { } - static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown) { + static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown, boolean wouldSneak) { IPlayerContext ctx = baritone.getPlayerContext(); - Optional<Rotation> direct = RotationUtils.reachable(ctx, placeAt); // we assume that if there is a block there, it must be replacable + Optional<Rotation> direct = RotationUtils.reachable(ctx, placeAt, wouldSneak); // we assume that if there is a block there, it must be replacable boolean found = false; if (direct.isPresent()) { state.setTarget(new MovementState.MovementTarget(direct.get(), true)); @@ -522,7 +522,7 @@ public interface MovementHelper extends ActionCosts, Helper { double faceY = (placeAt.getY() + against1.getY() + 0.5D) * 0.5D; double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D; Rotation place = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()); - RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance()); + RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance(), wouldSneak); if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(placeAt)) { state.setTarget(new MovementState.MovementTarget(place, true)); found = true; @@ -540,11 +540,17 @@ public interface MovementHelper extends ActionCosts, Helper { EnumFacing side = ctx.objectMouseOver().sideHit; // only way for selectedBlock.equals(placeAt) to be true is if it's replacable if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(placeAt))) { + if (wouldSneak) { + state.setInput(Input.SNEAK, true); + } ((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ()); return PlaceResult.READY_TO_PLACE; } } if (found) { + if (wouldSneak) { + state.setInput(Input.SNEAK, true); + } ((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ()); return PlaceResult.ATTEMPTING; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 4f35ef8e..161ffdac 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -175,7 +175,7 @@ public class MovementAscend extends Movement { IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace); if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) { ticksWithoutPlacement++; - if (MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false) == PlaceResult.READY_TO_PLACE) { + if (MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false, true) == PlaceResult.READY_TO_PLACE) { state.setInput(Input.SNEAK, true); if (ctx.player().isSneaking()) { state.setInput(Input.CLICK_RIGHT, true); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 67b7cd95..128d1bf9 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -224,7 +224,7 @@ public class MovementDescend extends Movement { double destZ = (src.getZ() + 0.5) * 0.17 + (dest.getZ() + 0.5) * 0.83; EntityPlayerSP player = ctx.player(); state.setTarget(new MovementState.MovementTarget( - new Rotation(RotationUtils.calcRotationFromVec3d(player.getPositionEyes(1.0F), + new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(destX, dest.getY(), destZ), new Rotation(player.rotationYaw, player.rotationPitch)).getYaw(), player.rotationPitch), false diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 3d3426da..b9a0fd44 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -250,7 +250,7 @@ public class MovementParkour extends Movement { } } else if (!ctx.playerFeet().equals(src)) { if (ctx.playerFeet().equals(src.offset(direction)) || ctx.player().posY - src.y > 0.0001) { - if (!MovementHelper.canWalkOn(ctx, dest.down()) && !ctx.player().onGround && MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), true) == PlaceResult.READY_TO_PLACE) { + if (!MovementHelper.canWalkOn(ctx, dest.down()) && !ctx.player().onGround && MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), true, false) == PlaceResult.READY_TO_PLACE) { // go in the opposite order to check DOWN before all horizontals -- down is preferable because you don't have to look to the side while in midair, which could mess up the trajectory state.setInput(Input.CLICK_RIGHT, true); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index f6f8fc0d..b9d59933 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -184,7 +184,7 @@ public class MovementPillar extends Movement { } boolean ladder = fromDown.getBlock() == Blocks.LADDER || fromDown.getBlock() == Blocks.VINE; boolean vine = fromDown.getBlock() == Blocks.VINE; - Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.player().getPositionEyes(1.0F), + Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(positionToPlace), new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch)); if (!ladder) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 9990ed74..1ecf0f92 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -280,7 +280,7 @@ public class MovementTraverse extends Movement { } } double dist1 = Math.max(Math.abs(ctx.player().posX - (dest.getX() + 0.5D)), Math.abs(ctx.player().posZ - (dest.getZ() + 0.5D))); - PlaceResult p = MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false); + PlaceResult p = MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false, true); if ((p == PlaceResult.READY_TO_PLACE || dist1 < 0.6) && !Baritone.settings().assumeSafeWalk.value) { state.setInput(Input.SNEAK, true); } diff --git a/src/main/java/baritone/process/BackfillProcess.java b/src/main/java/baritone/process/BackfillProcess.java index f025c393..04b3ca78 100644 --- a/src/main/java/baritone/process/BackfillProcess.java +++ b/src/main/java/baritone/process/BackfillProcess.java @@ -75,7 +75,7 @@ public final class BackfillProcess extends BaritoneProcessHelper { baritone.getInputOverrideHandler().clearAllKeys(); for (BlockPos toPlace : toFillIn()) { MovementState fake = new MovementState(); - switch (MovementHelper.attemptToPlaceABlock(fake, baritone, toPlace, false)) { + switch (MovementHelper.attemptToPlaceABlock(fake, baritone, toPlace, false, false)) { case NO_OPTION: continue; case READY_TO_PLACE: diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index 00273a9f..a91fda60 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -232,7 +232,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro both.addAll(openSoulsand); for (BlockPos pos : both) { boolean soulsand = openSoulsand.contains(pos); - Optional<Rotation> rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance()); + Optional<Rotation> rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false); if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) { RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance()); if (result.typeOfHit == RayTraceResult.Type.BLOCK && result.sideHit == EnumFacing.UP) { From 61563c93594186976070611dce19b832be99791a Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Mon, 24 Feb 2020 19:27:11 -0800 Subject: [PATCH 064/133] builderprocess should use hypothetical sneaking --- src/main/java/baritone/process/BuilderProcess.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 4efa2c95..5af43492 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -278,8 +278,8 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil double placeX = placeAgainstPos.x + aabb.minX * placementMultiplier.x + aabb.maxX * (1 - placementMultiplier.x); double placeY = placeAgainstPos.y + aabb.minY * placementMultiplier.y + aabb.maxY * (1 - placementMultiplier.y); double placeZ = placeAgainstPos.z + aabb.minZ * placementMultiplier.z + aabb.maxZ * (1 - placementMultiplier.z); - Rotation rot = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(placeX, placeY, placeZ), ctx.playerRotations()); - RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot, ctx.playerController().getBlockReachDistance()); + Rotation rot = RotationUtils.calcRotationFromVec3d(RayTraceUtils.inferSneakingEyePosition(ctx.player()), new Vec3d(placeX, placeY, placeZ), ctx.playerRotations()); + RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot, ctx.playerController().getBlockReachDistance(), true); if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK && result.getBlockPos().equals(placeAgainstPos) && result.sideHit == against.getOpposite()) { OptionalInt hotbar = hasAnyItemThatWouldPlace(toPlace, result, rot); if (hotbar.isPresent()) { From 4b526f724281d970ebb297b8e1c4cba5ad625f80 Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Tue, 25 Feb 2020 21:13:20 -0500 Subject: [PATCH 065/133] Custom Tunneling --- .../command/defaults/TunnelCommand.java | 64 +++++++++++++++---- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/src/main/java/baritone/command/defaults/TunnelCommand.java b/src/main/java/baritone/command/defaults/TunnelCommand.java index 991a7ff8..3a24ca3a 100644 --- a/src/main/java/baritone/command/defaults/TunnelCommand.java +++ b/src/main/java/baritone/command/defaults/TunnelCommand.java @@ -18,11 +18,13 @@ package baritone.command.defaults; import baritone.api.IBaritone; +import baritone.api.command.Command; +import baritone.api.command.argument.IArgConsumer; +import baritone.api.command.exception.CommandException; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalStrictDirection; -import baritone.api.command.Command; -import baritone.api.command.exception.CommandException; -import baritone.api.command.argument.IArgConsumer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; import java.util.Arrays; import java.util.List; @@ -36,13 +38,50 @@ public class TunnelCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { - args.requireMax(0); - Goal goal = new GoalStrictDirection( - ctx.playerFeet(), - ctx.player().getHorizontalFacing() - ); - baritone.getCustomGoalProcess().setGoalAndPath(goal); - logDirect(String.format("Goal: %s", goal.toString())); + args.requireMax(3); + if (args.hasExactly(3)) { + boolean cont = true; + int depth = Integer.parseInt(args.peekString(0))-1; + int height = Integer.parseInt(args.peekString(1))-1; + int width = Integer.parseInt(args.peekString(2))-1; + + if (width < 1 || height < 2) { + logDirect("Width must at least be 1 block, Height must at least be 2 blocks"); + cont = false; + } + + if (cont) { + BlockPos corner1 = null, corner2 = null; + EnumFacing enumfacing = ctx.player().getHorizontalFacing(); + int addition = ((width % 2 == 0) ? 0 : 1); + switch (enumfacing) { + case EAST: + corner1 = new BlockPos(ctx.playerFeet().x, ctx.playerFeet().y, ctx.playerFeet().z - width / 2); + corner2 = new BlockPos(ctx.playerFeet().x + depth, ctx.playerFeet().y + height, ctx.playerFeet().z + width / 2 + addition); + break; + case WEST: + corner1 = new BlockPos(ctx.playerFeet().x, ctx.playerFeet().y, ctx.playerFeet().z + width / 2 + addition); + corner2 = new BlockPos(ctx.playerFeet().x - depth, ctx.playerFeet().y + height, ctx.playerFeet().z - width / 2); + break; + case NORTH: + corner1 = new BlockPos(ctx.playerFeet().x - width / 2, ctx.playerFeet().y, ctx.playerFeet().z); + corner2 = new BlockPos(ctx.playerFeet().x + width / 2 + addition, ctx.playerFeet().y + height, ctx.playerFeet().z - depth); + break; + case SOUTH: + corner1 = new BlockPos(ctx.playerFeet().x + width / 2 + addition, ctx.playerFeet().y, ctx.playerFeet().z); + corner2 = new BlockPos(ctx.playerFeet().x - width / 2, ctx.playerFeet().y + height, ctx.playerFeet().z + depth); + break; + } + baritone.getBuilderProcess().clearArea(corner1, corner2); + } + } else { + Goal goal = new GoalStrictDirection( + ctx.playerFeet(), + ctx.player().getHorizontalFacing() + ); + baritone.getCustomGoalProcess().setGoalAndPath(goal); + logDirect(String.format("Goal: %s", goal.toString())); + } } @Override @@ -61,7 +100,8 @@ public class TunnelCommand extends Command { "The tunnel command sets a goal that tells Baritone to mine completely straight in the direction that you're facing.", "", "Usage:", - "> tunnel" + "> tunnel - No arguments, mines in a 1x2 radius.", + "> tunnel depth/height/width - Tunnels in a user defined depth, height and width." ); } -} +} \ No newline at end of file From 3c2838df9eb584dc75acbb0af42bd0dbb3512590 Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Tue, 25 Feb 2020 21:22:35 -0500 Subject: [PATCH 066/133] lol --- src/main/java/baritone/command/defaults/TunnelCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/TunnelCommand.java b/src/main/java/baritone/command/defaults/TunnelCommand.java index 3a24ca3a..2831675b 100644 --- a/src/main/java/baritone/command/defaults/TunnelCommand.java +++ b/src/main/java/baritone/command/defaults/TunnelCommand.java @@ -41,7 +41,7 @@ public class TunnelCommand extends Command { args.requireMax(3); if (args.hasExactly(3)) { boolean cont = true; - int depth = Integer.parseInt(args.peekString(0))-1; + int depth = Integer.parseInt(args.peekString(0)); int height = Integer.parseInt(args.peekString(1))-1; int width = Integer.parseInt(args.peekString(2))-1; From acd9bcceeba16fac47f19a2bcf47a074fd246a46 Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Tue, 25 Feb 2020 21:47:35 -0500 Subject: [PATCH 067/133] Codacy --- src/main/java/baritone/command/defaults/TunnelCommand.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/TunnelCommand.java b/src/main/java/baritone/command/defaults/TunnelCommand.java index 2831675b..3972a325 100644 --- a/src/main/java/baritone/command/defaults/TunnelCommand.java +++ b/src/main/java/baritone/command/defaults/TunnelCommand.java @@ -51,7 +51,8 @@ public class TunnelCommand extends Command { } if (cont) { - BlockPos corner1 = null, corner2 = null; + BlockPos corner1; + BlockPos corner2; EnumFacing enumfacing = ctx.player().getHorizontalFacing(); int addition = ((width % 2 == 0) ? 0 : 1); switch (enumfacing) { @@ -71,6 +72,8 @@ public class TunnelCommand extends Command { corner1 = new BlockPos(ctx.playerFeet().x + width / 2 + addition, ctx.playerFeet().y, ctx.playerFeet().z); corner2 = new BlockPos(ctx.playerFeet().x - width / 2, ctx.playerFeet().y + height, ctx.playerFeet().z + depth); break; + default: + throw new IllegalStateException("Unexpected value: " + enumfacing); } baritone.getBuilderProcess().clearArea(corner1, corner2); } From 6f136a90a28db9527fbbec7cd5db90194d9d6df9 Mon Sep 17 00:00:00 2001 From: CDAGaming <cstack2011@yahoo.com> Date: Wed, 26 Feb 2020 07:55:21 -0600 Subject: [PATCH 068/133] [Change] Adjustments --- .../command/defaults/TunnelCommand.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/baritone/command/defaults/TunnelCommand.java b/src/main/java/baritone/command/defaults/TunnelCommand.java index 3972a325..6121679a 100644 --- a/src/main/java/baritone/command/defaults/TunnelCommand.java +++ b/src/main/java/baritone/command/defaults/TunnelCommand.java @@ -41,21 +41,21 @@ public class TunnelCommand extends Command { args.requireMax(3); if (args.hasExactly(3)) { boolean cont = true; - int depth = Integer.parseInt(args.peekString(0)); - int height = Integer.parseInt(args.peekString(1))-1; - int width = Integer.parseInt(args.peekString(2))-1; + int depth = Integer.parseInt(args.getArgs().get(0).getValue()); + int height = Integer.parseInt(args.getArgs().get(1).getValue()); + int width = Integer.parseInt(args.getArgs().get(2).getValue()); - if (width < 1 || height < 2) { - logDirect("Width must at least be 1 block, Height must at least be 2 blocks"); + if (width < 1 || height < 2 || depth < 1) { + logDirect("Width and depth must at least be 1 block; Height must at least be 2 blocks"); cont = false; } if (cont) { BlockPos corner1; BlockPos corner2; - EnumFacing enumfacing = ctx.player().getHorizontalFacing(); + EnumFacing enumFacing = ctx.player().getHorizontalFacing(); int addition = ((width % 2 == 0) ? 0 : 1); - switch (enumfacing) { + switch (enumFacing) { case EAST: corner1 = new BlockPos(ctx.playerFeet().x, ctx.playerFeet().y, ctx.playerFeet().z - width / 2); corner2 = new BlockPos(ctx.playerFeet().x + depth, ctx.playerFeet().y + height, ctx.playerFeet().z + width / 2 + addition); @@ -73,8 +73,9 @@ public class TunnelCommand extends Command { corner2 = new BlockPos(ctx.playerFeet().x - width / 2, ctx.playerFeet().y + height, ctx.playerFeet().z + depth); break; default: - throw new IllegalStateException("Unexpected value: " + enumfacing); + throw new IllegalStateException("Unexpected value: " + enumFacing); } + logDirect(String.format("Creating a tunnel %s block(s) deep, %s block(s) wide, and %s block(s) high", depth, width, height)); baritone.getBuilderProcess().clearArea(corner1, corner2); } } else { @@ -107,4 +108,4 @@ public class TunnelCommand extends Command { "> tunnel depth/height/width - Tunnels in a user defined depth, height and width." ); } -} \ No newline at end of file +} From e3b91c884a8e3664a72a4c5c36518d6e6b099b09 Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Wed, 26 Feb 2020 12:30:07 -0500 Subject: [PATCH 069/133] More logical argument order --- .../baritone/command/defaults/TunnelCommand.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/command/defaults/TunnelCommand.java b/src/main/java/baritone/command/defaults/TunnelCommand.java index 6121679a..e404f23b 100644 --- a/src/main/java/baritone/command/defaults/TunnelCommand.java +++ b/src/main/java/baritone/command/defaults/TunnelCommand.java @@ -41,16 +41,18 @@ public class TunnelCommand extends Command { args.requireMax(3); if (args.hasExactly(3)) { boolean cont = true; - int depth = Integer.parseInt(args.getArgs().get(0).getValue()); - int height = Integer.parseInt(args.getArgs().get(1).getValue()); - int width = Integer.parseInt(args.getArgs().get(2).getValue()); + int height = Integer.parseInt(args.getArgs().get(0).getValue()); + int width = Integer.parseInt(args.getArgs().get(1).getValue()); + int depth = Integer.parseInt(args.getArgs().get(2).getValue()); - if (width < 1 || height < 2 || depth < 1) { - logDirect("Width and depth must at least be 1 block; Height must at least be 2 blocks"); + if (width < 1 || height < 2 || depth < 1 || height > 255) { + logDirect("Width and depth must at least be 1 block; Height must at least be 2 blocks, and cannot be greater than the build limit."); cont = false; } if (cont) { + height--; + width--; BlockPos corner1; BlockPos corner2; EnumFacing enumFacing = ctx.player().getHorizontalFacing(); @@ -75,7 +77,7 @@ public class TunnelCommand extends Command { default: throw new IllegalStateException("Unexpected value: " + enumFacing); } - logDirect(String.format("Creating a tunnel %s block(s) deep, %s block(s) wide, and %s block(s) high", depth, width, height)); + logDirect(String.format("Creating a tunnel %s block(s) high, %s block(s) wide, and %s block(s) deep", height+1, width+1, depth)); baritone.getBuilderProcess().clearArea(corner1, corner2); } } else { From 628ec0f2b570248a372d7240e5e4198e0354225a Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Wed, 26 Feb 2020 13:04:10 -0500 Subject: [PATCH 070/133] updated longDesc --- src/main/java/baritone/command/defaults/TunnelCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/TunnelCommand.java b/src/main/java/baritone/command/defaults/TunnelCommand.java index e404f23b..d346e9df 100644 --- a/src/main/java/baritone/command/defaults/TunnelCommand.java +++ b/src/main/java/baritone/command/defaults/TunnelCommand.java @@ -107,7 +107,7 @@ public class TunnelCommand extends Command { "", "Usage:", "> tunnel - No arguments, mines in a 1x2 radius.", - "> tunnel depth/height/width - Tunnels in a user defined depth, height and width." + "> tunnel height/width/depth - Tunnels in a user defined height, width and depth." ); } } From f1f4adf8a6c04f262458813c872af33365d74500 Mon Sep 17 00:00:00 2001 From: Bella Who <bella.who.two@gmail.com> Date: Thu, 27 Feb 2020 17:42:12 -0500 Subject: [PATCH 071/133] Update USAGE.md as per #1332 --- USAGE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USAGE.md b/USAGE.md index d1592acd..ce761b8e 100644 --- a/USAGE.md +++ b/USAGE.md @@ -44,7 +44,7 @@ Some common examples: - `save waypointName` to save a waypoint. `goto waypointName` to go to it. - `build` to build a schematic. `build blah` will load `schematics/blah.schematic` and build it with the origin being your player feet. `build blah x y z` to set the origin. Any of those can be relative to your player (`~ 69 ~-420` would build at x=player x, y=69, z=player z-420). - `schematica` to build the schematic that is currently open in schematica -- `tunnel` to dig just straight ahead and make a tunnel +- `tunnel height/width/depth` to dig and make a tunnel. If you don't supply numbers then it just digs a 1x2 tunnel. - `farm` to automatically harvest, replant, or bone meal crops - `axis` to go to an axis or diagonal axis at y=120 (`axisHeight` is a configurable setting, defaults to 120). - `explore x z` to explore the world from the origin of x,z. Leave out x and z to default to player feet. This will continually path towards the closest chunk to the origin that it's never seen before. `explorefilter filter.json` with optional invert can be used to load in a list of chunks to load. From 220fa79057e0458bad7665ef5a9596010610a6ea Mon Sep 17 00:00:00 2001 From: fw4hre0xxq <60912178+fw4hre0xxq@users.noreply.github.com> Date: Thu, 27 Feb 2020 17:14:12 -0800 Subject: [PATCH 072/133] fix #1339 --- src/main/java/baritone/pathing/movement/MovementHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 7e1c567a..d6f0b9a2 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -302,7 +302,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) { return true; } - if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST) { + if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST ) { return true; } if (isWater(block)) { From 9fb46946b57c110df8aacb37fad70e27fc886b05 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Thu, 27 Feb 2020 18:05:05 -0800 Subject: [PATCH 073/133] fix sprint while paused bug, fixes #1331 --- src/launch/java/baritone/launch/mixins/MixinMinecraft.java | 2 +- src/main/java/baritone/behavior/PathingBehavior.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java index 3de4a0f5..51e9959f 100644 --- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -145,7 +145,7 @@ public class MixinMinecraft { ) private boolean isAllowUserInput(GuiScreen screen) { // allow user input is only the primary baritone - return (BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().getCurrent() != null && player != null) || screen.allowUserInput; + return (BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing() && player != null) || screen.allowUserInput; } @Inject( diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 86fd9505..50ca7425 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -103,7 +103,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, @Override public void onPlayerSprintState(SprintStateEvent event) { - if (current != null) { + if (isPathing()) { event.setState(current.isSprinting()); } } From 17c691b1cfa4f05e97906ff7abf64c7d1e06b692 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Thu, 27 Feb 2020 18:06:11 -0800 Subject: [PATCH 074/133] the whole point is its better to do something nonsensical than to crash, so lets continue in that direction --- .../baritone/utils/BlockStateInterfaceAccessWrapper.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java b/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java index 6ce70193..6dded1dd 100644 --- a/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java +++ b/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java @@ -19,6 +19,7 @@ package baritone.utils; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Biomes; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -44,12 +45,12 @@ public final class BlockStateInterfaceAccessWrapper implements IBlockAccess { @Nullable @Override public TileEntity getTileEntity(BlockPos pos) { - throw new UnsupportedOperationException("getTileEntity not supported by BlockStateInterfaceAccessWrapper"); + return null; } @Override public int getCombinedLight(BlockPos pos, int lightValue) { - throw new UnsupportedOperationException("getCombinedLight not supported by BlockStateInterfaceAccessWrapper"); + return 0; } @Override @@ -65,12 +66,12 @@ public final class BlockStateInterfaceAccessWrapper implements IBlockAccess { @Override public Biome getBiome(BlockPos pos) { - throw new UnsupportedOperationException("getBiome not supported by BlockStateInterfaceAccessWrapper"); + return Biomes.FOREST; } @Override public int getStrongPower(BlockPos pos, EnumFacing direction) { - throw new UnsupportedOperationException("getStrongPower not supported by BlockStateInterfaceAccessWrapper"); + return 0; } @Override From 5f49bedc426dde9ea19708a768dbc3616d7ba029 Mon Sep 17 00:00:00 2001 From: Bella <bella.who.two@gmail.com> Date: Fri, 28 Feb 2020 17:26:59 -0500 Subject: [PATCH 075/133] Change 1.14 to 1.15 in SETUP.md --- SETUP.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SETUP.md b/SETUP.md index 7efab34f..ae9e82c4 100644 --- a/SETUP.md +++ b/SETUP.md @@ -2,7 +2,9 @@ The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. -For 1.14.4, [click here](https://www.dropbox.com/s/rkml3hjokd3qv0m/1.14.4-Baritone.zip?dl=1). +1.14.4 and lower is located on the [releases](https://github.com/cabaletta/baritone/releases/) page, if you don't want to use Impact. + +For 1.15.2, [click here](https://www.dropbox.com/s/8rx6f0kts9hvd4f/1.15.2-Baritone.zip?dl=1). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. From 4c79701d22633d9626eb9185ddbb904803099b5a Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Sat, 29 Feb 2020 11:28:18 -0500 Subject: [PATCH 076/133] Make desktop notifications more useful --- src/api/java/baritone/api/Settings.java | 27 ++++++++++++++++++- .../java/baritone/process/BuilderProcess.java | 4 +++ .../baritone/process/CustomGoalProcess.java | 4 +++ .../java/baritone/process/ExploreProcess.java | 7 +++++ .../java/baritone/process/FarmProcess.java | 4 +++ .../java/baritone/process/MineProcess.java | 4 +++ 6 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 1bbde3b2..5fd6b64c 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -1047,10 +1047,35 @@ public final class Settings { public final Setting<Boolean> renderSelectionCorners = new Setting<>(true); /** - * Desktop Notifications + * Desktop notifications */ public final Setting<Boolean> desktopNotifications = new Setting<>(false); + /** + * Desktop notification on path complete + */ + public final Setting<Boolean> notificationOnPathComplete = new Setting<>(true); + + /** + * Desktop notification on farm fail + */ + public final Setting<Boolean> notificationOnFarmFail = new Setting<>(true); + + /** + * Desktop notification on build finished + */ + public final Setting<Boolean> notificationOnBuildFinished = new Setting<>(true); + + /** + * Desktop notification on explore finished + */ + public final Setting<Boolean> notificationOnExploreFinished = new Setting<>(true); + + /** + * Desktop notification on mine fail + */ + public final Setting<Boolean> notificationOnMineFail = new Setting<>(true); + /** * A map of lowercase setting field names to their respective setting */ diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 5af43492..4d57a347 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -39,6 +39,7 @@ import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; +import baritone.utils.NotificationHelper; import baritone.utils.PathingCommandContext; import baritone.utils.schematic.MapArtSchematic; import baritone.utils.schematic.SchematicSystem; @@ -406,6 +407,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil numRepeats++; if (repeat.equals(new Vec3i(0, 0, 0)) || (max != -1 && numRepeats >= max)) { logDirect("Done building"); + if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnBuildFinished.value) { + NotificationHelper.notify("Done building", false); + } onLostControl(); return null; } diff --git a/src/main/java/baritone/process/CustomGoalProcess.java b/src/main/java/baritone/process/CustomGoalProcess.java index b45c7d6f..f925bec7 100644 --- a/src/main/java/baritone/process/CustomGoalProcess.java +++ b/src/main/java/baritone/process/CustomGoalProcess.java @@ -23,6 +23,7 @@ import baritone.api.process.ICustomGoalProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.utils.BaritoneProcessHelper; +import baritone.utils.NotificationHelper; /** * As set by ExampleBaritoneControl or something idk @@ -93,6 +94,9 @@ public final class CustomGoalProcess extends BaritoneProcessHelper implements IC if (Baritone.settings().disconnectOnArrival.value) { ctx.world().sendQuittingDisconnectingPacket(); } + if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnPathComplete.value) { + NotificationHelper.notify("Pathing complete", false); + } return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL); } return new PathingCommand(this.goal, PathingCommandType.SET_GOAL_AND_PATH); diff --git a/src/main/java/baritone/process/ExploreProcess.java b/src/main/java/baritone/process/ExploreProcess.java index 220ae3b1..c42ece0e 100644 --- a/src/main/java/baritone/process/ExploreProcess.java +++ b/src/main/java/baritone/process/ExploreProcess.java @@ -29,6 +29,7 @@ import baritone.api.process.PathingCommandType; import baritone.api.utils.MyChunkPos; import baritone.cache.CachedWorld; import baritone.utils.BaritoneProcessHelper; +import baritone.utils.NotificationHelper; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; @@ -83,12 +84,18 @@ public final class ExploreProcess extends BaritoneProcessHelper implements IExpl public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { if (calcFailed) { logDirect("Failed"); + if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnExploreFinished.value) { + NotificationHelper.notify("Exploration failed", true); + } onLostControl(); return null; } IChunkFilter filter = calcFilter(); if (!Baritone.settings().disableCompletionCheck.value && filter.countRemain() == 0) { logDirect("Explored all chunks"); + if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnExploreFinished.value) { + NotificationHelper.notify("Explored all chunks", false); + } onLostControl(); return null; } diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index a91fda60..407157b3 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -31,6 +31,7 @@ import baritone.api.utils.input.Input; import baritone.cache.WorldScanner; import baritone.pathing.movement.MovementHelper; import baritone.utils.BaritoneProcessHelper; +import baritone.utils.NotificationHelper; import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; @@ -257,6 +258,9 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro if (calcFailed) { logDirect("Farm failed"); + if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnFarmFail.value) { + NotificationHelper.notify("Farm failed", true); + } onLostControl(); return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); } diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index a76121b8..b44709e3 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -30,6 +30,7 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; +import baritone.utils.NotificationHelper; import net.minecraft.block.Block; import net.minecraft.block.BlockAir; import net.minecraft.block.BlockFalling; @@ -221,6 +222,9 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro locs.addAll(dropped); if (locs.isEmpty()) { logDirect("No locations for " + filter + " known, cancelling"); + if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnMineFail.value) { + NotificationHelper.notify("No locations for " + filter + " known, cancelling", true); + } cancel(); return; } From 0434e1c5d3cb73364c5ce8fe93725f16c939ab00 Mon Sep 17 00:00:00 2001 From: aUniqueUser <ds458@pm.me> Date: Sat, 29 Feb 2020 12:24:06 -0500 Subject: [PATCH 077/133] Add more entries to MineProcess --- src/main/java/baritone/process/MineProcess.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index b44709e3..6e8ba245 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -89,10 +89,16 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro if (calcFailed) { if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) { logDirect("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance..."); + if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnMineFail.value) { + NotificationHelper.notify("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance...", true); + } knownOreLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(blacklist::add); knownOreLocations.removeIf(blacklist::contains); } else { logDirect("Unable to find any path to " + filter + ", canceling mine"); + if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnMineFail.value) { + NotificationHelper.notify("Unable to find any path to " + filter + ", canceling mine", true); + } cancel(); return null; } From 0ca3c496de110b71aa8031b0bc1d856dcb7b88cf Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Mon, 2 Mar 2020 13:40:43 -0600 Subject: [PATCH 078/133] Fix tunnel command usage --- src/main/java/baritone/command/defaults/TunnelCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/TunnelCommand.java b/src/main/java/baritone/command/defaults/TunnelCommand.java index d346e9df..6f7304a6 100644 --- a/src/main/java/baritone/command/defaults/TunnelCommand.java +++ b/src/main/java/baritone/command/defaults/TunnelCommand.java @@ -107,7 +107,7 @@ public class TunnelCommand extends Command { "", "Usage:", "> tunnel - No arguments, mines in a 1x2 radius.", - "> tunnel height/width/depth - Tunnels in a user defined height, width and depth." + "> tunnel <height> <width> <depth> - Tunnels in a user defined height, width and depth." ); } } From 96a8bb90c9444a3e15f91ad8be6f656703d1d6bb Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Mon, 2 Mar 2020 13:41:21 -0600 Subject: [PATCH 079/133] Fix tunnel usage in USAGE.md --- USAGE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USAGE.md b/USAGE.md index ce761b8e..681298b0 100644 --- a/USAGE.md +++ b/USAGE.md @@ -44,7 +44,7 @@ Some common examples: - `save waypointName` to save a waypoint. `goto waypointName` to go to it. - `build` to build a schematic. `build blah` will load `schematics/blah.schematic` and build it with the origin being your player feet. `build blah x y z` to set the origin. Any of those can be relative to your player (`~ 69 ~-420` would build at x=player x, y=69, z=player z-420). - `schematica` to build the schematic that is currently open in schematica -- `tunnel height/width/depth` to dig and make a tunnel. If you don't supply numbers then it just digs a 1x2 tunnel. +- `tunnel height width depth` to dig and make a tunnel. If you don't supply numbers then it just digs a 1x2 tunnel. - `farm` to automatically harvest, replant, or bone meal crops - `axis` to go to an axis or diagonal axis at y=120 (`axisHeight` is a configurable setting, defaults to 120). - `explore x z` to explore the world from the origin of x,z. Leave out x and z to default to player feet. This will continually path towards the closest chunk to the origin that it's never seen before. `explorefilter filter.json` with optional invert can be used to load in a list of chunks to load. From c8856cfea4ffd19fe0909a0446d4aa34813df53c Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Sat, 7 Mar 2020 17:34:27 -0600 Subject: [PATCH 080/133] Fix #1250 --- .../java/baritone/process/BuilderProcess.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 5af43492..17a8f5f9 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -206,7 +206,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil continue; // irrelevant } IBlockState curr = bcc.bsi.get0(x, y, z); - if (curr.getBlock() != Blocks.AIR && !(curr.getBlock() instanceof BlockLiquid) && !valid(curr, desired)) { + if (curr.getBlock() != Blocks.AIR && !(curr.getBlock() instanceof BlockLiquid) && !valid(curr, desired, false)) { BetterBlockPos pos = new BetterBlockPos(x, y, z); Optional<Rotation> rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); if (rot.isPresent()) { @@ -247,7 +247,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil continue; // irrelevant } IBlockState curr = bcc.bsi.get0(x, y, z); - if (MovementHelper.isReplaceable(x, y, z, curr, bcc.bsi) && !valid(curr, desired)) { + if (MovementHelper.isReplaceable(x, y, z, curr, bcc.bsi) && !valid(curr, desired, false)) { if (dy == 1 && bcc.bsi.get0(x, y + 1, z).getBlock() == Blocks.AIR) { continue; } @@ -314,7 +314,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil ); ctx.player().rotationYaw = originalYaw; ctx.player().rotationPitch = originalPitch; - if (valid(wouldBePlaced, desired)) { + if (valid(wouldBePlaced, desired, true)) { return OptionalInt.of(i); } } @@ -457,7 +457,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil outer: for (IBlockState desired : desirableOnHotbar) { for (int i = 0; i < 9; i++) { - if (valid(approxPlaceable.get(i), desired)) { + if (valid(approxPlaceable.get(i), desired, true)) { usefulSlots.add(i); continue outer; } @@ -468,7 +468,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil outer: for (int i = 9; i < 36; i++) { for (IBlockState desired : noValidHotbarOption) { - if (valid(approxPlaceable.get(i), desired)) { + if (valid(approxPlaceable.get(i), desired, true)) { baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains); break outer; } @@ -524,7 +524,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (desired != null) { // we care about this position BetterBlockPos pos = new BetterBlockPos(x, y, z); - if (valid(bcc.bsi.get0(x, y, z), desired)) { + if (valid(bcc.bsi.get0(x, y, z), desired, false)) { incorrectPositions.remove(pos); observedCompleted.add(BetterBlockPos.longHash(pos)); } else { @@ -551,7 +551,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } if (bcc.bsi.worldContainsLoadedChunk(blockX, blockZ)) { // check if its in render distance, not if its in cache // we can directly observe this block, it is in render distance - if (valid(bcc.bsi.get0(blockX, blockY, blockZ), schematic.desiredState(x, y, z, current, this.approxPlaceable))) { + if (valid(bcc.bsi.get0(blockX, blockY, blockZ), schematic.desiredState(x, y, z, current, this.approxPlaceable), false)) { observedCompleted.add(BetterBlockPos.longHash(blockX, blockY, blockZ)); } else { incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ)); @@ -769,7 +769,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil return result; } - private boolean valid(IBlockState current, IBlockState desired) { + private boolean valid(IBlockState current, IBlockState desired, boolean itemVerify) { if (desired == null) { return true; } @@ -780,7 +780,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (desired.getBlock() instanceof BlockAir && Baritone.settings().buildIgnoreBlocks.value.contains(current.getBlock())) { return true; } - if (!(current.getBlock() instanceof BlockAir) && Baritone.settings().buildIgnoreExisting.value) { + if (!(current.getBlock() instanceof BlockAir) && Baritone.settings().buildIgnoreExisting.value && !itemVerify) { return true; } return current.equals(desired); @@ -862,7 +862,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } // it should be a real block // is it already that block? - if (valid(bsi.get0(x, y, z), sch)) { + if (valid(bsi.get0(x, y, z), sch, false)) { return Baritone.settings().breakCorrectBlockPenaltyMultiplier.value; } else { // can break if it's wrong From eda18207738ba8d773607e3c6e8f14f0c7bff490 Mon Sep 17 00:00:00 2001 From: Brady <zeromemesdev@gmail.com> Date: Sat, 7 Mar 2020 20:17:53 -0600 Subject: [PATCH 081/133] Fix Cubecraft Crash (Affects 1.13.2+) --- .../launch/mixins/MixinNetHandlerPlayClient.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java b/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java index e2cc9842..96e9cc29 100644 --- a/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java +++ b/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java @@ -21,6 +21,7 @@ import baritone.api.BaritoneAPI; import baritone.api.IBaritone; import baritone.api.event.events.ChunkEvent; import baritone.api.event.events.type.EventState; +import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.play.server.SPacketChunkData; import net.minecraft.network.play.server.SPacketCombatEvent; @@ -45,7 +46,8 @@ public class MixinNetHandlerPlayClient { ) private void preRead(SPacketChunkData packetIn, CallbackInfo ci) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { - if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) { + EntityPlayerSP player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (NetHandlerPlayClient) (Object) this) { ibaritone.getGameEventHandler().onChunkEvent( new ChunkEvent( EventState.PRE, @@ -64,7 +66,8 @@ public class MixinNetHandlerPlayClient { ) private void postHandleChunkData(SPacketChunkData packetIn, CallbackInfo ci) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { - if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) { + EntityPlayerSP player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (NetHandlerPlayClient) (Object) this) { ibaritone.getGameEventHandler().onChunkEvent( new ChunkEvent( EventState.POST, @@ -86,7 +89,8 @@ public class MixinNetHandlerPlayClient { ) private void onPlayerDeath(SPacketCombatEvent packetIn, CallbackInfo ci) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { - if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) { + EntityPlayerSP player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (NetHandlerPlayClient) (Object) this) { ibaritone.getGameEventHandler().onPlayerDeath(); } } From d6106a44f753974927418a12bfb654acb68ffde5 Mon Sep 17 00:00:00 2001 From: Bella Who <bella.who.two@gmail.com> Date: Fri, 13 Mar 2020 09:00:17 -0400 Subject: [PATCH 082/133] Remove dropbox link as 1.15.2 is now officially released --- SETUP.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/SETUP.md b/SETUP.md index ae9e82c4..f2e0c303 100644 --- a/SETUP.md +++ b/SETUP.md @@ -2,9 +2,7 @@ The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. -1.14.4 and lower is located on the [releases](https://github.com/cabaletta/baritone/releases/) page, if you don't want to use Impact. - -For 1.15.2, [click here](https://www.dropbox.com/s/8rx6f0kts9hvd4f/1.15.2-Baritone.zip?dl=1). +1.15.2 and lower is located on the [releases](https://github.com/cabaletta/baritone/releases/) page, if you don't want to use Impact. Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. From 67256c17cf07d25f2a69c295fe2585fedc163589 Mon Sep 17 00:00:00 2001 From: Bella Who <bella.who.two@gmail.com> Date: Sat, 14 Mar 2020 12:10:26 -0400 Subject: [PATCH 083/133] Add modified settings to bug template --- .github/ISSUE_TEMPLATE/bug.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index e2b8874c..34487ff7 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -25,6 +25,9 @@ Mac: `/Library/Application\ Support/minecraft/logs/` ## How to reproduce Add your steps to reproduce the issue/bug experienced here. +## Modified settings +To get the modified settings run `#modified` in game + ## Final checklist - [x] I know how to properly use check boxes - [ ] I have included the version of Minecraft I'm running, baritone's version and forge mods (if used). From f4842aa512af76dcfbff6098d5006ce8d860f305 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 14 Mar 2020 11:50:16 -0700 Subject: [PATCH 084/133] fix actual underlying sneak issue --- src/main/java/baritone/command/defaults/BuildCommand.java | 6 +++--- src/main/java/baritone/utils/InputOverrideHandler.java | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/command/defaults/BuildCommand.java b/src/main/java/baritone/command/defaults/BuildCommand.java index 3d549587..273c5bc3 100644 --- a/src/main/java/baritone/command/defaults/BuildCommand.java +++ b/src/main/java/baritone/command/defaults/BuildCommand.java @@ -19,13 +19,13 @@ package baritone.command.defaults; import baritone.Baritone; import baritone.api.IBaritone; -import baritone.api.utils.BetterBlockPos; import baritone.api.command.Command; +import baritone.api.command.argument.IArgConsumer; import baritone.api.command.datatypes.RelativeBlockPos; import baritone.api.command.datatypes.RelativeFile; import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandInvalidStateException; -import baritone.api.command.argument.IArgConsumer; +import baritone.api.utils.BetterBlockPos; import net.minecraft.client.Minecraft; import org.apache.commons.io.FilenameUtils; @@ -59,7 +59,7 @@ public class BuildCommand extends Command { } boolean success = baritone.getBuilderProcess().build(file.getName(), file, buildOrigin); if (!success) { - throw new CommandInvalidStateException("Couldn't load the schematic"); + throw new CommandInvalidStateException("Couldn't load the schematic. Make sure to use the FULL file name, including the extension (e.g. blah.schematic)."); } logDirect(String.format("Successfully loaded schematic for building\nOrigin: %s", buildOrigin)); } diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index 47a06854..d1c4689a 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -108,6 +108,11 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri } private boolean inControl() { + for (Input input : new Input[]{Input.MOVE_FORWARD, Input.MOVE_BACK, Input.MOVE_LEFT, Input.MOVE_RIGHT, Input.SNEAK}) { + if (isInputForcedDown(input)) { + return true; + } + } // if we are not primary (a bot) we should set the movementinput even when idle (not pathing) return baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone(); } From 43f11aaf0cce77cb38518776ece7f581a16da3db Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 14 Mar 2020 12:09:19 -0700 Subject: [PATCH 085/133] finally update usage to furry code --- USAGE.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/USAGE.md b/USAGE.md index 681298b0..b2253740 100644 --- a/USAGE.md +++ b/USAGE.md @@ -16,7 +16,7 @@ Try `#help` I promise it won't just send you back here =) "wtf where is cleararea" -> look at `#help sel` -"wtf where is goto death, goto waypoint" -> look at `#help wp` (a "tag" is like "home" (created automatically on right clicking a bed) or "death" (created automatically on death) or "user" (has to be created manually)). So you might want `#wp save user coolbiome` then, to set the goal `#wp goal coolbiome` then `#path` to path to it. For death, `#wp goal death` (remember stuff is clickable!). +"wtf where is goto death, goto waypoint" -> look at `#help wp` just look at `#help` lmao @@ -40,11 +40,11 @@ Some common examples: - `goto portal` or `goto ender_chest` or `goto block_type` to go to a block. (in Impact, `.goto` is an alias for `.b goto` for the most part) - `mine diamond_ore iron_ore` to mine diamond ore or iron ore (turn on the setting `legitMine` to only mine ores that it can actually see. It will explore randomly around y=11 until it finds them.) An amount of blocks can also be specified, for example, `mine diamond_ore 64`. - `click` to click your destination on the screen. Right click path to on top of the block, left click to path into it (either at foot level or eye level), and left click and drag to clear all blocks from an area. -- `follow playerName` to follow a player. `followplayers` to follow any players in range (combine with Kill Aura for a fun time). `followentities` to follow any entities. `followentity pig` to follow entities of a specific type. -- `save waypointName` to save a waypoint. `goto waypointName` to go to it. -- `build` to build a schematic. `build blah` will load `schematics/blah.schematic` and build it with the origin being your player feet. `build blah x y z` to set the origin. Any of those can be relative to your player (`~ 69 ~-420` would build at x=player x, y=69, z=player z-420). +- `follow player playerName` to follow a player. `follow players` to follow any players in range (combine with Kill Aura for a fun time). `follow entities` to follow any entities. `follow entity pig` to follow entities of a specific type. +- `wp` for waypoints. A "tag" is like "home" (created automatically on right clicking a bed) or "death" (created automatically on death) or "user" (has to be created manually). So you might want `#wp save user coolbiome`, then to set the goal `#wp goal coolbiome` then `#path` to path to it. For death, `#wp goal death` will list waypoints under the "death" tag (remember stuff is clickable!) +- `build` to build a schematic. `build blah.schematic` will load `schematics/blah.schematic` and build it with the origin being your player feet. `build blah.schematic x y z` to set the origin. Any of those can be relative to your player (`~ 69 ~-420` would build at x=player x, y=69, z=player z-420). - `schematica` to build the schematic that is currently open in schematica -- `tunnel height width depth` to dig and make a tunnel. If you don't supply numbers then it just digs a 1x2 tunnel. +- `tunnel` to dig and make a tunnel, 1x2. It will only deviate from the straight line if necessary such as to avoid lava. For a dumber tunnel that is really just cleararea, you can `tunnel 3 2 100`, to clear an area 3 high, 2 wide, and 100 deep. - `farm` to automatically harvest, replant, or bone meal crops - `axis` to go to an axis or diagonal axis at y=120 (`axisHeight` is a configurable setting, defaults to 120). - `explore x z` to explore the world from the origin of x,z. Leave out x and z to default to player feet. This will continually path towards the closest chunk to the origin that it's never seen before. `explorefilter filter.json` with optional invert can be used to load in a list of chunks to load. @@ -94,4 +94,4 @@ So you'll need to use the `#` prefix or edit `baritone/settings.txt` in your Min ## Why can I do `.goto x z` in Impact but nowhere else? Why can I do `-path to x z` in KAMI but nowhere else? These are custom commands that they added; those aren't from Baritone. -The equivalent you're looking for is `goal x z` then `path`. +The equivalent you're looking for is `goto x z`. From 12481cc4919a603c71792e9648c8ee69f71865cb Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 14 Mar 2020 12:09:35 -0700 Subject: [PATCH 086/133] v1.2.12 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9912a92a..a1963670 100755 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ */ group 'baritone' -version '1.2.11' +version '1.2.12' buildscript { repositories { From d759c676f7b2e638c9a09cfef17c23bbcb35af89 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 14 Mar 2020 12:13:45 -0700 Subject: [PATCH 087/133] disable broken code --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 371639be..e0f412ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ install: script: - docker run --rm cabaletta/baritone ./gradlew javadoc -- docker run --name baritone cabaletta/baritone /bin/sh -c "set -e; /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 128x128x24 -ac +extension GLX +render; DISPLAY=:99 BARITONE_AUTO_TEST=true ./gradlew runClient" +#- docker run --name baritone cabaletta/baritone /bin/sh -c "set -e; /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 128x128x24 -ac +extension GLX +render; DISPLAY=:99 BARITONE_AUTO_TEST=true ./gradlew runClient" - docker cp baritone:/code/dist dist - ls dist - cat dist/checksums.txt From 69e871eaad137347105c8629ac6cc818f7d01a1c Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 14 Mar 2020 12:19:39 -0700 Subject: [PATCH 088/133] we can copy from this image sure --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e0f412ac..2e793a75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ install: - travis_retry docker build -t cabaletta/baritone . script: -- docker run --rm cabaletta/baritone ./gradlew javadoc +- docker run --name baritone cabaletta/baritone ./gradlew javadoc #- docker run --name baritone cabaletta/baritone /bin/sh -c "set -e; /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 128x128x24 -ac +extension GLX +render; DISPLAY=:99 BARITONE_AUTO_TEST=true ./gradlew runClient" - docker cp baritone:/code/dist dist - ls dist From 62b808ad484554fe2894991c912b328adf1f3564 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Wed, 18 Mar 2020 19:15:47 -0700 Subject: [PATCH 089/133] nickhasbugs --- src/main/java/baritone/pathing/movement/MovementHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index d6f0b9a2..87ab4510 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -89,7 +89,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 || block instanceof BlockTrapDoor) { + if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull || block instanceof BlockTrapDoor || block == Blocks.END_ROD) { return false; } if (Baritone.settings().blocksToAvoid.value.contains(block)) { @@ -302,7 +302,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) { return true; } - if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST ) { + if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) { return true; } if (isWater(block)) { From dff92beea1b9ed62930a3a2667e3878486a7666a Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Wed, 25 Mar 2020 17:17:10 -0700 Subject: [PATCH 090/133] v1.2.13 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a1963670..ce97e61c 100755 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ */ group 'baritone' -version '1.2.12' +version '1.2.13' buildscript { repositories { From ac2a88d186384199037849d48e444897082b8bfd Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Wed, 25 Mar 2020 21:50:12 -0700 Subject: [PATCH 091/133] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9bc29c66..3fb823cb 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,13 @@ A Minecraft pathfinder bot. Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do. -The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. +By far the easiest and most user-friendly way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. -For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. +The second easiest way (for 1.12.2 Forge or 1.15.2 Forge only) is to install the v1.2.* or v1.5.* (respectively) "forge-api" jar from [releases](https://github.com/cabaletta/baritone/releases). For 1.12.2, click [here](https://github.com/cabaletta/baritone/releases/download/v1.2.13/baritone-api-forge-1.2.13.jar). For 1.15.2 you will also need a second mod to allow Baritone's forge mod to work. Mod 1 (baritone) is [here](https://github.com/cabaletta/baritone/releases/download/v1.5.3/baritone-api-forge-1.5.3.jar). Mod 2 (mixinbootstrap) is [here](https://github.com/LXGaming/MixinBootstrap/releases/download/v1.0.2/MixinBootstrap-1.0.2.jar). They must go in `mods`. Not in `mods/1.15.2` or anything. Otherwise, see [Installation & setup](SETUP.md). + +For 1.15.2 vanilla version (no Forge), [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. + +Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 through 1.15.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). From 3cc4c0ea98a41166705d9b97281c1b54d92ff1b0 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Wed, 25 Mar 2020 21:52:42 -0700 Subject: [PATCH 092/133] Revert "Update README.md" This reverts commit ac2a88d186384199037849d48e444897082b8bfd. --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3fb823cb..9bc29c66 100644 --- a/README.md +++ b/README.md @@ -33,13 +33,9 @@ A Minecraft pathfinder bot. Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do. -By far the easiest and most user-friendly way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. +The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. -The second easiest way (for 1.12.2 Forge or 1.15.2 Forge only) is to install the v1.2.* or v1.5.* (respectively) "forge-api" jar from [releases](https://github.com/cabaletta/baritone/releases). For 1.12.2, click [here](https://github.com/cabaletta/baritone/releases/download/v1.2.13/baritone-api-forge-1.2.13.jar). For 1.15.2 you will also need a second mod to allow Baritone's forge mod to work. Mod 1 (baritone) is [here](https://github.com/cabaletta/baritone/releases/download/v1.5.3/baritone-api-forge-1.5.3.jar). Mod 2 (mixinbootstrap) is [here](https://github.com/LXGaming/MixinBootstrap/releases/download/v1.0.2/MixinBootstrap-1.0.2.jar). They must go in `mods`. Not in `mods/1.15.2` or anything. Otherwise, see [Installation & setup](SETUP.md). - -For 1.15.2 vanilla version (no Forge), [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. - -Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. +For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 through 1.15.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). From e218ced2c786ef0e3f42bce758ab9ed7384e7593 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Mon, 30 Mar 2020 22:23:43 -0700 Subject: [PATCH 093/133] i hate myself --- src/main/java/baritone/pathing/movement/MovementHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 87ab4510..1a3faf57 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -521,7 +521,7 @@ public interface MovementHelper extends ActionCosts, Helper { double faceX = (placeAt.getX() + against1.getX() + 1.0D) * 0.5D; double faceY = (placeAt.getY() + against1.getY() + 0.5D) * 0.5D; double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D; - Rotation place = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()); + Rotation place = RotationUtils.calcRotationFromVec3d(wouldSneak ? RayTraceUtils.inferSneakingEyePosition(ctx.player()) : ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()); RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance(), wouldSneak); if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(placeAt)) { state.setTarget(new MovementState.MovementTarget(place, true)); From 0e7bf25de72c4607aa360b59ac5b0a7c567e5fb7 Mon Sep 17 00:00:00 2001 From: Dominika <bella.who.two@gmail.com> Date: Thu, 9 Apr 2020 17:01:26 -0400 Subject: [PATCH 094/133] fix setup.md as per leij's recommendations --- SETUP.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SETUP.md b/SETUP.md index f2e0c303..ff16acbb 100644 --- a/SETUP.md +++ b/SETUP.md @@ -2,7 +2,7 @@ The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. -1.15.2 and lower is located on the [releases](https://github.com/cabaletta/baritone/releases/) page, if you don't want to use Impact. +You can also use a custom version json for Minecraft, with the [1.14.4](https://www.dropbox.com/s/rkml3hjokd3qv0m/1.14.4-Baritone.zip?dl=1) version or the [1.15.2](https://www.dropbox.com/s/8rx6f0kts9hvd4f/1.15.2-Baritone.zip?dl=1) version Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. From c32652394ebc28dfad00bc0a92977fa915fbac4f Mon Sep 17 00:00:00 2001 From: Babbaj <babbaj45@gmail.com> Date: Sun, 12 Apr 2020 03:01:24 -0400 Subject: [PATCH 095/133] Annotation for proguard -keep --- scripts/proguard.pro | 7 +++++++ src/main/java/baritone/KeepName.java | 21 +++++++++++++++++++ .../command/defaults/FollowCommand.java | 3 +++ 3 files changed, 31 insertions(+) create mode 100644 src/main/java/baritone/KeepName.java diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 52b843dd..af920a59 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -23,6 +23,13 @@ -keep class baritone.api.utils.MyChunkPos { *; } # even in standalone we need to keep this for gson reflect +# Keep any class or member annotated with @KeepName so we dont have to put everything in the script +-keep,allowobfuscation @interface baritone.KeepName +-keep @baritone.KeepName class * +-keepclassmembers class * { + @baritone.KeepName *; +} + # setting names are reflected from field names, so keep field names -keepclassmembers class baritone.api.Settings { public <fields>; diff --git a/src/main/java/baritone/KeepName.java b/src/main/java/baritone/KeepName.java new file mode 100644 index 00000000..20f08e7b --- /dev/null +++ b/src/main/java/baritone/KeepName.java @@ -0,0 +1,21 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see <https://www.gnu.org/licenses/>. + */ + +package baritone; + +// Annotation for classes and class members that should not be renamed by proguard +public @interface KeepName { } diff --git a/src/main/java/baritone/command/defaults/FollowCommand.java b/src/main/java/baritone/command/defaults/FollowCommand.java index 755fc535..c6347020 100644 --- a/src/main/java/baritone/command/defaults/FollowCommand.java +++ b/src/main/java/baritone/command/defaults/FollowCommand.java @@ -17,6 +17,7 @@ package baritone.command.defaults; +import baritone.KeepName; import baritone.api.IBaritone; import baritone.api.command.Command; import baritone.api.command.datatypes.EntityClassById; @@ -130,6 +131,7 @@ public class FollowCommand extends Command { ); } + @KeepName private enum FollowGroup { ENTITIES(EntityLiving.class::isInstance), PLAYERS(EntityPlayer.class::isInstance); /* , @@ -142,6 +144,7 @@ public class FollowCommand extends Command { } } + @KeepName private enum FollowList { ENTITY(EntityClassById.INSTANCE), PLAYER(NearbyPlayer.INSTANCE); From ff3234fcdd0dcb0ff6dce5a5989ea504830a5604 Mon Sep 17 00:00:00 2001 From: ByteZ1337 <cr33pycode@gmail.com> Date: Mon, 13 Apr 2020 20:39:56 +0200 Subject: [PATCH 096/133] Fixed Typo Fixed Typo in the Long Description of the Goto Command --- src/main/java/baritone/command/defaults/GotoCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/GotoCommand.java b/src/main/java/baritone/command/defaults/GotoCommand.java index 28e76829..a6fe4e22 100644 --- a/src/main/java/baritone/command/defaults/GotoCommand.java +++ b/src/main/java/baritone/command/defaults/GotoCommand.java @@ -72,7 +72,7 @@ public class GotoCommand extends Command { @Override public List<String> getLongDesc() { return Arrays.asList( - "The got command tells Baritone to head towards a given goal or block.", + "The goto command tells Baritone to head towards a given goal or block.", "", "Wherever a coordinate is expected, you can use ~ just like in regular Minecraft commands. Or, you can just use regular numbers.", "", From ec92ab8b39a2aa4e97471acc25eec4b10d380b42 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 18 Apr 2020 22:07:18 -0700 Subject: [PATCH 097/133] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9bc29c66..75ce5513 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # Baritone +[![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone/) +[![GitHub All Releases](https://img.shields.io/github/downloads/cabaletta/baritone/total.svg)](https://github.com/cabaletta/baritone/releases/) + [![Build Status](https://travis-ci.com/cabaletta/baritone.svg?branch=master)](https://travis-ci.com/cabaletta/baritone/) [![Release](https://img.shields.io/github/release/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/releases/) [![License](https://img.shields.io/badge/license-LGPL--3.0%20with%20anime%20exception-green.svg)](LICENSE) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a73d037823b64a5faf597a18d71e3400)](https://www.codacy.com/app/leijurv/baritone?utm_source=github.com&utm_medium=referral&utm_content=cabaletta/baritone&utm_campaign=Badge_Grade) -[![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone/) -[![GitHub All Releases](https://img.shields.io/github/downloads/cabaletta/baritone/total.svg)](https://github.com/cabaletta/baritone/releases/) [![Minecraft](https://img.shields.io/badge/MC-1.12.2-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/master/) [![Minecraft](https://img.shields.io/badge/MC-1.13.2-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/1.13.2/) [![Minecraft](https://img.shields.io/badge/MC-1.14.4-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/1.14.4/) From 33d4dd47bb2814367e373f1891e2ef4233cdf232 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Tue, 21 Apr 2020 12:02:07 -0700 Subject: [PATCH 098/133] v1.2.14 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ce97e61c..a91926dd 100755 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ */ group 'baritone' -version '1.2.13' +version '1.2.14' buildscript { repositories { From c2624bbaafd88b7c02b07f8fc4d65c35637b9f1a Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Tue, 21 Apr 2020 13:32:47 -0700 Subject: [PATCH 099/133] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75ce5513..5e19309d 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ A Minecraft pathfinder bot. Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do. -The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. +The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). For 1.12.2, click [here](https://github.com/cabaletta/baritone/releases/download/v1.2.14/baritone-api-forge-1.2.14.jar). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. From 10677040e07c93e60ae7d07f8e01680fad6f0328 Mon Sep 17 00:00:00 2001 From: Dominika <bella.who.two@gmail.com> Date: Sun, 26 Apr 2020 15:22:24 -0400 Subject: [PATCH 100/133] Fix broken API Settings link in USAGE. Close #1040 --- USAGE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USAGE.md b/USAGE.md index b2253740..d817c24c 100644 --- a/USAGE.md +++ b/USAGE.md @@ -52,7 +52,7 @@ Some common examples: - `version` to get the version of Baritone you're running - `damn` daniel -For the rest of the commands, you can take a look at the code [here](https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/utils/ExampleBaritoneControl.java). +For the rest of the commands, you can take a look at the code [here](https://baritone.leijurv.com/baritone/api/Settings.html). All the settings and documentation are <a href="https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/Settings.java">here</a>. If you find HTML easier to read than Javadoc, you can look <a href="https://baritone.leijurv.com/baritone/api/Settings.html#field.detail">here</a>. From d0f594065d9fe86a4f1ecfca6e3314c8c506a59e Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sun, 26 Apr 2020 13:22:55 -0700 Subject: [PATCH 101/133] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5e19309d..21ae5cd7 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,9 @@ A Minecraft pathfinder bot. Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do. -The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). For 1.12.2, click [here](https://github.com/cabaletta/baritone/releases/download/v1.2.14/baritone-api-forge-1.2.14.jar). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. +The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* `api-forge` jar from [releases](https://github.com/cabaletta/baritone/releases). For 1.12.2, click [here](https://github.com/cabaletta/baritone/releases/download/v1.2.14/baritone-api-forge-1.2.14.jar). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. -For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. +For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. If you need Forge 1.15.2, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.5.3), follow the instructions, and get the `api-forge` jar. This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 through 1.15.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). From 89ab78a329a86d980f1660e30f6d04d4426e5a1c Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sun, 3 May 2020 18:51:21 -0700 Subject: [PATCH 102/133] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 21ae5cd7..e0d5ee70 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ A Minecraft pathfinder bot. Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do. -The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* `api-forge` jar from [releases](https://github.com/cabaletta/baritone/releases). For 1.12.2, click [here](https://github.com/cabaletta/baritone/releases/download/v1.2.14/baritone-api-forge-1.2.14.jar). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. +The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* `api-forge` jar from [releases](https://github.com/cabaletta/baritone/releases). **For 1.12.2 Forge, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.2.14/baritone-api-forge-1.2.14.jar)**. Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. If you need Forge 1.15.2, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.5.3), follow the instructions, and get the `api-forge` jar. From 806dc8f0171907c394e32b7c8a69c8cf052aeaa0 Mon Sep 17 00:00:00 2001 From: Babbaj <babbaj45@gmail.com> Date: Mon, 4 May 2020 01:15:18 -0400 Subject: [PATCH 103/133] This had to be done --- src/main/java/baritone/BaritoneProvider.java | 4 ++-- .../{BaritoneChatControl.java => ExampleBaritoneControl.java} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/baritone/command/{BaritoneChatControl.java => ExampleBaritoneControl.java} (98%) diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java index 84034ef3..6f64a835 100644 --- a/src/main/java/baritone/BaritoneProvider.java +++ b/src/main/java/baritone/BaritoneProvider.java @@ -22,7 +22,7 @@ import baritone.api.IBaritoneProvider; import baritone.api.cache.IWorldScanner; import baritone.api.command.ICommandSystem; import baritone.api.schematic.ISchematicSystem; -import baritone.command.BaritoneChatControl; +import baritone.command.ExampleBaritoneControl; import baritone.cache.WorldScanner; import baritone.command.CommandSystem; import baritone.utils.schematic.SchematicSystem; @@ -44,7 +44,7 @@ public final class BaritoneProvider implements IBaritoneProvider { this.all = Collections.singletonList(this.primary); // Setup chat control, just for the primary instance - new BaritoneChatControl(this.primary); + new ExampleBaritoneControl(this.primary); } @Override diff --git a/src/main/java/baritone/command/BaritoneChatControl.java b/src/main/java/baritone/command/ExampleBaritoneControl.java similarity index 98% rename from src/main/java/baritone/command/BaritoneChatControl.java rename to src/main/java/baritone/command/ExampleBaritoneControl.java index 15f15abe..53b34df0 100644 --- a/src/main/java/baritone/command/BaritoneChatControl.java +++ b/src/main/java/baritone/command/ExampleBaritoneControl.java @@ -49,12 +49,12 @@ import java.util.stream.Stream; import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; -public class BaritoneChatControl implements Helper, AbstractGameEventListener { +public class ExampleBaritoneControl implements Helper, AbstractGameEventListener { private static final Settings settings = BaritoneAPI.getSettings(); private final ICommandManager manager; - public BaritoneChatControl(IBaritone baritone) { + public ExampleBaritoneControl(IBaritone baritone) { this.manager = baritone.getCommandManager(); baritone.getGameEventHandler().registerEventListener(this); } From a76cf0fe9a1837ab3abbc8fe425a3be5b6cff220 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sun, 17 May 2020 18:35:41 -0700 Subject: [PATCH 104/133] brady more like brainletdy --- src/main/java/baritone/command/defaults/BuildCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/BuildCommand.java b/src/main/java/baritone/command/defaults/BuildCommand.java index 273c5bc3..72458286 100644 --- a/src/main/java/baritone/command/defaults/BuildCommand.java +++ b/src/main/java/baritone/command/defaults/BuildCommand.java @@ -46,7 +46,7 @@ public class BuildCommand extends Command { public void execute(String label, IArgConsumer args) throws CommandException { File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile(); if (FilenameUtils.getExtension(file.getAbsolutePath()).isEmpty()) { - file = new File(file.getAbsolutePath() + "." + Baritone.settings().schematicFallbackExtension); + file = new File(file.getAbsolutePath() + "." + Baritone.settings().schematicFallbackExtension.value); } BetterBlockPos origin = ctx.playerFeet(); BetterBlockPos buildOrigin; From ca831bc734c5de76c458f89f311843df14b14e0f Mon Sep 17 00:00:00 2001 From: Dominika <sokolov.dominika@gmail.com> Date: Mon, 18 May 2020 13:47:57 -0400 Subject: [PATCH 105/133] Added blue badge to integrations badges --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e0d5ee70..dbb1331c 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ [![GitHub contributors](https://img.shields.io/github/contributors/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/graphs/contributors/) [![GitHub commits](https://img.shields.io/github/commits-since/cabaletta/baritone/v1.0.0.svg)](https://github.com/cabaletta/baritone/commit/) [![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.10%20/%20v1.3.5%20/%20v1.4.3-brightgreen.svg)](https://impactclient.net/) +[![KAMI Blue integration](https://img.shields.io/badge/KAMI%20Blue%20integration-v1.2.14--master-brightgreen)](https://github.com/kami-blue/client) [![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/) [![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api) [![rootNET integration](https://img.shields.io/badge/rootNET%20integration-v1.2.11-green.svg)](https://rootnet.dev/) From 80c8294f5f956896ffc3f12cbf51e476d6859f8a Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Thu, 4 Jun 2020 11:32:20 -0700 Subject: [PATCH 106/133] maintain obscenely obvious pro impact bias in subconscious coloring --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dbb1331c..0d36fdcc 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ [![GitHub contributors](https://img.shields.io/github/contributors/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/graphs/contributors/) [![GitHub commits](https://img.shields.io/github/commits-since/cabaletta/baritone/v1.0.0.svg)](https://github.com/cabaletta/baritone/commit/) [![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.10%20/%20v1.3.5%20/%20v1.4.3-brightgreen.svg)](https://impactclient.net/) -[![KAMI Blue integration](https://img.shields.io/badge/KAMI%20Blue%20integration-v1.2.14--master-brightgreen)](https://github.com/kami-blue/client) +[![KAMI Blue integration](https://img.shields.io/badge/KAMI%20Blue%20integration-v1.2.14--master-green)](https://github.com/kami-blue/client) [![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/) [![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api) [![rootNET integration](https://img.shields.io/badge/rootNET%20integration-v1.2.11-green.svg)](https://rootnet.dev/) From e42c19bfec7f4769f53421481cc6eae8810ce9b2 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sat, 27 Jun 2020 22:25:47 -0700 Subject: [PATCH 107/133] thebes uwu --- src/api/java/baritone/api/Settings.java | 11 ++++++++++- src/main/java/baritone/process/BuilderProcess.java | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 1bbde3b2..283e4e0a 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -30,8 +30,8 @@ import java.awt.*; import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.*; import java.util.List; +import java.util.*; import java.util.function.Consumer; /** @@ -193,6 +193,15 @@ public final class Settings { ))); + /** + * A list of blocks to become air + * <p> + * If a schematic asks for a block on this list, only air will be accepted at that location (and nothing on buildIgnoreBlocks) + */ + public final Setting<List<Block>> okIfAir = new Setting<>(new ArrayList<>(Arrays.asList( + + ))); + /** * If this is true, the builder will treat all non-air blocks as correct. It will only place new blocks. */ diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 17a8f5f9..b8f77ce2 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -206,6 +206,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil continue; // irrelevant } IBlockState curr = bcc.bsi.get0(x, y, z); + Blocks.ICE; if (curr.getBlock() != Blocks.AIR && !(curr.getBlock() instanceof BlockLiquid) && !valid(curr, desired, false)) { BetterBlockPos pos = new BetterBlockPos(x, y, z); Optional<Rotation> rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); @@ -773,10 +774,12 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (desired == null) { return true; } - // TODO more complicated comparison logic I guess if (current.getBlock() instanceof BlockLiquid && Baritone.settings().okIfWater.value) { return true; } + if (current.getBlock() instanceof BlockAir && Baritone.settings().okIfAir.value.contains(desired.getBlock())) { + return true; + } if (desired.getBlock() instanceof BlockAir && Baritone.settings().buildIgnoreBlocks.value.contains(current.getBlock())) { return true; } From eafca1e1fe46d277fc573760b68ce5beae315ef2 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Mon, 6 Jul 2020 17:07:59 -0700 Subject: [PATCH 108/133] yourkit --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d36fdcc..16641d61 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,16 @@ That's what it's for, sure! (As long as usage is in compliance with the LGPL 3.0 Magic. (Hours of [leijurv](https://github.com/leijurv/) enduring excruciating pain) +### Additional Special Thanks To: + +![YourKit-Logo](https://www.yourkit.com/images/yklogo.png) + +YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications. + +YourKit is the creator of the [YourKit Java Profiler](https://www.yourkit.com/java/profiler/), [YourKit .NET Profiler](https://www.yourkit.com/.net/profiler/), and [YourKit YouMonitor](https://www.yourkit.com/youmonitor/). + +We thank them for granting Baritone an OSS license so that we can make our software the best it can be. + ## Why is it called Baritone? -It's named for FitMC's deep sultry voice. +It's named for FitMC's deep sultry voice. From f02476ff3aaf722f2dd76e5c94d0fce27b8e0760 Mon Sep 17 00:00:00 2001 From: CorruptedSeal <68251040+CorruptedSeal@users.noreply.github.com> Date: Wed, 15 Jul 2020 01:18:01 -0600 Subject: [PATCH 109/133] Update ProguardTask.java --- .../baritone/gradle/task/ProguardTask.java | 105 +++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index 30ffddfb..dbeca172 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -21,13 +21,21 @@ import baritone.gradle.util.Determinizer; import baritone.gradle.util.MappingType; import baritone.gradle.util.ReobfWrapper; import org.apache.commons.io.IOUtils; +import org.gradle.api.JavaVersion; import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; +import org.gradle.api.internal.file.IdentityFileResolver; import org.gradle.api.internal.plugins.DefaultConvention; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.TaskAction; +import org.gradle.api.tasks.TaskCollection; +import org.gradle.api.tasks.compile.ForkOptions; +import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.internal.Pair; +import org.gradle.internal.jvm.Jvm; +import org.gradle.internal.jvm.inspection.DefaultJvmVersionDetector; +import org.gradle.process.internal.DefaultExecActionFactory; import java.io.*; import java.lang.reflect.Field; @@ -101,6 +109,101 @@ public class ProguardTask extends BaritoneGradleTask { } } + private String getJavaBinPathForProguard() { + String path; + try { + path = findJavaPathByGradleConfig(); + if (path != null) return path; + } + catch (Exception ex) { + System.err.println("Unable to find java by javaCompile options"); + ex.printStackTrace(); + } + + try { + path = findJavaByJavaHome(); + if (path != null) return path; + } + catch(Exception ex) { + System.err.println("Unable to find java by JAVA_HOME"); + ex.printStackTrace(); + } + + + path = findJavaByGradleCurrentRuntime(); + if (path != null) return path; + + throw new RuntimeException("Unable to find java to determine ProGuard libraryjars. Please specify forkOptions.executable in javaCompile," + + " JAVA_HOME environment variable, or make sure to run Gradle with the correct JDK (a v1.8 only)"); + } + + private String findJavaByGradleCurrentRuntime() { + String path = Jvm.current().getJavaExecutable().getAbsolutePath(); + + if (this.validateJavaVersion(path)) { + System.out.println("Using Gradle's runtime Java for ProGuard"); + return path; + } + return null; + } + + private String findJavaByJavaHome() { + final String javaHomeEnv = System.getenv("JAVA_HOME"); + if (javaHomeEnv != null) { + + String path = Jvm.forHome(new File(javaHomeEnv)).getJavaExecutable().getAbsolutePath(); + if (this.validateJavaVersion(path)) { + System.out.println("Detected Java path by JAVA_HOME"); + return path; + } + } + return null; + } + + private String findJavaPathByGradleConfig() { + final TaskCollection<JavaCompile> javaCompiles = super.getProject().getTasks().withType(JavaCompile.class); + + final JavaCompile compileTask = javaCompiles.iterator().next(); + final ForkOptions forkOptions = compileTask.getOptions().getForkOptions(); + + if (forkOptions != null) { + String javacPath = forkOptions.getExecutable(); + if (javacPath != null) { + File javacFile = new File(javacPath); + if (javacFile.exists()) { + File[] maybeJava = javacFile.getParentFile().listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.equals("java"); + } + }); + + if (maybeJava != null && maybeJava.length > 0) { + String path = maybeJava[0].getAbsolutePath(); + if (this.validateJavaVersion(path)) { + System.out.println("Detected Java path by forkOptions"); + return path; + } + } + } + } + } + return null; + } + + private boolean validateJavaVersion(String java) { + final JavaVersion javaVersion = new DefaultJvmVersionDetector(new DefaultExecActionFactory(new IdentityFileResolver())).getJavaVersion(java); + + if (!javaVersion.getMajorVersion().equals("8")) { + System.out.println("Failed to validate Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars"); + // throw new RuntimeException("Java version incorrect: " + javaVersion.getMajorVersion() + " for " + java); + return false; + } + + System.out.println("Validated Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars"); + return true; + } + private void generateConfigs() throws Exception { Files.copy(getRelativeFile(PROGUARD_CONFIG_TEMPLATE), getTemporaryFile(PROGUARD_CONFIG_DEST), REPLACE_EXISTING); @@ -110,7 +213,7 @@ public class ProguardTask extends BaritoneGradleTask { template.add(1, "-outjars " + this.getTemporaryFile(PROGUARD_EXPORT_PATH)); // Acquire the RT jar using "java -verbose". This doesn't work on Java 9+ - Process p = new ProcessBuilder("java", "-verbose").start(); + Process p = new ProcessBuilder(this.getJavaBinPathForProguard(), "-verbose").start(); String out = IOUtils.toString(p.getInputStream(), "UTF-8").split("\n")[0].split("Opened ")[1].replace("]", ""); template.add(2, "-libraryjars '" + out + "'"); From d522f9dfa3e2b5c000e4ebf8e57a6a00607f45ea Mon Sep 17 00:00:00 2001 From: CorruptedSeal <68251040+CorruptedSeal@users.noreply.github.com> Date: Wed, 15 Jul 2020 01:34:19 -0600 Subject: [PATCH 110/133] Update ProguardTask.java --- buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index dbeca172..ead398b3 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -132,8 +132,8 @@ public class ProguardTask extends BaritoneGradleTask { path = findJavaByGradleCurrentRuntime(); if (path != null) return path; - - throw new RuntimeException("Unable to find java to determine ProGuard libraryjars. Please specify forkOptions.executable in javaCompile," + + + throw new Exception("Unable to find java to determine ProGuard libraryjars. Please specify forkOptions.executable in javaCompile," + " JAVA_HOME environment variable, or make sure to run Gradle with the correct JDK (a v1.8 only)"); } From 6603e8b11e0b5453433183f164b05bd3edb6cfae Mon Sep 17 00:00:00 2001 From: CorruptedSeal <68251040+CorruptedSeal@users.noreply.github.com> Date: Thu, 16 Jul 2020 03:45:23 -0600 Subject: [PATCH 111/133] Update ExecutionControlCommands.java --- .../baritone/command/defaults/ExecutionControlCommands.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java index 4a04b9e0..1b024c3b 100644 --- a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java +++ b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java @@ -79,7 +79,7 @@ public class ExecutionControlCommands { } } ); - pauseCommand = new Command(baritone, "pause") { + pauseCommand = new Command(baritone, "pause", "p") { @Override public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); @@ -112,7 +112,7 @@ public class ExecutionControlCommands { ); } }; - resumeCommand = new Command(baritone, "resume") { + resumeCommand = new Command(baritone, "resume", "r") { @Override public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); @@ -171,7 +171,7 @@ public class ExecutionControlCommands { ); } }; - cancelCommand = new Command(baritone, "cancel", "stop") { + cancelCommand = new Command(baritone, "cancel", "c", "stop") { @Override public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); From cbb3483456c74e509b18e5ee98ea2369c65ee4b7 Mon Sep 17 00:00:00 2001 From: elongated muskrat <56513556+elonmusksama@users.noreply.github.com> Date: Thu, 16 Jul 2020 14:35:17 -0300 Subject: [PATCH 112/133] updated compatible versions to future badge updated the compatible versions to the future integrations badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 16641d61..83305b61 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ [![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api) [![rootNET integration](https://img.shields.io/badge/rootNET%20integration-v1.2.11-green.svg)](https://rootnet.dev/) [![WWE integration](https://img.shields.io/badge/WWE%20%22integration%22-master%3F-green.svg)](https://wweclient.com/) -[![Future integration](https://img.shields.io/badge/Future%20integration-Soonβ„’%3F%3F%3F-red.svg)](https://futureclient.net/) +[![Future integration](https://img.shields.io/badge/Future%20integration-v1.2.12%20%2F%20v1.3.6%20%2F%20v1.4.4-red)](https://futureclient.net/) [![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](http://forthebadge.com/) [![forthebadge](https://forthebadge.com/images/badges/mom-made-pizza-rolls.svg)](http://forthebadge.com/) From 2acf64a0d069e33eccb7e6d10840467809f8b843 Mon Sep 17 00:00:00 2001 From: John <43681932+John200410@users.noreply.github.com> Date: Mon, 20 Jul 2020 03:12:24 -0400 Subject: [PATCH 113/133] add rusherhack integration badge as of rusherhack v1.0 there is baritone API integration, similar to future's. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 83305b61..a095a2e5 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ [![rootNET integration](https://img.shields.io/badge/rootNET%20integration-v1.2.11-green.svg)](https://rootnet.dev/) [![WWE integration](https://img.shields.io/badge/WWE%20%22integration%22-master%3F-green.svg)](https://wweclient.com/) [![Future integration](https://img.shields.io/badge/Future%20integration-v1.2.12%20%2F%20v1.3.6%20%2F%20v1.4.4-red)](https://futureclient.net/) +[![RusherHack integration](https://img.shields.io/badge/RusherHack%20integration-v1.2.14-green)](https://rusherhack.org/) [![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](http://forthebadge.com/) [![forthebadge](https://forthebadge.com/images/badges/mom-made-pizza-rolls.svg)](http://forthebadge.com/) From 9e45998a656a2f203c874e831677b99d86028572 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Sun, 26 Jul 2020 13:21:51 -0700 Subject: [PATCH 114/133] brady shouldn't merge PRs that don't compile, thanks cdagaming --- buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index ead398b3..01e56177 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -109,7 +109,7 @@ public class ProguardTask extends BaritoneGradleTask { } } - private String getJavaBinPathForProguard() { + private String getJavaBinPathForProguard() throws Exception { String path; try { path = findJavaPathByGradleConfig(); From c180eb9975257b8d18368b7de62c6e34b0fe4ea1 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Wed, 29 Jul 2020 12:52:19 -0700 Subject: [PATCH 115/133] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 83305b61..0f33c9d5 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ ![Lines of Code](https://tokei.rs/b1/github/cabaletta/baritone?category=code) [![GitHub contributors](https://img.shields.io/github/contributors/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/graphs/contributors/) [![GitHub commits](https://img.shields.io/github/commits-since/cabaletta/baritone/v1.0.0.svg)](https://github.com/cabaletta/baritone/commit/) -[![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.10%20/%20v1.3.5%20/%20v1.4.3-brightgreen.svg)](https://impactclient.net/) +[![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.14%20/%20v1.3.8%20/%20v1.4.6%20/%20v1.5.3-brightgreen.svg)](https://impactclient.net/) [![KAMI Blue integration](https://img.shields.io/badge/KAMI%20Blue%20integration-v1.2.14--master-green)](https://github.com/kami-blue/client) [![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/) [![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api) From 7081cf7172d4b385dec5be95686089eeefc9ee44 Mon Sep 17 00:00:00 2001 From: orsondmc <orsondmc@gmail.com> Date: Thu, 6 Aug 2020 16:23:13 +1000 Subject: [PATCH 116/133] Introduce startAtLayer to start building at a specific layer in the schematic. To be used only with buildWithLayers true. --- src/api/java/baritone/api/Settings.java | 6 ++++++ src/main/java/baritone/process/BuilderProcess.java | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 1bbde3b2..e3716751 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -752,6 +752,12 @@ public final class Settings { */ public final Setting<Boolean> layerOrder = new Setting<>(false); + /** + * Start building the schematic at a specific layer. + * Can help on larger builds when schematic wants to break things its already built + */ + public final Setting<Integer> startAtLayer = new Setting<>(1); + /** * How far to move before repeating the build. 0 to disable repeating on a certain axis, 0,0,0 to disable entirely */ diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 17a8f5f9..e25a30af 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -97,7 +97,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } this.origin = new Vec3i(x, y, z); this.paused = false; - this.layer = 0; + this.layer = Baritone.settings().startAtLayer.value; this.numRepeats = 0; this.observedCompleted = new LongOpenHashSet(); } @@ -743,7 +743,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil name = null; schematic = null; realSchematic = null; - layer = 0; + layer = Baritone.settings().startAtLayer.value; numRepeats = 0; paused = false; observedCompleted = null; From b187d860741c7e5b6cb6aab64a5b80dcdadec9a9 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Wed, 5 Aug 2020 23:31:32 -0700 Subject: [PATCH 117/133] fix orsond rock brain moment --- src/api/java/baritone/api/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index e3716751..3da1d21b 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -756,7 +756,7 @@ public final class Settings { * Start building the schematic at a specific layer. * Can help on larger builds when schematic wants to break things its already built */ - public final Setting<Integer> startAtLayer = new Setting<>(1); + public final Setting<Integer> startAtLayer = new Setting<>(0); /** * How far to move before repeating the build. 0 to disable repeating on a certain axis, 0,0,0 to disable entirely From 2ddc2c3660d591d42e39a935bb46c27e924ee22a Mon Sep 17 00:00:00 2001 From: RealIndrit <jia@twinflower.net> Date: Thu, 13 Aug 2020 22:36:34 +0200 Subject: [PATCH 118/133] Add auto tool settings because 2 lines of code lols --- src/api/java/baritone/api/Settings.java | 5 +++++ src/main/java/baritone/utils/ToolSet.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 3da1d21b..c03b0b72 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -61,6 +61,11 @@ public final class Settings { */ public final Setting<Boolean> allowInventory = new Setting<>(false); + /** + * Allow player to decide if to use auto tool or not + */ + public final Setting<Boolean> autoTool = new Setting<>(true); + /** * It doesn't actually take twenty ticks to place a block, this cost is so high * because we want to generally conserve blocks which might be limited. diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index b6446b30..01784302 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -127,7 +127,7 @@ public class ToolSet { } } } - return best; + return Baritone.settings().autoTool.value? best : player.inventory.currentItem; } /** From 2b6fe188ed15a658141bd670c476b8ab5e84f874 Mon Sep 17 00:00:00 2001 From: RealIndrit <jia@twinflower.net> Date: Thu, 13 Aug 2020 22:47:40 +0200 Subject: [PATCH 119/133] Why calculate stuff that isnt needed... --- src/main/java/baritone/pathing/movement/MovementHelper.java | 4 +++- src/main/java/baritone/utils/ToolSet.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 1a3faf57..7dae4cea 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -432,7 +432,9 @@ public interface MovementHelper extends ActionCosts, Helper { * @param ts previously calculated ToolSet */ static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts, boolean preferSilkTouch) { - ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock(), preferSilkTouch); + if(Baritone.settings().autoTool.value){ + ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock(), preferSilkTouch); + } } static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 01784302..b6446b30 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -127,7 +127,7 @@ public class ToolSet { } } } - return Baritone.settings().autoTool.value? best : player.inventory.currentItem; + return best; } /** From 2ed3e10833bd08cdd4993af3387fa909a2aff742 Mon Sep 17 00:00:00 2001 From: RealIndrit <jia@twinflower.net> Date: Thu, 13 Aug 2020 23:20:30 +0200 Subject: [PATCH 120/133] And we try this again, because wtf?? --- src/main/java/baritone/pathing/movement/MovementHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 7dae4cea..7ae57ae4 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -432,7 +432,7 @@ public interface MovementHelper extends ActionCosts, Helper { * @param ts previously calculated ToolSet */ static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts, boolean preferSilkTouch) { - if(Baritone.settings().autoTool.value){ + if (Baritone.settings().autoTool.value) { ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock(), preferSilkTouch); } } From f8872e1cd450cbf205974d6dc9db1e1c6b8d676e Mon Sep 17 00:00:00 2001 From: RealIndrit <jia@twinflower.net> Date: Fri, 14 Aug 2020 10:14:02 +0200 Subject: [PATCH 121/133] Everything can be traced back to getBestSlot(); --- src/main/java/baritone/pathing/movement/MovementHelper.java | 4 +--- src/main/java/baritone/utils/ToolSet.java | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 7ae57ae4..1a3faf57 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -432,9 +432,7 @@ public interface MovementHelper extends ActionCosts, Helper { * @param ts previously calculated ToolSet */ static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts, boolean preferSilkTouch) { - if (Baritone.settings().autoTool.value) { - ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock(), preferSilkTouch); - } + ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock(), preferSilkTouch); } static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index b6446b30..101a4294 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -18,6 +18,7 @@ package baritone.utils; import baritone.Baritone; +import baritone.command.argparser.DefaultArgParsers; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.entity.EntityPlayerSP; @@ -102,6 +103,11 @@ public class ToolSet { * @return An int containing the index in the tools array that worked best */ public int getBestSlot(Block b, boolean preferSilkTouch) { + // Make all depending calculation respect auto tool value without doing unecessary calculations... + if (Baritone.settings().autoTool.value) { + return player.inventory.currentItem; + } + int best = 0; double highestSpeed = Double.NEGATIVE_INFINITY; int lowestCost = Integer.MIN_VALUE; From 49db52673a1dfd60828ecbb6e6a01e330610dd34 Mon Sep 17 00:00:00 2001 From: RealIndrit <jia@twinflower.net> Date: Fri, 14 Aug 2020 10:25:51 +0200 Subject: [PATCH 122/133] Lol --- src/main/java/baritone/utils/ToolSet.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 101a4294..c6161f07 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -18,7 +18,6 @@ package baritone.utils; import baritone.Baritone; -import baritone.command.argparser.DefaultArgParsers; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.entity.EntityPlayerSP; From e0ff16e2dd8366f9c7e94003a3de6dc997115d4b Mon Sep 17 00:00:00 2001 From: RealIndrit <jia@twinflower.net> Date: Fri, 14 Aug 2020 10:34:21 +0200 Subject: [PATCH 123/133] Nice brainfart --- src/main/java/baritone/utils/ToolSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index c6161f07..cd347d20 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -103,7 +103,7 @@ public class ToolSet { */ public int getBestSlot(Block b, boolean preferSilkTouch) { // Make all depending calculation respect auto tool value without doing unecessary calculations... - if (Baritone.settings().autoTool.value) { + if (!Baritone.settings().autoTool.value) { return player.inventory.currentItem; } From 19355cb4f252489356e91a37bfac877055247ae3 Mon Sep 17 00:00:00 2001 From: RealIndrit <jia@twinflower.net> Date: Fri, 14 Aug 2020 10:58:15 +0200 Subject: [PATCH 124/133] Added AutoToolMovement bypass setting for special usage cases, should not be used it not actually necessary --- src/api/java/baritone/api/Settings.java | 8 ++++++++ .../java/baritone/pathing/movement/MovementHelper.java | 4 +++- src/main/java/baritone/utils/ToolSet.java | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index c03b0b72..5b0d58ed 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -66,6 +66,14 @@ public final class Settings { */ public final Setting<Boolean> autoTool = new Setting<>(true); + /** + * Should movement cost calculation ignore the cost of breaking blocks with current slot? + * Only use this if actually necessary, make sure to put this back to original state (false), or it + * will mess up pathing in some combinations with auto tool setting. (just fall back to original settings if any + * problems occurs) + */ + public final Setting<Boolean> ignoreAutoToolMovementCost = new Setting<>(false); + /** * It doesn't actually take twenty ticks to place a block, this cost is so high * because we want to generally conserve blocks which might be limited. diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 1a3faf57..7ae57ae4 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -432,7 +432,9 @@ public interface MovementHelper extends ActionCosts, Helper { * @param ts previously calculated ToolSet */ static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts, boolean preferSilkTouch) { - ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock(), preferSilkTouch); + if (Baritone.settings().autoTool.value) { + ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock(), preferSilkTouch); + } } static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index cd347d20..2d8a1a2a 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -103,7 +103,7 @@ public class ToolSet { */ public int getBestSlot(Block b, boolean preferSilkTouch) { // Make all depending calculation respect auto tool value without doing unecessary calculations... - if (!Baritone.settings().autoTool.value) { + if (!Baritone.settings().ignoreAutoToolMovementCost.value) { return player.inventory.currentItem; } From 94ac15a8fcc5fff7b08f1337a66c3ec3fd7158d7 Mon Sep 17 00:00:00 2001 From: RealIndrit <jia@twinflower.net> Date: Fri, 14 Aug 2020 17:06:41 +0200 Subject: [PATCH 125/133] KEK False != True :clown: --- src/main/java/baritone/utils/ToolSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 2d8a1a2a..e3eb56f5 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -103,7 +103,7 @@ public class ToolSet { */ public int getBestSlot(Block b, boolean preferSilkTouch) { // Make all depending calculation respect auto tool value without doing unecessary calculations... - if (!Baritone.settings().ignoreAutoToolMovementCost.value) { + if (Baritone.settings().ignoreAutoToolMovementCost.value) { return player.inventory.currentItem; } From 88e2fba447ed82abd23760dad1540010567c9300 Mon Sep 17 00:00:00 2001 From: RealIndrit <jia@twinflower.net> Date: Fri, 14 Aug 2020 17:11:31 +0200 Subject: [PATCH 126/133] Ok, Im actually retarded --- src/main/java/baritone/utils/ToolSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index e3eb56f5..2d8a1a2a 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -103,7 +103,7 @@ public class ToolSet { */ public int getBestSlot(Block b, boolean preferSilkTouch) { // Make all depending calculation respect auto tool value without doing unecessary calculations... - if (Baritone.settings().ignoreAutoToolMovementCost.value) { + if (!Baritone.settings().ignoreAutoToolMovementCost.value) { return player.inventory.currentItem; } From ac55de63e9a8665770d0e80316793d28f2bf914a Mon Sep 17 00:00:00 2001 From: RealIndrit <jia@twinflower.net> Date: Fri, 14 Aug 2020 17:55:10 +0200 Subject: [PATCH 127/133] Maybe dont have ignore cost calculation override auto tool? --- src/api/java/baritone/api/Settings.java | 2 +- src/main/java/baritone/utils/ToolSet.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 5b0d58ed..0776d2b3 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -69,7 +69,7 @@ public final class Settings { /** * Should movement cost calculation ignore the cost of breaking blocks with current slot? * Only use this if actually necessary, make sure to put this back to original state (false), or it - * will mess up pathing in some combinations with auto tool setting. (just fall back to original settings if any + * migth mess up pathing in some combinations with auto tool setting. (just fall back to original settings if any * problems occurs) */ public final Setting<Boolean> ignoreAutoToolMovementCost = new Setting<>(false); diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 2d8a1a2a..0f791cb7 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -101,9 +101,14 @@ public class ToolSet { * @param b the blockstate to be mined * @return An int containing the index in the tools array that worked best */ + public int getBestSlot(Block b, boolean preferSilkTouch) { + return getBestSlot(b, preferSilkTouch, false); + } + + public int getBestSlot(Block b, boolean preferSilkTouch, boolean pathingCalculation) { // Make all depending calculation respect auto tool value without doing unecessary calculations... - if (!Baritone.settings().ignoreAutoToolMovementCost.value) { + if (!Baritone.settings().ignoreAutoToolMovementCost.value && pathingCalculation) { return player.inventory.currentItem; } @@ -142,7 +147,7 @@ public class ToolSet { * @return A double containing the destruction ticks with the best tool */ private double getBestDestructionTime(Block b) { - ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b, false)); + ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b, false, true)); return calculateSpeedVsBlock(stack, b.getDefaultState()) * avoidanceMultiplier(b); } From 2eba22031a524215993da1f57a5bf7c5385e0a13 Mon Sep 17 00:00:00 2001 From: RealIndrit <jia@twinflower.net> Date: Fri, 14 Aug 2020 22:47:39 +0200 Subject: [PATCH 128/133] Maybe dont have ignore cost calculation override auto tool? --- src/api/java/baritone/api/Settings.java | 6 ++++-- src/main/java/baritone/utils/ToolSet.java | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 0776d2b3..15c9ba35 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -67,9 +67,11 @@ public final class Settings { public final Setting<Boolean> autoTool = new Setting<>(true); /** - * Should movement cost calculation ignore the cost of breaking blocks with current slot? + * Should movement cost calculation ignore the cost of breaking blocks with current slot, and assume best possible + * item in the hotbar? + * * Only use this if actually necessary, make sure to put this back to original state (false), or it - * migth mess up pathing in some combinations with auto tool setting. (just fall back to original settings if any + * might mess up pathing in some combinations with auto tool setting. (just fall back to original settings if any * problems occurs) */ public final Setting<Boolean> ignoreAutoToolMovementCost = new Setting<>(false); diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 0f791cb7..b903bdf3 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -96,7 +96,8 @@ public class ToolSet { } /** - * Calculate which tool on the hotbar is best for mining + * Calculate which tool on the hotbar is best for mining, depending on an override setting, + * related to auto tool movement cost, it will either return current selected slot, or the best slot. * * @param b the blockstate to be mined * @return An int containing the index in the tools array that worked best @@ -107,7 +108,11 @@ public class ToolSet { } public int getBestSlot(Block b, boolean preferSilkTouch, boolean pathingCalculation) { - // Make all depending calculation respect auto tool value without doing unecessary calculations... + + /* + If we actually want know what efficiency our held item has instead of the best one + possible, this lets us make pathing depending on the actual tool used (if auto tool is disabled) + */ if (!Baritone.settings().ignoreAutoToolMovementCost.value && pathingCalculation) { return player.inventory.currentItem; } From e6ba4ef309bf356dfd92e571bc9e55801c0c86b3 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Mon, 17 Aug 2020 15:00:57 -0700 Subject: [PATCH 129/133] we don't compile here --- src/main/java/baritone/process/BuilderProcess.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index b45a7f3b..ecb40a22 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -206,7 +206,6 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil continue; // irrelevant } IBlockState curr = bcc.bsi.get0(x, y, z); - Blocks.ICE; if (curr.getBlock() != Blocks.AIR && !(curr.getBlock() instanceof BlockLiquid) && !valid(curr, desired, false)) { BetterBlockPos pos = new BetterBlockPos(x, y, z); Optional<Rotation> rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); From 38d047dbd1de4fc48619a59f3b06da381ac311b4 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Mon, 17 Aug 2020 15:19:11 -0700 Subject: [PATCH 130/133] make the packer queue super cute and deduplicated --- src/main/java/baritone/cache/CachedWorld.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index 23d7ca8c..1d113246 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -26,6 +26,7 @@ import baritone.api.utils.Helper; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; import net.minecraft.world.chunk.Chunk; import java.io.IOException; @@ -33,6 +34,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.LinkedBlockingQueue; /** @@ -56,7 +59,17 @@ public final class CachedWorld implements ICachedWorld, Helper { */ private final String directory; - private final LinkedBlockingQueue<Chunk> toPack = new LinkedBlockingQueue<>(); + /** + * Queue of positions to pack. Refers to the toPackMap, in that every element of this queue will be a + * key in that map. + */ + private final LinkedBlockingQueue<ChunkPos> toPackQueue = new LinkedBlockingQueue<>(); + + /** + * All chunk positions pending packing. This map will be updated in-place if a new update to the chunk occurs + * while waiting in the queue for the packer thread to get to it. + */ + private final Map<ChunkPos, Chunk> toPackMap = new ConcurrentHashMap<>(); private final int dimension; @@ -89,10 +102,8 @@ public final class CachedWorld implements ICachedWorld, Helper { @Override public final void queueForPacking(Chunk chunk) { - try { - toPack.put(chunk); - } catch (InterruptedException e) { - e.printStackTrace(); + if (toPackMap.put(chunk.getPos(), chunk) == null) { + toPackQueue.add(chunk.getPos()); } } @@ -293,13 +304,9 @@ public final class CachedWorld implements ICachedWorld, Helper { public void run() { while (true) { - // TODO: Add CachedWorld unloading to remove the redundancy of having this - LinkedBlockingQueue<Chunk> queue = toPack; - if (queue == null) { - break; - } try { - Chunk chunk = queue.take(); + ChunkPos pos = toPackQueue.take(); + Chunk chunk = toPackMap.remove(pos); CachedChunk cached = ChunkPacker.pack(chunk); CachedWorld.this.updateCachedChunk(cached); //System.out.println("Processed chunk at " + chunk.x + "," + chunk.z); From f3561cab47693799c01b6a59ee9fbaf2b7c0842c Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Mon, 17 Aug 2020 15:54:42 -0700 Subject: [PATCH 131/133] SUPER cute code for repackOnAnyBlockChange --- src/api/java/baritone/api/Settings.java | 5 ++ .../mixins/MixinNetHandlerPlayClient.java | 67 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 4e622dc2..4b44d3e5 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -439,6 +439,11 @@ public final class Settings { */ public final Setting<Boolean> simplifyUnloadedYCoord = new Setting<>(true); + /** + * Whenever a block changes, repack the whole chunk that it's in + */ + public final Setting<Boolean> repackOnAnyBlockChange = new Setting<>(true); + /** * If a movement takes this many ticks more than its initial cost estimate, cancel it */ diff --git a/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java b/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java index 96e9cc29..f1c1f797 100644 --- a/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java +++ b/src/launch/java/baritone/launch/mixins/MixinNetHandlerPlayClient.java @@ -17,14 +17,19 @@ package baritone.launch.mixins; +import baritone.Baritone; import baritone.api.BaritoneAPI; import baritone.api.IBaritone; import baritone.api.event.events.ChunkEvent; import baritone.api.event.events.type.EventState; +import baritone.cache.CachedChunk; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.network.play.server.SPacketBlockChange; import net.minecraft.network.play.server.SPacketChunkData; import net.minecraft.network.play.server.SPacketCombatEvent; +import net.minecraft.network.play.server.SPacketMultiBlockChange; +import net.minecraft.util.math.ChunkPos; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -80,6 +85,68 @@ public class MixinNetHandlerPlayClient { } } + @Inject( + method = "handleBlockChange", + at = @At("RETURN") + ) + private void postHandleBlockChange(SPacketBlockChange packetIn, CallbackInfo ci) { + if (!Baritone.settings().repackOnAnyBlockChange.value) { + return; + } + if (!CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(packetIn.getBlockState().getBlock())) { + return; + } + for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { + EntityPlayerSP player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (NetHandlerPlayClient) (Object) this) { + ibaritone.getGameEventHandler().onChunkEvent( + new ChunkEvent( + EventState.POST, + ChunkEvent.Type.POPULATE_FULL, + packetIn.getBlockPosition().getX() >> 4, + packetIn.getBlockPosition().getZ() >> 4 + ) + ); + } + } + } + + @Inject( + method = "handleMultiBlockChange", + at = @At("RETURN") + ) + private void postHandleMultiBlockChange(SPacketMultiBlockChange packetIn, CallbackInfo ci) { + if (!Baritone.settings().repackOnAnyBlockChange.value) { + return; + } + if (packetIn.getChangedBlocks().length == 0) { + return; + } + https://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.15 + { + for (SPacketMultiBlockChange.BlockUpdateData update : packetIn.getChangedBlocks()) { + if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(update.getBlockState().getBlock())) { + break https; + } + } + return; + } + ChunkPos pos = new ChunkPos(packetIn.getChangedBlocks()[0].getPos()); + for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { + EntityPlayerSP player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (NetHandlerPlayClient) (Object) this) { + ibaritone.getGameEventHandler().onChunkEvent( + new ChunkEvent( + EventState.POST, + ChunkEvent.Type.POPULATE_FULL, + pos.x, + pos.z + ) + ); + } + } + } + @Inject( method = "handleCombatEvent", at = @At( From 98516235574282d213f62107e261cc8a55f2e7f2 Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Mon, 17 Aug 2020 16:03:04 -0700 Subject: [PATCH 132/133] anti-indrit-cringe --- src/api/java/baritone/api/Settings.java | 16 +++++++--------- .../pathing/movement/MovementHelper.java | 2 +- src/main/java/baritone/utils/ToolSet.java | 4 ++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index b48bf55f..5dfcef6a 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -62,19 +62,17 @@ public final class Settings { public final Setting<Boolean> allowInventory = new Setting<>(false); /** - * Allow player to decide if to use auto tool or not + * Disable baritone's auto-tool at runtime, but still assume that another mod will provide auto tool functionality + * <p> + * Specifically, path calculation will still assume that an auto tool wil run at execution time, even though + * Baritone itself will not do that. */ - public final Setting<Boolean> autoTool = new Setting<>(true); + public final Setting<Boolean> assumeExternalAutoTool = new Setting<>(false); /** - * Should movement cost calculation ignore the cost of breaking blocks with current slot, and assume best possible - * item in the hotbar? - * - * Only use this if actually necessary, make sure to put this back to original state (false), or it - * might mess up pathing in some combinations with auto tool setting. (just fall back to original settings if any - * problems occurs) + * If this setting is on, no auto tool will occur at all, not at calculation time nor execution time */ - public final Setting<Boolean> ignoreAutoToolMovementCost = new Setting<>(false); + public final Setting<Boolean> disableAutoTool = new Setting<>(false); /** * It doesn't actually take twenty ticks to place a block, this cost is so high diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 7ae57ae4..7165303c 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -432,7 +432,7 @@ public interface MovementHelper extends ActionCosts, Helper { * @param ts previously calculated ToolSet */ static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts, boolean preferSilkTouch) { - if (Baritone.settings().autoTool.value) { + if (!Baritone.settings().disableAutoTool.value && !Baritone.settings().assumeExternalAutoTool.value) { ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock(), preferSilkTouch); } } diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index b903bdf3..aa8819ce 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -111,9 +111,9 @@ public class ToolSet { /* If we actually want know what efficiency our held item has instead of the best one - possible, this lets us make pathing depending on the actual tool used (if auto tool is disabled) + possible, this lets us make pathing depend on the actual tool to be used (if auto tool is disabled) */ - if (!Baritone.settings().ignoreAutoToolMovementCost.value && pathingCalculation) { + if (Baritone.settings().disableAutoTool.value && pathingCalculation) { return player.inventory.currentItem; } From 02e7886e77364a7249c1d310ee9f730dda96abbd Mon Sep 17 00:00:00 2001 From: Leijurv <leijurv@gmail.com> Date: Mon, 17 Aug 2020 16:15:56 -0700 Subject: [PATCH 133/133] properly set isSafeToCancel in MovementDiagonal, fixes #1788 --- .../pathing/movement/movements/MovementDiagonal.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 450144c0..2631af84 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -56,6 +56,14 @@ public class MovementDiagonal extends Movement { super(baritone, start, end, new BetterBlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}); } + @Override + protected boolean safeToCancel(MovementState state) { + return ctx.playerFeet().equals(src) || (( + MovementHelper.canWalkOn(ctx, new BlockPos(src.x, src.y - 1, dest.z)) + ) && + MovementHelper.canWalkOn(ctx, new BlockPos(dest.x, src.y - 1, src.z))); + } + @Override public double calculateCost(CalculationContext context) { MutableMoveResult result = new MutableMoveResult();