From 2b96a2e4636f4d1714c5fb16712a53832a2cd8fb Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Mon, 1 Apr 2024 14:12:46 -0700 Subject: [PATCH 01/12] don't apply block break delay to insta-breaks --- .../baritone/api/utils/IPlayerController.java | 6 ++- .../launch/mixins/MixinPlayerController.java | 10 ++-- .../java/baritone/utils/BlockBreakHelper.java | 47 ++++++++++--------- .../utils/accessor/IPlayerControllerMP.java | 8 ++-- .../player/BaritonePlayerController.java | 13 +++-- 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/api/java/baritone/api/utils/IPlayerController.java b/src/api/java/baritone/api/utils/IPlayerController.java index 48142d13b..dbe152fc8 100644 --- a/src/api/java/baritone/api/utils/IPlayerController.java +++ b/src/api/java/baritone/api/utils/IPlayerController.java @@ -37,7 +37,7 @@ public interface IPlayerController { void syncHeldItem(); - boolean hasBrokenBlock(); + boolean isDestroyingBlock(); boolean onPlayerDamageBlock(BlockPos pos, Direction side); @@ -53,7 +53,9 @@ public interface IPlayerController { boolean clickBlock(BlockPos loc, Direction face); - void setHittingBlock(boolean hittingBlock); + void setDestroyingBlock(boolean hittingBlock); + + void setDestroyDelay(int destroyDelay); default double getBlockReachDistance() { return this.getGameType().isCreative() ? 5.0F : BaritoneAPI.getSettings().blockReachDistance.value; diff --git a/src/launch/java/baritone/launch/mixins/MixinPlayerController.java b/src/launch/java/baritone/launch/mixins/MixinPlayerController.java index 34f39aee9..a486b8ec3 100644 --- a/src/launch/java/baritone/launch/mixins/MixinPlayerController.java +++ b/src/launch/java/baritone/launch/mixins/MixinPlayerController.java @@ -29,13 +29,17 @@ public abstract class MixinPlayerController implements IPlayerControllerMP { @Accessor("isDestroying") @Override - public abstract void setIsHittingBlock(boolean isHittingBlock); + public abstract void setIsDestroyingBlock(boolean isDestroyingBlock); - @Accessor("destroyBlockPos") + @Accessor("isDestroying") @Override - public abstract BlockPos getCurrentBlock(); + public abstract boolean isDestroyingBlock(); @Invoker("ensureHasSentCarriedItem") @Override public abstract void callSyncCurrentPlayItem(); + + @Accessor("destroyDelay") + @Override + public abstract void setDestroyDelay(int destroyDelay); } diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index 3332aec76..c70e5584a 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -29,10 +29,10 @@ import net.minecraft.world.phys.HitResult; */ public final class BlockBreakHelper { // base ticks between block breaks caused by tick logic - private static final int BASE_BREAK_DELAY = 2; + private static final int BASE_BREAK_DELAY = 1; private final IPlayerContext ctx; - private boolean didBreakLastTick; + private boolean wasDestroyingBlockLastTick; private int breakDelayTimer = 0; BlockBreakHelper(IPlayerContext ctx) { @@ -41,13 +41,10 @@ public final class BlockBreakHelper { public void stopBreakingBlock() { // The player controller will never be null, but the player can be - if (ctx.player() != null && didBreakLastTick) { - if (!ctx.playerController().hasBrokenBlock()) { - // insane bypass to check breaking succeeded - ctx.playerController().setHittingBlock(true); - } + if (ctx.player() != null && wasDestroyingBlockLastTick) { + ctx.playerController().setDestroyingBlock(false); ctx.playerController().resetBlockRemoving(); - didBreakLastTick = false; + wasDestroyingBlockLastTick = false; } } @@ -60,24 +57,30 @@ public final class BlockBreakHelper { boolean isBlockTrace = trace != null && trace.getType() == HitResult.Type.BLOCK; if (isLeftClick && isBlockTrace) { - if (!didBreakLastTick) { + ctx.playerController().setDestroyingBlock(wasDestroyingBlockLastTick); + if (!ctx.playerController().isDestroyingBlock()) { ctx.playerController().syncHeldItem(); ctx.playerController().clickBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection()); ctx.player().swing(InteractionHand.MAIN_HAND); + } else { + if (ctx.playerController().onPlayerDamageBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection())) { + ctx.player().swing(InteractionHand.MAIN_HAND); + } + if (!ctx.playerController().isDestroyingBlock()) { // block broken this tick + // break delay timer only applies for multi-tick block breaks like vanilla + breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY; + // must reset controller's destroy delay to prevent the client from delaying itself unnecessarily + ctx.playerController().setDestroyDelay(0); + } } - - // Attempt to break the block - if (ctx.playerController().onPlayerDamageBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection())) { - ctx.player().swing(InteractionHand.MAIN_HAND); - } - - ctx.playerController().setHittingBlock(false); - - didBreakLastTick = true; - } else if (didBreakLastTick) { - stopBreakingBlock(); - breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY; - didBreakLastTick = false; + // if true, we're breaking a block. if false, we broke the block this tick + wasDestroyingBlockLastTick = ctx.playerController().isDestroyingBlock(); + // this value will be reset by the MC client handling mouse keys + // since we're not spoofing the click keybind to the client, the client will stop the break if isDestroyingBlock is true + // we store and restore this value on the next tick to determine if we're breaking a block + ctx.playerController().setDestroyingBlock(false); + } else { + wasDestroyingBlockLastTick = false; } } } diff --git a/src/main/java/baritone/utils/accessor/IPlayerControllerMP.java b/src/main/java/baritone/utils/accessor/IPlayerControllerMP.java index 72e6f7ee3..9d1839b54 100644 --- a/src/main/java/baritone/utils/accessor/IPlayerControllerMP.java +++ b/src/main/java/baritone/utils/accessor/IPlayerControllerMP.java @@ -17,13 +17,13 @@ package baritone.utils.accessor; -import net.minecraft.core.BlockPos; - public interface IPlayerControllerMP { - void setIsHittingBlock(boolean isHittingBlock); + void setIsDestroyingBlock(boolean isDestroyingBlock); - BlockPos getCurrentBlock(); + boolean isDestroyingBlock(); void callSyncCurrentPlayItem(); + + void setDestroyDelay(int destroyDelay); } diff --git a/src/main/java/baritone/utils/player/BaritonePlayerController.java b/src/main/java/baritone/utils/player/BaritonePlayerController.java index 42ba49052..419b45f9c 100644 --- a/src/main/java/baritone/utils/player/BaritonePlayerController.java +++ b/src/main/java/baritone/utils/player/BaritonePlayerController.java @@ -53,8 +53,13 @@ public final class BaritonePlayerController implements IPlayerController { } @Override - public boolean hasBrokenBlock() { - return ((IPlayerControllerMP) mc.gameMode).getCurrentBlock().getY() == -1; + public boolean isDestroyingBlock() { + return ((IPlayerControllerMP) mc.gameMode).isDestroyingBlock(); + } + + @Override + public void setDestroyDelay(int destroyDelay) { + ((IPlayerControllerMP) mc.gameMode).setDestroyDelay(destroyDelay); } @Override @@ -94,7 +99,7 @@ public final class BaritonePlayerController implements IPlayerController { } @Override - public void setHittingBlock(boolean hittingBlock) { - ((IPlayerControllerMP) mc.gameMode).setIsHittingBlock(hittingBlock); + public void setDestroyingBlock(boolean destroyingBlock) { + ((IPlayerControllerMP) mc.gameMode).setIsDestroyingBlock(destroyingBlock); } } From 848b7c6de0eb13e729302133c1226e7a94eb9927 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Tue, 2 Apr 2024 21:32:01 +0200 Subject: [PATCH 02/12] Fix recursive parsers Does not affect existing parsers since all nested parameterized setting types are `Map>` so there is no difference between the first parameter of the inner type and the first parameter of the outer type --- .../java/baritone/api/utils/SettingsUtil.java | 57 +++++++------------ 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index 53283cd33..23c2acddb 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -149,7 +149,7 @@ public class SettingsUtil { throw new IllegalStateException("Missing " + setting.getValueClass() + " " + setting.getName()); } - return io.toString(new ParserContext(setting), value); + return io.toString(setting.getType(), value); } public static String settingValueToString(Settings.Setting setting) throws IllegalArgumentException { @@ -196,7 +196,7 @@ public class SettingsUtil { } Class intendedType = setting.getValueClass(); ISettingParser ioMethod = Parser.getParser(setting.getType()); - Object parsed = ioMethod.parse(new ParserContext(setting), settingValue); + Object parsed = ioMethod.parse(setting.getType(), settingValue); if (!intendedType.isInstance(parsed)) { throw new IllegalStateException(ioMethod + " parser returned incorrect type, expected " + intendedType + " got " + parsed + " which is " + parsed.getClass()); } @@ -205,26 +205,13 @@ public class SettingsUtil { private interface ISettingParser { - T parse(ParserContext context, String raw); + T parse(Type type, String raw); - String toString(ParserContext context, T value); + String toString(Type type, T value); boolean accepts(Type type); } - private static class ParserContext { - - private final Settings.Setting setting; - - private ParserContext(Settings.Setting setting) { - this.setting = setting; - } - - private Settings.Setting getSetting() { - return this.setting; - } - } - private enum Parser implements ISettingParser { DOUBLE(Double.class, Double::parseDouble), @@ -256,21 +243,21 @@ public class SettingsUtil { ), LIST() { @Override - public Object parse(ParserContext context, String raw) { - Type type = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0]; - Parser parser = Parser.getParser(type); + public Object parse(Type type, String raw) { + Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0]; + Parser parser = Parser.getParser(elementType); return Stream.of(raw.split(",")) - .map(s -> parser.parse(context, s)) + .map(s -> parser.parse(elementType, s)) .collect(Collectors.toList()); } @Override - public String toString(ParserContext context, Object value) { - Type type = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0]; - Parser parser = Parser.getParser(type); + public String toString(Type type, Object value) { + Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0]; + Parser parser = Parser.getParser(elementType); return ((List) value).stream() - .map(o -> parser.toString(context, o)) + .map(o -> parser.toString(elementType, o)) .collect(Collectors.joining(",")); } @@ -281,26 +268,26 @@ public class SettingsUtil { }, MAPPING() { @Override - public Object parse(ParserContext context, String raw) { - Type keyType = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0]; - Type valueType = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[1]; + public Object parse(Type type, String raw) { + Type keyType = ((ParameterizedType) type).getActualTypeArguments()[0]; + Type valueType = ((ParameterizedType) type).getActualTypeArguments()[1]; Parser keyParser = Parser.getParser(keyType); Parser valueParser = Parser.getParser(valueType); return Stream.of(raw.split(",(?=[^,]*->)")) .map(s -> s.split("->")) - .collect(Collectors.toMap(s -> keyParser.parse(context, s[0]), s -> valueParser.parse(context, s[1]))); + .collect(Collectors.toMap(s -> keyParser.parse(keyType, s[0]), s -> valueParser.parse(valueType, s[1]))); } @Override - public String toString(ParserContext context, Object value) { - Type keyType = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0]; - Type valueType = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[1]; + public String toString(Type type, Object value) { + Type keyType = ((ParameterizedType) type).getActualTypeArguments()[0]; + Type valueType = ((ParameterizedType) type).getActualTypeArguments()[1]; Parser keyParser = Parser.getParser(keyType); Parser valueParser = Parser.getParser(valueType); return ((Map) value).entrySet().stream() - .map(o -> keyParser.toString(context, o.getKey()) + "->" + valueParser.toString(context, o.getValue())) + .map(o -> keyParser.toString(keyType, o.getKey()) + "->" + valueParser.toString(valueType, o.getValue())) .collect(Collectors.joining(",")); } @@ -331,14 +318,14 @@ public class SettingsUtil { } @Override - public Object parse(ParserContext context, String raw) { + public Object parse(Type type, String raw) { Object parsed = this.parser.apply(raw); Objects.requireNonNull(parsed); return parsed; } @Override - public String toString(ParserContext context, Object value) { + public String toString(Type type, Object value) { return this.toString.apply(value); } From 15fdbb2312d663d7b401ac56d74ea83c676f11ee Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Sun, 7 Apr 2024 20:24:04 -0700 Subject: [PATCH 03/12] revert API renaming --- src/api/java/baritone/api/Settings.java | 2 +- .../baritone/api/utils/IPlayerController.java | 6 ++--- .../launch/mixins/MixinPlayerController.java | 8 +++++-- .../java/baritone/utils/BlockBreakHelper.java | 23 ++++++++++--------- .../utils/accessor/IPlayerControllerMP.java | 8 +++++-- .../player/BaritonePlayerController.java | 14 ++++------- 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 8609a0a88..071354620 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -387,7 +387,7 @@ public final class Settings { /** * How many ticks between breaking a block and starting to break the next block. Default in game is 6 ticks. - * Values under 2 will be clamped. + * Values under 1 will be clamped. The delay only applies to non-instant (1-tick) breaks. */ public final Setting blockBreakSpeed = new Setting<>(6); diff --git a/src/api/java/baritone/api/utils/IPlayerController.java b/src/api/java/baritone/api/utils/IPlayerController.java index dbe152fc8..48142d13b 100644 --- a/src/api/java/baritone/api/utils/IPlayerController.java +++ b/src/api/java/baritone/api/utils/IPlayerController.java @@ -37,7 +37,7 @@ public interface IPlayerController { void syncHeldItem(); - boolean isDestroyingBlock(); + boolean hasBrokenBlock(); boolean onPlayerDamageBlock(BlockPos pos, Direction side); @@ -53,9 +53,7 @@ public interface IPlayerController { boolean clickBlock(BlockPos loc, Direction face); - void setDestroyingBlock(boolean hittingBlock); - - void setDestroyDelay(int destroyDelay); + void setHittingBlock(boolean hittingBlock); default double getBlockReachDistance() { return this.getGameType().isCreative() ? 5.0F : BaritoneAPI.getSettings().blockReachDistance.value; diff --git a/src/launch/java/baritone/launch/mixins/MixinPlayerController.java b/src/launch/java/baritone/launch/mixins/MixinPlayerController.java index a486b8ec3..7a77d4849 100644 --- a/src/launch/java/baritone/launch/mixins/MixinPlayerController.java +++ b/src/launch/java/baritone/launch/mixins/MixinPlayerController.java @@ -29,11 +29,15 @@ public abstract class MixinPlayerController implements IPlayerControllerMP { @Accessor("isDestroying") @Override - public abstract void setIsDestroyingBlock(boolean isDestroyingBlock); + public abstract void setIsHittingBlock(boolean isHittingBlock); @Accessor("isDestroying") @Override - public abstract boolean isDestroyingBlock(); + public abstract boolean isHittingBlock(); + + @Accessor("destroyBlockPos") + @Override + public abstract BlockPos getCurrentBlock(); @Invoker("ensureHasSentCarriedItem") @Override diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index c70e5584a..0c5cf6f00 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -19,6 +19,7 @@ package baritone.utils; import baritone.api.BaritoneAPI; import baritone.api.utils.IPlayerContext; +import baritone.utils.accessor.IPlayerControllerMP; import net.minecraft.world.InteractionHand; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; @@ -32,7 +33,7 @@ public final class BlockBreakHelper { private static final int BASE_BREAK_DELAY = 1; private final IPlayerContext ctx; - private boolean wasDestroyingBlockLastTick; + private boolean wasHitting; private int breakDelayTimer = 0; BlockBreakHelper(IPlayerContext ctx) { @@ -41,10 +42,10 @@ public final class BlockBreakHelper { public void stopBreakingBlock() { // The player controller will never be null, but the player can be - if (ctx.player() != null && wasDestroyingBlockLastTick) { - ctx.playerController().setDestroyingBlock(false); + if (ctx.player() != null && wasHitting) { + ctx.playerController().setHittingBlock(false); ctx.playerController().resetBlockRemoving(); - wasDestroyingBlockLastTick = false; + wasHitting = false; } } @@ -57,8 +58,8 @@ public final class BlockBreakHelper { boolean isBlockTrace = trace != null && trace.getType() == HitResult.Type.BLOCK; if (isLeftClick && isBlockTrace) { - ctx.playerController().setDestroyingBlock(wasDestroyingBlockLastTick); - if (!ctx.playerController().isDestroyingBlock()) { + ctx.playerController().setHittingBlock(wasHitting); + if (ctx.playerController().hasBrokenBlock()) { ctx.playerController().syncHeldItem(); ctx.playerController().clickBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection()); ctx.player().swing(InteractionHand.MAIN_HAND); @@ -66,21 +67,21 @@ public final class BlockBreakHelper { if (ctx.playerController().onPlayerDamageBlock(((BlockHitResult) trace).getBlockPos(), ((BlockHitResult) trace).getDirection())) { ctx.player().swing(InteractionHand.MAIN_HAND); } - if (!ctx.playerController().isDestroyingBlock()) { // block broken this tick + if (ctx.playerController().hasBrokenBlock()) { // block broken this tick // break delay timer only applies for multi-tick block breaks like vanilla breakDelayTimer = BaritoneAPI.getSettings().blockBreakSpeed.value - BASE_BREAK_DELAY; // must reset controller's destroy delay to prevent the client from delaying itself unnecessarily - ctx.playerController().setDestroyDelay(0); + ((IPlayerControllerMP) ctx.minecraft().gameMode).setDestroyDelay(0); } } // if true, we're breaking a block. if false, we broke the block this tick - wasDestroyingBlockLastTick = ctx.playerController().isDestroyingBlock(); + wasHitting = !ctx.playerController().hasBrokenBlock(); // this value will be reset by the MC client handling mouse keys // since we're not spoofing the click keybind to the client, the client will stop the break if isDestroyingBlock is true // we store and restore this value on the next tick to determine if we're breaking a block - ctx.playerController().setDestroyingBlock(false); + ctx.playerController().setHittingBlock(false); } else { - wasDestroyingBlockLastTick = false; + wasHitting = false; } } } diff --git a/src/main/java/baritone/utils/accessor/IPlayerControllerMP.java b/src/main/java/baritone/utils/accessor/IPlayerControllerMP.java index 9d1839b54..55fa43316 100644 --- a/src/main/java/baritone/utils/accessor/IPlayerControllerMP.java +++ b/src/main/java/baritone/utils/accessor/IPlayerControllerMP.java @@ -17,11 +17,15 @@ package baritone.utils.accessor; +import net.minecraft.core.BlockPos; + public interface IPlayerControllerMP { - void setIsDestroyingBlock(boolean isDestroyingBlock); + void setIsHittingBlock(boolean isHittingBlock); - boolean isDestroyingBlock(); + boolean isHittingBlock(); + + BlockPos getCurrentBlock(); void callSyncCurrentPlayItem(); diff --git a/src/main/java/baritone/utils/player/BaritonePlayerController.java b/src/main/java/baritone/utils/player/BaritonePlayerController.java index 419b45f9c..b7e729b70 100644 --- a/src/main/java/baritone/utils/player/BaritonePlayerController.java +++ b/src/main/java/baritone/utils/player/BaritonePlayerController.java @@ -20,7 +20,6 @@ package baritone.utils.player; import baritone.api.utils.IPlayerController; import baritone.utils.accessor.IPlayerControllerMP; import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -53,13 +52,8 @@ public final class BaritonePlayerController implements IPlayerController { } @Override - public boolean isDestroyingBlock() { - return ((IPlayerControllerMP) mc.gameMode).isDestroyingBlock(); - } - - @Override - public void setDestroyDelay(int destroyDelay) { - ((IPlayerControllerMP) mc.gameMode).setDestroyDelay(destroyDelay); + public boolean hasBrokenBlock() { + return !((IPlayerControllerMP) mc.gameMode).isHittingBlock(); } @Override @@ -99,7 +93,7 @@ public final class BaritonePlayerController implements IPlayerController { } @Override - public void setDestroyingBlock(boolean destroyingBlock) { - ((IPlayerControllerMP) mc.gameMode).setIsDestroyingBlock(destroyingBlock); + public void setHittingBlock(boolean hittingBlock) { + ((IPlayerControllerMP) mc.gameMode).setIsHittingBlock(hittingBlock); } } From 4572b75db74c174312ce2794e896e5365b3d221d Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Wed, 10 Apr 2024 13:28:16 +0200 Subject: [PATCH 04/12] Fix NPE in break time calculation --- src/main/java/baritone/utils/ToolSet.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 38b1fafdd..ed4b166cf 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -177,7 +177,13 @@ public class ToolSet { * @return how long it would take in ticks */ public static double calculateSpeedVsBlock(ItemStack item, BlockState state) { - float hardness = state.getDestroySpeed(null, null); + float hardness; + try { + hardness = state.getDestroySpeed(null, null); + } catch (NullPointerException npe) { + // can't easily determine the hardness so treat it as unbreakable + return -1; + } if (hardness < 0) { return -1; } From f9a8aa0c2b1bbf87992921cfaa009fabf6606266 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 26 May 2024 03:19:35 +0200 Subject: [PATCH 05/12] Remove logspam --- src/main/java/baritone/utils/GuiClick.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/baritone/utils/GuiClick.java b/src/main/java/baritone/utils/GuiClick.java index d5e908727..7cb5fd508 100644 --- a/src/main/java/baritone/utils/GuiClick.java +++ b/src/main/java/baritone/utils/GuiClick.java @@ -73,13 +73,11 @@ public class GuiClick extends Screen implements Helper { Vec3 far = toWorld(mx, my, 1); // "Use 0.945 that's what stack overflow says" - leijurv if (near != null && far != null) { - /// Vec3 viewerPos = new Vec3(PathRenderer.posX(), PathRenderer.posY(), PathRenderer.posZ()); LocalPlayer player = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().player(); HitResult result = player.level.clip(new ClipContext(near.add(viewerPos), far.add(viewerPos), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)); if (result != null && result.getType() == HitResult.Type.BLOCK) { currentMouseOver = ((BlockHitResult) result).getBlockPos(); - System.out.println("currentMouseOver = " + currentMouseOver); } } } From 402079d7db82ccf0224e6d77a6d8d16ac748e28a Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 9 Jun 2024 16:29:39 +0200 Subject: [PATCH 06/12] Fail if there is no target position --- src/main/java/baritone/process/FarmProcess.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index aea598807..c0703581f 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -359,6 +359,14 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro } } } + if (goalz.isEmpty()) { + logDirect("Farm failed"); + if (Baritone.settings().notificationOnFarmFail.value) { + logNotification("Farm failed", true); + } + onLostControl(); + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + } return new PathingCommand(new GoalComposite(goalz.toArray(new Goal[0])), PathingCommandType.SET_GOAL_AND_PATH); } From 10851ddf1404313390c147166cf3c3cef088b666 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 9 Jun 2024 16:38:02 +0200 Subject: [PATCH 07/12] Only create scan list when needed --- .../java/baritone/process/FarmProcess.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index c0703581f..b574ab7e6 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -191,19 +191,19 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro @Override public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { - ArrayList scan = new ArrayList<>(); - for (Harvest harvest : Harvest.values()) { - scan.add(harvest.block); - } - if (Baritone.settings().replantCrops.value) { - scan.add(Blocks.FARMLAND); - scan.add(Blocks.JUNGLE_LOG); - if (Baritone.settings().replantNetherWart.value) { - scan.add(Blocks.SOUL_SAND); - } - } - if (Baritone.settings().mineGoalUpdateInterval.value != 0 && tickCount++ % Baritone.settings().mineGoalUpdateInterval.value == 0) { + ArrayList scan = new ArrayList<>(); + for (Harvest harvest : Harvest.values()) { + scan.add(harvest.block); + } + if (Baritone.settings().replantCrops.value) { + scan.add(Blocks.FARMLAND); + scan.add(Blocks.JUNGLE_LOG); + if (Baritone.settings().replantNetherWart.value) { + scan.add(Blocks.SOUL_SAND); + } + } + Baritone.getExecutor().execute(() -> locations = BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(ctx, scan, 256, 10, 10)); } if (locations == null) { From 98e90e72f77fdcecd2199f3284536a33241babc0 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 9 Jun 2024 17:56:18 +0200 Subject: [PATCH 08/12] Make farm scan limit configurable --- src/api/java/baritone/api/Settings.java | 5 +++++ src/main/java/baritone/process/FarmProcess.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 071354620..1812fe486 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -973,6 +973,11 @@ public final class Settings { */ public final Setting replantNetherWart = new Setting<>(false); + /** + * Farming will scan for at most this many blocks. + */ + public final Setting farmMaxScanSize = new Setting<>(256); + /** * When the cache scan gives less blocks than the maximum threshold (but still above zero), scan the main world too. *

diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index b574ab7e6..0dc0905a5 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -204,7 +204,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro } } - Baritone.getExecutor().execute(() -> locations = BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(ctx, scan, 256, 10, 10)); + Baritone.getExecutor().execute(() -> locations = BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(ctx, scan, Baritone.settings().farmMaxScanSize.value, 10, 10)); } if (locations == null) { return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); From b25a6305ce23d68ffb2c948418668599789bcee7 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 9 Jun 2024 17:58:10 +0200 Subject: [PATCH 09/12] Don't bother testing reachability for far away blocks This is a massive performance improvement for big farms. --- .../java/baritone/process/FarmProcess.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index 0dc0905a5..399799f58 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -256,7 +256,12 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro } baritone.getInputOverrideHandler().clearAllKeys(); + BetterBlockPos playerPos = ctx.playerFeet(); + double blockReachDistance = ctx.playerController().getBlockReachDistance(); for (BlockPos pos : toBreak) { + if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) { + continue; + } Optional rot = RotationUtils.reachable(ctx, pos); if (rot.isPresent() && isSafeToCancel) { baritone.getLookBehavior().updateTarget(rot.get(), true); @@ -270,10 +275,13 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro ArrayList both = new ArrayList<>(openFarmland); both.addAll(openSoulsand); for (BlockPos pos : both) { + if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) { + continue; + } boolean soulsand = openSoulsand.contains(pos); - Optional rot = RotationUtils.reachableOffset(ctx, pos, new Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false); + Optional rot = RotationUtils.reachableOffset(ctx, pos, new Vec3(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), blockReachDistance, false); if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) { - HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance()); + HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), blockReachDistance); if (result instanceof BlockHitResult && ((BlockHitResult) result).getDirection() == Direction.UP) { baritone.getLookBehavior().updateTarget(rot.get(), true); if (ctx.isLookingAt(pos)) { @@ -284,14 +292,17 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro } } for (BlockPos pos : openLog) { + if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) { + continue; + } for (Direction dir : Direction.Plane.HORIZONTAL) { if (!(ctx.world().getBlockState(pos.relative(dir)).getBlock() instanceof AirBlock)) { continue; } Vec3 faceCenter = Vec3.atCenterOf(pos).add(Vec3.atLowerCornerOf(dir.getNormal()).scale(0.5)); - Optional rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, ctx.playerController().getBlockReachDistance(), false); + Optional rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, blockReachDistance, false); if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isCocoa)) { - HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance()); + HitResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), blockReachDistance); if (result instanceof BlockHitResult && ((BlockHitResult) result).getDirection() == dir) { baritone.getLookBehavior().updateTarget(rot.get(), true); if (ctx.isLookingAt(pos)) { @@ -303,6 +314,9 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro } } for (BlockPos pos : bonemealable) { + if (playerPos.distSqr(pos) > blockReachDistance * blockReachDistance) { + continue; + } Optional rot = RotationUtils.reachable(ctx, pos); if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isBoneMeal)) { baritone.getLookBehavior().updateTarget(rot.get(), true); From 42c62a05593c1e7a58b620632d19ba9ba8d1f87d Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sun, 16 Jun 2024 23:46:27 -0500 Subject: [PATCH 10/12] clean up proguard task --- build.gradle | 10 +- .../gradle/task/BaritoneGradleTask.java | 4 +- .../baritone/gradle/task/ProguardTask.java | 154 ++++-------------- fabric/build.gradle | 3 +- forge/build.gradle | 3 +- gradle.properties | 4 + tweaker/build.gradle | 3 +- 7 files changed, 45 insertions(+), 136 deletions(-) diff --git a/build.gradle b/build.gradle index 4ffc147e0..822832aad 100755 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,13 @@ allprojects { } group = rootProject.maven_group - sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = targetCompatibility = JavaVersion.toVersion(project.java_version) + + java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(sourceCompatibility.majorVersion.toInteger())) + } + } repositories { maven { @@ -93,7 +99,7 @@ allprojects { tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" - def targetVersion = 17 + def targetVersion = project.java_version.toInteger() if (JavaVersion.current().isJava9Compatible()) { it.options.release = targetVersion } diff --git a/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java b/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java index 2dad551f2..f27df9aaa 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/BaritoneGradleTask.java @@ -36,8 +36,8 @@ import java.nio.file.Paths; class BaritoneGradleTask extends DefaultTask { protected static final String - PROGUARD_ZIP = "proguard.zip", - PROGUARD_JAR = "proguard.jar", + PROGUARD_ZIP = "proguard-%s.zip", + PROGUARD_JAR = "proguard-%s.jar", PROGUARD_CONFIG_TEMPLATE = "scripts/proguard.pro", PROGUARD_CONFIG_DEST = "template.pro", PROGUARD_API_CONFIG = "api.pro", diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index a9c7f94ea..d5e05a19c 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -26,6 +26,9 @@ import org.gradle.api.tasks.TaskCollection; import org.gradle.api.tasks.compile.ForkOptions; import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.internal.jvm.Jvm; +import org.gradle.jvm.toolchain.JavaLanguageVersion; +import org.gradle.jvm.toolchain.JavaLauncher; +import org.gradle.jvm.toolchain.JavaToolchainService; import xyz.wagyourtail.unimined.api.UniminedExtension; import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig; @@ -47,17 +50,10 @@ import java.util.zip.ZipFile; public class ProguardTask extends BaritoneGradleTask { @Input - private String url; + private String proguardVersion; - public String getUrl() { - return url; - } - - @Input - private String extract; - - public String getExtract() { - return extract; + public String getProguardVersion() { + return proguardVersion; } private List requiredLibraries; @@ -99,98 +95,33 @@ public class ProguardTask extends BaritoneGradleTask { } private void downloadProguard() throws Exception { - Path proguardZip = getTemporaryFile(PROGUARD_ZIP); + Path proguardZip = getTemporaryFile(String.format(PROGUARD_ZIP, proguardVersion)); if (!Files.exists(proguardZip)) { - write(new URL(this.url).openStream(), proguardZip); + write(new URL(String.format("https://github.com/Guardsquare/proguard/releases/download/v%s/proguard-%s.zip", proguardVersion, proguardVersion)).openStream(), proguardZip); } } private void extractProguard() throws Exception { - Path proguardJar = getTemporaryFile(PROGUARD_JAR); + Path proguardJar = getTemporaryFile(String.format(PROGUARD_JAR, proguardVersion)); if (!Files.exists(proguardJar)) { - ZipFile zipFile = new ZipFile(getTemporaryFile(PROGUARD_ZIP).toFile()); - ZipEntry zipJarEntry = zipFile.getEntry(this.extract); + ZipFile zipFile = new ZipFile(getTemporaryFile(String.format(PROGUARD_ZIP, proguardVersion)).toFile()); + ZipEntry zipJarEntry = zipFile.getEntry(String.format("proguard-%s/lib/proguard.jar", proguardVersion)); write(zipFile.getInputStream(zipJarEntry), proguardJar); zipFile.close(); } } - private String getJavaBinPathForProguard() throws Exception { - 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(); + private JavaLauncher getJavaLauncherForProguard() { + var toolchains = getProject().getExtensions().getByType(JavaToolchainService.class); + var toolchain = toolchains.launcherFor((spec) -> { + spec.getLanguageVersion().set(JavaLanguageVersion.of(getProject().findProperty("java_version").toString())); + }).getOrNull(); + + if (toolchain == null) { + throw new IllegalStateException("Java toolchain not found"); } - path = findJavaByGradleCurrentRuntime(); - if (path != null) return path; - - try { - path = findJavaByJavaHome(); - if (path != null) return path; - } catch (Exception ex) { - System.err.println("Unable to find java by JAVA_HOME"); - ex.printStackTrace(); - } - - 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)"); - } - - private String findJavaByGradleCurrentRuntime() { - String path = Jvm.current().getJavaExecutable().getAbsolutePath(); - System.out.println("Using Gradle's runtime Java for ProGuard"); - return path; - } - - private String findJavaByJavaHome() { - final String javaHomeEnv = System.getenv("JAVA_HOME"); - if (javaHomeEnv != null) { - String path = Jvm.forHome(new File(javaHomeEnv)).getJavaExecutable().getAbsolutePath(); - System.out.println("Detected Java path by JAVA_HOME"); - return path; - } - return null; - } - - private String findJavaPathByGradleConfig() { - final TaskCollection 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((dir, name) -> name.equals("java")); - if (maybeJava != null && maybeJava.length > 0) { - String path = maybeJava[0].getAbsolutePath(); - System.out.println("Detected Java path by forkOptions"); - return path; - } - } - } - } - return null; - } - - private boolean validateJavaVersion(String java) { - //TODO: fix for j16 -// 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; + return toolchain; } private void generateConfigs() throws Exception { @@ -284,13 +215,8 @@ public class ProguardTask extends BaritoneGradleTask { } catch (IOException ignored) {} } - public void setUrl(String url) { - this.url = url; - } - - - public void setExtract(String extract) { - this.extract = extract; + public void setProguardVersion(String url) { + this.proguardVersion = url; } private void runProguard(Path config) throws Exception { @@ -299,39 +225,15 @@ public class ProguardTask extends BaritoneGradleTask { Files.delete(this.proguardOut); } - // Make paths relative to work directory; fixes spaces in path to config, @"" doesn't work Path workingDirectory = getTemporaryFile(""); - Path proguardJar = workingDirectory.relativize(getTemporaryFile(PROGUARD_JAR)); - config = workingDirectory.relativize(config); - // Honestly, if you still have spaces in your path at this point, you're SOL. + getProject().javaexec(spec -> { + spec.workingDir(workingDirectory.toFile()); + spec.args("@" + workingDirectory.relativize(config)); + spec.classpath(getTemporaryFile(String.format(PROGUARD_JAR, proguardVersion))); - Process p = new ProcessBuilder("java", "-jar", proguardJar.toString(), "@" + config.toString()) - .directory(workingDirectory.toFile()) // Set the working directory to the temporary folder] - .start(); - - // We can't do output inherit process I/O with gradle for some reason and have it work, so we have to do this - this.printOutputLog(p.getInputStream(), System.out); - this.printOutputLog(p.getErrorStream(), System.err); - - // Halt the current thread until the process is complete, if the exit code isn't 0, throw an exception - int exitCode = p.waitFor(); - if (exitCode != 0) { - Thread.sleep(1000); - throw new IllegalStateException("Proguard exited with code " + exitCode); - } + spec.executable(getJavaLauncherForProguard().getExecutablePath().getAsFile()); + }).assertNormalExitValue().rethrowFailure(); } - private void printOutputLog(InputStream stream, PrintStream outerr) { - new Thread(() -> { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) { - String line; - while ((line = reader.readLine()) != null) { - outerr.println(line); - } - } catch (Exception e) { - e.printStackTrace(); - } - }).start(); - } } diff --git a/fabric/build.gradle b/fabric/build.gradle index e0d5d8442..caeb009aa 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -78,8 +78,7 @@ components.java { } task proguard(type: ProguardTask) { - url 'https://github.com/Guardsquare/proguard/releases/download/v7.2.1/proguard-7.2.1.zip' - extract 'proguard-7.2.1/lib/proguard.jar' + proguardVersion "7.2.1" compType "fabric" } diff --git a/forge/build.gradle b/forge/build.gradle index 334bd968c..b2c81567e 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -99,8 +99,7 @@ components.java { } task proguard(type: ProguardTask) { - url 'https://github.com/Guardsquare/proguard/releases/download/v7.2.1/proguard-7.2.1.zip' - extract 'proguard-7.2.1/lib/proguard.jar' + proguardVersion "7.2.1" compType "forge" } diff --git a/gradle.properties b/gradle.properties index d3db032c2..77516438f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,12 @@ mod_version=1.9.3 maven_group=baritone archives_base_name=baritone +java_version=17 + minecraft_version=1.19.4 + forge_version=45.0.43 + fabric_version=0.14.11 nether_pathfinder_version=1.4.1 \ No newline at end of file diff --git a/tweaker/build.gradle b/tweaker/build.gradle index 724c50d29..d6662a5de 100644 --- a/tweaker/build.gradle +++ b/tweaker/build.gradle @@ -95,8 +95,7 @@ jar { } task proguard(type: ProguardTask) { - url 'https://github.com/Guardsquare/proguard/releases/download/v7.2.1/proguard-7.2.1.zip' - extract 'proguard-7.2.1/lib/proguard.jar' + proguardVersion "7.2.1" } task createDist(type: CreateDistTask, dependsOn: proguard) From 52aa609ac7a70e532d3afa160f422e2b822ce740 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 14 Jul 2024 10:37:31 +0200 Subject: [PATCH 11/12] Add bamboo to `FarmProcess` targets --- src/main/java/baritone/process/FarmProcess.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index 399799f58..05b893a27 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -42,6 +42,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.AirBlock; +import net.minecraft.world.level.block.BambooStalkBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.BonemealableBlock; @@ -95,6 +96,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro Items.NETHER_WART, Items.COCOA_BEANS, Blocks.SUGAR_CANE.asItem(), + Blocks.BAMBOO.asItem(), Blocks.CACTUS.asItem() ); @@ -137,6 +139,15 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro return true; } }, + BAMBOO(Blocks.BAMBOO, null) { + @Override + public boolean readyToHarvest(Level world, BlockPos pos, BlockState state) { + if (Baritone.settings().replantCrops.value) { + return world.getBlockState(pos.below()).getBlock() instanceof BambooStalkBlock; + } + return true; + } + }, CACTUS(Blocks.CACTUS, null) { @Override public boolean readyToHarvest(Level world, BlockPos pos, BlockState state) { From 1947459acf42e3afafdd9028d7ffe319d9b01a5d Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Mon, 31 Jul 2023 17:46:58 +0200 Subject: [PATCH 12/12] Move tweak class to its own package Launchwrapper automatically adds a classloader exclusion for every package containing a tweak class, forcing the whole package to load through the parent class loader. --- buildSrc/src/main/java/baritone/gradle/util/Determinizer.java | 4 ++-- tweaker/build.gradle | 2 +- .../java/baritone/launch/{ => tweaker}/BaritoneTweaker.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename tweaker/src/main/java/baritone/launch/{ => tweaker}/BaritoneTweaker.java (98%) diff --git a/buildSrc/src/main/java/baritone/gradle/util/Determinizer.java b/buildSrc/src/main/java/baritone/gradle/util/Determinizer.java index 781aaec24..04bd74947 100644 --- a/buildSrc/src/main/java/baritone/gradle/util/Determinizer.java +++ b/buildSrc/src/main/java/baritone/gradle/util/Determinizer.java @@ -71,10 +71,10 @@ public class Determinizer { ByteArrayOutputStream cancer = new ByteArrayOutputStream(); copy(jarFile.getInputStream(entry), cancer); String manifest = new String(cancer.toByteArray()); - if (!manifest.contains("baritone.launch.BaritoneTweaker")) { + if (!manifest.contains("baritone.launch.tweaker.BaritoneTweaker")) { throw new IllegalStateException("unable to replace"); } - manifest = manifest.replace("baritone.launch.BaritoneTweaker", "org.spongepowered.asm.launch.MixinTweaker"); + manifest = manifest.replace("baritone.launch.tweaker.BaritoneTweaker", "org.spongepowered.asm.launch.MixinTweaker"); jos.write(manifest.getBytes()); } else { copy(jarFile.getInputStream(entry), jos); diff --git a/tweaker/build.gradle b/tweaker/build.gradle index d6662a5de..d4345485b 100644 --- a/tweaker/build.gradle +++ b/tweaker/build.gradle @@ -26,7 +26,7 @@ plugins { unimined.minecraft { runs.client = { mainClass = "net.minecraft.launchwrapper.Launch" - args.addAll(["--tweakClass", "baritone.launch.BaritoneTweaker"]) + args.addAll(["--tweakClass", "baritone.launch.tweaker.BaritoneTweaker"]) } } diff --git a/tweaker/src/main/java/baritone/launch/BaritoneTweaker.java b/tweaker/src/main/java/baritone/launch/tweaker/BaritoneTweaker.java similarity index 98% rename from tweaker/src/main/java/baritone/launch/BaritoneTweaker.java rename to tweaker/src/main/java/baritone/launch/tweaker/BaritoneTweaker.java index b9db9b6a5..694aef533 100644 --- a/tweaker/src/main/java/baritone/launch/BaritoneTweaker.java +++ b/tweaker/src/main/java/baritone/launch/tweaker/BaritoneTweaker.java @@ -15,7 +15,7 @@ * along with Baritone. If not, see . */ -package baritone.launch; +package baritone.launch.tweaker; import io.github.impactdevelopment.simpletweaker.SimpleTweaker; import net.minecraft.launchwrapper.Launch;