From e6ee5fc6b84c17164633607a43aed12477839cde Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sat, 5 Mar 2022 17:56:20 +0100 Subject: [PATCH 01/78] Make positions from #find clickable --- .../command/defaults/FindCommand.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/FindCommand.java b/src/main/java/baritone/command/defaults/FindCommand.java index 65eb9b5c3..b20857b4c 100644 --- a/src/main/java/baritone/command/defaults/FindCommand.java +++ b/src/main/java/baritone/command/defaults/FindCommand.java @@ -24,12 +24,19 @@ import baritone.api.command.datatypes.BlockById; import baritone.api.command.exception.CommandException; import baritone.api.utils.BetterBlockPos; import net.minecraft.block.Block; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.event.ClickEvent; +import net.minecraft.util.text.event.HoverEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Stream; +import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; + public class FindCommand extends Command { public FindCommand(IBaritone baritone) { @@ -54,10 +61,23 @@ public class FindCommand extends Command { ).stream() ) .map(BetterBlockPos::new) - .map(BetterBlockPos::toString) + .map(this::positionToComponent) .forEach(this::logDirect); } + private ITextComponent positionToComponent(BetterBlockPos pos) { + String positionText = String.format("%s %s %s", pos.x, pos.y, pos.z); + String command = String.format("%sgoal %s", FORCE_COMMAND_PREFIX, positionText); + ITextComponent baseComponent = new TextComponentString(pos.toString()); + ITextComponent hoverComponent = new TextComponentString("Click to set goal to this position"); + baseComponent.getStyle() + .setColor(TextFormatting.GRAY) + .setInsertion(positionText) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)) + .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent)); + return baseComponent; + } + @Override public Stream tabComplete(String label, IArgConsumer args) { return args.tabCompleteDatatype(BlockById.INSTANCE); From ef4e19002b9f6453907cc59928d0837a0911200c Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sat, 5 Mar 2022 21:04:24 +0100 Subject: [PATCH 02/78] Provide more information for #find Always log something to chat so people don't think it's broken and make sure they know about the restriction to cached blocks. --- .../command/defaults/FindCommand.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/command/defaults/FindCommand.java b/src/main/java/baritone/command/defaults/FindCommand.java index b20857b4c..b20f14e98 100644 --- a/src/main/java/baritone/command/defaults/FindCommand.java +++ b/src/main/java/baritone/command/defaults/FindCommand.java @@ -22,7 +22,9 @@ import baritone.api.command.Command; import baritone.api.command.argument.IArgConsumer; import baritone.api.command.datatypes.BlockById; import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.TabCompleteHelper; import baritone.api.utils.BetterBlockPos; +import baritone.cache.CachedChunk; import net.minecraft.block.Block; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; @@ -45,12 +47,13 @@ public class FindCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { + args.requireMin(1); List toFind = new ArrayList<>(); while (args.hasAny()) { toFind.add(args.getDatatypeFor(BlockById.INSTANCE)); } BetterBlockPos origin = ctx.playerFeet(); - toFind.stream() + ITextComponent[] components = toFind.stream() .flatMap(block -> ctx.worldData().getCachedWorld().getLocationsOf( Block.REGISTRY.getNameForObject(block).getPath(), @@ -62,7 +65,12 @@ public class FindCommand extends Command { ) .map(BetterBlockPos::new) .map(this::positionToComponent) - .forEach(this::logDirect); + .toArray(ITextComponent[]::new); + if (components.length > 0) { + Arrays.asList(components).forEach(this::logDirect); + } else { + logDirect("No positions known, are you sure the blocks are cached?"); + } } private ITextComponent positionToComponent(BetterBlockPos pos) { @@ -79,8 +87,16 @@ public class FindCommand extends Command { } @Override - public Stream tabComplete(String label, IArgConsumer args) { - return args.tabCompleteDatatype(BlockById.INSTANCE); + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { + return new TabCompleteHelper() + .append( + CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.stream() + .map(Block.REGISTRY::getNameForObject) + .map(Object::toString) + ) + .filterPrefixNamespaced(args.getString()) + .sortAlphabetically() + .stream(); } @Override @@ -92,9 +108,10 @@ public class FindCommand extends Command { public List getLongDesc() { return Arrays.asList( "The find command searches through Baritone's cache and attempts to find the location of the block.", + "Tab completion will suggest only cached blocks and uncached blocks can not be found.", "", "Usage:", - "> find - Find positions of a certain block" + "> find [...] - Try finding the listed blocks" ); } } From af1eb58bb87cbb7ce38e01a6fcf96def3222850c Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Tue, 31 May 2022 14:43:58 +0100 Subject: [PATCH 03/78] Implement Leijurv's precomputed data idea --- src/api/java/baritone/api/Settings.java | 6 + .../api/event/events/SettingChangedEvent.java | 33 +++ .../listener/AbstractGameEventListener.java | 3 + .../event/listener/IGameEventListener.java | 7 + .../java/baritone/api/utils/SettingsUtil.java | 4 +- .../baritone/behavior/PathingBehavior.java | 17 +- .../baritone/command/defaults/SetCommand.java | 3 +- .../java/baritone/event/GameEventHandler.java | 5 + .../pathing/movement/CalculationContext.java | 8 +- .../pathing/movement/MovementHelper.java | 3 + .../movement/movements/MovementAscend.java | 4 +- .../movement/movements/MovementDescend.java | 12 +- .../movement/movements/MovementDiagonal.java | 30 +-- .../movement/movements/MovementDownward.java | 2 +- .../movement/movements/MovementParkour.java | 6 +- .../movement/movements/MovementPillar.java | 2 +- .../movement/movements/MovementTraverse.java | 2 +- .../baritone/pathing/path/PathExecutor.java | 2 +- .../pathing/precompute/PrecomputedData.java | 237 ++++++++++++++++++ .../PrecomputedDataForBlockState.java | 71 ++++++ .../java/baritone/process/BuilderProcess.java | 3 +- .../baritone/process/GetToBlockProcess.java | 2 +- .../java/baritone/process/MineProcess.java | 2 +- 23 files changed, 422 insertions(+), 42 deletions(-) create mode 100644 src/api/java/baritone/api/event/events/SettingChangedEvent.java create mode 100644 src/main/java/baritone/pathing/precompute/PrecomputedData.java create mode 100644 src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 897182898..1ce87c681 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -17,6 +17,7 @@ package baritone.api; +import baritone.api.event.events.SettingChangedEvent; import baritone.api.utils.NotificationHelper; import baritone.api.utils.SettingsUtil; import baritone.api.utils.TypeUtils; @@ -1302,6 +1303,11 @@ public final class Settings { return value; } + public void set(T value) { + this.value = value; + BaritoneAPI.getProvider().getAllBaritones().forEach(iBaritone -> iBaritone.getGameEventHandler().onSettingChanged(new SettingChangedEvent(this))); + } + public final String getName() { return name; } diff --git a/src/api/java/baritone/api/event/events/SettingChangedEvent.java b/src/api/java/baritone/api/event/events/SettingChangedEvent.java new file mode 100644 index 000000000..d92384e03 --- /dev/null +++ b/src/api/java/baritone/api/event/events/SettingChangedEvent.java @@ -0,0 +1,33 @@ +/* + * 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.api.event.events; + +import baritone.api.Settings; + +public class SettingChangedEvent { + + private final Settings.Setting setting; + + public SettingChangedEvent(Settings.Setting setting) { + this.setting = setting; + } + + public Settings.Setting getSetting() { + return setting; + } +} diff --git a/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java b/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java index 9eac8de46..9f1d2418a 100644 --- a/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java +++ b/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java @@ -71,4 +71,7 @@ public interface AbstractGameEventListener extends IGameEventListener { @Override default void onPathEvent(PathEvent event) {} + + @Override + default void onSettingChanged(SettingChangedEvent event) {} } diff --git a/src/api/java/baritone/api/event/listener/IGameEventListener.java b/src/api/java/baritone/api/event/listener/IGameEventListener.java index b074e978b..28afdfffe 100644 --- a/src/api/java/baritone/api/event/listener/IGameEventListener.java +++ b/src/api/java/baritone/api/event/listener/IGameEventListener.java @@ -144,4 +144,11 @@ public interface IGameEventListener { * @param event The event */ void onPathEvent(PathEvent event); + + /** + * When the player changes a setting + * + * @param event The event + */ + void onSettingChanged(SettingChangedEvent event); } diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index 0e95965f9..b098c1e0f 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -176,7 +176,7 @@ public class SettingsUtil { /** * This should always be the same as whether the setting can be parsed from or serialized to a string * - * @param the setting + * @param setting The Setting * @return true if the setting can not be set or read by the user */ public static boolean javaOnlySetting(Settings.Setting setting) { @@ -199,7 +199,7 @@ public class SettingsUtil { if (!intendedType.isInstance(parsed)) { throw new IllegalStateException(ioMethod + " parser returned incorrect type, expected " + intendedType + " got " + parsed + " which is " + parsed.getClass()); } - setting.value = parsed; + setting.set(parsed); } private interface ISettingParser { diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index f9c56c5a4..50e2a0c2e 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -33,6 +33,7 @@ import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; import baritone.pathing.path.PathExecutor; +import baritone.pathing.precompute.PrecomputedData; import baritone.utils.PathRenderer; import baritone.utils.PathingCommandContext; import baritone.utils.pathing.Favoring; @@ -74,8 +75,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, private final LinkedBlockingQueue toDispatch = new LinkedBlockingQueue<>(); + public PrecomputedData precomputedData; + public PathingBehavior(Baritone baritone) { super(baritone); + precomputedData = new PrecomputedData(); } private void queuePathEvent(PathEvent event) { @@ -259,7 +263,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, if (command instanceof PathingCommandContext) { context = ((PathingCommandContext) command).desiredCalcContext; } else { - context = new CalculationContext(baritone, true); + context = new CalculationContext(baritone, true, precomputedData); } if (goal == null) { return false; @@ -418,7 +422,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, */ public BetterBlockPos pathStart() { // TODO move to a helper or util class BetterBlockPos feet = ctx.playerFeet(); - if (!MovementHelper.canWalkOn(ctx, feet.down())) { + if (!precomputedData.canWalkOn(ctx, feet.down())) { if (ctx.player().onGround) { double playerX = ctx.player().posX; double playerZ = ctx.player().posZ; @@ -437,7 +441,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, // can't possibly be sneaking off of this one, we're too far away continue; } - if (MovementHelper.canWalkOn(ctx, possibleSupport.down()) && MovementHelper.canWalkThrough(ctx, possibleSupport) && MovementHelper.canWalkThrough(ctx, possibleSupport.up())) { + if (precomputedData.canWalkOn(ctx, possibleSupport.down()) && precomputedData.canWalkThrough(ctx, possibleSupport) && context.precomputedData.canWalkThrough(ctx, possibleSupport.up())) { // this is plausible //logDebug("Faking path start assuming player is standing off the edge of a block"); return possibleSupport; @@ -447,7 +451,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } else { // !onGround // we're in the middle of a jump - if (MovementHelper.canWalkOn(ctx, feet.down().down())) { + if (precomputedData.canWalkOn(ctx, feet.down().down())) { //logDebug("Faking path start assuming player is midair and falling"); return feet.down(); } @@ -456,6 +460,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, return feet; } + @Override + public void onSettingChanged(SettingChangedEvent event) { + this.precomputedData.refresh(); + } + /** * In a new thread, pathfind to target blockpos * diff --git a/src/main/java/baritone/command/defaults/SetCommand.java b/src/main/java/baritone/command/defaults/SetCommand.java index e9e35d413..1b395f5a9 100644 --- a/src/main/java/baritone/command/defaults/SetCommand.java +++ b/src/main/java/baritone/command/defaults/SetCommand.java @@ -147,7 +147,8 @@ public class SetCommand extends Command { throw new CommandInvalidTypeException(args.consumed(), "a toggleable setting", "some other setting"); } //noinspection unchecked - ((Settings.Setting) setting).value ^= true; + Settings.Setting asBoolSetting = (Settings.Setting) setting; + asBoolSetting.set(!asBoolSetting.value); logDirect(String.format( "Toggled setting %s to %s", setting.getName(), diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index 8916f7f37..1bdba6b9a 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -156,6 +156,11 @@ public final class GameEventHandler implements IEventBus, Helper { listeners.forEach(l -> l.onPathEvent(event)); } + @Override + public void onSettingChanged(SettingChangedEvent event) { + listeners.forEach(l -> l.onSettingChanged(event)); + } + @Override public final void registerEventListener(IGameEventListener listener) { this.listeners.add(listener); diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index d5d6c93c8..b4782fb59 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -21,6 +21,7 @@ import baritone.Baritone; import baritone.api.IBaritone; import baritone.api.pathing.movement.ActionCosts; import baritone.cache.WorldData; +import baritone.pathing.precompute.PrecomputedData; import baritone.utils.BlockStateInterface; import baritone.utils.ToolSet; import baritone.utils.pathing.BetterWorldBorder; @@ -76,11 +77,14 @@ public class CalculationContext { public final double walkOnWaterOnePenalty; public final BetterWorldBorder worldBorder; + public final PrecomputedData precomputedData; + public CalculationContext(IBaritone baritone) { - this(baritone, false); + this(baritone, false, new PrecomputedData()); } - public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) { + public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread, PrecomputedData precomputedData) { + this.precomputedData = precomputedData; this.safeForThreadedUse = forUseOnAnotherThread; this.baritone = baritone; EntityPlayerSP player = baritone.getPlayerContext().player(); diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index dd0ddff48..197f10576 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -88,6 +88,7 @@ public interface MovementHelper extends ActionCosts, Helper { return canWalkThrough(bsi, x, y, z, bsi.get0(x, y, z)); } + // if changing something in this function remember to also change it in precomputed data static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { Block block = state.getBlock(); if (block == Blocks.AIR) { // early return for most common case @@ -285,6 +286,8 @@ public interface MovementHelper extends ActionCosts, Helper { * through? Includes water because we know that we automatically jump on * water * + * If changing something in this function remember to also change it in precomputed data + * * @param bsi Block state provider * @param x The block's x position * @param y The block's y position diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 161ffdacd..bbc09f521 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -68,7 +68,7 @@ public class MovementAscend extends Movement { public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { IBlockState toPlace = context.get(destX, y, destZ); double additionalPlacementCost = 0; - if (!MovementHelper.canWalkOn(context.bsi, destX, y, destZ, toPlace)) { + if (!context.precomputedData.canWalkOn(context.bsi, x, y, z, toPlace)) { additionalPlacementCost = context.costOfPlacingAt(destX, y, destZ, toPlace); if (additionalPlacementCost >= COST_INF) { return COST_INF; @@ -94,7 +94,7 @@ public class MovementAscend extends Movement { } } IBlockState srcUp2 = context.get(x, y + 2, z); // used lower down anyway - if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(context.bsi, x, y + 1, z) || !(srcUp2.getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us + if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (context.precomputedData.canWalkThrough(context.bsi, x, y + 1, z) || !(srcUp2.getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us // HOWEVER, we assume that we're standing in the start position // that means that src and src.up(1) are both air // maybe they aren't now, but they will be by the time this starts diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 128d1bf99..d0f7d9b3f 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -101,7 +101,7 @@ public class MovementDescend extends Movement { //C, D, etc determine the length of the fall IBlockState below = context.get(destX, y - 2, destZ); - if (!MovementHelper.canWalkOn(context.bsi, destX, y - 2, destZ, below)) { + if (!context.precomputedData.canWalkOn(context.bsi, destX, y - 2, destZ, below)) { dynamicFallCost(context, x, y, z, destX, destZ, totalCost, below, res); return; } @@ -130,7 +130,7 @@ public class MovementDescend extends Movement { // and potentially replace the water we're going to fall into return false; } - if (!MovementHelper.canWalkThrough(context.bsi, destX, y - 2, destZ, below)) { + if (!context.precomputedData.canWalkThrough(context.bsi, destX, y - 2, destZ, below)) { return false; } double costSoFar = 0; @@ -146,7 +146,7 @@ public class MovementDescend extends Movement { int unprotectedFallHeight = fallHeight - (y - effectiveStartHeight); // equal to fallHeight - y + effectiveFallHeight, which is equal to -newY + effectiveFallHeight, which is equal to effectiveFallHeight - newY double tentativeCost = WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[unprotectedFallHeight] + frontBreak + costSoFar; if (MovementHelper.isWater(ontoBlock.getBlock())) { - if (!MovementHelper.canWalkThrough(context.bsi, destX, newY, destZ, ontoBlock)) { + if (!context.precomputedData.canWalkThrough(context.bsi, destX, newY, destZ, ontoBlock)) { return false; } if (context.assumeWalkOnWater) { @@ -155,7 +155,7 @@ public class MovementDescend extends Movement { if (MovementHelper.isFlowing(destX, newY, destZ, ontoBlock, context.bsi)) { return false; // TODO flowing check required here? } - if (!MovementHelper.canWalkOn(context.bsi, destX, newY - 1, destZ)) { + if (!context.precomputedData.canWalkOn(context.bsi, destX, newY - 1, destZ)) { // we could punch right through the water into something else return false; } @@ -174,10 +174,10 @@ public class MovementDescend extends Movement { effectiveStartHeight = newY; continue; } - if (MovementHelper.canWalkThrough(context.bsi, destX, newY, destZ, ontoBlock)) { + if (context.precomputedData.canWalkThrough(context.bsi, destX, newY, destZ, ontoBlock)) { continue; } - if (!MovementHelper.canWalkOn(context.bsi, destX, newY, destZ, ontoBlock)) { + if (!context.precomputedData.canWalkOn(context.bsi, destX, newY, destZ, ontoBlock)) { return false; } if (MovementHelper.isBottomSlab(ontoBlock)) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 933c86092..45d319eb6 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -58,9 +58,9 @@ public class MovementDiagonal extends Movement { } @Override - protected boolean safeToCancel(MovementState state) { + protected boolean safeToCancel(MovementState state) { // TODO move this function to use precomputed data, not urgent as it only runs once a tick //too simple. backfill does not work after cornering with this - //return MovementHelper.canWalkOn(ctx, ctx.playerFeet().down()); + //return context.precomputedData.canWalkOn(ctx, ctx.playerFeet().down()); EntityPlayerSP player = ctx.player(); double offset = 0.25; double x = player.posX; @@ -110,24 +110,24 @@ public class MovementDiagonal extends Movement { } public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) { - if (!MovementHelper.canWalkThrough(context.bsi, destX, y + 1, destZ)) { + if (!context.precomputedData.canWalkThrough(context.bsi, destX, y + 1, destZ)) { return; } IBlockState destInto = context.get(destX, y, destZ); boolean ascend = false; IBlockState destWalkOn; boolean descend = false; - if (!MovementHelper.canWalkThrough(context.bsi, destX, y, destZ, destInto)) { + if (!context.precomputedData.canWalkThrough(context.bsi, destX, y, destZ, destInto)) { ascend = true; - if (!context.allowDiagonalAscend || !MovementHelper.canWalkThrough(context.bsi, x, y + 2, z) || !MovementHelper.canWalkOn(context.bsi, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi, destX, y + 2, destZ)) { + if (!context.allowDiagonalAscend || !context.precomputedData.canWalkThrough(context.bsi, x, y + 2, z) || !context.precomputedData.canWalkOn(context.bsi, destX, y, destZ, destInto) || !context.precomputedData.canWalkThrough(context.bsi, destX, y + 2, destZ)) { return; } destWalkOn = destInto; } else { destWalkOn = context.get(destX, y - 1, destZ); - if (!MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destWalkOn)) { + if (!context.precomputedData.canWalkOn(context.bsi, destX, y - 1, destZ, destWalkOn)) { descend = true; - if (!context.allowDiagonalDescend || !MovementHelper.canWalkOn(context.bsi, destX, y - 2, destZ) || !MovementHelper.canWalkThrough(context.bsi, destX, y - 1, destZ, destWalkOn)) { + if (!context.allowDiagonalDescend || !context.precomputedData.canWalkOn(context.bsi, destX, y - 2, destZ) || !context.precomputedData.canWalkThrough(context.bsi, destX, y - 1, destZ, destWalkOn)) { return; } } @@ -169,17 +169,17 @@ public class MovementDiagonal extends Movement { IBlockState pb0 = context.get(x, y, destZ); IBlockState pb2 = context.get(destX, y, z); if (ascend) { - boolean ATop = MovementHelper.canWalkThrough(context.bsi, x, y + 2, destZ); - boolean AMid = MovementHelper.canWalkThrough(context.bsi, x, y + 1, destZ); - boolean ALow = MovementHelper.canWalkThrough(context.bsi, x, y, destZ, pb0); - boolean BTop = MovementHelper.canWalkThrough(context.bsi, destX, y + 2, z); - boolean BMid = MovementHelper.canWalkThrough(context.bsi, destX, y + 1, z); - boolean BLow = MovementHelper.canWalkThrough(context.bsi, destX, y, z, pb2); + boolean ATop = context.precomputedData.canWalkThrough(context.bsi, x, y + 2, destZ); + boolean AMid = context.precomputedData.canWalkThrough(context.bsi, x, y + 1, destZ); + boolean ALow = context.precomputedData.canWalkThrough(context.bsi, x, y, destZ, pb0); + boolean BTop = context.precomputedData.canWalkThrough(context.bsi, destX, y + 2, z); + boolean BMid = context.precomputedData.canWalkThrough(context.bsi, destX, y + 1, z); + boolean BLow = context.precomputedData.canWalkThrough(context.bsi, destX, y, z, pb2); if ((!(ATop && AMid && ALow) && !(BTop && BMid && BLow)) // no option || MovementHelper.avoidWalkingInto(pb0.getBlock()) // bad || MovementHelper.avoidWalkingInto(pb2.getBlock()) // bad - || (ATop && AMid && MovementHelper.canWalkOn(context.bsi, x, y, destZ, pb0)) // we could just ascend - || (BTop && BMid && MovementHelper.canWalkOn(context.bsi, destX, y, z, pb2)) // we could just ascend + || (ATop && AMid && context.precomputedData.canWalkOn(context.bsi, x, y, destZ, pb0)) // we could just ascend + || (BTop && BMid && context.precomputedData.canWalkOn(context.bsi, destX, y, z, pb2)) // we could just ascend || (!ATop && AMid && ALow) // head bonk A || (!BTop && BMid && BLow)) { // head bonk B return; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index da5e3f893..d10a7d269 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -59,7 +59,7 @@ public class MovementDownward extends Movement { if (!context.allowDownward) { return COST_INF; } - if (!MovementHelper.canWalkOn(context.bsi, x, y - 2, z)) { + if (!context.precomputedData.canWalkOn(context.bsi, x, y - 2, z)) { return COST_INF; } IBlockState down = context.get(x, y - 1, z); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index e5d17b9ac..07140cf12 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -74,7 +74,7 @@ public class MovementParkour extends Movement { return; } IBlockState adj = context.get(x + xDiff, y - 1, z + zDiff); - if (MovementHelper.canWalkOn(context.bsi, x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) + if (context.precomputedData.canWalkOn(context.bsi, x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) // second most common case -- we could just traverse not parkour return; } @@ -122,7 +122,7 @@ public class MovementParkour extends Movement { // check for ascend landing position IBlockState destInto = context.bsi.get0(destX, y, destZ); 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)) { + if (i <= 3 && context.allowParkourAscend && context.canSprint && context.precomputedData.canWalkOn(context.bsi, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) { res.x = destX; res.y = y + 1; res.z = destZ; @@ -135,7 +135,7 @@ public class MovementParkour extends Movement { // check for flat landing position IBlockState landingOn = context.bsi.get0(destX, y - 1, destZ); // farmland needs to be canWalkOn otherwise farm can never work at all, but we want to specifically disallow ending a jump on farmland haha - if (landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, landingOn)) { + if (landingOn.getBlock() != Blocks.FARMLAND && context.precomputedData.canWalkOn(context.bsi, destX, y - 1, destZ, landingOn)) { if (checkOvershootSafety(context.bsi, destX + xDiff, y, destZ + zDiff)) { res.x = destX; res.y = y; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index b9d599334..bcd420ecc 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -120,7 +120,7 @@ public class MovementPillar extends Movement { } } // this is commented because it may have had a purpose, but it's very unclear what it was. it's from the minebot era. - //if (!MovementHelper.canWalkOn(chkPos, check) || MovementHelper.canWalkThrough(chkPos, check)) {//if the block above where we want to break is not a full block, don't do it + //if (!context.precomputedData.canWalkOn(chkPos, check) || context.precomputedData.canWalkThrough(chkPos, check)) {//if the block above where we want to break is not a full block, don't do it // TODO why does canWalkThrough mean this action is COST_INF? // BlockFalling makes sense, and !canWalkOn deals with weird cases like if it were lava // but I don't understand why canWalkThrough makes it impossible diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 1ecf0f92c..2afce2f44 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -72,7 +72,7 @@ public class MovementTraverse extends Movement { IBlockState pb1 = context.get(destX, y, destZ); IBlockState destOn = context.get(destX, y - 1, destZ); Block srcDown = context.getBlock(x, y - 1, z); - if (MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge + if (context.precomputedData.canWalkOn(context.bsi, destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge double WC = WALK_ONE_BLOCK_COST; boolean water = false; if (MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock())) { diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 7e4f76a3b..b28abb618 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -350,7 +350,7 @@ public class PathExecutor implements IPathExecutor, Helper { behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false); // first and foremost, if allowSprint is off, or if we don't have enough hunger, don't try and sprint - if (!new CalculationContext(behavior.baritone).canSprint) { + if (!new CalculationContext(behavior.baritone, false, null).canSprint) { return false; } IMovement current = path.movements().get(pathPosition); diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedData.java b/src/main/java/baritone/pathing/precompute/PrecomputedData.java new file mode 100644 index 000000000..7531c21ac --- /dev/null +++ b/src/main/java/baritone/pathing/precompute/PrecomputedData.java @@ -0,0 +1,237 @@ +/* + * 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.pathing.precompute; + +import baritone.Baritone; +import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.IPlayerContext; +import baritone.pathing.movement.MovementHelper; +import baritone.utils.BlockStateInterface; +import net.minecraft.block.*; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.math.BlockPos; + +import java.util.Optional; + +import static baritone.pathing.movement.MovementHelper.isFlowing; +import static baritone.pathing.movement.MovementHelper.isWater; + +public class PrecomputedData { // TODO add isFullyPassable + + PrecomputedDataForBlockState canWalkOn; + PrecomputedDataForBlockState canWalkThrough; + + public PrecomputedData() { // currently designed for this to be remade on setting change, however that could always be changed + long startTime = System.nanoTime(); + + canWalkOn = new PrecomputedDataForBlockState((state) -> { // this is just copied from the old MovementHelperFunction + Block block = state.getBlock(); + if (block == Blocks.AIR || block == Blocks.MAGMA) { + return Optional.of(false); + } + if (state.isBlockNormalCube()) { + return Optional.of(true); + } + if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.value)) { // TODO reconsider this + return Optional.of(true); + } + if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) { + return Optional.of(true); + } + if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) { + return Optional.of(true); + } + if (isWater(block)) { + return Optional.empty(); + } + if (Baritone.settings().assumeWalkOnLava.value && MovementHelper.isLava(block)) { + return Optional.empty(); + } + + if (block instanceof BlockSlab) { + if (!Baritone.settings().allowWalkOnBottomSlab.value) { + if (((BlockSlab) block).isDouble()) { + return Optional.of(true); + } + return Optional.of(state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM); + } + return Optional.of(true); + } + + return Optional.of(block instanceof BlockStairs); + }, (bsi, x, y, z, blockState) -> { // This should just be water or lava, and could probably be made more efficient + Block block = blockState.getBlock(); + if (isWater(block)) { + // since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()" + // BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think it's a decrease in readability + Block up = bsi.get0(x, y + 1, z).getBlock(); + if (up == Blocks.WATERLILY || up == Blocks.CARPET) { + return true; + } + if (MovementHelper.isFlowing(x, y, z, blockState, bsi) || block == Blocks.FLOWING_WATER) { + // the only scenario in which we can walk on flowing water is if it's under still water with jesus off + return isWater(up) && !Baritone.settings().assumeWalkOnWater.value; + } + // if assumeWalkOnWater is on, we can only walk on water if there isn't water above it + // if assumeWalkOnWater is off, we can only walk on water if there is water above it + return isWater(up) ^ Baritone.settings().assumeWalkOnWater.value; + } + + if (Baritone.settings().assumeWalkOnLava.value && MovementHelper.isLava(block) && !MovementHelper.isFlowing(x, y, z, blockState, bsi)) { + return true; + } + + return false; // If we don't recognise it then we want to just return false to be safe. + }); + + canWalkThrough = new PrecomputedDataForBlockState((blockState) -> { + Block block = blockState.getBlock(); + + if (block == Blocks.AIR) { + return Optional.of(true); + } + + 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 Optional.of(false); + } + + if (Baritone.settings().blocksToAvoid.value.contains(block)) { + return Optional.of(false); + } + + if (block instanceof BlockDoor || block instanceof BlockFenceGate) { + // Because there's no nice method in vanilla to check if a door is openable or not, we just have to assume + // that anything that isn't an iron door isn't openable, ignoring that some doors introduced in mods can't + // be opened by just interacting. + return Optional.of(block != Blocks.IRON_DOOR); + } + + if (block == Blocks.CARPET) { + return Optional.empty(); + } + + if (block instanceof BlockSnow) { + if (blockState.getValue(BlockSnow.LAYERS) >= 3) { + return Optional.of(false); + } + + return Optional.empty(); + } + + if (block instanceof BlockLiquid) { + if (blockState.getValue(BlockLiquid.LEVEL) != 0) { + return Optional.of(false); + } else { + return Optional.empty(); + } + } + + if (block instanceof BlockCauldron) { + return Optional.of(false); + } + + try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information + return Optional.of(block.isPassable(null, null)); + } catch (NullPointerException exception) { + return Optional.empty(); + } + }, (bsi, x, y, z, blockState) -> { + Block block = blockState.getBlock(); + + if (block == Blocks.CARPET) { + return canWalkOn(bsi, x, y - 1, z); + } + + if (block instanceof BlockSnow) { // TODO see if this case is necessary, shouldn't it also check this somewhere else? + return canWalkOn(bsi, x, y - 1, z); + } + + if (block instanceof BlockLiquid) { + if (isFlowing(x, y, z, blockState, bsi)) { + return false; + } + // Everything after this point has to be a special case as it relies on the water not being flowing, which means a special case is needed. + if (Baritone.settings().assumeWalkOnWater.value) { + return false; + } + + IBlockState up = bsi.get0(x, y + 1, z); + if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { + return false; + } + return block == Blocks.WATER || block == Blocks.FLOWING_WATER; + } + + return block.isPassable(bsi.access, bsi.isPassableBlockPos.setPos(x, y, z)); + }); + + long endTime = System.nanoTime(); + + System.out.println(endTime - startTime); + Thread.dumpStack(); + } + + public boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { + return canWalkOn.get(bsi, x, y, z, state); + } + + public boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos, IBlockState state) { + return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z, state); + } + + public boolean canWalkOn(IPlayerContext ctx, BlockPos pos) { + return canWalkOn(new BlockStateInterface(ctx), pos.getX(), pos.getY(), pos.getZ()); + } + + public boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos) { + return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z); + } + + public boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z) { + return canWalkOn(bsi, x, y, z, bsi.get0(x, y, z)); + } + + public boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { + return false; + } + + public boolean canWalkThrough(IPlayerContext ctx, BetterBlockPos pos) { + return canWalkThrough(new BlockStateInterface(ctx), pos.x, pos.y, pos.z); + } + + public boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z) { + return canWalkThrough(bsi, x, y, z, bsi.get0(x, y, z)); + } + + /** + * Refresh the precomputed data, for use when settings have changed etc. + */ + public void refresh() { + long startTime = System.nanoTime(); + + for (int i = 0; i < 10; i++) { + canWalkThrough.refresh(); + canWalkOn.refresh(); + } + + long endTime = System.nanoTime(); + + System.out.println(endTime - startTime); + } +} diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java b/src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java new file mode 100644 index 000000000..c7a2f67df --- /dev/null +++ b/src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java @@ -0,0 +1,71 @@ +/* + * 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.pathing.precompute; + +import baritone.utils.BlockStateInterface; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.world.IBlockAccess; + +import java.lang.reflect.Array; +import java.util.Optional; +import java.util.function.Function; + +public class PrecomputedDataForBlockState { + boolean[] dataPerBlockState = new boolean[Block.BLOCK_STATE_IDS.size()]; // Has to be of type boolean due to otherwise it has a generic type + boolean[] specialCases = new boolean[Block.BLOCK_STATE_IDS.size()]; // We can also be certain that size will return the highest as it fills in all positions with null until we get to the highest block state + + private final SpecialCaseFunction specialCaseHandler; + private final Function> precomputer; + + public PrecomputedDataForBlockState(Function> precomputer, SpecialCaseFunction specialCaseHandler) { + this.specialCaseHandler = specialCaseHandler; + this.precomputer = precomputer; + + this.refresh(); + } + + public void refresh() { + for (IBlockState state : Block.BLOCK_STATE_IDS) { // state should never be null + Optional applied = precomputer.apply(state); + + int id = Block.BLOCK_STATE_IDS.get(state); + + if (applied.isPresent()) { + dataPerBlockState[id] = applied.get(); + specialCases[id] = false; + } else { + dataPerBlockState[id] = false; + specialCases[id] = true; + } + } + } + + public boolean get(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { + int id = Block.BLOCK_STATE_IDS.get(state); + if (specialCases[id]) { + return specialCaseHandler.apply(bsi, x, y, z, state); + } else { + return dataPerBlockState[id]; + } + } + + interface SpecialCaseFunction { + public boolean apply(BlockStateInterface bsi, int x, int y, int z, IBlockState blockState); + } +} diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 1766af623..39c222488 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -38,6 +38,7 @@ import baritone.api.utils.input.Input; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; +import baritone.pathing.precompute.PrecomputedData; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import baritone.utils.PathingCommandContext; @@ -893,7 +894,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil private final int originZ; public BuilderCalculationContext() { - super(BuilderProcess.this.baritone, true); // wew lad + super(BuilderProcess.this.baritone, true, new PrecomputedData()); // wew lad this.placeable = approxPlaceable(9); this.schematic = BuilderProcess.this.schematic; this.originX = origin.getX(); diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 16fc3dda5..2d1e0e985 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -158,7 +158,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG public class GetToBlockCalculationContext extends CalculationContext { public GetToBlockCalculationContext(boolean forUseOnAnotherThread) { - super(GetToBlockProcess.super.baritone, forUseOnAnotherThread); + super(GetToBlockProcess.super.baritone, forUseOnAnotherThread, null); } @Override diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 1ec47cd92..988089347 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -111,7 +111,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; List curr = new ArrayList<>(knownOreLocations); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain - CalculationContext context = new CalculationContext(baritone, true); + CalculationContext context = new CalculationContext(baritone, true, null); // Precomputed data should never be used on this calculation context Baritone.getExecutor().execute(() -> rescan(curr, context)); } if (Baritone.settings().legitMine.value) { From 2dad6262cf045da884cc615fff9466232e9c7688 Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Tue, 31 May 2022 14:56:23 +0100 Subject: [PATCH 04/78] Remove some benchmarking and fix loading of settings. --- src/api/java/baritone/api/Settings.java | 4 +++- .../pathing/precompute/PrecomputedData.java | 17 +++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 1ce87c681..fd120585c 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -1305,7 +1305,9 @@ public final class Settings { public void set(T value) { this.value = value; - BaritoneAPI.getProvider().getAllBaritones().forEach(iBaritone -> iBaritone.getGameEventHandler().onSettingChanged(new SettingChangedEvent(this))); + if (BaritoneAPI.getProvider() != null) { + BaritoneAPI.getProvider().getAllBaritones().forEach(iBaritone -> iBaritone.getGameEventHandler().onSettingChanged(new SettingChangedEvent(this))); + } } public final String getName() { diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedData.java b/src/main/java/baritone/pathing/precompute/PrecomputedData.java index 7531c21ac..d354f2d57 100644 --- a/src/main/java/baritone/pathing/precompute/PrecomputedData.java +++ b/src/main/java/baritone/pathing/precompute/PrecomputedData.java @@ -149,6 +149,7 @@ public class PrecomputedData { // TODO add isFullyPassable try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information return Optional.of(block.isPassable(null, null)); } catch (NullPointerException exception) { + System.out.println("Error"); return Optional.empty(); } }, (bsi, x, y, z, blockState) -> { @@ -181,10 +182,6 @@ public class PrecomputedData { // TODO add isFullyPassable return block.isPassable(bsi.access, bsi.isPassableBlockPos.setPos(x, y, z)); }); - long endTime = System.nanoTime(); - - System.out.println(endTime - startTime); - Thread.dumpStack(); } public boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { @@ -223,15 +220,7 @@ public class PrecomputedData { // TODO add isFullyPassable * Refresh the precomputed data, for use when settings have changed etc. */ public void refresh() { - long startTime = System.nanoTime(); - - for (int i = 0; i < 10; i++) { - canWalkThrough.refresh(); - canWalkOn.refresh(); - } - - long endTime = System.nanoTime(); - - System.out.println(endTime - startTime); + canWalkThrough.refresh(); + canWalkOn.refresh(); } } From a6557121a033cce192cbafe91db3d3e641c6970a Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Tue, 31 May 2022 15:08:52 +0100 Subject: [PATCH 05/78] fix github actions compiling. --- .../pathing/precompute/PrecomputedDataForBlockState.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java b/src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java index c7a2f67df..533c54954 100644 --- a/src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java +++ b/src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java @@ -23,6 +23,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.world.IBlockAccess; import java.lang.reflect.Array; +import java.util.Iterator; import java.util.Optional; import java.util.function.Function; @@ -41,7 +42,8 @@ public class PrecomputedDataForBlockState { } public void refresh() { - for (IBlockState state : Block.BLOCK_STATE_IDS) { // state should never be null + for (Iterator it = Block.BLOCK_STATE_IDS.iterator(); it.hasNext(); ) { // Can be replaced with an enhanced for because that breaks github actions for some reason I can't be bothered to dig into + IBlockState state = it.next(); // state should never be null Optional applied = precomputer.apply(state); int id = Block.BLOCK_STATE_IDS.get(state); From 9e1a5008edc07b6cbfd983daa46b06115c0145c8 Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Tue, 7 Jun 2022 21:52:24 +0100 Subject: [PATCH 06/78] Move caching functions into MovementHelper --- .../baritone/behavior/PathingBehavior.java | 8 +- .../pathing/movement/MovementHelper.java | 164 +++++++++++----- .../movement/movements/MovementAscend.java | 4 +- .../movement/movements/MovementDescend.java | 10 +- .../movement/movements/MovementDiagonal.java | 26 +-- .../movement/movements/MovementDownward.java | 2 +- .../movement/movements/MovementParkour.java | 6 +- .../movement/movements/MovementTraverse.java | 2 +- .../pathing/precompute/PrecomputedData.java | 181 +----------------- 9 files changed, 148 insertions(+), 255 deletions(-) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 50e2a0c2e..6bdfe2e78 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -422,7 +422,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, */ public BetterBlockPos pathStart() { // TODO move to a helper or util class BetterBlockPos feet = ctx.playerFeet(); - if (!precomputedData.canWalkOn(ctx, feet.down())) { + if (!MovementHelper.canWalkOn(ctx, feet.down())) { if (ctx.player().onGround) { double playerX = ctx.player().posX; double playerZ = ctx.player().posZ; @@ -441,7 +441,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, // can't possibly be sneaking off of this one, we're too far away continue; } - if (precomputedData.canWalkOn(ctx, possibleSupport.down()) && precomputedData.canWalkThrough(ctx, possibleSupport) && context.precomputedData.canWalkThrough(ctx, possibleSupport.up())) { + if (MovementHelper.canWalkOn(ctx, possibleSupport.down()) && MovementHelper.canWalkThrough(ctx, possibleSupport) && MovementHelper.canWalkThrough(ctx, possibleSupport.up())) { // this is plausible //logDebug("Faking path start assuming player is standing off the edge of a block"); return possibleSupport; @@ -451,7 +451,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } else { // !onGround // we're in the middle of a jump - if (precomputedData.canWalkOn(ctx, feet.down().down())) { + if (MovementHelper.canWalkOn(ctx, feet.down().down())) { //logDebug("Faking path start assuming player is midair and falling"); return feet.down(); } @@ -462,7 +462,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, @Override public void onSettingChanged(SettingChangedEvent event) { - this.precomputedData.refresh(); + this.precomputedData = new PrecomputedData(); } /** diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 197f10576..dc4ad31b1 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -88,62 +88,105 @@ public interface MovementHelper extends ActionCosts, Helper { return canWalkThrough(bsi, x, y, z, bsi.get0(x, y, z)); } - // if changing something in this function remember to also change it in precomputed data + static boolean canWalkThrough(CalculationContext context, int x, int y, int z, IBlockState state) { + return context.precomputedData.canWalkThrough(context.bsi, x, y, z, state); + } + + static boolean canWalkThrough(CalculationContext context, int x, int y, int z) { + return context.precomputedData.canWalkThrough(context.bsi, x, y, z, context.get(x, y, z)); + } + + static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { + Optional canWalkOn = canWalkThroughBlockState(state); + return canWalkOn.orElseGet(() -> canWalkThroughPosition(bsi, x, y, z, state)); + } + + static Optional canWalkThroughBlockState(IBlockState state) { Block block = state.getBlock(); - if (block == Blocks.AIR) { // early return for most common case - return true; + + if (block == Blocks.AIR) { + return Optional.of(true); } + 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; + return Optional.of(false); } + if (Baritone.settings().blocksToAvoid.value.contains(block)) { - return false; + return Optional.of(false); } + if (block instanceof BlockDoor || block instanceof BlockFenceGate) { // Because there's no nice method in vanilla to check if a door is openable or not, we just have to assume // that anything that isn't an iron door isn't openable, ignoring that some doors introduced in mods can't // be opened by just interacting. - return block != Blocks.IRON_DOOR; + return Optional.of(block != Blocks.IRON_DOOR); } + + if (block == Blocks.CARPET) { + return Optional.empty(); + } + + if (block instanceof BlockSnow) { + if (state.getValue(BlockSnow.LAYERS) >= 3) { + return Optional.of(false); + } + + return Optional.empty(); + } + + if (block instanceof BlockLiquid) { + if (state.getValue(BlockLiquid.LEVEL) != 0) { + return Optional.of(false); + } else { + return Optional.empty(); + } + } + + if (block instanceof BlockCauldron) { + return Optional.of(false); + } + + try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information + return Optional.of(block.isPassable(null, null)); + } catch (NullPointerException exception) { + System.out.println("Error"); + return Optional.empty(); + } + } + + static boolean canWalkThroughPosition(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { + Block block = state.getBlock(); + if (block == Blocks.CARPET) { return canWalkOn(bsi, x, y - 1, z); } - if (block instanceof BlockSnow) { - // we've already checked doors and fence gates - // so the only remaining dynamic isPassables are snow and trapdoor - // if they're cached as a top block, we don't know their metadata - // default to true (mostly because it would otherwise make long distance pathing through snowy biomes impossible) - if (!bsi.worldContainsLoadedChunk(x, z)) { - return true; - } - // the check in BlockSnow.isPassable is layers < 5 - // while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling - if (state.getValue(BlockSnow.LAYERS) >= 3) { - return false; - } - // ok, it's low enough we could walk through it, but is it supported? + + if (block instanceof BlockSnow) { // TODO see if this case is necessary, shouldn't it also check this somewhere else? return canWalkOn(bsi, x, y - 1, z); } - if (isFlowing(x, y, z, state, bsi)) { - return false; // Don't walk through flowing liquids - } + if (block instanceof BlockLiquid) { + if (isFlowing(x, y, z, state, bsi)) { + return false; + } + // Everything after this point has to be a special case as it relies on the water not being flowing, which means a special case is needed. if (Baritone.settings().assumeWalkOnWater.value) { return false; } + IBlockState up = bsi.get0(x, y + 1, z); if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { return false; } return block == Blocks.WATER || block == Blocks.FLOWING_WATER; } - if (block instanceof BlockCauldron) { - return false; - } + return block.isPassable(bsi.access, 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) @@ -296,32 +339,57 @@ public interface MovementHelper extends ActionCosts, Helper { * @return Whether or not the specified block can be walked on */ static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { + Optional canWalkOn = canWalkOnBlockState(state); + return canWalkOn.orElseGet(() -> canWalkOnPosition(bsi, x, y, z, state)); + } + + static Optional canWalkOnBlockState(IBlockState state) { Block block = state.getBlock(); if (block == Blocks.AIR || block == Blocks.MAGMA) { - // early return for most common case (air) - // plus magma, which is a normal cube but it hurts you - return false; + return Optional.of(false); } if (state.isBlockNormalCube()) { - return true; + return Optional.of(true); } if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.value)) { // TODO reconsider this - return true; + return Optional.of(true); } if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) { - return true; + return Optional.of(true); } if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) { - return true; + return Optional.of(true); } + if (isWater(block)) { + return Optional.empty(); + } + if (Baritone.settings().assumeWalkOnLava.value && MovementHelper.isLava(block)) { + return Optional.empty(); + } + + if (block instanceof BlockSlab) { + if (!Baritone.settings().allowWalkOnBottomSlab.value) { + if (((BlockSlab) block).isDouble()) { + return Optional.of(true); + } + return Optional.of(state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM); + } + return Optional.of(true); + } + + return Optional.of(block instanceof BlockStairs); + } + + static boolean canWalkOnPosition(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { + Block block = state.getBlock(); if (isWater(block)) { // since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()" - // BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think its a decrease in readability + // BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think it's a decrease in readability Block up = bsi.get0(x, y + 1, z).getBlock(); if (up == Blocks.WATERLILY || up == Blocks.CARPET) { return true; } - if (isFlowing(x, y, z, state, bsi) || block == Blocks.FLOWING_WATER) { + if (MovementHelper.isFlowing(x, y, z, state, bsi) || block == Blocks.FLOWING_WATER) { // the only scenario in which we can walk on flowing water is if it's under still water with jesus off return isWater(up) && !Baritone.settings().assumeWalkOnWater.value; } @@ -329,22 +397,20 @@ public interface MovementHelper extends ActionCosts, Helper { // if assumeWalkOnWater is off, we can only walk on water if there is water above it return isWater(up) ^ Baritone.settings().assumeWalkOnWater.value; } - if (Baritone.settings().assumeWalkOnLava.value && isLava(block) && !isFlowing(x, y, z, state, bsi)) { + + if (Baritone.settings().assumeWalkOnLava.value && MovementHelper.isLava(block) && !MovementHelper.isFlowing(x, y, z, state, bsi)) { return true; } - if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) { - return true; - } - if (block instanceof BlockSlab) { - if (!Baritone.settings().allowWalkOnBottomSlab.value) { - if (((BlockSlab) block).isDouble()) { - return true; - } - return state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM; - } - return true; - } - return block instanceof BlockStairs; + + return false; // If we don't recognise it then we want to just return false to be safe. + } + + static boolean canWalkOn(CalculationContext context, int x, int y, int z, IBlockState state) { + return context.precomputedData.canWalkOn(context.bsi, x, y, z, state); + } + + static boolean canWalkOn(CalculationContext context, int x, int y, int z) { + return canWalkOn(context, x, y, z, context.get(x, y, z)); } static boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos, IBlockState state) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index bbc09f521..3d6a6cb3c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -68,7 +68,7 @@ public class MovementAscend extends Movement { public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { IBlockState toPlace = context.get(destX, y, destZ); double additionalPlacementCost = 0; - if (!context.precomputedData.canWalkOn(context.bsi, x, y, z, toPlace)) { + if (!MovementHelper.canWalkOn(context, destX, y, destZ, toPlace)) { additionalPlacementCost = context.costOfPlacingAt(destX, y, destZ, toPlace); if (additionalPlacementCost >= COST_INF) { return COST_INF; @@ -94,7 +94,7 @@ public class MovementAscend extends Movement { } } IBlockState srcUp2 = context.get(x, y + 2, z); // used lower down anyway - if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (context.precomputedData.canWalkThrough(context.bsi, x, y + 1, z) || !(srcUp2.getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us + if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(context, x, y + 1, z) || !(srcUp2.getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us // HOWEVER, we assume that we're standing in the start position // that means that src and src.up(1) are both air // maybe they aren't now, but they will be by the time this starts diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index d0f7d9b3f..fc66987ef 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -101,7 +101,7 @@ public class MovementDescend extends Movement { //C, D, etc determine the length of the fall IBlockState below = context.get(destX, y - 2, destZ); - if (!context.precomputedData.canWalkOn(context.bsi, destX, y - 2, destZ, below)) { + if (!MovementHelper.canWalkOn(context, destX, y - 2, destZ, below)) { dynamicFallCost(context, x, y, z, destX, destZ, totalCost, below, res); return; } @@ -146,7 +146,7 @@ public class MovementDescend extends Movement { int unprotectedFallHeight = fallHeight - (y - effectiveStartHeight); // equal to fallHeight - y + effectiveFallHeight, which is equal to -newY + effectiveFallHeight, which is equal to effectiveFallHeight - newY double tentativeCost = WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[unprotectedFallHeight] + frontBreak + costSoFar; if (MovementHelper.isWater(ontoBlock.getBlock())) { - if (!context.precomputedData.canWalkThrough(context.bsi, destX, newY, destZ, ontoBlock)) { + if (!MovementHelper.canWalkThrough(context, destX, newY, destZ, ontoBlock)) { return false; } if (context.assumeWalkOnWater) { @@ -155,7 +155,7 @@ public class MovementDescend extends Movement { if (MovementHelper.isFlowing(destX, newY, destZ, ontoBlock, context.bsi)) { return false; // TODO flowing check required here? } - if (!context.precomputedData.canWalkOn(context.bsi, destX, newY - 1, destZ)) { + if (!MovementHelper.canWalkOn(context, destX, newY - 1, destZ)) { // we could punch right through the water into something else return false; } @@ -174,10 +174,10 @@ public class MovementDescend extends Movement { effectiveStartHeight = newY; continue; } - if (context.precomputedData.canWalkThrough(context.bsi, destX, newY, destZ, ontoBlock)) { + if (MovementHelper.canWalkThrough(context, destX, newY, destZ, ontoBlock)) { continue; } - if (!context.precomputedData.canWalkOn(context.bsi, destX, newY, destZ, ontoBlock)) { + if (!MovementHelper.canWalkOn(context, destX, newY, destZ, ontoBlock)) { return false; } if (MovementHelper.isBottomSlab(ontoBlock)) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 45d319eb6..c1d86d093 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -110,24 +110,24 @@ public class MovementDiagonal extends Movement { } public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) { - if (!context.precomputedData.canWalkThrough(context.bsi, destX, y + 1, destZ)) { + if (!MovementHelper.canWalkThrough(context, destX, y + 1, destZ)) { return; } IBlockState destInto = context.get(destX, y, destZ); boolean ascend = false; IBlockState destWalkOn; boolean descend = false; - if (!context.precomputedData.canWalkThrough(context.bsi, destX, y, destZ, destInto)) { + if (!MovementHelper.canWalkThrough(context, destX, y, destZ, destInto)) { ascend = true; - if (!context.allowDiagonalAscend || !context.precomputedData.canWalkThrough(context.bsi, x, y + 2, z) || !context.precomputedData.canWalkOn(context.bsi, destX, y, destZ, destInto) || !context.precomputedData.canWalkThrough(context.bsi, destX, y + 2, destZ)) { + if (!context.allowDiagonalAscend || !MovementHelper.canWalkThrough(context, x, y + 2, z) || !MovementHelper.canWalkOn(context, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context, destX, y + 2, destZ)) { return; } destWalkOn = destInto; } else { destWalkOn = context.get(destX, y - 1, destZ); - if (!context.precomputedData.canWalkOn(context.bsi, destX, y - 1, destZ, destWalkOn)) { + if (!MovementHelper.canWalkOn(context, destX, y - 1, destZ, destWalkOn)) { descend = true; - if (!context.allowDiagonalDescend || !context.precomputedData.canWalkOn(context.bsi, destX, y - 2, destZ) || !context.precomputedData.canWalkThrough(context.bsi, destX, y - 1, destZ, destWalkOn)) { + if (!context.allowDiagonalDescend || !MovementHelper.canWalkOn(context, destX, y - 2, destZ) || !MovementHelper.canWalkThrough(context, destX, y - 1, destZ, destWalkOn)) { return; } } @@ -169,17 +169,17 @@ public class MovementDiagonal extends Movement { IBlockState pb0 = context.get(x, y, destZ); IBlockState pb2 = context.get(destX, y, z); if (ascend) { - boolean ATop = context.precomputedData.canWalkThrough(context.bsi, x, y + 2, destZ); - boolean AMid = context.precomputedData.canWalkThrough(context.bsi, x, y + 1, destZ); - boolean ALow = context.precomputedData.canWalkThrough(context.bsi, x, y, destZ, pb0); - boolean BTop = context.precomputedData.canWalkThrough(context.bsi, destX, y + 2, z); - boolean BMid = context.precomputedData.canWalkThrough(context.bsi, destX, y + 1, z); - boolean BLow = context.precomputedData.canWalkThrough(context.bsi, destX, y, z, pb2); + boolean ATop = MovementHelper.canWalkThrough(context, x, y + 2, destZ); + boolean AMid = MovementHelper.canWalkThrough(context, x, y + 1, destZ); + boolean ALow = MovementHelper.canWalkThrough(context, x, y, destZ, pb0); + boolean BTop = MovementHelper.canWalkThrough(context, destX, y + 2, z); + boolean BMid = MovementHelper.canWalkThrough(context, destX, y + 1, z); + boolean BLow = MovementHelper.canWalkThrough(context, destX, y, z, pb2); if ((!(ATop && AMid && ALow) && !(BTop && BMid && BLow)) // no option || MovementHelper.avoidWalkingInto(pb0.getBlock()) // bad || MovementHelper.avoidWalkingInto(pb2.getBlock()) // bad - || (ATop && AMid && context.precomputedData.canWalkOn(context.bsi, x, y, destZ, pb0)) // we could just ascend - || (BTop && BMid && context.precomputedData.canWalkOn(context.bsi, destX, y, z, pb2)) // we could just ascend + || (ATop && AMid && MovementHelper.canWalkOn(context, x, y, destZ, pb0)) // we could just ascend + || (BTop && BMid && MovementHelper.canWalkOn(context, destX, y, z, pb2)) // we could just ascend || (!ATop && AMid && ALow) // head bonk A || (!BTop && BMid && BLow)) { // head bonk B return; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index d10a7d269..5a6ec5ce7 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -59,7 +59,7 @@ public class MovementDownward extends Movement { if (!context.allowDownward) { return COST_INF; } - if (!context.precomputedData.canWalkOn(context.bsi, x, y - 2, z)) { + if (!MovementHelper.canWalkOn(context, x, y - 2, z)) { return COST_INF; } IBlockState down = context.get(x, y - 1, z); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 07140cf12..557f30266 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -74,7 +74,7 @@ public class MovementParkour extends Movement { return; } IBlockState adj = context.get(x + xDiff, y - 1, z + zDiff); - if (context.precomputedData.canWalkOn(context.bsi, x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) + if (MovementHelper.canWalkOn(context, x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) // second most common case -- we could just traverse not parkour return; } @@ -122,7 +122,7 @@ public class MovementParkour extends Movement { // check for ascend landing position IBlockState destInto = context.bsi.get0(destX, y, destZ); if (!MovementHelper.fullyPassable(context.bsi.access, context.bsi.isPassableBlockPos.setPos(destX, y, destZ), destInto)) { - if (i <= 3 && context.allowParkourAscend && context.canSprint && context.precomputedData.canWalkOn(context.bsi, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) { + if (i <= 3 && context.allowParkourAscend && context.canSprint && MovementHelper.canWalkOn(context, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) { res.x = destX; res.y = y + 1; res.z = destZ; @@ -135,7 +135,7 @@ public class MovementParkour extends Movement { // check for flat landing position IBlockState landingOn = context.bsi.get0(destX, y - 1, destZ); // farmland needs to be canWalkOn otherwise farm can never work at all, but we want to specifically disallow ending a jump on farmland haha - if (landingOn.getBlock() != Blocks.FARMLAND && context.precomputedData.canWalkOn(context.bsi, destX, y - 1, destZ, landingOn)) { + if (landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context, destX, y - 1, destZ, landingOn)) { if (checkOvershootSafety(context.bsi, destX + xDiff, y, destZ + zDiff)) { res.x = destX; res.y = y; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 2afce2f44..d932c5f8b 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -72,7 +72,7 @@ public class MovementTraverse extends Movement { IBlockState pb1 = context.get(destX, y, destZ); IBlockState destOn = context.get(destX, y - 1, destZ); Block srcDown = context.getBlock(x, y - 1, z); - if (context.precomputedData.canWalkOn(context.bsi, destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge + if (MovementHelper.canWalkOn(context, destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge double WC = WALK_ONE_BLOCK_COST; boolean water = false; if (MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock())) { diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedData.java b/src/main/java/baritone/pathing/precompute/PrecomputedData.java index d354f2d57..42ff69b23 100644 --- a/src/main/java/baritone/pathing/precompute/PrecomputedData.java +++ b/src/main/java/baritone/pathing/precompute/PrecomputedData.java @@ -37,190 +37,17 @@ public class PrecomputedData { // TODO add isFullyPassable PrecomputedDataForBlockState canWalkOn; PrecomputedDataForBlockState canWalkThrough; - public PrecomputedData() { // currently designed for this to be remade on setting change, however that could always be changed - long startTime = System.nanoTime(); - - canWalkOn = new PrecomputedDataForBlockState((state) -> { // this is just copied from the old MovementHelperFunction - Block block = state.getBlock(); - if (block == Blocks.AIR || block == Blocks.MAGMA) { - return Optional.of(false); - } - if (state.isBlockNormalCube()) { - return Optional.of(true); - } - if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.value)) { // TODO reconsider this - return Optional.of(true); - } - if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) { - return Optional.of(true); - } - if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) { - return Optional.of(true); - } - if (isWater(block)) { - return Optional.empty(); - } - if (Baritone.settings().assumeWalkOnLava.value && MovementHelper.isLava(block)) { - return Optional.empty(); - } - - if (block instanceof BlockSlab) { - if (!Baritone.settings().allowWalkOnBottomSlab.value) { - if (((BlockSlab) block).isDouble()) { - return Optional.of(true); - } - return Optional.of(state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM); - } - return Optional.of(true); - } - - return Optional.of(block instanceof BlockStairs); - }, (bsi, x, y, z, blockState) -> { // This should just be water or lava, and could probably be made more efficient - Block block = blockState.getBlock(); - if (isWater(block)) { - // since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()" - // BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think it's a decrease in readability - Block up = bsi.get0(x, y + 1, z).getBlock(); - if (up == Blocks.WATERLILY || up == Blocks.CARPET) { - return true; - } - if (MovementHelper.isFlowing(x, y, z, blockState, bsi) || block == Blocks.FLOWING_WATER) { - // the only scenario in which we can walk on flowing water is if it's under still water with jesus off - return isWater(up) && !Baritone.settings().assumeWalkOnWater.value; - } - // if assumeWalkOnWater is on, we can only walk on water if there isn't water above it - // if assumeWalkOnWater is off, we can only walk on water if there is water above it - return isWater(up) ^ Baritone.settings().assumeWalkOnWater.value; - } - - if (Baritone.settings().assumeWalkOnLava.value && MovementHelper.isLava(block) && !MovementHelper.isFlowing(x, y, z, blockState, bsi)) { - return true; - } - - return false; // If we don't recognise it then we want to just return false to be safe. - }); - - canWalkThrough = new PrecomputedDataForBlockState((blockState) -> { - Block block = blockState.getBlock(); - - if (block == Blocks.AIR) { - return Optional.of(true); - } - - 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 Optional.of(false); - } - - if (Baritone.settings().blocksToAvoid.value.contains(block)) { - return Optional.of(false); - } - - if (block instanceof BlockDoor || block instanceof BlockFenceGate) { - // Because there's no nice method in vanilla to check if a door is openable or not, we just have to assume - // that anything that isn't an iron door isn't openable, ignoring that some doors introduced in mods can't - // be opened by just interacting. - return Optional.of(block != Blocks.IRON_DOOR); - } - - if (block == Blocks.CARPET) { - return Optional.empty(); - } - - if (block instanceof BlockSnow) { - if (blockState.getValue(BlockSnow.LAYERS) >= 3) { - return Optional.of(false); - } - - return Optional.empty(); - } - - if (block instanceof BlockLiquid) { - if (blockState.getValue(BlockLiquid.LEVEL) != 0) { - return Optional.of(false); - } else { - return Optional.empty(); - } - } - - if (block instanceof BlockCauldron) { - return Optional.of(false); - } - - try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information - return Optional.of(block.isPassable(null, null)); - } catch (NullPointerException exception) { - System.out.println("Error"); - return Optional.empty(); - } - }, (bsi, x, y, z, blockState) -> { - Block block = blockState.getBlock(); - - if (block == Blocks.CARPET) { - return canWalkOn(bsi, x, y - 1, z); - } - - if (block instanceof BlockSnow) { // TODO see if this case is necessary, shouldn't it also check this somewhere else? - return canWalkOn(bsi, x, y - 1, z); - } - - if (block instanceof BlockLiquid) { - if (isFlowing(x, y, z, blockState, bsi)) { - return false; - } - // Everything after this point has to be a special case as it relies on the water not being flowing, which means a special case is needed. - if (Baritone.settings().assumeWalkOnWater.value) { - return false; - } - - IBlockState up = bsi.get0(x, y + 1, z); - if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { - return false; - } - return block == Blocks.WATER || block == Blocks.FLOWING_WATER; - } - - return block.isPassable(bsi.access, bsi.isPassableBlockPos.setPos(x, y, z)); - }); + public PrecomputedData() { + canWalkOn = new PrecomputedDataForBlockState(MovementHelper::canWalkOnBlockState, MovementHelper::canWalkOnPosition); + canWalkThrough = new PrecomputedDataForBlockState(MovementHelper::canWalkThroughBlockState, MovementHelper::canWalkThroughPosition); } public boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { return canWalkOn.get(bsi, x, y, z, state); } - public boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos, IBlockState state) { - return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z, state); - } - - public boolean canWalkOn(IPlayerContext ctx, BlockPos pos) { - return canWalkOn(new BlockStateInterface(ctx), pos.getX(), pos.getY(), pos.getZ()); - } - - public boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos) { - return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z); - } - - public boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z) { - return canWalkOn(bsi, x, y, z, bsi.get0(x, y, z)); - } - public boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { - return false; - } - - public boolean canWalkThrough(IPlayerContext ctx, BetterBlockPos pos) { - return canWalkThrough(new BlockStateInterface(ctx), pos.x, pos.y, pos.z); - } - - public boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z) { - return canWalkThrough(bsi, x, y, z, bsi.get0(x, y, z)); - } - - /** - * Refresh the precomputed data, for use when settings have changed etc. - */ - public void refresh() { - canWalkThrough.refresh(); - canWalkOn.refresh(); + return canWalkThrough.get(bsi, x, y, z, state); } } From e7c357ab7f1765546cb3255f1ce73be352ea132b Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Wed, 8 Jun 2022 14:14:14 +0100 Subject: [PATCH 07/78] Make precomputed data refresh every 200 ticks (10 seconds) --- src/main/java/baritone/behavior/PathingBehavior.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 6bdfe2e78..d1ca21301 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -103,6 +103,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, baritone.getPathingControlManager().cancelEverything(); return; } + + if (ticksElapsedSoFar % 200 == 0) { + precomputedData = new PrecomputedData(); // This is here for now in case settings aren't changed in normal ways, should mean it is updated whatever once every 10 seconds + } + expectedSegmentStart = pathStart(); baritone.getPathingControlManager().preTick(); tickPath(); From 868c023dbdd91012a074002ead135eee78d8c6d3 Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Wed, 8 Jun 2022 14:20:25 +0100 Subject: [PATCH 08/78] Fix a couple of things I missed --- .../baritone/pathing/movement/movements/MovementDescend.java | 2 +- .../baritone/pathing/movement/movements/MovementDiagonal.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index fc66987ef..8675fa04a 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -130,7 +130,7 @@ public class MovementDescend extends Movement { // and potentially replace the water we're going to fall into return false; } - if (!context.precomputedData.canWalkThrough(context.bsi, destX, y - 2, destZ, below)) { + if (!MovementHelper.canWalkThrough(context, destX, y - 2, destZ, below)) { return false; } double costSoFar = 0; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index c1d86d093..48b4ed237 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -58,7 +58,7 @@ public class MovementDiagonal extends Movement { } @Override - protected boolean safeToCancel(MovementState state) { // TODO move this function to use precomputed data, not urgent as it only runs once a tick + protected boolean safeToCancel(MovementState state) { //too simple. backfill does not work after cornering with this //return context.precomputedData.canWalkOn(ctx, ctx.playerFeet().down()); EntityPlayerSP player = ctx.player(); From 2741fc2683be6f49edbd4fdfdfce6ab5d3593217 Mon Sep 17 00:00:00 2001 From: Echocage Date: Mon, 27 Jun 2022 15:06:27 -0500 Subject: [PATCH 09/78] Swapped the order of checks within canSprintFromDescendInto --- src/main/java/baritone/pathing/path/PathExecutor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 7e4f76a3b..0ff113df8 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -536,12 +536,12 @@ public class PathExecutor implements IPathExecutor, Helper { } private static boolean canSprintFromDescendInto(IPlayerContext ctx, IMovement current, IMovement next) { - if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) { - return true; - } if (!MovementHelper.canWalkOn(ctx, current.getDest().add(current.getDirection()))) { return false; } + if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) { + return true; + } if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection())) { return true; } From 57c4f9e1033cad41353c4bc74cee158d2041025a Mon Sep 17 00:00:00 2001 From: Echocage Date: Mon, 27 Jun 2022 18:38:54 -0500 Subject: [PATCH 10/78] Undid previous change, updated to instead check the next and the next_next block --- src/main/java/baritone/pathing/path/PathExecutor.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 0ff113df8..0ff7a3ac0 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -385,7 +385,7 @@ public class PathExecutor implements IPathExecutor, Helper { return false; } - if (pathPosition < path.length() - 2) { + if (pathPosition < path.length() - 3) { IMovement next = path.movements().get(pathPosition + 1); if (next instanceof MovementAscend && current.getDirection().up().equals(next.getDirection().down())) { // a descend then an ascend in the same direction @@ -396,7 +396,8 @@ public class PathExecutor implements IPathExecutor, Helper { logDebug("Skipping descend to straight ascend"); return true; } - if (canSprintFromDescendInto(ctx, current, next)) { + if (canSprintFromDescendInto(ctx, current, next) && + canSprintFromDescendInto(ctx, next, path.movements().get(pathPosition + 2))) { if (ctx.playerFeet().equals(current.getDest())) { pathPosition++; onChangeInPathPosition(); @@ -536,12 +537,12 @@ public class PathExecutor implements IPathExecutor, Helper { } private static boolean canSprintFromDescendInto(IPlayerContext ctx, IMovement current, IMovement next) { - if (!MovementHelper.canWalkOn(ctx, current.getDest().add(current.getDirection()))) { - return false; - } if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) { return true; } + if (!MovementHelper.canWalkOn(ctx, current.getDest().add(current.getDirection()))) { + return false; + } if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection())) { return true; } From 441dceb73174cfc376eaf455ba5673b3679a8102 Mon Sep 17 00:00:00 2001 From: Echocage Date: Wed, 29 Jun 2022 17:54:28 -0500 Subject: [PATCH 11/78] Narrowed scope and we now only call canSprintFromDescendInto when our next & next_next movements are both MovementDescends --- .../baritone/pathing/path/PathExecutor.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 0ff7a3ac0..17fa788db 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -73,8 +73,8 @@ public class PathExecutor implements IPathExecutor, Helper { private HashSet toPlace = new HashSet<>(); private HashSet toWalkInto = new HashSet<>(); - private PathingBehavior behavior; - private IPlayerContext ctx; + private final PathingBehavior behavior; + private final IPlayerContext ctx; private boolean sprintNextTick; @@ -385,7 +385,7 @@ public class PathExecutor implements IPathExecutor, Helper { return false; } - if (pathPosition < path.length() - 3) { + if (pathPosition < path.length() - 2) { IMovement next = path.movements().get(pathPosition + 1); if (next instanceof MovementAscend && current.getDirection().up().equals(next.getDirection().down())) { // a descend then an ascend in the same direction @@ -396,13 +396,21 @@ public class PathExecutor implements IPathExecutor, Helper { logDebug("Skipping descend to straight ascend"); return true; } - if (canSprintFromDescendInto(ctx, current, next) && - canSprintFromDescendInto(ctx, next, path.movements().get(pathPosition + 2))) { + if (canSprintFromDescendInto(ctx, current, next)) { + + if (next instanceof MovementDescend && pathPosition < path.length() - 3) { + IMovement next_next = path.movements().get(pathPosition + 2); + if (next_next instanceof MovementDescend && !canSprintFromDescendInto(ctx, next, next_next)) { + return false; + } + + } if (ctx.playerFeet().equals(current.getDest())) { pathPosition++; onChangeInPathPosition(); onTick(); } + return true; } //logDebug("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection())); From 3e7f9039c4230dfcae3096e6628d6d90b0220e3b Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Wed, 6 Jul 2022 14:38:33 +0100 Subject: [PATCH 12/78] Don't construct new optionals in movement helper --- .../pathing/movement/MovementHelper.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index dc4ad31b1..e3ad6800e 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -47,6 +47,8 @@ import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____S * @author leijurv */ public interface MovementHelper extends ActionCosts, Helper { + static final Optional TRUE = Optional.of(true); + static final Optional FALSE = Optional.of(false); static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { if (!bsi.worldBorder.canPlaceAt(x, y)) { @@ -106,15 +108,15 @@ public interface MovementHelper extends ActionCosts, Helper { Block block = state.getBlock(); if (block == Blocks.AIR) { - return Optional.of(true); + 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 || block == Blocks.END_ROD) { - return Optional.of(false); + return FALSE; } if (Baritone.settings().blocksToAvoid.value.contains(block)) { - return Optional.of(false); + return FALSE; } if (block instanceof BlockDoor || block instanceof BlockFenceGate) { @@ -130,7 +132,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block instanceof BlockSnow) { if (state.getValue(BlockSnow.LAYERS) >= 3) { - return Optional.of(false); + return FALSE; } return Optional.empty(); @@ -138,14 +140,14 @@ public interface MovementHelper extends ActionCosts, Helper { if (block instanceof BlockLiquid) { if (state.getValue(BlockLiquid.LEVEL) != 0) { - return Optional.of(false); + return FALSE; } else { return Optional.empty(); } } if (block instanceof BlockCauldron) { - return Optional.of(false); + return FALSE; } try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information @@ -346,19 +348,19 @@ public interface MovementHelper extends ActionCosts, Helper { static Optional canWalkOnBlockState(IBlockState state) { Block block = state.getBlock(); if (block == Blocks.AIR || block == Blocks.MAGMA) { - return Optional.of(false); + return FALSE; } if (state.isBlockNormalCube()) { - return Optional.of(true); + return TRUE; } if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.value)) { // TODO reconsider this - return Optional.of(true); + return TRUE; } if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) { - return Optional.of(true); + return TRUE; } if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) { - return Optional.of(true); + return TRUE; } if (isWater(block)) { return Optional.empty(); @@ -370,11 +372,11 @@ public interface MovementHelper extends ActionCosts, Helper { if (block instanceof BlockSlab) { if (!Baritone.settings().allowWalkOnBottomSlab.value) { if (((BlockSlab) block).isDouble()) { - return Optional.of(true); + return TRUE; } return Optional.of(state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM); } - return Optional.of(true); + return TRUE; } return Optional.of(block instanceof BlockStairs); From 8d480cefb96b5e868717af7910a18fd678483239 Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Wed, 6 Jul 2022 14:45:54 +0100 Subject: [PATCH 13/78] Switch to throwable and readd check for glass / stained glass --- .../java/baritone/pathing/movement/MovementHelper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index e3ad6800e..b710d7f68 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -152,8 +152,8 @@ public interface MovementHelper extends ActionCosts, Helper { try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information return Optional.of(block.isPassable(null, null)); - } catch (NullPointerException exception) { - System.out.println("Error"); + } catch (Throwable exception) { + System.out.println("The block " + state.getBlock().getLocalizedName() + " requires a special case due to the exception " + exception.getMessage()); return Optional.empty(); } } @@ -369,6 +369,10 @@ public interface MovementHelper extends ActionCosts, Helper { return Optional.empty(); } + if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) { + return TRUE; + } + if (block instanceof BlockSlab) { if (!Baritone.settings().allowWalkOnBottomSlab.value) { if (((BlockSlab) block).isDouble()) { From 51275b3a65c83851f0d9177408bc896a25e31df8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 9 Jul 2022 22:06:39 -0700 Subject: [PATCH 14/78] make #paws be an alias for #pause --- .../baritone/command/defaults/ExecutionControlCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java index 8a53e7d41..5b3f85db6 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", "p") { + pauseCommand = new Command(baritone, "pause", "p", "paws") { @Override public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); From 4e2095d25114dd88fa01baf21a805d3f6e1b8ee9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 9 Jul 2022 22:15:20 -0700 Subject: [PATCH 15/78] almost forgot --- .../baritone/command/defaults/ExecutionControlCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java index 5b3f85db6..eaab75286 100644 --- a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java +++ b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java @@ -112,7 +112,7 @@ public class ExecutionControlCommands { ); } }; - resumeCommand = new Command(baritone, "resume", "r", "unpause") { + resumeCommand = new Command(baritone, "resume", "r", "unpause", "unpaws") { @Override public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); From fdcdcbb85fa077c156f7ecb744a06a2ea762d613 Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Thu, 14 Jul 2022 12:49:47 +0100 Subject: [PATCH 16/78] Switch to using an int[] for storing precomputed data, and also use lazy loading --- .../pathing/precompute/PrecomputedData.java | 58 +++++++++++++-- .../PrecomputedDataForBlockState.java | 73 ------------------- 2 files changed, 52 insertions(+), 79 deletions(-) delete mode 100644 src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedData.java b/src/main/java/baritone/pathing/precompute/PrecomputedData.java index 42ff69b23..3a0faced6 100644 --- a/src/main/java/baritone/pathing/precompute/PrecomputedData.java +++ b/src/main/java/baritone/pathing/precompute/PrecomputedData.java @@ -27,27 +27,73 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; +import java.util.Arrays; import java.util.Optional; import static baritone.pathing.movement.MovementHelper.isFlowing; import static baritone.pathing.movement.MovementHelper.isWater; public class PrecomputedData { // TODO add isFullyPassable + private final int[] data = new int[Block.BLOCK_STATE_IDS.size()]; // Has to be of type boolean due to otherwise it has a generic type - PrecomputedDataForBlockState canWalkOn; - PrecomputedDataForBlockState canWalkThrough; + private final int completedMask = 0b1; + private final int canWalkOnMask = 0b10; + private final int canWalkOnSpecialMask = 0b100; + private final int canWalkThroughMask = 0b1000; + private final int canWalkThroughSpecialMask = 0b10000; public PrecomputedData() { - canWalkOn = new PrecomputedDataForBlockState(MovementHelper::canWalkOnBlockState, MovementHelper::canWalkOnPosition); + Arrays.fill(data, 0); + } - canWalkThrough = new PrecomputedDataForBlockState(MovementHelper::canWalkThroughBlockState, MovementHelper::canWalkThroughPosition); + private void fillData(int id, IBlockState state) { + Optional canWalkOnState = MovementHelper.canWalkOnBlockState(state); + if (canWalkOnState.isPresent()) { + if (canWalkOnState.get()) { + data[id] = data[id] | canWalkOnMask; + } + } else { + data[id] = data[id] | canWalkOnSpecialMask; + } + + Optional canWalkThroughState = MovementHelper.canWalkThroughBlockState(state); + if (canWalkThroughState.isPresent()) { + if (canWalkThroughState.get()) { + data[id] = data[id] | canWalkThroughMask; + } + } else { + data[id] = data[id] | canWalkThroughSpecialMask; + } + + + data[id] = data[id] | completedMask; } public boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { - return canWalkOn.get(bsi, x, y, z, state); + int id = Block.BLOCK_STATE_IDS.get(state); + + if ((data[id] & completedMask) == 0) { // we need to fill in the data + fillData(id, state); + } + + if ((data[id] & canWalkOnSpecialMask) != 0) { + return MovementHelper.canWalkOnPosition(bsi, x, y, z, state); + } else { + return (data[id] & canWalkOnMask) != 0; + } } public boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { - return canWalkThrough.get(bsi, x, y, z, state); + int id = Block.BLOCK_STATE_IDS.get(state); + + if ((data[id] & completedMask) == 0) { // we need to fill in the data + fillData(id, state); + } + + if ((data[id] & canWalkThroughSpecialMask) != 0) { + return MovementHelper.canWalkOnPosition(bsi, x, y, z, state); + } else { + return (data[id] & canWalkThroughMask) != 0; + } } } diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java b/src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java deleted file mode 100644 index 533c54954..000000000 --- a/src/main/java/baritone/pathing/precompute/PrecomputedDataForBlockState.java +++ /dev/null @@ -1,73 +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 . - */ - -package baritone.pathing.precompute; - -import baritone.utils.BlockStateInterface; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.world.IBlockAccess; - -import java.lang.reflect.Array; -import java.util.Iterator; -import java.util.Optional; -import java.util.function.Function; - -public class PrecomputedDataForBlockState { - boolean[] dataPerBlockState = new boolean[Block.BLOCK_STATE_IDS.size()]; // Has to be of type boolean due to otherwise it has a generic type - boolean[] specialCases = new boolean[Block.BLOCK_STATE_IDS.size()]; // We can also be certain that size will return the highest as it fills in all positions with null until we get to the highest block state - - private final SpecialCaseFunction specialCaseHandler; - private final Function> precomputer; - - public PrecomputedDataForBlockState(Function> precomputer, SpecialCaseFunction specialCaseHandler) { - this.specialCaseHandler = specialCaseHandler; - this.precomputer = precomputer; - - this.refresh(); - } - - public void refresh() { - for (Iterator it = Block.BLOCK_STATE_IDS.iterator(); it.hasNext(); ) { // Can be replaced with an enhanced for because that breaks github actions for some reason I can't be bothered to dig into - IBlockState state = it.next(); // state should never be null - Optional applied = precomputer.apply(state); - - int id = Block.BLOCK_STATE_IDS.get(state); - - if (applied.isPresent()) { - dataPerBlockState[id] = applied.get(); - specialCases[id] = false; - } else { - dataPerBlockState[id] = false; - specialCases[id] = true; - } - } - } - - public boolean get(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { - int id = Block.BLOCK_STATE_IDS.get(state); - if (specialCases[id]) { - return specialCaseHandler.apply(bsi, x, y, z, state); - } else { - return dataPerBlockState[id]; - } - } - - interface SpecialCaseFunction { - public boolean apply(BlockStateInterface bsi, int x, int y, int z, IBlockState blockState); - } -} From 6b0fb1721bced0de9a33bb021bb96456c5b4d1f1 Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Thu, 14 Jul 2022 17:18:02 +0100 Subject: [PATCH 17/78] These should be all the suggested changes for the caching of can walk through block states --- .../pathing/movement/MovementHelper.java | 16 +++++++++++----- .../movement/movements/MovementPillar.java | 2 +- .../pathing/precompute/PrecomputedData.java | 1 + src/main/java/baritone/process/MineProcess.java | 3 ++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index b710d7f68..58a166535 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -30,6 +30,7 @@ import baritone.utils.ToolSet; import net.minecraft.block.*; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -98,10 +99,12 @@ public interface MovementHelper extends ActionCosts, Helper { return context.precomputedData.canWalkThrough(context.bsi, x, y, z, context.get(x, y, z)); } - static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { - Optional canWalkOn = canWalkThroughBlockState(state); - return canWalkOn.orElseGet(() -> canWalkThroughPosition(bsi, x, y, z, state)); + Optional canWalkThrough = canWalkThroughBlockState(state); + if (canWalkThrough.isPresent()) { + return canWalkThrough.get(); + } + return canWalkThroughPosition(bsi, x, y, z, state); } static Optional canWalkThroughBlockState(IBlockState state) { @@ -342,7 +345,10 @@ public interface MovementHelper extends ActionCosts, Helper { */ static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { Optional canWalkOn = canWalkOnBlockState(state); - return canWalkOn.orElseGet(() -> canWalkOnPosition(bsi, x, y, z, state)); + if (canWalkOn.isPresent()) { + return canWalkOn.get(); + } + return canWalkOnPosition(bsi, x, y, z, state); } static Optional canWalkOnBlockState(IBlockState state) { @@ -463,7 +469,7 @@ public interface MovementHelper extends ActionCosts, Helper { static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) { Block block = state.getBlock(); - if (!canWalkThrough(context.bsi, x, y, z, state)) { + if (!canWalkThrough(context, x, y, z, state)) { if (block instanceof BlockLiquid) { return COST_INF; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index bcd420ecc..73731aacd 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -120,7 +120,7 @@ public class MovementPillar extends Movement { } } // this is commented because it may have had a purpose, but it's very unclear what it was. it's from the minebot era. - //if (!context.precomputedData.canWalkOn(chkPos, check) || context.precomputedData.canWalkThrough(chkPos, check)) {//if the block above where we want to break is not a full block, don't do it + //if (!MovementHelper.canWalkOn(context, chkPos, check) || MovementHelper.canWalkThrough(context, chkPos, check)) {//if the block above where we want to break is not a full block, don't do it // TODO why does canWalkThrough mean this action is COST_INF? // BlockFalling makes sense, and !canWalkOn deals with weird cases like if it were lava // but I don't understand why canWalkThrough makes it impossible diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedData.java b/src/main/java/baritone/pathing/precompute/PrecomputedData.java index 3a0faced6..01eb6dfca 100644 --- a/src/main/java/baritone/pathing/precompute/PrecomputedData.java +++ b/src/main/java/baritone/pathing/precompute/PrecomputedData.java @@ -24,6 +24,7 @@ import baritone.pathing.movement.MovementHelper; import baritone.utils.BlockStateInterface; import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 988089347..586c57627 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -28,6 +28,7 @@ import baritone.cache.CachedChunk; import baritone.cache.WorldScanner; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; +import baritone.pathing.precompute.PrecomputedData; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; @@ -111,7 +112,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; List curr = new ArrayList<>(knownOreLocations); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain - CalculationContext context = new CalculationContext(baritone, true, null); // Precomputed data should never be used on this calculation context + CalculationContext context = new CalculationContext(baritone, true, new PrecomputedData()); Baritone.getExecutor().execute(() -> rescan(curr, context)); } if (Baritone.settings().legitMine.value) { From 85ab317c6cb7b38cda25105deb6d04336560185a Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 21:35:30 -0700 Subject: [PATCH 18/78] simplify, remove setting changed event, always construct new precomputeddata --- src/api/java/baritone/api/Settings.java | 14 ++------ .../api/event/events/SettingChangedEvent.java | 33 ------------------- .../listener/AbstractGameEventListener.java | 3 -- .../event/listener/IGameEventListener.java | 7 ---- .../java/baritone/api/utils/SettingsUtil.java | 2 +- .../baritone/behavior/PathingBehavior.java | 15 +-------- .../baritone/command/defaults/SetCommand.java | 2 +- .../java/baritone/event/GameEventHandler.java | 5 --- .../pathing/movement/CalculationContext.java | 6 ++-- .../baritone/pathing/path/PathExecutor.java | 2 +- .../pathing/precompute/PrecomputedData.java | 31 +++++------------ .../java/baritone/process/BuilderProcess.java | 9 +++-- .../baritone/process/GetToBlockProcess.java | 2 +- .../java/baritone/process/MineProcess.java | 2 +- 14 files changed, 25 insertions(+), 108 deletions(-) delete mode 100644 src/api/java/baritone/api/event/events/SettingChangedEvent.java diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index fd120585c..98e8700d7 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -17,7 +17,6 @@ package baritone.api; -import baritone.api.event.events.SettingChangedEvent; import baritone.api.utils.NotificationHelper; import baritone.api.utils.SettingsUtil; import baritone.api.utils.TypeUtils; @@ -35,8 +34,8 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.List; import java.util.*; -import java.util.function.Consumer; import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * Baritone's settings. Settings apply to all Baritone instances. @@ -197,7 +196,7 @@ public final class Settings { * Blocks that Baritone is not allowed to break */ public final Setting> blocksToDisallowBreaking = new Setting<>(new ArrayList<>( - // Leave Empty by Default + // Leave Empty by Default )); /** @@ -913,7 +912,7 @@ public final class Settings { /** * Only build the selected part of schematics */ - public final Setting buildOnlySelection = new Setting<>(false); + public final Setting buildOnlySelection = new Setting<>(false); /** * How far to move before repeating the build. 0 to disable repeating on a certain axis, 0,0,0 to disable entirely @@ -1303,13 +1302,6 @@ public final class Settings { return value; } - public void set(T value) { - this.value = value; - if (BaritoneAPI.getProvider() != null) { - BaritoneAPI.getProvider().getAllBaritones().forEach(iBaritone -> iBaritone.getGameEventHandler().onSettingChanged(new SettingChangedEvent(this))); - } - } - public final String getName() { return name; } diff --git a/src/api/java/baritone/api/event/events/SettingChangedEvent.java b/src/api/java/baritone/api/event/events/SettingChangedEvent.java deleted file mode 100644 index d92384e03..000000000 --- a/src/api/java/baritone/api/event/events/SettingChangedEvent.java +++ /dev/null @@ -1,33 +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 . - */ - -package baritone.api.event.events; - -import baritone.api.Settings; - -public class SettingChangedEvent { - - private final Settings.Setting setting; - - public SettingChangedEvent(Settings.Setting setting) { - this.setting = setting; - } - - public Settings.Setting getSetting() { - return setting; - } -} diff --git a/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java b/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java index 9f1d2418a..9eac8de46 100644 --- a/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java +++ b/src/api/java/baritone/api/event/listener/AbstractGameEventListener.java @@ -71,7 +71,4 @@ public interface AbstractGameEventListener extends IGameEventListener { @Override default void onPathEvent(PathEvent event) {} - - @Override - default void onSettingChanged(SettingChangedEvent event) {} } diff --git a/src/api/java/baritone/api/event/listener/IGameEventListener.java b/src/api/java/baritone/api/event/listener/IGameEventListener.java index 28afdfffe..b074e978b 100644 --- a/src/api/java/baritone/api/event/listener/IGameEventListener.java +++ b/src/api/java/baritone/api/event/listener/IGameEventListener.java @@ -144,11 +144,4 @@ public interface IGameEventListener { * @param event The event */ void onPathEvent(PathEvent event); - - /** - * When the player changes a setting - * - * @param event The event - */ - void onSettingChanged(SettingChangedEvent event); } diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index b098c1e0f..8b4b90b17 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -199,7 +199,7 @@ public class SettingsUtil { if (!intendedType.isInstance(parsed)) { throw new IllegalStateException(ioMethod + " parser returned incorrect type, expected " + intendedType + " got " + parsed + " which is " + parsed.getClass()); } - setting.set(parsed); + setting.value = parsed; } private interface ISettingParser { diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index d1ca21301..33ef14ef2 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -33,7 +33,6 @@ import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; import baritone.pathing.path.PathExecutor; -import baritone.pathing.precompute.PrecomputedData; import baritone.utils.PathRenderer; import baritone.utils.PathingCommandContext; import baritone.utils.pathing.Favoring; @@ -75,11 +74,8 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, private final LinkedBlockingQueue toDispatch = new LinkedBlockingQueue<>(); - public PrecomputedData precomputedData; - public PathingBehavior(Baritone baritone) { super(baritone); - precomputedData = new PrecomputedData(); } private void queuePathEvent(PathEvent event) { @@ -104,10 +100,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, return; } - if (ticksElapsedSoFar % 200 == 0) { - precomputedData = new PrecomputedData(); // This is here for now in case settings aren't changed in normal ways, should mean it is updated whatever once every 10 seconds - } - expectedSegmentStart = pathStart(); baritone.getPathingControlManager().preTick(); tickPath(); @@ -268,7 +260,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, if (command instanceof PathingCommandContext) { context = ((PathingCommandContext) command).desiredCalcContext; } else { - context = new CalculationContext(baritone, true, precomputedData); + context = new CalculationContext(baritone, true); } if (goal == null) { return false; @@ -465,11 +457,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, return feet; } - @Override - public void onSettingChanged(SettingChangedEvent event) { - this.precomputedData = new PrecomputedData(); - } - /** * In a new thread, pathfind to target blockpos * diff --git a/src/main/java/baritone/command/defaults/SetCommand.java b/src/main/java/baritone/command/defaults/SetCommand.java index 1b395f5a9..fd9bb0457 100644 --- a/src/main/java/baritone/command/defaults/SetCommand.java +++ b/src/main/java/baritone/command/defaults/SetCommand.java @@ -148,7 +148,7 @@ public class SetCommand extends Command { } //noinspection unchecked Settings.Setting asBoolSetting = (Settings.Setting) setting; - asBoolSetting.set(!asBoolSetting.value); + asBoolSetting.value ^= true; logDirect(String.format( "Toggled setting %s to %s", setting.getName(), diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index 1bdba6b9a..8916f7f37 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -156,11 +156,6 @@ public final class GameEventHandler implements IEventBus, Helper { listeners.forEach(l -> l.onPathEvent(event)); } - @Override - public void onSettingChanged(SettingChangedEvent event) { - listeners.forEach(l -> l.onSettingChanged(event)); - } - @Override public final void registerEventListener(IGameEventListener listener) { this.listeners.add(listener); diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index b4782fb59..5a8d98390 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -80,11 +80,11 @@ public class CalculationContext { public final PrecomputedData precomputedData; public CalculationContext(IBaritone baritone) { - this(baritone, false, new PrecomputedData()); + this(baritone, false); } - public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread, PrecomputedData precomputedData) { - this.precomputedData = precomputedData; + public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) { + this.precomputedData = new PrecomputedData(); this.safeForThreadedUse = forUseOnAnotherThread; this.baritone = baritone; EntityPlayerSP player = baritone.getPlayerContext().player(); diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index b28abb618..2ac67e221 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -350,7 +350,7 @@ public class PathExecutor implements IPathExecutor, Helper { behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false); // first and foremost, if allowSprint is off, or if we don't have enough hunger, don't try and sprint - if (!new CalculationContext(behavior.baritone, false, null).canSprint) { + if (!new CalculationContext(behavior.baritone, false).canSprint) { return false; } IMovement current = path.movements().get(pathPosition); diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedData.java b/src/main/java/baritone/pathing/precompute/PrecomputedData.java index 01eb6dfca..99a25944a 100644 --- a/src/main/java/baritone/pathing/precompute/PrecomputedData.java +++ b/src/main/java/baritone/pathing/precompute/PrecomputedData.java @@ -17,25 +17,16 @@ package baritone.pathing.precompute; -import baritone.Baritone; -import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.IPlayerContext; import baritone.pathing.movement.MovementHelper; import baritone.utils.BlockStateInterface; -import net.minecraft.block.*; +import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.init.Blocks; -import net.minecraft.util.math.BlockPos; -import java.util.Arrays; import java.util.Optional; -import static baritone.pathing.movement.MovementHelper.isFlowing; -import static baritone.pathing.movement.MovementHelper.isWater; - public class PrecomputedData { // TODO add isFullyPassable - private final int[] data = new int[Block.BLOCK_STATE_IDS.size()]; // Has to be of type boolean due to otherwise it has a generic type + + private final int[] data = new int[Block.BLOCK_STATE_IDS.size()]; private final int completedMask = 0b1; private final int canWalkOnMask = 0b10; @@ -43,31 +34,27 @@ public class PrecomputedData { // TODO add isFullyPassable private final int canWalkThroughMask = 0b1000; private final int canWalkThroughSpecialMask = 0b10000; - public PrecomputedData() { - Arrays.fill(data, 0); - } - private void fillData(int id, IBlockState state) { Optional canWalkOnState = MovementHelper.canWalkOnBlockState(state); if (canWalkOnState.isPresent()) { if (canWalkOnState.get()) { - data[id] = data[id] | canWalkOnMask; + data[id] |= canWalkOnMask; } } else { - data[id] = data[id] | canWalkOnSpecialMask; + data[id] |= canWalkOnSpecialMask; } Optional canWalkThroughState = MovementHelper.canWalkThroughBlockState(state); if (canWalkThroughState.isPresent()) { if (canWalkThroughState.get()) { - data[id] = data[id] | canWalkThroughMask; + data[id] |= canWalkThroughMask; } } else { - data[id] = data[id] | canWalkThroughSpecialMask; + data[id] |= canWalkThroughSpecialMask; } - data[id] = data[id] | completedMask; + data[id] |= completedMask; } public boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { @@ -92,7 +79,7 @@ public class PrecomputedData { // TODO add isFullyPassable } if ((data[id] & canWalkThroughSpecialMask) != 0) { - return MovementHelper.canWalkOnPosition(bsi, x, y, z, state); + return MovementHelper.canWalkThroughPosition(bsi, x, y, z, state); } else { return (data[id] & canWalkThroughMask) != 0; } diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 39c222488..181c58d77 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -26,9 +26,9 @@ import baritone.api.process.IBuilderProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.api.schematic.FillSchematic; -import baritone.api.schematic.SubstituteSchematic; import baritone.api.schematic.ISchematic; import baritone.api.schematic.IStaticSchematic; +import baritone.api.schematic.SubstituteSchematic; import baritone.api.schematic.format.ISchematicFormat; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.RayTraceUtils; @@ -38,13 +38,12 @@ import baritone.api.utils.input.Input; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; -import baritone.pathing.precompute.PrecomputedData; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import baritone.utils.PathingCommandContext; import baritone.utils.schematic.MapArtSchematic; -import baritone.utils.schematic.SelectionSchematic; import baritone.utils.schematic.SchematicSystem; +import baritone.utils.schematic.SelectionSchematic; import baritone.utils.schematic.schematica.SchematicaHelper; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -607,7 +606,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } // this is not in render distance if (!observedCompleted.contains(BetterBlockPos.longHash(blockX, blockY, blockZ)) - && !Baritone.settings().buildSkipBlocks.value.contains(schematic.desiredState(x, y, z, current, this.approxPlaceable).getBlock())) { + && !Baritone.settings().buildSkipBlocks.value.contains(schematic.desiredState(x, y, z, current, this.approxPlaceable).getBlock())) { // and we've never seen this position be correct // therefore mark as incorrect incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ)); @@ -894,7 +893,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil private final int originZ; public BuilderCalculationContext() { - super(BuilderProcess.this.baritone, true, new PrecomputedData()); // wew lad + super(BuilderProcess.this.baritone, true); // wew lad this.placeable = approxPlaceable(9); this.schematic = BuilderProcess.this.schematic; this.originX = origin.getX(); diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 2d1e0e985..16fc3dda5 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -158,7 +158,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG public class GetToBlockCalculationContext extends CalculationContext { public GetToBlockCalculationContext(boolean forUseOnAnotherThread) { - super(GetToBlockProcess.super.baritone, forUseOnAnotherThread, null); + super(GetToBlockProcess.super.baritone, forUseOnAnotherThread); } @Override diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 586c57627..23631f27f 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -112,7 +112,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; List curr = new ArrayList<>(knownOreLocations); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain - CalculationContext context = new CalculationContext(baritone, true, new PrecomputedData()); + CalculationContext context = new CalculationContext(baritone, true); Baritone.getExecutor().execute(() -> rescan(curr, context)); } if (Baritone.settings().legitMine.value) { From 8018dac39603f31f06021163d662b7b213207566 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 21:38:02 -0700 Subject: [PATCH 19/78] fix default case that instantiated an optional for non stairs --- .../baritone/pathing/movement/MovementHelper.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 58a166535..cc7b42266 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -30,7 +30,6 @@ import baritone.utils.ToolSet; import net.minecraft.block.*; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -48,8 +47,9 @@ import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____S * @author leijurv */ public interface MovementHelper extends ActionCosts, Helper { - static final Optional TRUE = Optional.of(true); - static final Optional FALSE = Optional.of(false); + + Optional TRUE = Optional.of(true); + Optional FALSE = Optional.of(false); static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { if (!bsi.worldBorder.canPlaceAt(x, y)) { @@ -333,7 +333,7 @@ public interface MovementHelper extends ActionCosts, Helper { * Can I walk on this block without anything weird happening like me falling * through? Includes water because we know that we automatically jump on * water - * + *

* If changing something in this function remember to also change it in precomputed data * * @param bsi Block state provider @@ -389,7 +389,11 @@ public interface MovementHelper extends ActionCosts, Helper { return TRUE; } - return Optional.of(block instanceof BlockStairs); + if (block instanceof BlockStairs) { + return TRUE; + } + + return FALSE; } static boolean canWalkOnPosition(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { From 5b7bee977bf9f8e6e2bcfaf6bc53ea80e1750ab6 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 21:38:38 -0700 Subject: [PATCH 20/78] also don't construct an optional for slabs --- src/main/java/baritone/pathing/movement/MovementHelper.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index cc7b42266..a29e06bb6 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -384,7 +384,10 @@ public interface MovementHelper extends ActionCosts, Helper { if (((BlockSlab) block).isDouble()) { return TRUE; } - return Optional.of(state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM); + if (state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM) { + return TRUE; + } + return FALSE; } return TRUE; } From 93fa6cf8753c0d2d8b3da7ab3b8203bd6848125d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 21:42:38 -0700 Subject: [PATCH 21/78] introduce MAYBE and fix more allocation cases --- .../pathing/movement/MovementHelper.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index a29e06bb6..4a45cd990 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -50,6 +50,7 @@ public interface MovementHelper extends ActionCosts, Helper { Optional TRUE = Optional.of(true); Optional FALSE = Optional.of(false); + Optional MAYBE = Optional.empty(); static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { if (!bsi.worldBorder.canPlaceAt(x, y)) { @@ -126,11 +127,14 @@ public interface MovementHelper extends ActionCosts, Helper { // Because there's no nice method in vanilla to check if a door is openable or not, we just have to assume // that anything that isn't an iron door isn't openable, ignoring that some doors introduced in mods can't // be opened by just interacting. - return Optional.of(block != Blocks.IRON_DOOR); + if (block == Blocks.IRON_DOOR) { + return FALSE; + } + return TRUE; } if (block == Blocks.CARPET) { - return Optional.empty(); + return MAYBE; } if (block instanceof BlockSnow) { @@ -138,14 +142,14 @@ public interface MovementHelper extends ActionCosts, Helper { return FALSE; } - return Optional.empty(); + return MAYBE; } if (block instanceof BlockLiquid) { if (state.getValue(BlockLiquid.LEVEL) != 0) { return FALSE; } else { - return Optional.empty(); + return MAYBE; } } @@ -157,7 +161,7 @@ public interface MovementHelper extends ActionCosts, Helper { return Optional.of(block.isPassable(null, null)); } catch (Throwable exception) { System.out.println("The block " + state.getBlock().getLocalizedName() + " requires a special case due to the exception " + exception.getMessage()); - return Optional.empty(); + return MAYBE; } } @@ -369,10 +373,10 @@ public interface MovementHelper extends ActionCosts, Helper { return TRUE; } if (isWater(block)) { - return Optional.empty(); + return MAYBE; } if (Baritone.settings().assumeWalkOnLava.value && MovementHelper.isLava(block)) { - return Optional.empty(); + return MAYBE; } if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) { From 5c7cae9ab0585c2026301da3b99da01da85fef3b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 21:43:14 -0700 Subject: [PATCH 22/78] fix literally wrong comment that did not match subsequent code --- src/main/java/baritone/pathing/movement/MovementHelper.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 4a45cd990..c96dee789 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -124,9 +124,7 @@ public interface MovementHelper extends ActionCosts, Helper { } if (block instanceof BlockDoor || block instanceof BlockFenceGate) { - // Because there's no nice method in vanilla to check if a door is openable or not, we just have to assume - // that anything that isn't an iron door isn't openable, ignoring that some doors introduced in mods can't - // be opened by just interacting. + // TODO this assumes that all doors in all mods are openable if (block == Blocks.IRON_DOOR) { return FALSE; } From 5c9aeab6b4b3c276ec704306ece5fefebcf2ec76 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 21:44:42 -0700 Subject: [PATCH 23/78] add cmt --- 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 c96dee789..b121a0b3c 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -102,7 +102,7 @@ public interface MovementHelper extends ActionCosts, Helper { static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { Optional canWalkThrough = canWalkThroughBlockState(state); - if (canWalkThrough.isPresent()) { + if (canWalkThrough.isPresent()) { // note: don't replace this with the functional style, because the lambda is impure (it captures local variables as context), meaning it allocates return canWalkThrough.get(); } return canWalkThroughPosition(bsi, x, y, z, state); From ee16eb7fde54055bd4374a51f571a71b120bbb1c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 21:47:18 -0700 Subject: [PATCH 24/78] funnier this way --- .../pathing/movement/MovementHelper.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index b121a0b3c..f915dd781 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -48,8 +48,8 @@ import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____S */ public interface MovementHelper extends ActionCosts, Helper { - Optional TRUE = Optional.of(true); - Optional FALSE = Optional.of(false); + Optional YES = Optional.of(true); + Optional NO = Optional.of(false); Optional MAYBE = Optional.empty(); static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { @@ -112,23 +112,23 @@ public interface MovementHelper extends ActionCosts, Helper { Block block = state.getBlock(); if (block == Blocks.AIR) { - return TRUE; + return YES; } 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; + return NO; } if (Baritone.settings().blocksToAvoid.value.contains(block)) { - return FALSE; + return NO; } if (block instanceof BlockDoor || block instanceof BlockFenceGate) { // TODO this assumes that all doors in all mods are openable if (block == Blocks.IRON_DOOR) { - return FALSE; + return NO; } - return TRUE; + return YES; } if (block == Blocks.CARPET) { @@ -137,7 +137,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block instanceof BlockSnow) { if (state.getValue(BlockSnow.LAYERS) >= 3) { - return FALSE; + return NO; } return MAYBE; @@ -145,14 +145,14 @@ public interface MovementHelper extends ActionCosts, Helper { if (block instanceof BlockLiquid) { if (state.getValue(BlockLiquid.LEVEL) != 0) { - return FALSE; + return NO; } else { return MAYBE; } } if (block instanceof BlockCauldron) { - return FALSE; + return NO; } try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information @@ -356,19 +356,19 @@ public interface MovementHelper extends ActionCosts, Helper { static Optional canWalkOnBlockState(IBlockState state) { Block block = state.getBlock(); if (block == Blocks.AIR || block == Blocks.MAGMA) { - return FALSE; + return NO; } if (state.isBlockNormalCube()) { - return TRUE; + return YES; } if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.value)) { // TODO reconsider this - return TRUE; + return YES; } if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) { - return TRUE; + return YES; } if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) { - return TRUE; + return YES; } if (isWater(block)) { return MAYBE; @@ -378,27 +378,27 @@ public interface MovementHelper extends ActionCosts, Helper { } if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) { - return TRUE; + return YES; } if (block instanceof BlockSlab) { if (!Baritone.settings().allowWalkOnBottomSlab.value) { if (((BlockSlab) block).isDouble()) { - return TRUE; + return YES; } if (state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM) { - return TRUE; + return YES; } - return FALSE; + return NO; } - return TRUE; + return YES; } if (block instanceof BlockStairs) { - return TRUE; + return YES; } - return FALSE; + return NO; } static boolean canWalkOnPosition(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { From 0c1fec5d1efe85c62c04a19eb0ba5203fd8ea0b7 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 21:54:32 -0700 Subject: [PATCH 25/78] crucial performance optimization --- .../pathing/precompute/PrecomputedData.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedData.java b/src/main/java/baritone/pathing/precompute/PrecomputedData.java index 99a25944a..6d3a742cd 100644 --- a/src/main/java/baritone/pathing/precompute/PrecomputedData.java +++ b/src/main/java/baritone/pathing/precompute/PrecomputedData.java @@ -34,54 +34,60 @@ public class PrecomputedData { // TODO add isFullyPassable private final int canWalkThroughMask = 0b1000; private final int canWalkThroughSpecialMask = 0b10000; - private void fillData(int id, IBlockState state) { + private int fillData(int id, IBlockState state) { + int blockData = 0; + Optional canWalkOnState = MovementHelper.canWalkOnBlockState(state); if (canWalkOnState.isPresent()) { if (canWalkOnState.get()) { - data[id] |= canWalkOnMask; + blockData |= canWalkOnMask; } } else { - data[id] |= canWalkOnSpecialMask; + blockData |= canWalkOnSpecialMask; } Optional canWalkThroughState = MovementHelper.canWalkThroughBlockState(state); if (canWalkThroughState.isPresent()) { if (canWalkThroughState.get()) { - data[id] |= canWalkThroughMask; + blockData |= canWalkThroughMask; } } else { - data[id] |= canWalkThroughSpecialMask; + blockData |= canWalkThroughSpecialMask; } + blockData |= completedMask; - data[id] |= completedMask; + data[id] = blockData; // in theory, this is thread "safe" because every thread should compute the exact same int to write? + return blockData; } public boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { int id = Block.BLOCK_STATE_IDS.get(state); + int blockData = data[id]; - if ((data[id] & completedMask) == 0) { // we need to fill in the data - fillData(id, state); + if ((blockData & completedMask) == 0) { // we need to fill in the data + blockData = fillData(id, state); } - if ((data[id] & canWalkOnSpecialMask) != 0) { + if ((blockData & canWalkOnSpecialMask) != 0) { return MovementHelper.canWalkOnPosition(bsi, x, y, z, state); } else { - return (data[id] & canWalkOnMask) != 0; + return (blockData & canWalkOnMask) != 0; } } public boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { int id = Block.BLOCK_STATE_IDS.get(state); + int blockData = data[id]; - if ((data[id] & completedMask) == 0) { // we need to fill in the data - fillData(id, state); + if ((blockData & completedMask) == 0) { // we need to fill in the data + blockData = fillData(id, state); } - if ((data[id] & canWalkThroughSpecialMask) != 0) { + if ((blockData & canWalkThroughSpecialMask) != 0) { return MovementHelper.canWalkThroughPosition(bsi, x, y, z, state); } else { - return (data[id] & canWalkThroughMask) != 0; + return (blockData & canWalkThroughMask) != 0; } } } From 0bd16fb81a6ed5f7aca529c89ddca5c98fe0d434 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 21:56:25 -0700 Subject: [PATCH 26/78] bit literals are meh --- .../baritone/pathing/precompute/PrecomputedData.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedData.java b/src/main/java/baritone/pathing/precompute/PrecomputedData.java index 6d3a742cd..3ca2c4667 100644 --- a/src/main/java/baritone/pathing/precompute/PrecomputedData.java +++ b/src/main/java/baritone/pathing/precompute/PrecomputedData.java @@ -28,11 +28,11 @@ public class PrecomputedData { // TODO add isFullyPassable private final int[] data = new int[Block.BLOCK_STATE_IDS.size()]; - private final int completedMask = 0b1; - private final int canWalkOnMask = 0b10; - private final int canWalkOnSpecialMask = 0b100; - private final int canWalkThroughMask = 0b1000; - private final int canWalkThroughSpecialMask = 0b10000; + private final int completedMask = 1 << 0; + private final int canWalkOnMask = 1 << 1; + private final int canWalkOnSpecialMask = 1 << 2; + private final int canWalkThroughMask = 1 << 3; + private final int canWalkThroughSpecialMask = 1 << 4; private int fillData(int id, IBlockState state) { int blockData = 0; From 2d1b81dc20c360db96888eb9c1c1b496dbb3dab1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 22:00:18 -0700 Subject: [PATCH 27/78] vastly increase cuteness by removing the optional boolean --- .../pathing/movement/MovementHelper.java | 34 ++++++++++++------- .../pathing/precompute/PrecomputedData.java | 25 +++++++------- .../baritone/pathing/precompute/Ternary.java | 22 ++++++++++++ 3 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 src/main/java/baritone/pathing/precompute/Ternary.java diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index f915dd781..3d115d1d1 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -25,6 +25,7 @@ import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.*; import baritone.api.utils.input.Input; import baritone.pathing.movement.MovementState.MovementTarget; +import baritone.pathing.precompute.Ternary; import baritone.utils.BlockStateInterface; import baritone.utils.ToolSet; import net.minecraft.block.*; @@ -40,6 +41,7 @@ import net.minecraft.world.IBlockAccess; import java.util.Optional; import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP; +import static baritone.pathing.precompute.Ternary.*; /** * Static helpers for cost calculation @@ -48,10 +50,6 @@ import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____S */ public interface MovementHelper extends ActionCosts, Helper { - Optional YES = Optional.of(true); - Optional NO = Optional.of(false); - Optional MAYBE = Optional.empty(); - static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { if (!bsi.worldBorder.canPlaceAt(x, y)) { return true; @@ -101,14 +99,17 @@ public interface MovementHelper extends ActionCosts, Helper { } static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { - Optional canWalkThrough = canWalkThroughBlockState(state); - if (canWalkThrough.isPresent()) { // note: don't replace this with the functional style, because the lambda is impure (it captures local variables as context), meaning it allocates - return canWalkThrough.get(); + Ternary canWalkThrough = canWalkThroughBlockState(state); + if (canWalkThrough == YES) { + return true; + } + if (canWalkThrough == NO) { + return false; } return canWalkThroughPosition(bsi, x, y, z, state); } - static Optional canWalkThroughBlockState(IBlockState state) { + static Ternary canWalkThroughBlockState(IBlockState state) { Block block = state.getBlock(); if (block == Blocks.AIR) { @@ -156,7 +157,11 @@ public interface MovementHelper extends ActionCosts, Helper { } try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information - return Optional.of(block.isPassable(null, null)); + if (block.isPassable(null, null)) { + return YES; + } else { + return NO; + } } catch (Throwable exception) { System.out.println("The block " + state.getBlock().getLocalizedName() + " requires a special case due to the exception " + exception.getMessage()); return MAYBE; @@ -346,14 +351,17 @@ public interface MovementHelper extends ActionCosts, Helper { * @return Whether or not the specified block can be walked on */ static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { - Optional canWalkOn = canWalkOnBlockState(state); - if (canWalkOn.isPresent()) { - return canWalkOn.get(); + Ternary canWalkOn = canWalkOnBlockState(state); + if (canWalkOn == YES) { + return true; + } + if (canWalkOn == NO) { + return false; } return canWalkOnPosition(bsi, x, y, z, state); } - static Optional canWalkOnBlockState(IBlockState state) { + static Ternary canWalkOnBlockState(IBlockState state) { Block block = state.getBlock(); if (block == Blocks.AIR || block == Blocks.MAGMA) { return NO; diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedData.java b/src/main/java/baritone/pathing/precompute/PrecomputedData.java index 3ca2c4667..5b5bbc52c 100644 --- a/src/main/java/baritone/pathing/precompute/PrecomputedData.java +++ b/src/main/java/baritone/pathing/precompute/PrecomputedData.java @@ -22,7 +22,8 @@ import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; -import java.util.Optional; +import static baritone.pathing.precompute.Ternary.MAYBE; +import static baritone.pathing.precompute.Ternary.YES; public class PrecomputedData { // TODO add isFullyPassable @@ -37,21 +38,19 @@ public class PrecomputedData { // TODO add isFullyPassable private int fillData(int id, IBlockState state) { int blockData = 0; - Optional canWalkOnState = MovementHelper.canWalkOnBlockState(state); - if (canWalkOnState.isPresent()) { - if (canWalkOnState.get()) { - blockData |= canWalkOnMask; - } - } else { + Ternary canWalkOnState = MovementHelper.canWalkOnBlockState(state); + if (canWalkOnState == YES) { + blockData |= canWalkOnMask; + } + if (canWalkOnState == MAYBE) { blockData |= canWalkOnSpecialMask; } - Optional canWalkThroughState = MovementHelper.canWalkThroughBlockState(state); - if (canWalkThroughState.isPresent()) { - if (canWalkThroughState.get()) { - blockData |= canWalkThroughMask; - } - } else { + Ternary canWalkThroughState = MovementHelper.canWalkThroughBlockState(state); + if (canWalkThroughState == YES) { + blockData |= canWalkThroughMask; + } + if (canWalkOnState == MAYBE) { blockData |= canWalkThroughSpecialMask; } diff --git a/src/main/java/baritone/pathing/precompute/Ternary.java b/src/main/java/baritone/pathing/precompute/Ternary.java new file mode 100644 index 000000000..d4d8424e0 --- /dev/null +++ b/src/main/java/baritone/pathing/precompute/Ternary.java @@ -0,0 +1,22 @@ +/* + * 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.pathing.precompute; + +public enum Ternary { + YES, MAYBE, NO +} From 0587223da8aa6559fee32e4636c4a6d1e9e5f4d9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 22:02:19 -0700 Subject: [PATCH 28/78] better constants --- .../pathing/precompute/PrecomputedData.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedData.java b/src/main/java/baritone/pathing/precompute/PrecomputedData.java index 5b5bbc52c..72eb575b3 100644 --- a/src/main/java/baritone/pathing/precompute/PrecomputedData.java +++ b/src/main/java/baritone/pathing/precompute/PrecomputedData.java @@ -29,32 +29,32 @@ public class PrecomputedData { // TODO add isFullyPassable private final int[] data = new int[Block.BLOCK_STATE_IDS.size()]; - private final int completedMask = 1 << 0; - private final int canWalkOnMask = 1 << 1; - private final int canWalkOnSpecialMask = 1 << 2; - private final int canWalkThroughMask = 1 << 3; - private final int canWalkThroughSpecialMask = 1 << 4; + private static final int COMPLETED_MASK = 1 << 0; + private static final int CAN_WALK_ON_MASK = 1 << 1; + private static final int CAN_WALK_ON_SPECIAL_MASK = 1 << 2; + private static final int CAN_WALK_THROUGH_MASK = 1 << 3; + private static final int CAN_WALK_THROUGH_SPECIAL_MASK = 1 << 4; private int fillData(int id, IBlockState state) { int blockData = 0; Ternary canWalkOnState = MovementHelper.canWalkOnBlockState(state); if (canWalkOnState == YES) { - blockData |= canWalkOnMask; + blockData |= CAN_WALK_ON_MASK; } if (canWalkOnState == MAYBE) { - blockData |= canWalkOnSpecialMask; + blockData |= CAN_WALK_ON_SPECIAL_MASK; } Ternary canWalkThroughState = MovementHelper.canWalkThroughBlockState(state); if (canWalkThroughState == YES) { - blockData |= canWalkThroughMask; + blockData |= CAN_WALK_THROUGH_MASK; } if (canWalkOnState == MAYBE) { - blockData |= canWalkThroughSpecialMask; + blockData |= CAN_WALK_THROUGH_SPECIAL_MASK; } - blockData |= completedMask; + blockData |= COMPLETED_MASK; data[id] = blockData; // in theory, this is thread "safe" because every thread should compute the exact same int to write? return blockData; @@ -64,14 +64,14 @@ public class PrecomputedData { // TODO add isFullyPassable int id = Block.BLOCK_STATE_IDS.get(state); int blockData = data[id]; - if ((blockData & completedMask) == 0) { // we need to fill in the data + if ((blockData & COMPLETED_MASK) == 0) { // we need to fill in the data blockData = fillData(id, state); } - if ((blockData & canWalkOnSpecialMask) != 0) { + if ((blockData & CAN_WALK_ON_SPECIAL_MASK) != 0) { return MovementHelper.canWalkOnPosition(bsi, x, y, z, state); } else { - return (blockData & canWalkOnMask) != 0; + return (blockData & CAN_WALK_ON_MASK) != 0; } } @@ -79,14 +79,14 @@ public class PrecomputedData { // TODO add isFullyPassable int id = Block.BLOCK_STATE_IDS.get(state); int blockData = data[id]; - if ((blockData & completedMask) == 0) { // we need to fill in the data + if ((blockData & COMPLETED_MASK) == 0) { // we need to fill in the data blockData = fillData(id, state); } - if ((blockData & canWalkThroughSpecialMask) != 0) { + if ((blockData & CAN_WALK_THROUGH_SPECIAL_MASK) != 0) { return MovementHelper.canWalkThroughPosition(bsi, x, y, z, state); } else { - return (blockData & canWalkThroughMask) != 0; + return (blockData & CAN_WALK_THROUGH_MASK) != 0; } } } From 658048ff2dcc4892a9124a3194eaa21435e7e9b8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Jul 2022 22:11:13 -0700 Subject: [PATCH 29/78] fix snow and tweak others --- .../pathing/movement/MovementHelper.java | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 3d115d1d1..0b6d7e348 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -137,10 +137,8 @@ public interface MovementHelper extends ActionCosts, Helper { } if (block instanceof BlockSnow) { - if (state.getValue(BlockSnow.LAYERS) >= 3) { - return NO; - } - + // snow layers cached as the top layer of a packed chunk have no metadata, we can't make a decision based on their depth here + // it would otherwise make long distance pathing through snowy biomes impossible return MAYBE; } @@ -175,7 +173,18 @@ public interface MovementHelper extends ActionCosts, Helper { return canWalkOn(bsi, x, y - 1, z); } - if (block instanceof BlockSnow) { // TODO see if this case is necessary, shouldn't it also check this somewhere else? + if (block instanceof BlockSnow) { + // if they're cached as a top block, we don't know their metadata + // default to true (mostly because it would otherwise make long distance pathing through snowy biomes impossible) + if (!bsi.worldContainsLoadedChunk(x, z)) { + return true; + } + // the check in BlockSnow.isPassable is layers < 5 + // while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling + if (state.getValue(BlockSnow.LAYERS) >= 3) { + return false; + } + // ok, it's low enough we could walk through it, but is it supported? return canWalkOn(bsi, x, y - 1, z); } @@ -363,10 +372,7 @@ public interface MovementHelper extends ActionCosts, Helper { static Ternary canWalkOnBlockState(IBlockState state) { Block block = state.getBlock(); - if (block == Blocks.AIR || block == Blocks.MAGMA) { - return NO; - } - if (state.isBlockNormalCube()) { + if (state.isBlockNormalCube() && block != Blocks.MAGMA) { return YES; } if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.value)) { // TODO reconsider this @@ -378,17 +384,18 @@ public interface MovementHelper extends ActionCosts, Helper { if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) { return YES; } - if (isWater(block)) { - return MAYBE; - } - if (Baritone.settings().assumeWalkOnLava.value && MovementHelper.isLava(block)) { - return MAYBE; - } - if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) { return YES; } - + if (block instanceof BlockStairs) { + return YES; + } + if (isWater(block)) { + return MAYBE; + } + if (MovementHelper.isLava(block) && Baritone.settings().assumeWalkOnLava.value) { + return MAYBE; + } if (block instanceof BlockSlab) { if (!Baritone.settings().allowWalkOnBottomSlab.value) { if (((BlockSlab) block).isDouble()) { @@ -401,11 +408,6 @@ public interface MovementHelper extends ActionCosts, Helper { } return YES; } - - if (block instanceof BlockStairs) { - return YES; - } - return NO; } @@ -427,7 +429,7 @@ public interface MovementHelper extends ActionCosts, Helper { return isWater(up) ^ Baritone.settings().assumeWalkOnWater.value; } - if (Baritone.settings().assumeWalkOnLava.value && MovementHelper.isLava(block) && !MovementHelper.isFlowing(x, y, z, state, bsi)) { + if (MovementHelper.isLava(block) && !MovementHelper.isFlowing(x, y, z, state, bsi) && Baritone.settings().assumeWalkOnLava.value) { // if we get here it means that assumeWalkOnLava must be true, so put it last return true; } From 80a4757242ac7653602ed025169776968b42d387 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 15 Jul 2022 01:36:01 -0700 Subject: [PATCH 30/78] baritone complies faster if the files are less bytes --- .../java/baritone/pathing/movement/MovementHelper.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 0b6d7e348..e3fc6a038 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -111,19 +111,15 @@ public interface MovementHelper extends ActionCosts, Helper { static Ternary canWalkThroughBlockState(IBlockState state) { Block block = state.getBlock(); - if (block == Blocks.AIR) { return YES; } - 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 NO; } - if (Baritone.settings().blocksToAvoid.value.contains(block)) { return NO; } - if (block instanceof BlockDoor || block instanceof BlockFenceGate) { // TODO this assumes that all doors in all mods are openable if (block == Blocks.IRON_DOOR) { @@ -131,17 +127,14 @@ public interface MovementHelper extends ActionCosts, Helper { } return YES; } - if (block == Blocks.CARPET) { return MAYBE; } - if (block instanceof BlockSnow) { // snow layers cached as the top layer of a packed chunk have no metadata, we can't make a decision based on their depth here // it would otherwise make long distance pathing through snowy biomes impossible return MAYBE; } - if (block instanceof BlockLiquid) { if (state.getValue(BlockLiquid.LEVEL) != 0) { return NO; @@ -149,11 +142,9 @@ public interface MovementHelper extends ActionCosts, Helper { return MAYBE; } } - if (block instanceof BlockCauldron) { return NO; } - try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information if (block.isPassable(null, null)) { return YES; From d7fc916d20e6f8d2abdc3f83953ebb2d0565ee99 Mon Sep 17 00:00:00 2001 From: Lucas Arden Date: Sun, 24 Jul 2022 21:37:45 -0700 Subject: [PATCH 31/78] Added check for pathing --- src/main/java/baritone/process/BackfillProcess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/BackfillProcess.java b/src/main/java/baritone/process/BackfillProcess.java index 04b3ca78b..84969e6b7 100644 --- a/src/main/java/baritone/process/BackfillProcess.java +++ b/src/main/java/baritone/process/BackfillProcess.java @@ -93,7 +93,7 @@ public final class BackfillProcess extends BaritoneProcessHelper { } private void amIBreakingABlockHMMMMMMM() { - if (!ctx.getSelectedBlock().isPresent()) { + if (!ctx.getSelectedBlock().isPresent() || !baritone.getPathingBehavior().isPathing()) { return; } blocksToReplace.put(ctx.getSelectedBlock().get(), ctx.world().getBlockState(ctx.getSelectedBlock().get())); From d37a6a0b2d083e40989766676dee442fc6718bb7 Mon Sep 17 00:00:00 2001 From: Lucas Arden Date: Tue, 26 Jul 2022 14:21:32 -0700 Subject: [PATCH 32/78] Added check for placed blocks in backfill --- src/main/java/baritone/process/BackfillProcess.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/process/BackfillProcess.java b/src/main/java/baritone/process/BackfillProcess.java index 84969e6b7..f42dfbe53 100644 --- a/src/main/java/baritone/process/BackfillProcess.java +++ b/src/main/java/baritone/process/BackfillProcess.java @@ -56,12 +56,12 @@ public final class BackfillProcess extends BaritoneProcessHelper { Baritone.settings().backfill.value = false; return false; } - amIBreakingABlockHMMMMMMM(); for (BlockPos pos : new ArrayList<>(blocksToReplace.keySet())) { - if (ctx.world().getChunk(pos) instanceof EmptyChunk) { + if (ctx.world().getChunk(pos) instanceof EmptyChunk || ctx.world().getBlockState(pos).getBlock() != Blocks.AIR) { blocksToReplace.remove(pos); } } + amIBreakingABlockHMMMMMMM(); baritone.getInputOverrideHandler().clearAllKeys(); return !toFillIn().isEmpty(); From 344085f4efc5708e0be4b26dcd24eeb0c975b82f Mon Sep 17 00:00:00 2001 From: Imeguras Date: Mon, 8 Aug 2022 12:00:48 +0100 Subject: [PATCH 33/78] Added the ability to use KmM as abreviatures for example 1m is equals to 1 million while 1K is 1000 --- .../api/command/datatypes/RelativeCoordinate.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java b/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java index 7d77a96c7..b8f30a774 100644 --- a/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java @@ -26,7 +26,8 @@ import java.util.stream.Stream; public enum RelativeCoordinate implements IDatatypePost { INSTANCE; - private static Pattern PATTERN = Pattern.compile("^(~?)([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)([k-k]?)|)$"); + private static String ScalesAliasRegex = "[kKmM]"; + private static Pattern PATTERN = Pattern.compile("^(~?)([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)("+ScalesAliasRegex+"?)|)$"); @Override public Double apply(IDatatypeContext ctx, Double origin) throws CommandException { @@ -41,11 +42,15 @@ public enum RelativeCoordinate implements IDatatypePost { boolean isRelative = !matcher.group(1).isEmpty(); - double offset = matcher.group(2).isEmpty() ? 0 : Double.parseDouble(matcher.group(2).replaceAll("k", "")); - - if (matcher.group(2).contains("k")) { + double offset = matcher.group(2).isEmpty() ? 0 : Double.parseDouble(matcher.group(2).replaceAll(ScalesAliasRegex, "")); + + if (matcher.group(2).toLowerCase().contains("k")) { offset *= 1000; } + if (matcher.group(2).toLowerCase().contains("m")) { + offset *= 1000000; + } + if (isRelative) { return origin + offset; From 40449400d3270ccb91560c939b04197414625e32 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Sun, 25 Sep 2022 16:55:08 +0200 Subject: [PATCH 34/78] State of Emerson --- .../format/DefaultSchematicFormats.java | 11 + .../format/defaults/LitematicaSchematic.java | 217 ++++++++++++++++++ 2 files changed, 228 insertions(+) create mode 100644 src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index fb20164bd..6cea77fe0 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -21,6 +21,7 @@ import baritone.api.schematic.IStaticSchematic; import baritone.api.schematic.format.ISchematicFormat; import baritone.utils.schematic.format.defaults.MCEditSchematic; import baritone.utils.schematic.format.defaults.SpongeSchematic; +import baritone.utils.schematic.format.defaults.LitematicaSchematic; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import org.apache.commons.io.FilenameUtils; @@ -65,6 +66,16 @@ public enum DefaultSchematicFormats implements ISchematicFormat { throw new UnsupportedOperationException("Unsupported Version of a Sponge Schematic"); } } + }, + + /** + * The Litematica schematic specification. Commonly denoted by the ".litematic" file extension. + */ + Litematica("litematic") { + @Override + public IStaticSchematic parse(InputStream input) throws IOException { + return new LitematicaSchematic(CompressedStreamTools.readCompressed(input)); + } }; private final String extension; diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java new file mode 100644 index 000000000..9c647a0b3 --- /dev/null +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -0,0 +1,217 @@ +/* + * 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.schematic.format.defaults; + +import baritone.utils.schematic.StaticSchematic; +import net.minecraft.block.*; +import net.minecraft.block.properties.IProperty; +import net.minecraft.nbt.*; +import net.minecraft.util.ResourceLocation; +import net.minecraft.block.state.IBlockState; + +import org.apache.commons.lang3.Validate; +import javax.annotation.Nullable; +import java.util.*; + +/** + * @author Emerson + * @since 12/27/2020 + */ +public final class LitematicaSchematic extends StaticSchematic { + + public LitematicaSchematic(NBTTagCompound nbt) { + String regionName = (String) nbt.getCompoundTag("Regions").getKeySet().toArray()[0]; + this.x = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("x")); + this.y = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("y")); + this.z = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("z")); + this.states = new IBlockState[this.x][this.z][this.y]; + + + NBTTagList paletteTag = nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTagList("BlockStatePalette",10); + // ListNBT paletteTag = nbt.getCompound("Regions").getCompound(regionName).getList("BlockStatePalette",10); + + // Create the block states array + IBlockState[] paletteBlockStates = new IBlockState[paletteTag.tagCount()]; + // For every part of the array + for (int i = 0; i propertiesMap = new HashMap<>(); + // Create a map for each state + for (int j = 0; j property = block.getBlockState().getProperty(keys[j].toString()); + if (property != null) { + blockState = setPropertyValue(blockState, property, propertiesMap.get(keys[j])); + } + } + paletteBlockStates[i] = blockState; + } + + + // BlockData is stored as an NBT long[] + int paletteSize = (int) Math.floor(log2(paletteTag.tagCount()))+1; + long litematicSize = (long) this.x*this.y*this.z; + + // In 1.12, the long array isn't exposed by the libraries so parsing has to be done manually + String rawBlockString = (nbt.getCompoundTag("Regions").getCompoundTag(regionName)).getTag("BlockStates").toString(); + rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); + String[] rawBlockArrayString = rawBlockString.split(","); + long[] rawBlockData = new long[rawBlockArrayString.length]; + for (int i = 0; i < rawBlockArrayString.length; i++) { + rawBlockData[i] = Long.parseLong(rawBlockArrayString[i].substring(0,rawBlockArrayString[i].length()-1)); + } + + + LitematicaBitArray bitArray = new LitematicaBitArray(paletteSize, litematicSize, rawBlockData); + if (paletteSize > 32) { + throw new IllegalStateException("Too many blocks in schematic to handle"); + } + + int[] serializedBlockStates = new int[(int) litematicSize]; + for (int i = 0; i> IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { + Optional parsed = property.parseValue(value).toJavaUtil(); + if (parsed.isPresent()) { + return state.withProperty(property, parsed.get()); + } else { + throw new IllegalArgumentException("Invalid value for property " + property); + } + } + + /** LitematicaBitArray class from litematica */ + private static class LitematicaBitArray + { + /** The long array that is used to store the data for this BitArray. */ + private final long[] longArray; + /** Number of bits a single entry takes up */ + private final int bitsPerEntry; + /** + * The maximum value for a single entry. This also works as a bitmask for a single entry. + * For instance, if bitsPerEntry were 5, this value would be 31 (ie, {@code 0b00011111}). + */ + private final long maxEntryValue; + /** Number of entries in this array (not the length of the long array that internally backs this array) */ + private final long arraySize; + + public LitematicaBitArray(int bitsPerEntryIn, long arraySizeIn, @Nullable long[] longArrayIn) + { + Validate.inclusiveBetween(1L, 32L, (long) bitsPerEntryIn); + this.arraySize = arraySizeIn; + this.bitsPerEntry = bitsPerEntryIn; + this.maxEntryValue = (1L << bitsPerEntryIn) - 1L; + + if (longArrayIn != null) + { + this.longArray = longArrayIn; + } + else + { + this.longArray = new long[(int) (roundUp((long) arraySizeIn * (long) bitsPerEntryIn, 64L) / 64L)]; + } + } + + public void setAt(long index, int value) + { + Validate.inclusiveBetween(0L, this.arraySize - 1L, (long) index); + Validate.inclusiveBetween(0L, this.maxEntryValue, (long) value); + long startOffset = index * (long) this.bitsPerEntry; + int startArrIndex = (int) (startOffset >> 6); // startOffset / 64 + int endArrIndex = (int) (((index + 1L) * (long) this.bitsPerEntry - 1L) >> 6); + int startBitOffset = (int) (startOffset & 0x3F); // startOffset % 64 + this.longArray[startArrIndex] = this.longArray[startArrIndex] & ~(this.maxEntryValue << startBitOffset) | ((long) value & this.maxEntryValue) << startBitOffset; + + if (startArrIndex != endArrIndex) + { + int endOffset = 64 - startBitOffset; + int j1 = this.bitsPerEntry - endOffset; + this.longArray[endArrIndex] = this.longArray[endArrIndex] >>> j1 << j1 | ((long) value & this.maxEntryValue) >> endOffset; + } + } + + public int getAt(long index) + { + Validate.inclusiveBetween(0L, this.arraySize - 1L, (long) index); + long startOffset = index * (long) this.bitsPerEntry; + int startArrIndex = (int) (startOffset >> 6); // startOffset / 64 + int endArrIndex = (int) (((index + 1L) * (long) this.bitsPerEntry - 1L) >> 6); + int startBitOffset = (int) (startOffset & 0x3F); // startOffset % 64 + + if (startArrIndex == endArrIndex) + { + return (int) (this.longArray[startArrIndex] >>> startBitOffset & this.maxEntryValue); + } + else + { + int endOffset = 64 - startBitOffset; + return (int) ((this.longArray[startArrIndex] >>> startBitOffset | this.longArray[endArrIndex] << endOffset) & this.maxEntryValue); + } + } + + + public long size() + { + return this.arraySize; + } + + public static long roundUp(long number, long interval) + { + if (interval == 0) + { + return 0; + } + else if (number == 0) + { + return interval; + } + else + { + if (number < 0) + { + interval *= -1; + } + + long i = number % interval; + return i == 0 ? number : number + interval - i; + } + } + } +} \ No newline at end of file From 240e81a9e0cfbb45529ba88fd130664a97bcd03f Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Sun, 25 Sep 2022 18:22:59 +0200 Subject: [PATCH 35/78] Refactoring --- .../format/defaults/LitematicaSchematic.java | 194 ++++++++++++------ 1 file changed, 132 insertions(+), 62 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 9c647a0b3..237040450 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -31,6 +31,9 @@ import java.util.*; /** * @author Emerson * @since 12/27/2020 + * @author rycbar + * @since 22.09.2022 + * */ public final class LitematicaSchematic extends StaticSchematic { @@ -41,80 +44,147 @@ public final class LitematicaSchematic extends StaticSchematic { this.z = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; + NBTTagList blockStatePalette = nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTagList("BlockStatePalette", 10); + // ListTag blockStatePalette = nbt.getCompound("Regions").getCompound(regionName).getList("BlockStatePalette",10); + IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); + // BlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); - NBTTagList paletteTag = nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTagList("BlockStatePalette",10); - // ListNBT paletteTag = nbt.getCompound("Regions").getCompound(regionName).getList("BlockStatePalette",10); + int bitsPerBlock = bitsPerBlock(blockStatePalette); + long schematicVolume = schematicVolume(); + long[] rawBlockData = rawBlockData(rawBlockArrayString(nbt, regionName)); - // Create the block states array - IBlockState[] paletteBlockStates = new IBlockState[paletteTag.tagCount()]; - // For every part of the array - for (int i = 0; i propertiesMap = new HashMap<>(); - // Create a map for each state - for (int j = 0; j property = block.getBlockState().getProperty(keys[j].toString()); - if (property != null) { - blockState = setPropertyValue(blockState, property, propertiesMap.get(keys[j])); - } - } - paletteBlockStates[i] = blockState; + LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, schematicVolume, rawBlockData); + + if (bitsPerBlock > 32) { + throw new IllegalStateException("Too many blocks in schematic to handle"); } + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + this.states[x][y][z] = paletteBlockStates[bitArray.getAt((y * this.z + z) * this.x + x)]; + } + } + } + } - // BlockData is stored as an NBT long[] - int paletteSize = (int) Math.floor(log2(paletteTag.tagCount()))+1; - long litematicSize = (long) this.x*this.y*this.z; + /** + * @param blockStatePalette List of all different block types used in the schematic. + * @return Array of BlockStates. + */ + private static IBlockState[] paletteBlockStates(NBTTagList blockStatePalette) { + // private static BlockState[] paletteBlockStates(TagList blockStatePalette) { + IBlockState[] paletteBlockStates = new IBlockState[blockStatePalette.tagCount()]; + //BlockState[] paletteBlockState = new BlockState[blockStatePalette.tagCount()]; - // In 1.12, the long array isn't exposed by the libraries so parsing has to be done manually - String rawBlockString = (nbt.getCompoundTag("Regions").getCompoundTag(regionName)).getTag("BlockStates").toString(); - rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); - String[] rawBlockArrayString = rawBlockString.split(","); + for (int i = 0; i< blockStatePalette.tagCount(); i++) { + Block block = Block.REGISTRY.getObject(new ResourceLocation((((NBTTagCompound) blockStatePalette.get(i)).getString("Name")))); + //Block block = Registry.BLOCK.get(new ResourceLocation((((CompoundTag) blockStatePalette.get(i)).getString("Name")))); + NBTTagCompound properties = ((NBTTagCompound) blockStatePalette.get(i)).getCompoundTag("Properties"); + //CompoundTag properties = ((CompoundTag) blockStatePalette.get(i)).getCompound("Properties"); + + paletteBlockStates[i] = getBlockState(block, properties); + } + return paletteBlockStates; + } + + /** + * @param block block. + * @param properties List of Properties the block has. + * @return A blockState. + */ + private static IBlockState getBlockState(Block block, NBTTagCompound properties) { + //private static BlockState getBlockState(Block block, CompoundTag properties) { + IBlockState blockState = block.getDefaultState(); + //BlockState blockState = block.defaultBlockState(); + + for (Object key : properties.getKeySet().toArray()) { + //for (Object key : properties.getAllKeys().toArray()) { + IProperty property = block.getBlockState().getProperty(key.toString()); + //Property property = block.getStateDefinition().getProperty(key.toString()); + if (property != null) { + blockState = setPropertyValue(blockState, property, propertiesMap(properties).get(key)); + } + } + return blockState; + } + + /** + * i haven't written this and i wont try to decode it. + * @param state + * @param property + * @param value + * @return + * @param + */ + private static > IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { + //private static > BlockState setPropertyValue(BlockState state, Property property, String value) { + Optional parsed = property.parseValue(value).toJavaUtil(); + //Optional parsed = property.getValue(value); + if (parsed.isPresent()) { + return state.withProperty(property, parsed.get()); + //return state.setValue(property, parsed.get()); + } else { + throw new IllegalArgumentException("Invalid value for property " + property); + } + } + + /** + * @param properties properties a block has. + * @return properties as map. + */ + private static Map propertiesMap(NBTTagCompound properties) { + //private static Map propertiesMap(CompoundTag properties) { + Map propertiesMap = new HashMap<>(); + + for (Object key : properties.getKeySet().toArray()) { + //for (Object key : properties.getAllKeys().toArray()) { + propertiesMap.put((String) key, (properties.getString((String) key))); + } + return propertiesMap; + } + + /** + * @param blockStatePalette List of all different block types used in the schematic. + * @return amount of bits used to encode a block. + */ + private static int bitsPerBlock(NBTTagList blockStatePalette) { + //private static int bitsPerBlock(ListTag blockStatePalette) { + return (int) Math.floor((Math.log(blockStatePalette.tagCount())) / Math.log(2))+1; + //return (int) Math.floor((Math.log(blockStatePalette.size())) / Math.log(2))+1; + } + + /** + * @return the amount of blocks in the schematic, including air blocks. + */ + private long schematicVolume() { + return (long) this.x*this.y*this.z; + } + + /** + * @param rawBlockArrayString String Array holding Long values as text. + * @return array of Long values. + */ + private static long[] rawBlockData(String[] rawBlockArrayString) { long[] rawBlockData = new long[rawBlockArrayString.length]; for (int i = 0; i < rawBlockArrayString.length; i++) { rawBlockData[i] = Long.parseLong(rawBlockArrayString[i].substring(0,rawBlockArrayString[i].length()-1)); } - - - LitematicaBitArray bitArray = new LitematicaBitArray(paletteSize, litematicSize, rawBlockData); - if (paletteSize > 32) { - throw new IllegalStateException("Too many blocks in schematic to handle"); - } - - int[] serializedBlockStates = new int[(int) litematicSize]; - for (int i = 0; i> IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { - Optional parsed = property.parseValue(value).toJavaUtil(); - if (parsed.isPresent()) { - return state.withProperty(property, parsed.get()); - } else { - throw new IllegalArgumentException("Invalid value for property " + property); - } + /** + * @param nbt schematic file. + * @param regionName Name of the region the schematic is in. + * @return String Array holding Long values as text. + */ + private static String[] rawBlockArrayString(NBTTagCompound nbt, String regionName) { + //private static String[] rawBlockArrayString(CompoundTag nbt, String regionName) { + + String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTag("BlockStates"))).toString(); + //String rawBlockString = Objects.requireNonNull((nbt.getCompound("Regions").getCompound(regionName).get("BlockStates"))).toString(); + rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); + return rawBlockString.split(","); } /** LitematicaBitArray class from litematica */ From 3cd8ce83236f4d2f27bc4d8c6c8b1f192f11a9e4 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 00:58:32 +0200 Subject: [PATCH 36/78] Multiple Sub-region support --- .../format/defaults/LitematicaSchematic.java | 110 +++++++++++++----- 1 file changed, 83 insertions(+), 27 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 237040450..5a9f6d904 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -36,38 +36,92 @@ import java.util.*; * */ public final class LitematicaSchematic extends StaticSchematic { + int minX=0,minY=0,minZ=0; + private static String reg = "Regions"; + private static String meta = "Metadata"; + private static String schemSize = "EnclosingSize"; + private static String[] regNames; + private static String blSt = "BlockStates"; + private static String blStPl = "BlockStatePalette"; + private static String pos = "Position"; + private static String size = "Size"; + private static NBTTagCompound nbt; public LitematicaSchematic(NBTTagCompound nbt) { - String regionName = (String) nbt.getCompoundTag("Regions").getKeySet().toArray()[0]; - this.x = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("x")); - this.y = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("y")); - this.z = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("z")); + this.nbt = nbt; + regNames = getRegions(); + + this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); + this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y")); + this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; - NBTTagList blockStatePalette = nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTagList("BlockStatePalette", 10); - // ListTag blockStatePalette = nbt.getCompound("Regions").getCompound(regionName).getList("BlockStatePalette",10); - IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); - // BlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); + minCord(); - int bitsPerBlock = bitsPerBlock(blockStatePalette); - long schematicVolume = schematicVolume(); - long[] rawBlockData = rawBlockData(rawBlockArrayString(nbt, regionName)); + for (String subReg : regNames) { + NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); + // ListTag blockStatePalette = nbt.getCompound(reg).getCompound(subReg).getList(blStPl,10); + IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); + // BlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); + int posX = getMin(subReg,"x"); + int posY = getMin(subReg,"y"); + int posZ = getMin(subReg,"z"); - LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, schematicVolume, rawBlockData); + int bitsPerBlock = bitsPerBlock(blockStatePalette); + long regionVolume = getVolume(subReg); + long[] rawBlockData = rawBlockData(rawBlockArrayString(subReg)); - if (bitsPerBlock > 32) { - throw new IllegalStateException("Too many blocks in schematic to handle"); - } + LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, rawBlockData); - for (int y = 0; y < this.y; y++) { - for (int z = 0; z < this.z; z++) { - for (int x = 0; x < this.x; x++) { - this.states[x][y][z] = paletteBlockStates[bitArray.getAt((y * this.z + z) * this.x + x)]; + if (bitsPerBlock > 32) { + throw new IllegalStateException("Too many blocks in schematic to handle"); + } + + int index = 0; + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + if (inSubregion(x, y, z, subReg)) { + int paletteIndex = bitArray.getAt(index); + this.states[x-(minX-posX)][z-(minZ-posZ)][y-(minY-posY)] = paletteBlockStates[paletteIndex]; + index++; + } + } } } } } + private static boolean inSubregion(int x, int y, int z, String subReg) { + boolean inspect = + x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && + y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && + z < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); + return inspect; + } + + private static int getMin(String subReg,String s) { + int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); + int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); + if (b < 0) { + b++; + } + return Math.min(a,a+b); + + } + + private void minCord() { + for (String subReg : regNames) { + this.minX = Math.min(this.minX,getMin(subReg,"x")); + this.minY = Math.min(this.minY,getMin(subReg,"y")); + this.minZ = Math.min(this.minZ,getMin(subReg,"z")); + } + } + + private static String[] getRegions() { + return nbt.getCompoundTag(reg).getKeySet().toArray(new String[0]); + } + /** * @param blockStatePalette List of all different block types used in the schematic. * @return Array of BlockStates. @@ -157,8 +211,11 @@ public final class LitematicaSchematic extends StaticSchematic { /** * @return the amount of blocks in the schematic, including air blocks. */ - private long schematicVolume() { - return (long) this.x*this.y*this.z; + private static long getVolume(String subReg) { + return Math.abs( + nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x") * + nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * + nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); } /** @@ -174,15 +231,14 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param nbt schematic file. - * @param regionName Name of the region the schematic is in. + * @param subReg Name of the region the schematic is in. * @return String Array holding Long values as text. */ - private static String[] rawBlockArrayString(NBTTagCompound nbt, String regionName) { - //private static String[] rawBlockArrayString(CompoundTag nbt, String regionName) { + private static String[] rawBlockArrayString(String subReg) { + //private static String[] rawBlockArrayString(String regionName) { - String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTag("BlockStates"))).toString(); - //String rawBlockString = Objects.requireNonNull((nbt.getCompound("Regions").getCompound(regionName).get("BlockStates"))).toString(); + String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt))).toString(); + //String rawBlockString = Objects.requireNonNull((nbt.getCompound(reg).getCompound(subReg).get(blSt))).toString(); rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); return rawBlockString.split(","); } From 75a3fc699ebbc8903510999d685d175f35db97c0 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 01:18:56 +0200 Subject: [PATCH 37/78] Code clean up --- .../format/defaults/LitematicaSchematic.java | 74 +++++++++---------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 5a9f6d904..a312b020f 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -37,27 +37,26 @@ import java.util.*; */ public final class LitematicaSchematic extends StaticSchematic { int minX=0,minY=0,minZ=0; - private static String reg = "Regions"; - private static String meta = "Metadata"; - private static String schemSize = "EnclosingSize"; + private static final String reg = "Regions"; + private static final String meta = "Metadata"; + private static final String schemSize = "EnclosingSize"; + private static final String blSt = "BlockStates"; + private static final String blStPl = "BlockStatePalette"; + private static final String pos = "Position"; + private static final String size = "Size"; private static String[] regNames; - private static String blSt = "BlockStates"; - private static String blStPl = "BlockStatePalette"; - private static String pos = "Position"; - private static String size = "Size"; private static NBTTagCompound nbt; public LitematicaSchematic(NBTTagCompound nbt) { - this.nbt = nbt; regNames = getRegions(); + LitematicaSchematic.nbt = nbt; + minCord(); this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y")); this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; - minCord(); - for (String subReg : regNames) { NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); // ListTag blockStatePalette = nbt.getCompound(reg).getCompound(subReg).getList(blStPl,10); @@ -82,8 +81,7 @@ public final class LitematicaSchematic extends StaticSchematic { for (int z = 0; z < this.z; z++) { for (int x = 0; x < this.x; x++) { if (inSubregion(x, y, z, subReg)) { - int paletteIndex = bitArray.getAt(index); - this.states[x-(minX-posX)][z-(minZ-posZ)][y-(minY-posY)] = paletteBlockStates[paletteIndex]; + this.states[x-(minX-posX)][z-(minZ-posZ)][y-(minY-posY)] = paletteBlockStates[bitArray.getAt(index)]; index++; } } @@ -92,14 +90,25 @@ public final class LitematicaSchematic extends StaticSchematic { } } + /** + * @param x cord of the schematic. + * @param y cord of the schematic. + * @param z cord of the schematic. + * @param subReg name of the subregion. + * @return if the current block is inside the subregion. + */ private static boolean inSubregion(int x, int y, int z, String subReg) { - boolean inspect = + return x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && z < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); - return inspect; } + /** + * @param subReg name of the subregion. + * @param s axis that should be read. + * @return the lower cord of the requested axis. + */ private static int getMin(String subReg,String s) { int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); @@ -110,6 +119,10 @@ public final class LitematicaSchematic extends StaticSchematic { } + /** + * Calculates the minimum cords/origin of the schematic as litematica schematics + * can have a non minimum origin. + */ private void minCord() { for (String subReg : regNames) { this.minX = Math.min(this.minX,getMin(subReg,"x")); @@ -118,6 +131,9 @@ public final class LitematicaSchematic extends StaticSchematic { } } + /** + * @return Array of subregion names. + */ private static String[] getRegions() { return nbt.getCompoundTag(reg).getKeySet().toArray(new String[0]); } @@ -165,11 +181,11 @@ public final class LitematicaSchematic extends StaticSchematic { /** * i haven't written this and i wont try to decode it. - * @param state - * @param property - * @param value - * @return - * @param + * @param state . + * @param property . + * @param value . + * @return . + * @param . */ private static > IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { //private static > BlockState setPropertyValue(BlockState state, Property property, String value) { @@ -209,7 +225,7 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @return the amount of blocks in the schematic, including air blocks. + * @return the volume of the subregion. */ private static long getVolume(String subReg) { return Math.abs( @@ -275,24 +291,6 @@ public final class LitematicaSchematic extends StaticSchematic { } } - public void setAt(long index, int value) - { - Validate.inclusiveBetween(0L, this.arraySize - 1L, (long) index); - Validate.inclusiveBetween(0L, this.maxEntryValue, (long) value); - long startOffset = index * (long) this.bitsPerEntry; - int startArrIndex = (int) (startOffset >> 6); // startOffset / 64 - int endArrIndex = (int) (((index + 1L) * (long) this.bitsPerEntry - 1L) >> 6); - int startBitOffset = (int) (startOffset & 0x3F); // startOffset % 64 - this.longArray[startArrIndex] = this.longArray[startArrIndex] & ~(this.maxEntryValue << startBitOffset) | ((long) value & this.maxEntryValue) << startBitOffset; - - if (startArrIndex != endArrIndex) - { - int endOffset = 64 - startBitOffset; - int j1 = this.bitsPerEntry - endOffset; - this.longArray[endArrIndex] = this.longArray[endArrIndex] >>> j1 << j1 | ((long) value & this.maxEntryValue) >> endOffset; - } - } - public int getAt(long index) { Validate.inclusiveBetween(0L, this.arraySize - 1L, (long) index); From 325aa7201bd549ba5ba8b8f544148b1194f1fb47 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 02:51:06 +0200 Subject: [PATCH 38/78] bug fix --- .../utils/schematic/format/defaults/LitematicaSchematic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index a312b020f..d19362c0f 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -48,8 +48,8 @@ public final class LitematicaSchematic extends StaticSchematic { private static NBTTagCompound nbt; public LitematicaSchematic(NBTTagCompound nbt) { + this.nbt = nbt; regNames = getRegions(); - LitematicaSchematic.nbt = nbt; minCord(); this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); From 70303634f548f0aaf9a7657a2f1f69ebc920a22a Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 15:59:55 +0200 Subject: [PATCH 39/78] ref files added --- .../schematic/format/schemfiles/1.12.0.litematic | Bin 0 -> 369 bytes .../schematic/format/schemfiles/1.12.1.litematic | Bin 0 -> 372 bytes .../schematic/format/schemfiles/1.12.2.litematic | Bin 0 -> 373 bytes .../schematic/format/schemfiles/1.14.2.litematic | Bin 0 -> 348 bytes .../schematic/format/schemfiles/1.14.3.litematic | Bin 0 -> 349 bytes .../schematic/format/schemfiles/1.14.4.litematic | Bin 0 -> 348 bytes .../schematic/format/schemfiles/1.15.0.litematic | Bin 0 -> 349 bytes .../schematic/format/schemfiles/1.15.1.litematic | Bin 0 -> 350 bytes .../schematic/format/schemfiles/1.15.2.litematic | Bin 0 -> 353 bytes .../schematic/format/schemfiles/1.16.0.litematic | Bin 0 -> 351 bytes .../schematic/format/schemfiles/1.16.1.litematic | Bin 0 -> 350 bytes .../schematic/format/schemfiles/1.16.2.litematic | Bin 0 -> 351 bytes .../schematic/format/schemfiles/1.16.3.litematic | Bin 0 -> 351 bytes .../schematic/format/schemfiles/1.16.4.litematic | Bin 0 -> 347 bytes .../schematic/format/schemfiles/1.16.5.litematic | Bin 0 -> 351 bytes .../schematic/format/schemfiles/1.17.1.litematic | Bin 0 -> 351 bytes .../schematic/format/schemfiles/1.18.2.litematic | Bin 0 -> 342 bytes .../schematic/format/schemfiles/1.19.2.litematic | Bin 0 -> 350 bytes 18 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.2.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.0.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.3.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.17.1.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.18.2.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic new file mode 100644 index 0000000000000000000000000000000000000000..d2154182cb4921a0725eb584122702d7859f80df GIT binary patch literal 369 zcmV-%0gnD3iwFP!000000G(1zPr^VDeYJ&_7W@ha{VUuQIM!4_u4ZWm+)#GOb}_=$ z|Lje1TE3!*7xpqcZ|A+4H`x$y(T=5})QE}g2`ffq3aJ&~6)yZk1}{VqlNA})c!-8_ zPF+L7QU*95tItmCp;@A_&g4WM;SjC9N^@OEH66$`xp3ZD&*iw{c*b#E<_Hk=s7Q@m z*s7(A=!vF$?dqknT;eb?)K=v8xlU&VBj*9?cT4-K4Scgo$HKhqYeqU>&WUTT19%UD zul}=A95aOQx57nu0Go&^)q!P8rL=>aas9U6er(_>A(ip;Rl!hhTZ3hSgk6=x?mS`V z$=P{21Cx)kiO9)X3i+kBAF4IqFTW$CVa+fxdO^lYDgyX#!brj9YlYQ{uxDKyS=)#I zc>dG~CG9E9Olory)74^jU|k+ri(DvPT?p^*H`r`8-{s0Ue(}oq8|BnjR+hrmsv8J? P<$Qhsq@|#=y8-|J&E>W- literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic new file mode 100644 index 0000000000000000000000000000000000000000..04a225e5c3ac62d2a242ebcceab5825308565367 GIT binary patch literal 372 zcmV-)0gL`0iwFP!000000G(3HQo=wG?2tf00=|la{)#sRj#wzj)moAPw+Oq`X0e2; zU+Kxu@T52i1WK#Cu$RfqPWMcAHUwO>dQwqr#Kd-l6(cg4)C%z4UHJP9UWlMaRwUfx zAsWg#wG9bN3E;e~K0g{B8hN#+6FHHGa)@SE#i`DunhxZeTsW`H=W<+etZ-cCIRZo- z%3>oIwixLmdY~zPw)Ik3ZgKLt+KTix)$uID_M8N$-7M|1Ht@|V9t-nS_KkG9oYSuF zB7k=%IQ1Wu;+PNhJP@c~Ef*6rzb2_A;H>d2i;uZV0$&^`xT2h_USmD~4opsTEMYcH!?ccp-uwS&?#& zhiD*Y)HWn6rGWFc{P=wL&?u@soyxI1ltVPTD#>&%)ub<1;l?Pg)0wSjMz$w-)|vTvxf#f)}+ z=K;Js!KweK6vq@H{Oy1|+!q^&Htc=N(uxrdE=IM>ZtK2|vzS!MDmD!RS+2mw#H_AZ zdZ!ILZO%?x1q?pW#v&tYDdd}Kxm0sj{)8(b4ReOE(Q`6ZQXas65k?9&p_*H*2qo&| zfZAUChw~>!C~1#Drc#@ukggWfJ?iv;nrA|>bs@aJ&tbh@e;1Z<{9?=aIc3yURu;q? TtLq4U<$QhsBc*4+!vX*R{jjpx literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic new file mode 100644 index 0000000000000000000000000000000000000000..3382eb96c0b36fa76cccddc5a9b1582a95995093 GIT binary patch literal 348 zcmV-i0i*sOiwFP!000000BuphQo=A4+|o)*3pzL)^jEwo;0*@_y?9_k`@jq#VbU-o zT>WmvSD;i!dwF@g+s)g&81T^vYxNqSS)c=x$(gL+7_GiemC2=^kK~qoc<=1zbKP*QaorX@A|yS^Q!7_) zf2EJ)iROIlnzeQ;@faB!C)AxX=^|(3JVO0;?cR(1Xe)?7vi9t0o5 zXRWzrh!Gx)^Y{cdk?dVZjw2P;9wf34f%cGe#?$WwV|ln5Y!eMRRWa-_Q|*`u z$4mhKT-gqVBIhVBUb7skwJab1Mo5bizNp~b8BHgmT@iCDv~>ScnKbq%)u|{W7L%0{ unnT10%7yH9yU#xhsgmETwalvIjbhV^`r2`NDzWHS&)+x4OUPng0ssJnpr$bZ literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic new file mode 100644 index 0000000000000000000000000000000000000000..ac61c3aae708ac0b5b62a5232a409f927de913b2 GIT binary patch literal 349 zcmV-j0iymNiwFP!000000BuoCPr^VHoYG253mOau{VU$&!y5(#y^^JU;D)kGw%bIw zdiE!q`U;e4w3oMUW;*+3UkJG9jisX4h@~A0D_+TDQY)Z2cj2EqT!aY5WJSUn57A6+ zXkbWKN&x3$SA6z8v`ciX6S2s5uVuR6^)#G2~>-lO27 z|DqJv1R?yRaTcDzHll;;)N-WK+QH4Dc{}Powa}fAN_hH%U?z`OgKdHdrz(d%Won!< z;gkvBpKIHRNXc3X%h#-i>TIgVzZ24+g0E^gvs%%a=+?x_2qo>mR3f$cN%d+iPQyVU(YoUIG9B%qggW literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic new file mode 100644 index 0000000000000000000000000000000000000000..1ea4bd2e38d0fb3de6a919c0bf884e9f0f8b7792 GIT binary patch literal 348 zcmV-i0i*sOiwFP!000000BuphPQpMGoYG253mOau{S|Ktc*CF|*Jf!SxS{Nl?KTmv z{-(cT@D(W4XfJQy%yjn6z7TNH8%afp5eqvIR?NucQY)YtyYSB)E8w~2Ypw%$PlAvB zt5RH3gz%5Xd3Xlfhz_n3%aKZJ2RHNP?XdUULU&9m<>?QCsXSf{wh6|ZsvP!|sd37L zQzn3au5HI6BWo!vU$Yvjv#uWhPDq0azN+EeYDH(FTN6tol(hd+snq5t)vGBjR`Dhi uibI6(s)g+L`>#I>sgplug-q+@t#Z>D4VC5eRAIrdp1*HVXg}m$0ssKn#i*tL literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic new file mode 100644 index 0000000000000000000000000000000000000000..ea6ca5ae1d77f518071bd828bdb4ca27733ab60f GIT binary patch literal 349 zcmV-j0iymNiwFP!000000BuphPQpMGoYD%V1r3IS{)0Df-W2eLK|!u$X&<;@*(KX; zqFnuMgRelTMtgbtW~Q@m_CL5j+V# zHeR*nnj%8uV4OuKu!VT8ZrRUp;@{&h{CxUIG9BAgior literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic new file mode 100644 index 0000000000000000000000000000000000000000..53df63aab72aefedea1eec60e5969362e4139c48 GIT binary patch literal 350 zcmV-k0ipgMiwFP!000000BuphPQpMGoZ3oD3mOau{S|Ktc*CF|SF*GZ+_3DD?UD#r z|H+RtG589UYP6TPZ)Q6CW?u~WX!oV2)QXww3Ma;7b7?eCoA?M%9nND!eR3jWO@L%1 zm(;N&9A$v_zV$vo0yGM=Z!$TP6&$14)2TAK)bpX-k`M2V{d}$)u4i1gMUMzcm-5ug zmD^wGBYCDdA3J8P9ZNh$M#c$suS~kg8M%m1yIZ?gV-ea-Iu&+OYQ{#bm&BT@2*IP^ zWB8&q*9(Fte!rH_2w06^LKh@D1kj{AeylT{YkYe%812e wrG(}XF@ka-yWQ^V&qAu?4{9y5DtW!ww4$DNoSsT7`qlII4I@*PY+eEY0DBXs3jhEB literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic new file mode 100644 index 0000000000000000000000000000000000000000..dfdcac5589a46e5d99030f7736ba6cbb7e76c36c GIT binary patch literal 353 zcmV-n0iOOJiwFP!000000Buo0Qo=wG?2t%80$Nxc^ef&J@P>tgT&X1)aEq`@Z8lZH z)sOfJzvT-ooB$zOn#=5TcY3FHLcm35AQi<%%xzCtF(H#lt$^Ueg@5XB79tps6$xuR zL}R(4t|4J50i3sO?fuh3vp@$rk#kwWAzFPEr#h2rF_K$y;k>e+%XP!G#&uit2oUus zi;Y~{{gp1FCtC2at8-;p;xIDSR-|{Sj+YrD=K<=sxqZKqSJgutho%} zJqSMf&q{Gk5W+tgXW~>9R8hD7A1UH!MQV(4?e=a1Q1rIqt~vFVI@+Oc~ovFKOM=NqwGb=_V9006T+uIc~) literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic new file mode 100644 index 0000000000000000000000000000000000000000..b671b1f9fd521a386334a77119e44799ee3d8bcd GIT binary patch literal 350 zcmV-k0ipgMiwFP!000000BuphPQpMCeWlfw1vD5A`YRqx6!3;YL9S$J2i#D0$#$Cv zSAWi*GB^cFHM*DCdGq$|ycq%b=nRym*vh%{Gi5X&LLcEN!o-kI2uX#X-hU}_n_UNg0 z^n{})fFD<~Lz$9uB#LR4O|@3#@NcEEDB;Tr&YaP7DzvM@!b+{&zokSO`?J)kN=7cH w>r`qsArO=c+3j{;e-=_Xe@t_gRL<+grc>%`$L^`bqF*_mZy>g4hh72z019oXnE(I) literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic new file mode 100644 index 0000000000000000000000000000000000000000..f3d137028149266913fb7183b9d8a824c13e1597 GIT binary patch literal 351 zcmV-l0igaLiwFP!000000BuphQo=A0eWit#6m(!X=&yKFz#9$cSVi}@jzsW zl^b{X(ntIxmUQi#Tsxw8giMX&>Q0$tl@W3gp>dnLS7Q;{Z8GO}R&rj9%GZK8-3Y-0 zr)&7EHN_MR;ZZnaXRw9%pgM76sgU+?HE&!Gdyh?Y#zLpm{edu*$FFHXh{oiqX!hi( zcJhRiCx9MTvSY45SWH#hDmYtORkcA_R|| zuHlQ;6f-b{2jQHZz!u`Y>d29$Qrg4ytZ~y%o|@lU(mT{3(* xT`R811Vd0QWVhRW{aHxu{6Q5mtDQH?O)JsYj@*k1i+<&Fz5%sbBC%cq006`_svQ6T literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic new file mode 100644 index 0000000000000000000000000000000000000000..a0ff6107aa675fdbd70db69ad2ba6d0a69a21fff GIT binary patch literal 347 zcmV-h0i^yPiwFP!000000BuphQo=A0eWlfw6m)Pn;ID8~z#9$z#vKy-YBmkd_|(U6=>nG+zMs5SL0 zNk=K*eeNUI4bUjip-I(3Rj@#Fpp(qxN-xK1Pd>a4*7G^;IMz7siyRT+KIMs38+ZKD zNBl}lzV^&kJEnMyOpKG+V`h?7&d5!K>xZp-Hx{AYC39(KC1+}~?V6Z#7a@3-d=1~U z=9oetJPGIG0yYpIRmYAk71AC$^XvOT`=yT7h;+)`9|;q6`kDuXXvD6HX3w5#XHPhL z0{C$yJCYeWN1~W!*;I2~4!PA`BS!4Y300LY&xTXcI=)?Ec%u6`38fMs7hV}007LgrYisd literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic new file mode 100644 index 0000000000000000000000000000000000000000..46aead9a275c48aa290e1ac2c1590027a791c385 GIT binary patch literal 351 zcmV-l0igaLiwFP!000000BuphQo=A0eWjI_6m)Pns6XP2HwC=mpdeQ!v;i}Ogh|sG z;pzwY#SU(PQXS1@vu|Hs_U$sjM`s|lNGzYb9(Q~qY$lBc*o}|yl;Mma8VJWz;sl7t zawWP}a3@m0``9*aKLa!ibYN0Bmle#=>gzx_?WlH1=nyQWBENz5=B>)wR{+7&u7xm?NyPS6?ZOqoLJ)kN;dhxg8YKGzSfXIytxj~MBIip6B_1PFM#! oIYffs-w$b$KdMsZP4ZUt(~5@LaeAt;_*c*C8{2wM-d+L#0L)3J&j0`b literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic new file mode 100644 index 0000000000000000000000000000000000000000..e3514b035da95b90a213587572ebfcc7371e66c5 GIT binary patch literal 350 zcmV-k0ipgMiwFP!00000|7}shPQpMGoZ3oD3mOau{R_|D6!3;YL9S$JAGl%JCEFzt zuKtIAYVZ{()o3qo-^}dno4y$E(e6u4sTDKV6;6!F=F(`OaqA;Ib*RON`s75$ngGd2 zE~#TlILZL;W83=l0yGM=Z!$TP6&$14)2TAK)bpX-k`M2l{d}$)u4i1gMUMzcm-5ug zmD@k*BYB}YA3J8P9ZNh$M#c&CpiH{R8M%m1yI;FEV-ea-Iu&+OYQ{#bm&BT@2*H!! zWB95y*9(Fte!rH_2w06^LKiAP3kj{Aey&%YDWqJ%FiICnlT{YkYe%812e wrG(}XF@ka-yWQ^V&qAu?k7_NmDtW!ww4$DNoSsT7`qlII4KBSA0$u_D03nR5`v3p{ literal 0 HcmV?d00001 From c89d8b69e5d50c5aa1dd7c6f03179492d3147c8b Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 16:08:37 +0200 Subject: [PATCH 40/78] ref files removed --- .../schematic/format/schemfiles/1.12.0.litematic | Bin 369 -> 0 bytes .../schematic/format/schemfiles/1.12.1.litematic | Bin 372 -> 0 bytes .../schematic/format/schemfiles/1.12.2.litematic | Bin 373 -> 0 bytes .../schematic/format/schemfiles/1.14.2.litematic | Bin 348 -> 0 bytes .../schematic/format/schemfiles/1.14.3.litematic | Bin 349 -> 0 bytes .../schematic/format/schemfiles/1.14.4.litematic | Bin 348 -> 0 bytes .../schematic/format/schemfiles/1.15.0.litematic | Bin 349 -> 0 bytes .../schematic/format/schemfiles/1.15.1.litematic | Bin 350 -> 0 bytes .../schematic/format/schemfiles/1.15.2.litematic | Bin 353 -> 0 bytes .../schematic/format/schemfiles/1.16.0.litematic | Bin 351 -> 0 bytes .../schematic/format/schemfiles/1.16.1.litematic | Bin 350 -> 0 bytes .../schematic/format/schemfiles/1.16.2.litematic | Bin 351 -> 0 bytes .../schematic/format/schemfiles/1.16.3.litematic | Bin 351 -> 0 bytes .../schematic/format/schemfiles/1.16.4.litematic | Bin 347 -> 0 bytes .../schematic/format/schemfiles/1.16.5.litematic | Bin 351 -> 0 bytes .../schematic/format/schemfiles/1.17.1.litematic | Bin 351 -> 0 bytes .../schematic/format/schemfiles/1.18.2.litematic | Bin 342 -> 0 bytes .../schematic/format/schemfiles/1.19.2.litematic | Bin 350 -> 0 bytes 18 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.2.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.0.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.3.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.17.1.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.18.2.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic deleted file mode 100644 index d2154182cb4921a0725eb584122702d7859f80df..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 369 zcmV-%0gnD3iwFP!000000G(1zPr^VDeYJ&_7W@ha{VUuQIM!4_u4ZWm+)#GOb}_=$ z|Lje1TE3!*7xpqcZ|A+4H`x$y(T=5})QE}g2`ffq3aJ&~6)yZk1}{VqlNA})c!-8_ zPF+L7QU*95tItmCp;@A_&g4WM;SjC9N^@OEH66$`xp3ZD&*iw{c*b#E<_Hk=s7Q@m z*s7(A=!vF$?dqknT;eb?)K=v8xlU&VBj*9?cT4-K4Scgo$HKhqYeqU>&WUTT19%UD zul}=A95aOQx57nu0Go&^)q!P8rL=>aas9U6er(_>A(ip;Rl!hhTZ3hSgk6=x?mS`V z$=P{21Cx)kiO9)X3i+kBAF4IqFTW$CVa+fxdO^lYDgyX#!brj9YlYQ{uxDKyS=)#I zc>dG~CG9E9Olory)74^jU|k+ri(DvPT?p^*H`r`8-{s0Ue(}oq8|BnjR+hrmsv8J? P<$Qhsq@|#=y8-|J&E>W- diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic deleted file mode 100644 index 04a225e5c3ac62d2a242ebcceab5825308565367..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 372 zcmV-)0gL`0iwFP!000000G(3HQo=wG?2tf00=|la{)#sRj#wzj)moAPw+Oq`X0e2; zU+Kxu@T52i1WK#Cu$RfqPWMcAHUwO>dQwqr#Kd-l6(cg4)C%z4UHJP9UWlMaRwUfx zAsWg#wG9bN3E;e~K0g{B8hN#+6FHHGa)@SE#i`DunhxZeTsW`H=W<+etZ-cCIRZo- z%3>oIwixLmdY~zPw)Ik3ZgKLt+KTix)$uID_M8N$-7M|1Ht@|V9t-nS_KkG9oYSuF zB7k=%IQ1Wu;+PNhJP@c~Ef*6rzb2_A;H>d2i;uZV0$&^`xT2h_USmD~4opsTEMYcH!?ccp-uwS&?#& zhiD*Y)HWn6rGWFc{P=wL&?u@soyxI1ltVPTD#>&%)ub<1;l?Pg)0wSjMz$w-)|vTvxf#f)}+ z=K;Js!KweK6vq@H{Oy1|+!q^&Htc=N(uxrdE=IM>ZtK2|vzS!MDmD!RS+2mw#H_AZ zdZ!ILZO%?x1q?pW#v&tYDdd}Kxm0sj{)8(b4ReOE(Q`6ZQXas65k?9&p_*H*2qo&| zfZAUChw~>!C~1#Drc#@ukggWfJ?iv;nrA|>bs@aJ&tbh@e;1Z<{9?=aIc3yURu;q? TtLq4U<$QhsBc*4+!vX*R{jjpx diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic deleted file mode 100644 index 3382eb96c0b36fa76cccddc5a9b1582a95995093..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 348 zcmV-i0i*sOiwFP!000000BuphQo=A4+|o)*3pzL)^jEwo;0*@_y?9_k`@jq#VbU-o zT>WmvSD;i!dwF@g+s)g&81T^vYxNqSS)c=x$(gL+7_GiemC2=^kK~qoc<=1zbKP*QaorX@A|yS^Q!7_) zf2EJ)iROIlnzeQ;@faB!C)AxX=^|(3JVO0;?cR(1Xe)?7vi9t0o5 zXRWzrh!Gx)^Y{cdk?dVZjw2P;9wf34f%cGe#?$WwV|ln5Y!eMRRWa-_Q|*`u z$4mhKT-gqVBIhVBUb7skwJab1Mo5bizNp~b8BHgmT@iCDv~>ScnKbq%)u|{W7L%0{ unnT10%7yH9yU#xhsgmETwalvIjbhV^`r2`NDzWHS&)+x4OUPng0ssJnpr$bZ diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic deleted file mode 100644 index ac61c3aae708ac0b5b62a5232a409f927de913b2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 349 zcmV-j0iymNiwFP!000000BuoCPr^VHoYG253mOau{VU$&!y5(#y^^JU;D)kGw%bIw zdiE!q`U;e4w3oMUW;*+3UkJG9jisX4h@~A0D_+TDQY)Z2cj2EqT!aY5WJSUn57A6+ zXkbWKN&x3$SA6z8v`ciX6S2s5uVuR6^)#G2~>-lO27 z|DqJv1R?yRaTcDzHll;;)N-WK+QH4Dc{}Powa}fAN_hH%U?z`OgKdHdrz(d%Won!< z;gkvBpKIHRNXc3X%h#-i>TIgVzZ24+g0E^gvs%%a=+?x_2qo>mR3f$cN%d+iPQyVU(YoUIG9B%qggW diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic deleted file mode 100644 index 1ea4bd2e38d0fb3de6a919c0bf884e9f0f8b7792..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 348 zcmV-i0i*sOiwFP!000000BuphPQpMGoYG253mOau{S|Ktc*CF|*Jf!SxS{Nl?KTmv z{-(cT@D(W4XfJQy%yjn6z7TNH8%afp5eqvIR?NucQY)YtyYSB)E8w~2Ypw%$PlAvB zt5RH3gz%5Xd3Xlfhz_n3%aKZJ2RHNP?XdUULU&9m<>?QCsXSf{wh6|ZsvP!|sd37L zQzn3au5HI6BWo!vU$Yvjv#uWhPDq0azN+EeYDH(FTN6tol(hd+snq5t)vGBjR`Dhi uibI6(s)g+L`>#I>sgplug-q+@t#Z>D4VC5eRAIrdp1*HVXg}m$0ssKn#i*tL diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic deleted file mode 100644 index ea6ca5ae1d77f518071bd828bdb4ca27733ab60f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 349 zcmV-j0iymNiwFP!000000BuphPQpMGoYD%V1r3IS{)0Df-W2eLK|!u$X&<;@*(KX; zqFnuMgRelTMtgbtW~Q@m_CL5j+V# zHeR*nnj%8uV4OuKu!VT8ZrRUp;@{&h{CxUIG9BAgior diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic deleted file mode 100644 index 53df63aab72aefedea1eec60e5969362e4139c48..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 350 zcmV-k0ipgMiwFP!000000BuphPQpMGoZ3oD3mOau{S|Ktc*CF|SF*GZ+_3DD?UD#r z|H+RtG589UYP6TPZ)Q6CW?u~WX!oV2)QXww3Ma;7b7?eCoA?M%9nND!eR3jWO@L%1 zm(;N&9A$v_zV$vo0yGM=Z!$TP6&$14)2TAK)bpX-k`M2V{d}$)u4i1gMUMzcm-5ug zmD^wGBYCDdA3J8P9ZNh$M#c$suS~kg8M%m1yIZ?gV-ea-Iu&+OYQ{#bm&BT@2*IP^ zWB8&q*9(Fte!rH_2w06^LKh@D1kj{AeylT{YkYe%812e wrG(}XF@ka-yWQ^V&qAu?4{9y5DtW!ww4$DNoSsT7`qlII4I@*PY+eEY0DBXs3jhEB diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic deleted file mode 100644 index dfdcac5589a46e5d99030f7736ba6cbb7e76c36c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 353 zcmV-n0iOOJiwFP!000000Buo0Qo=wG?2t%80$Nxc^ef&J@P>tgT&X1)aEq`@Z8lZH z)sOfJzvT-ooB$zOn#=5TcY3FHLcm35AQi<%%xzCtF(H#lt$^Ueg@5XB79tps6$xuR zL}R(4t|4J50i3sO?fuh3vp@$rk#kwWAzFPEr#h2rF_K$y;k>e+%XP!G#&uit2oUus zi;Y~{{gp1FCtC2at8-;p;xIDSR-|{Sj+YrD=K<=sxqZKqSJgutho%} zJqSMf&q{Gk5W+tgXW~>9R8hD7A1UH!MQV(4?e=a1Q1rIqt~vFVI@+Oc~ovFKOM=NqwGb=_V9006T+uIc~) diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic deleted file mode 100644 index b671b1f9fd521a386334a77119e44799ee3d8bcd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 350 zcmV-k0ipgMiwFP!000000BuphPQpMCeWlfw1vD5A`YRqx6!3;YL9S$J2i#D0$#$Cv zSAWi*GB^cFHM*DCdGq$|ycq%b=nRym*vh%{Gi5X&LLcEN!o-kI2uX#X-hU}_n_UNg0 z^n{})fFD<~Lz$9uB#LR4O|@3#@NcEEDB;Tr&YaP7DzvM@!b+{&zokSO`?J)kN=7cH w>r`qsArO=c+3j{;e-=_Xe@t_gRL<+grc>%`$L^`bqF*_mZy>g4hh72z019oXnE(I) diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic deleted file mode 100644 index f3d137028149266913fb7183b9d8a824c13e1597..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 351 zcmV-l0igaLiwFP!000000BuphQo=A0eWit#6m(!X=&yKFz#9$cSVi}@jzsW zl^b{X(ntIxmUQi#Tsxw8giMX&>Q0$tl@W3gp>dnLS7Q;{Z8GO}R&rj9%GZK8-3Y-0 zr)&7EHN_MR;ZZnaXRw9%pgM76sgU+?HE&!Gdyh?Y#zLpm{edu*$FFHXh{oiqX!hi( zcJhRiCx9MTvSY45SWH#hDmYtORkcA_R|| zuHlQ;6f-b{2jQHZz!u`Y>d29$Qrg4ytZ~y%o|@lU(mT{3(* xT`R811Vd0QWVhRW{aHxu{6Q5mtDQH?O)JsYj@*k1i+<&Fz5%sbBC%cq006`_svQ6T diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic deleted file mode 100644 index a0ff6107aa675fdbd70db69ad2ba6d0a69a21fff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 347 zcmV-h0i^yPiwFP!000000BuphQo=A0eWlfw6m)Pn;ID8~z#9$z#vKy-YBmkd_|(U6=>nG+zMs5SL0 zNk=K*eeNUI4bUjip-I(3Rj@#Fpp(qxN-xK1Pd>a4*7G^;IMz7siyRT+KIMs38+ZKD zNBl}lzV^&kJEnMyOpKG+V`h?7&d5!K>xZp-Hx{AYC39(KC1+}~?V6Z#7a@3-d=1~U z=9oetJPGIG0yYpIRmYAk71AC$^XvOT`=yT7h;+)`9|;q6`kDuXXvD6HX3w5#XHPhL z0{C$yJCYeWN1~W!*;I2~4!PA`BS!4Y300LY&xTXcI=)?Ec%u6`38fMs7hV}007LgrYisd diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic deleted file mode 100644 index 46aead9a275c48aa290e1ac2c1590027a791c385..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 351 zcmV-l0igaLiwFP!000000BuphQo=A0eWjI_6m)Pns6XP2HwC=mpdeQ!v;i}Ogh|sG z;pzwY#SU(PQXS1@vu|Hs_U$sjM`s|lNGzYb9(Q~qY$lBc*o}|yl;Mma8VJWz;sl7t zawWP}a3@m0``9*aKLa!ibYN0Bmle#=>gzx_?WlH1=nyQWBENz5=B>)wR{+7&u7xm?NyPS6?ZOqoLJ)kN;dhxg8YKGzSfXIytxj~MBIip6B_1PFM#! oIYffs-w$b$KdMsZP4ZUt(~5@LaeAt;_*c*C8{2wM-d+L#0L)3J&j0`b diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic deleted file mode 100644 index e3514b035da95b90a213587572ebfcc7371e66c5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 350 zcmV-k0ipgMiwFP!00000|7}shPQpMGoZ3oD3mOau{R_|D6!3;YL9S$JAGl%JCEFzt zuKtIAYVZ{()o3qo-^}dno4y$E(e6u4sTDKV6;6!F=F(`OaqA;Ib*RON`s75$ngGd2 zE~#TlILZL;W83=l0yGM=Z!$TP6&$14)2TAK)bpX-k`M2l{d}$)u4i1gMUMzcm-5ug zmD@k*BYB}YA3J8P9ZNh$M#c&CpiH{R8M%m1yI;FEV-ea-Iu&+OYQ{#bm&BT@2*H!! zWB95y*9(Fte!rH_2w06^LKiAP3kj{Aey&%YDWqJ%FiICnlT{YkYe%812e wrG(}XF@ka-yWQ^V&qAu?k7_NmDtW!ww4$DNoSsT7`qlII4KBSA0$u_D03nR5`v3p{ From 113e340474c3c33da94f885b81a029a07b33aa60 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 16:09:41 +0200 Subject: [PATCH 41/78] version check added --- .../schematic/format/DefaultSchematicFormats.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index 6cea77fe0..de142b391 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -74,7 +74,17 @@ public enum DefaultSchematicFormats implements ISchematicFormat { Litematica("litematic") { @Override public IStaticSchematic parse(InputStream input) throws IOException { - return new LitematicaSchematic(CompressedStreamTools.readCompressed(input)); + NBTTagCompound nbt = CompressedStreamTools.readCompressed(input); + int version = nbt.getInteger("Version"); + switch (version) { + case 4: + return new LitematicaSchematic(nbt); + case 5: + case 6: + throw new UnsupportedOperationException("This Schematic Verion is to new."); + default: + throw new UnsupportedOperationException("Unsuported Version of a Litematica Schematic"); + } } }; From 376d6422ec2c3f602dc2225c9008b2832ba8175e Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 16:18:43 +0200 Subject: [PATCH 42/78] refactoring --- .../format/defaults/LitematicaSchematic.java | 72 ++++++++++--------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index d19362c0f..f0e9d174b 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -44,6 +44,7 @@ public final class LitematicaSchematic extends StaticSchematic { private static final String blStPl = "BlockStatePalette"; private static final String pos = "Position"; private static final String size = "Size"; + private static String subReg; private static String[] regNames; private static NBTTagCompound nbt; @@ -57,33 +58,42 @@ public final class LitematicaSchematic extends StaticSchematic { this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; - for (String subReg : regNames) { + for (String subRegion : regNames) { + subReg = subRegion; NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); // ListTag blockStatePalette = nbt.getCompound(reg).getCompound(subReg).getList(blStPl,10); IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); // BlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); - int posX = getMin(subReg,"x"); - int posY = getMin(subReg,"y"); - int posZ = getMin(subReg,"z"); - int bitsPerBlock = bitsPerBlock(blockStatePalette); - long regionVolume = getVolume(subReg); - long[] rawBlockData = rawBlockData(rawBlockArrayString(subReg)); + int bitsPerBlock = bitsPerBlock(blockStatePalette.tagCount()); + long regionVolume = getVolume(); + long[] blockStateArray = getBlockStates(); - LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, rawBlockData); + LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, blockStateArray); if (bitsPerBlock > 32) { throw new IllegalStateException("Too many blocks in schematic to handle"); } - int index = 0; - for (int y = 0; y < this.y; y++) { - for (int z = 0; z < this.z; z++) { - for (int x = 0; x < this.x; x++) { - if (inSubregion(x, y, z, subReg)) { - this.states[x-(minX-posX)][z-(minZ-posZ)][y-(minY-posY)] = paletteBlockStates[bitArray.getAt(index)]; - index++; - } + createSchematicOfSubRegion(paletteBlockStates, bitArray); + } + } + + /** + * @param paletteBlockStates list with the different block types used in the schematic + * @param bitArray bit array that holds the placement pattern + */ + private void createSchematicOfSubRegion(IBlockState[] paletteBlockStates, LitematicaBitArray bitArray) { + int posX = getMin("x"); + int posY = getMin("y"); + int posZ = getMin("z"); + int index = 0; + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + if (inSubregion(x, y, z)) { + this.states[x-(minX- posX)][z-(minZ- posZ)][y-(minY- posY)] = paletteBlockStates[bitArray.getAt(index)]; + index++; } } } @@ -94,10 +104,9 @@ public final class LitematicaSchematic extends StaticSchematic { * @param x cord of the schematic. * @param y cord of the schematic. * @param z cord of the schematic. - * @param subReg name of the subregion. * @return if the current block is inside the subregion. */ - private static boolean inSubregion(int x, int y, int z, String subReg) { + private static boolean inSubregion(int x, int y, int z) { return x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && @@ -105,11 +114,10 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param subReg name of the subregion. * @param s axis that should be read. * @return the lower cord of the requested axis. */ - private static int getMin(String subReg,String s) { + private static int getMin(String s) { int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); if (b < 0) { @@ -124,10 +132,11 @@ public final class LitematicaSchematic extends StaticSchematic { * can have a non minimum origin. */ private void minCord() { - for (String subReg : regNames) { - this.minX = Math.min(this.minX,getMin(subReg,"x")); - this.minY = Math.min(this.minY,getMin(subReg,"y")); - this.minZ = Math.min(this.minZ,getMin(subReg,"z")); + for (String subRegion : regNames) { + subReg = subRegion; + this.minX = Math.min(this.minX,getMin("x")); + this.minY = Math.min(this.minY,getMin("y")); + this.minZ = Math.min(this.minZ,getMin("z")); } } @@ -215,19 +224,19 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param blockStatePalette List of all different block types used in the schematic. + * @param amountOfBlockTypes amount of block types in the schematic. * @return amount of bits used to encode a block. */ - private static int bitsPerBlock(NBTTagList blockStatePalette) { + private static int bitsPerBlock(int amountOfBlockTypes) { //private static int bitsPerBlock(ListTag blockStatePalette) { - return (int) Math.floor((Math.log(blockStatePalette.tagCount())) / Math.log(2))+1; + return (int) Math.floor((Math.log(amountOfBlockTypes)) / Math.log(2))+1; //return (int) Math.floor((Math.log(blockStatePalette.size())) / Math.log(2))+1; } /** * @return the volume of the subregion. */ - private static long getVolume(String subReg) { + private static long getVolume() { return Math.abs( nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x") * nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * @@ -235,10 +244,10 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param rawBlockArrayString String Array holding Long values as text. * @return array of Long values. */ - private static long[] rawBlockData(String[] rawBlockArrayString) { + private static long[] getBlockStates() { + String[] rawBlockArrayString = rawBlockArrayString(); long[] rawBlockData = new long[rawBlockArrayString.length]; for (int i = 0; i < rawBlockArrayString.length; i++) { rawBlockData[i] = Long.parseLong(rawBlockArrayString[i].substring(0,rawBlockArrayString[i].length()-1)); @@ -247,10 +256,9 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param subReg Name of the region the schematic is in. * @return String Array holding Long values as text. */ - private static String[] rawBlockArrayString(String subReg) { + private static String[] rawBlockArrayString() { //private static String[] rawBlockArrayString(String regionName) { String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt))).toString(); From 295265c2618a0e519117a17102358964d01cebb8 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 17:43:54 +0200 Subject: [PATCH 43/78] refactoring --- .../format/defaults/LitematicaSchematic.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index f0e9d174b..55723faf8 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -247,7 +247,9 @@ public final class LitematicaSchematic extends StaticSchematic { * @return array of Long values. */ private static long[] getBlockStates() { - String[] rawBlockArrayString = rawBlockArrayString(); + String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt))).toString(); + rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); + String[] rawBlockArrayString = rawBlockString.split(","); long[] rawBlockData = new long[rawBlockArrayString.length]; for (int i = 0; i < rawBlockArrayString.length; i++) { rawBlockData[i] = Long.parseLong(rawBlockArrayString[i].substring(0,rawBlockArrayString[i].length()-1)); @@ -255,17 +257,15 @@ public final class LitematicaSchematic extends StaticSchematic { return rawBlockData; } + // will only work after 1.12. will replace the getBlockStates() above. + /* /** - * @return String Array holding Long values as text. + * @return array of Long values. */ - private static String[] rawBlockArrayString() { - //private static String[] rawBlockArrayString(String regionName) { - - String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt))).toString(); - //String rawBlockString = Objects.requireNonNull((nbt.getCompound(reg).getCompound(subReg).get(blSt))).toString(); - rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); - return rawBlockString.split(","); - } + /* + private static long[] getBlockStates() { + return nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt).getLongArray(); + }*/ /** LitematicaBitArray class from litematica */ private static class LitematicaBitArray From 3d8eddc4e161e9fca6bfa7661125d55f4b3868f8 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 19:23:09 +0200 Subject: [PATCH 44/78] cleanup --- .../format/defaults/LitematicaSchematic.java | 51 +++---------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 55723faf8..4c8ce4c69 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -48,8 +48,8 @@ public final class LitematicaSchematic extends StaticSchematic { private static String[] regNames; private static NBTTagCompound nbt; - public LitematicaSchematic(NBTTagCompound nbt) { - this.nbt = nbt; + public LitematicaSchematic(NBTTagCompound nbtCompound) { + nbt = nbtCompound; regNames = getRegions(); minCord(); @@ -61,9 +61,7 @@ public final class LitematicaSchematic extends StaticSchematic { for (String subRegion : regNames) { subReg = subRegion; NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); - // ListTag blockStatePalette = nbt.getCompound(reg).getCompound(subReg).getList(blStPl,10); IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); - // BlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); int bitsPerBlock = bitsPerBlock(blockStatePalette.tagCount()); long regionVolume = getVolume(); @@ -129,7 +127,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * Calculates the minimum cords/origin of the schematic as litematica schematics - * can have a non minimum origin. + * can have a non-minimum origin. */ private void minCord() { for (String subRegion : regNames) { @@ -152,15 +150,11 @@ public final class LitematicaSchematic extends StaticSchematic { * @return Array of BlockStates. */ private static IBlockState[] paletteBlockStates(NBTTagList blockStatePalette) { - // private static BlockState[] paletteBlockStates(TagList blockStatePalette) { IBlockState[] paletteBlockStates = new IBlockState[blockStatePalette.tagCount()]; - //BlockState[] paletteBlockState = new BlockState[blockStatePalette.tagCount()]; for (int i = 0; i< blockStatePalette.tagCount(); i++) { Block block = Block.REGISTRY.getObject(new ResourceLocation((((NBTTagCompound) blockStatePalette.get(i)).getString("Name")))); - //Block block = Registry.BLOCK.get(new ResourceLocation((((CompoundTag) blockStatePalette.get(i)).getString("Name")))); NBTTagCompound properties = ((NBTTagCompound) blockStatePalette.get(i)).getCompoundTag("Properties"); - //CompoundTag properties = ((CompoundTag) blockStatePalette.get(i)).getCompound("Properties"); paletteBlockStates[i] = getBlockState(block, properties); } @@ -173,16 +167,13 @@ public final class LitematicaSchematic extends StaticSchematic { * @return A blockState. */ private static IBlockState getBlockState(Block block, NBTTagCompound properties) { - //private static BlockState getBlockState(Block block, CompoundTag properties) { IBlockState blockState = block.getDefaultState(); - //BlockState blockState = block.defaultBlockState(); + for (Object key : properties.getKeySet().toArray()) { - //for (Object key : properties.getAllKeys().toArray()) { - IProperty property = block.getBlockState().getProperty(key.toString()); - //Property property = block.getStateDefinition().getProperty(key.toString()); + IProperty property = block.getBlockState().getProperty((String) key); if (property != null) { - blockState = setPropertyValue(blockState, property, propertiesMap(properties).get(key)); + blockState = setPropertyValue(blockState, property, properties.getString((String) key)); } } return blockState; @@ -197,40 +188,20 @@ public final class LitematicaSchematic extends StaticSchematic { * @param . */ private static > IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { - //private static > BlockState setPropertyValue(BlockState state, Property property, String value) { Optional parsed = property.parseValue(value).toJavaUtil(); - //Optional parsed = property.getValue(value); if (parsed.isPresent()) { return state.withProperty(property, parsed.get()); - //return state.setValue(property, parsed.get()); } else { throw new IllegalArgumentException("Invalid value for property " + property); } } - /** - * @param properties properties a block has. - * @return properties as map. - */ - private static Map propertiesMap(NBTTagCompound properties) { - //private static Map propertiesMap(CompoundTag properties) { - Map propertiesMap = new HashMap<>(); - - for (Object key : properties.getKeySet().toArray()) { - //for (Object key : properties.getAllKeys().toArray()) { - propertiesMap.put((String) key, (properties.getString((String) key))); - } - return propertiesMap; - } - /** * @param amountOfBlockTypes amount of block types in the schematic. * @return amount of bits used to encode a block. */ private static int bitsPerBlock(int amountOfBlockTypes) { - //private static int bitsPerBlock(ListTag blockStatePalette) { return (int) Math.floor((Math.log(amountOfBlockTypes)) / Math.log(2))+1; - //return (int) Math.floor((Math.log(blockStatePalette.size())) / Math.log(2))+1; } /** @@ -257,16 +228,6 @@ public final class LitematicaSchematic extends StaticSchematic { return rawBlockData; } - // will only work after 1.12. will replace the getBlockStates() above. - /* - /** - * @return array of Long values. - */ - /* - private static long[] getBlockStates() { - return nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt).getLongArray(); - }*/ - /** LitematicaBitArray class from litematica */ private static class LitematicaBitArray { From 52aa0d9b8a111ad51cb073757a641650297848bf Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 20:04:57 +0200 Subject: [PATCH 45/78] more cleanup --- .../format/defaults/LitematicaSchematic.java | 154 +++++++++--------- 1 file changed, 75 insertions(+), 79 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 4c8ce4c69..411e1988a 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -51,7 +51,7 @@ public final class LitematicaSchematic extends StaticSchematic { public LitematicaSchematic(NBTTagCompound nbtCompound) { nbt = nbtCompound; regNames = getRegions(); - minCord(); + getMinimumCorner(); this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y")); @@ -60,81 +60,16 @@ public final class LitematicaSchematic extends StaticSchematic { for (String subRegion : regNames) { subReg = subRegion; - NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); - IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); + NBTTagList usedBlockTypes = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); + IBlockState[] blockList = getBlockList(usedBlockTypes); - int bitsPerBlock = bitsPerBlock(blockStatePalette.tagCount()); + int bitsPerBlock = getBitsPerBlock(usedBlockTypes.tagCount()); long regionVolume = getVolume(); long[] blockStateArray = getBlockStates(); LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, blockStateArray); - if (bitsPerBlock > 32) { - throw new IllegalStateException("Too many blocks in schematic to handle"); - } - - createSchematicOfSubRegion(paletteBlockStates, bitArray); - } - } - - /** - * @param paletteBlockStates list with the different block types used in the schematic - * @param bitArray bit array that holds the placement pattern - */ - private void createSchematicOfSubRegion(IBlockState[] paletteBlockStates, LitematicaBitArray bitArray) { - int posX = getMin("x"); - int posY = getMin("y"); - int posZ = getMin("z"); - int index = 0; - for (int y = 0; y < this.y; y++) { - for (int z = 0; z < this.z; z++) { - for (int x = 0; x < this.x; x++) { - if (inSubregion(x, y, z)) { - this.states[x-(minX- posX)][z-(minZ- posZ)][y-(minY- posY)] = paletteBlockStates[bitArray.getAt(index)]; - index++; - } - } - } - } - } - - /** - * @param x cord of the schematic. - * @param y cord of the schematic. - * @param z cord of the schematic. - * @return if the current block is inside the subregion. - */ - private static boolean inSubregion(int x, int y, int z) { - return - x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && - y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && - z < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); - } - - /** - * @param s axis that should be read. - * @return the lower cord of the requested axis. - */ - private static int getMin(String s) { - int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); - int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); - if (b < 0) { - b++; - } - return Math.min(a,a+b); - - } - - /** - * Calculates the minimum cords/origin of the schematic as litematica schematics - * can have a non-minimum origin. - */ - private void minCord() { - for (String subRegion : regNames) { - subReg = subRegion; - this.minX = Math.min(this.minX,getMin("x")); - this.minY = Math.min(this.minY,getMin("y")); - this.minZ = Math.min(this.minZ,getMin("z")); + writeSubregionIntoSchematic(blockList, bitArray); } } @@ -145,20 +80,47 @@ public final class LitematicaSchematic extends StaticSchematic { return nbt.getCompoundTag(reg).getKeySet().toArray(new String[0]); } + /** + * Calculates the minimum cords/origin of the schematic as litematica schematics + * can have a non-minimum origin. + */ + private void getMinimumCorner() { + for (String subRegion : regNames) { + subReg = subRegion; + this.minX = Math.min(this.minX, getMinimumCord("x")); + this.minY = Math.min(this.minY, getMinimumCord("y")); + this.minZ = Math.min(this.minZ, getMinimumCord("z")); + } + } + + /** + * @param s axis that should be read. + * @return the lower cord of the requested axis. + */ + private static int getMinimumCord(String s) { + int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); + int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); + if (b < 0) { + b++; + } + return Math.min(a,a+b); + + } + /** * @param blockStatePalette List of all different block types used in the schematic. * @return Array of BlockStates. */ - private static IBlockState[] paletteBlockStates(NBTTagList blockStatePalette) { - IBlockState[] paletteBlockStates = new IBlockState[blockStatePalette.tagCount()]; + private static IBlockState[] getBlockList(NBTTagList blockStatePalette) { + IBlockState[] blockList = new IBlockState[blockStatePalette.tagCount()]; for (int i = 0; i< blockStatePalette.tagCount(); i++) { Block block = Block.REGISTRY.getObject(new ResourceLocation((((NBTTagCompound) blockStatePalette.get(i)).getString("Name")))); NBTTagCompound properties = ((NBTTagCompound) blockStatePalette.get(i)).getCompoundTag("Properties"); - paletteBlockStates[i] = getBlockState(block, properties); + blockList[i] = getBlockState(block, properties); } - return paletteBlockStates; + return blockList; } /** @@ -169,11 +131,11 @@ public final class LitematicaSchematic extends StaticSchematic { private static IBlockState getBlockState(Block block, NBTTagCompound properties) { IBlockState blockState = block.getDefaultState(); - for (Object key : properties.getKeySet().toArray()) { IProperty property = block.getBlockState().getProperty((String) key); + String propertyValue = properties.getString((String) key); if (property != null) { - blockState = setPropertyValue(blockState, property, properties.getString((String) key)); + blockState = setPropertyValue(blockState, property, propertyValue); } } return blockState; @@ -200,7 +162,7 @@ public final class LitematicaSchematic extends StaticSchematic { * @param amountOfBlockTypes amount of block types in the schematic. * @return amount of bits used to encode a block. */ - private static int bitsPerBlock(int amountOfBlockTypes) { + private static int getBitsPerBlock(int amountOfBlockTypes) { return (int) Math.floor((Math.log(amountOfBlockTypes)) / Math.log(2))+1; } @@ -210,8 +172,8 @@ public final class LitematicaSchematic extends StaticSchematic { private static long getVolume() { return Math.abs( nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x") * - nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * - nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); + nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * + nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); } /** @@ -228,6 +190,40 @@ public final class LitematicaSchematic extends StaticSchematic { return rawBlockData; } + /** + * @param blockList list with the different block types used in the schematic + * @param bitArray bit array that holds the placement pattern + */ + private void writeSubregionIntoSchematic(IBlockState[] blockList, LitematicaBitArray bitArray) { + int posX = getMinimumCord("x"); + int posY = getMinimumCord("y"); + int posZ = getMinimumCord("z"); + int index = 0; + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + if (inSubregion(x, y, z)) { + this.states[x-(minX- posX)][z-(minZ- posZ)][y-(minY- posY)] = blockList[bitArray.getAt(index)]; + index++; + } + } + } + } + } + + /** + * @param x cord of the schematic. + * @param y cord of the schematic. + * @param z cord of the schematic. + * @return if the current block is inside the subregion. + */ + private static boolean inSubregion(int x, int y, int z) { + return + x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && + y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && + z < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); + } + /** LitematicaBitArray class from litematica */ private static class LitematicaBitArray { From a091c17b83cd7f97e9dff2b87823c99ad4cfad55 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 21:04:09 +0200 Subject: [PATCH 46/78] Added mixin to properly handle Long Arrays --- .../launch/mixins/MixinNBTTagLongArray.java | 37 +++++++++++++++++++ src/launch/resources/mixins.baritone.json | 3 +- .../utils/accessor/INBTTagLongArray.java | 27 ++++++++++++++ .../format/defaults/LitematicaSchematic.java | 10 +---- 4 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java create mode 100644 src/main/java/baritone/utils/accessor/INBTTagLongArray.java diff --git a/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java b/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java new file mode 100644 index 000000000..a4cd739ac --- /dev/null +++ b/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java @@ -0,0 +1,37 @@ +/* + * 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.launch.mixins; + +import baritone.utils.accessor.INBTTagLongArray; +import net.minecraft.nbt.NBTTagLongArray; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +/** + * @author rycbar + * @since 26.09.2022 + */ +@Mixin(NBTTagLongArray.class) +public abstract class MixinNBTTagLongArray implements INBTTagLongArray { + + @Accessor("data") + @Override + public abstract long[] getLongArray(); + + +} \ No newline at end of file diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index fdcd14b92..c4b88481c 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -31,6 +31,7 @@ "MixinStateImplementation", "MixinTabCompleter", "MixinVboRenderList", - "MixinWorldClient" + "MixinWorldClient", + "MixinNBTTagLongArray" ] } \ No newline at end of file diff --git a/src/main/java/baritone/utils/accessor/INBTTagLongArray.java b/src/main/java/baritone/utils/accessor/INBTTagLongArray.java new file mode 100644 index 000000000..fe4f0bd87 --- /dev/null +++ b/src/main/java/baritone/utils/accessor/INBTTagLongArray.java @@ -0,0 +1,27 @@ +/* + * 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.accessor; + +/** + * @author rycbar + * @since 26.09.2022 + */ +public interface INBTTagLongArray { + + long[] getLongArray(); +} \ No newline at end of file diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 411e1988a..defbd3ea4 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -18,6 +18,7 @@ package baritone.utils.schematic.format.defaults; import baritone.utils.schematic.StaticSchematic; +import baritone.utils.accessor.INBTTagLongArray; import net.minecraft.block.*; import net.minecraft.block.properties.IProperty; import net.minecraft.nbt.*; @@ -180,14 +181,7 @@ public final class LitematicaSchematic extends StaticSchematic { * @return array of Long values. */ private static long[] getBlockStates() { - String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt))).toString(); - rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); - String[] rawBlockArrayString = rawBlockString.split(","); - long[] rawBlockData = new long[rawBlockArrayString.length]; - for (int i = 0; i < rawBlockArrayString.length; i++) { - rawBlockData[i] = Long.parseLong(rawBlockArrayString[i].substring(0,rawBlockArrayString[i].length()-1)); - } - return rawBlockData; + return ((INBTTagLongArray) nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt)).getLongArray(); } /** From 8aa891812473ef67a62ed4ab15d4fcf53abc7124 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 22:23:38 +0200 Subject: [PATCH 47/78] codacy issue #1 and #5 fix --- .../format/defaults/LitematicaSchematic.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index defbd3ea4..8aea77a50 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -37,7 +37,9 @@ import java.util.*; * */ public final class LitematicaSchematic extends StaticSchematic { - int minX=0,minY=0,minZ=0; + int minX=0; + int minY=0; + int minZ=0; private static final String reg = "Regions"; private static final String meta = "Metadata"; private static final String schemSize = "EnclosingSize"; @@ -277,6 +279,7 @@ public final class LitematicaSchematic extends StaticSchematic { public static long roundUp(long number, long interval) { + int sign = 1; if (interval == 0) { return 0; @@ -289,11 +292,11 @@ public final class LitematicaSchematic extends StaticSchematic { { if (number < 0) { - interval *= -1; + sign = -1; } - long i = number % interval; - return i == 0 ? number : number + interval - i; + long i = number % (interval * sign); + return i == 0 ? number : number + (interval * sign) - i; } } } From 7a48824ced82e8b7e7dfd12a169cd378e3bd1356 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 22:32:25 +0200 Subject: [PATCH 48/78] codacy issue #2,#3 and #4 fix --- .../format/defaults/LitematicaSchematic.java | 49 ++++++++----------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 8aea77a50..37d132fb3 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -47,39 +47,33 @@ public final class LitematicaSchematic extends StaticSchematic { private static final String blStPl = "BlockStatePalette"; private static final String pos = "Position"; private static final String size = "Size"; - private static String subReg; - private static String[] regNames; - private static NBTTagCompound nbt; - public LitematicaSchematic(NBTTagCompound nbtCompound) { - nbt = nbtCompound; - regNames = getRegions(); - getMinimumCorner(); + public LitematicaSchematic(NBTTagCompound nbt) { + getMinimumCorner(nbt); this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y")); this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; - for (String subRegion : regNames) { - subReg = subRegion; + for (String subReg : getRegions(nbt)) { NBTTagList usedBlockTypes = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); IBlockState[] blockList = getBlockList(usedBlockTypes); int bitsPerBlock = getBitsPerBlock(usedBlockTypes.tagCount()); - long regionVolume = getVolume(); - long[] blockStateArray = getBlockStates(); + long regionVolume = getVolume(nbt, subReg); + long[] blockStateArray = getBlockStates(nbt, subReg); LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, blockStateArray); - writeSubregionIntoSchematic(blockList, bitArray); + writeSubregionIntoSchematic(nbt, subReg, blockList, bitArray); } } /** * @return Array of subregion names. */ - private static String[] getRegions() { + private static String[] getRegions(NBTTagCompound nbt) { return nbt.getCompoundTag(reg).getKeySet().toArray(new String[0]); } @@ -87,12 +81,11 @@ public final class LitematicaSchematic extends StaticSchematic { * Calculates the minimum cords/origin of the schematic as litematica schematics * can have a non-minimum origin. */ - private void getMinimumCorner() { - for (String subRegion : regNames) { - subReg = subRegion; - this.minX = Math.min(this.minX, getMinimumCord("x")); - this.minY = Math.min(this.minY, getMinimumCord("y")); - this.minZ = Math.min(this.minZ, getMinimumCord("z")); + private void getMinimumCorner(NBTTagCompound nbt) { + for (String subReg : getRegions(nbt)) { + this.minX = Math.min(this.minX, getMinimumCord(nbt, subReg,"x")); + this.minY = Math.min(this.minY, getMinimumCord(nbt, subReg,"y")); + this.minZ = Math.min(this.minZ, getMinimumCord(nbt, subReg,"z")); } } @@ -100,7 +93,7 @@ public final class LitematicaSchematic extends StaticSchematic { * @param s axis that should be read. * @return the lower cord of the requested axis. */ - private static int getMinimumCord(String s) { + private static int getMinimumCord(NBTTagCompound nbt, String subReg, String s) { int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); if (b < 0) { @@ -172,7 +165,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * @return the volume of the subregion. */ - private static long getVolume() { + private static long getVolume(NBTTagCompound nbt, String subReg) { return Math.abs( nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x") * nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * @@ -182,7 +175,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * @return array of Long values. */ - private static long[] getBlockStates() { + private static long[] getBlockStates(NBTTagCompound nbt, String subReg) { return ((INBTTagLongArray) nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt)).getLongArray(); } @@ -190,15 +183,15 @@ public final class LitematicaSchematic extends StaticSchematic { * @param blockList list with the different block types used in the schematic * @param bitArray bit array that holds the placement pattern */ - private void writeSubregionIntoSchematic(IBlockState[] blockList, LitematicaBitArray bitArray) { - int posX = getMinimumCord("x"); - int posY = getMinimumCord("y"); - int posZ = getMinimumCord("z"); + private void writeSubregionIntoSchematic(NBTTagCompound nbt, String subReg, IBlockState[] blockList, LitematicaBitArray bitArray) { + int posX = getMinimumCord(nbt, subReg,"x"); + int posY = getMinimumCord(nbt, subReg,"y"); + int posZ = getMinimumCord(nbt, subReg,"z"); int index = 0; for (int y = 0; y < this.y; y++) { for (int z = 0; z < this.z; z++) { for (int x = 0; x < this.x; x++) { - if (inSubregion(x, y, z)) { + if (inSubregion(nbt, subReg, x, y, z)) { this.states[x-(minX- posX)][z-(minZ- posZ)][y-(minY- posY)] = blockList[bitArray.getAt(index)]; index++; } @@ -213,7 +206,7 @@ public final class LitematicaSchematic extends StaticSchematic { * @param z cord of the schematic. * @return if the current block is inside the subregion. */ - private static boolean inSubregion(int x, int y, int z) { + private static boolean inSubregion(NBTTagCompound nbt, String subReg, int x, int y, int z) { return x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && From d928e705b91f7cb19f38e8b193721e781422a7d3 Mon Sep 17 00:00:00 2001 From: schmar03 Date: Wed, 28 Sep 2022 12:09:38 +0200 Subject: [PATCH 49/78] LitematicaCommand added to build loaded schematics --- .../baritone/api/process/IBuilderProcess.java | 2 + .../command/defaults/DefaultCommands.java | 1 + .../command/defaults/LitematicaCommand.java | 60 +++++++++++++++ .../java/baritone/process/BuilderProcess.java | 22 ++++++ .../litematica/LitematicaHelper.java | 74 +++++++++++++++++++ 5 files changed, 159 insertions(+) create mode 100644 src/main/java/baritone/command/defaults/LitematicaCommand.java create mode 100644 src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java diff --git a/src/api/java/baritone/api/process/IBuilderProcess.java b/src/api/java/baritone/api/process/IBuilderProcess.java index 9063b9900..dc17d0419 100644 --- a/src/api/java/baritone/api/process/IBuilderProcess.java +++ b/src/api/java/baritone/api/process/IBuilderProcess.java @@ -58,6 +58,8 @@ public interface IBuilderProcess extends IBaritoneProcess { void buildOpenSchematic(); + void buildOpenLitematic(); + void pause(); boolean isPaused(); diff --git a/src/main/java/baritone/command/defaults/DefaultCommands.java b/src/main/java/baritone/command/defaults/DefaultCommands.java index e998dcc97..901fda713 100644 --- a/src/main/java/baritone/command/defaults/DefaultCommands.java +++ b/src/main/java/baritone/command/defaults/DefaultCommands.java @@ -43,6 +43,7 @@ public final class DefaultCommands { new RepackCommand(baritone), new BuildCommand(baritone), new SchematicaCommand(baritone), + new LitematicaCommand(baritone), new ComeCommand(baritone), new AxisCommand(baritone), new ForceCancelCommand(baritone), diff --git a/src/main/java/baritone/command/defaults/LitematicaCommand.java b/src/main/java/baritone/command/defaults/LitematicaCommand.java new file mode 100644 index 000000000..56360331e --- /dev/null +++ b/src/main/java/baritone/command/defaults/LitematicaCommand.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 . + */ + +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 java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +public class LitematicaCommand extends Command { + + public LitematicaCommand(IBaritone baritone) { + super(baritone, "litematica"); + } + + @Override + public void execute(String label, IArgConsumer args) throws CommandException { + args.requireMax(0); + baritone.getBuilderProcess().buildOpenLitematic(); + } + + @Override + public Stream tabComplete(String label, IArgConsumer args) { + return Stream.empty(); + } + + @Override + public String getShortDesc() { + return "Builds the loaded schematic"; + } + + @Override + public List getLongDesc() { + return Arrays.asList( + "Builds the schematic currently open in Litematica.", + "", + "Usage:", + "> litematica" + ); + } +} \ No newline at end of file diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 1766af623..437c2c8d9 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -44,9 +44,13 @@ import baritone.utils.PathingCommandContext; import baritone.utils.schematic.MapArtSchematic; import baritone.utils.schematic.SelectionSchematic; import baritone.utils.schematic.SchematicSystem; +import baritone.utils.schematic.litematica.LitematicaHelper; import baritone.utils.schematic.schematica.SchematicaHelper; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import fi.dy.masa.litematica.data.DataManager; +import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; +import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import net.minecraft.block.*; import net.minecraft.block.properties.IProperty; @@ -176,6 +180,24 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } } + @Override + public void buildOpenLitematic() { + if (LitematicaHelper.isLitematicaPresent()) { + SchematicPlacementManager placementManager = DataManager.getSchematicPlacementManager(); + List placementList = placementManager.getAllSchematicsPlacements(); + if (placementList.size()>0) { + String name = LitematicaHelper.getName(placementList,0); + File schemFile = LitematicaHelper.getSchematicFile(placementList,0); + Vec3i origin = LitematicaHelper.getOrigin(placementList,0); + + build(name, schemFile, origin); + } else { + logDirect("No schematic currently open"); + } + logDirect("Litematica is not present"); + } + } + public void clearArea(BlockPos corner1, BlockPos corner2) { BlockPos origin = new BlockPos(Math.min(corner1.getX(), corner2.getX()), Math.min(corner1.getY(), corner2.getY()), Math.min(corner1.getZ(), corner2.getZ())); int widthX = Math.abs(corner1.getX() - corner2.getX()) + 1; diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java new file mode 100644 index 000000000..825332583 --- /dev/null +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -0,0 +1,74 @@ +/* + * 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.schematic.litematica; + +import com.github.lunatrius.schematica.Schematica; +import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; +import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager; +import net.minecraft.util.math.Vec3i; + +import java.io.File; +import java.util.List; + +public enum LitematicaHelper { ; + public static boolean isLitematicaPresent() { + try { + Class.forName(Schematica.class.getName()); + return true; + } catch (ClassNotFoundException | NoClassDefFoundError ex) { + return false; + } + } + public static String getName(List placementList, int i) { + return placementList.get(i).getName(); + } + public static Vec3i getOrigin(List placementList, int i) { + int x,y,z; + x=placementList.get(i).getOrigin().getX(); + y=placementList.get(i).getOrigin().getY(); + z=placementList.get(i).getOrigin().getZ(); + return new Vec3i(x,y,z); + } + public static File getSchematicFile(List placementList, int i) { + return placementList.get(i).getSchematicFile(); + } +} + + + + + + + + + + + + + + + + + + + + + + + + From 293f5db172b4705a5c1e62e0d5c461847a6a6e57 Mon Sep 17 00:00:00 2001 From: schmar03 Date: Wed, 28 Sep 2022 14:15:48 +0200 Subject: [PATCH 50/78] LitematicaCommand added to build loaded schematics --- .../java/baritone/process/BuilderProcess.java | 7 ++-- .../litematica/LitematicaHelper.java | 5 +-- .../fi/dy/masa/litematica/Litematica.java | 21 ++++++++++ .../dy/masa/litematica/data/DataManager.java | 31 +++++++++++++++ .../placement/SchematicPlacement.java | 22 +++++++++++ .../placement/SchematicPlacementManager.java | 29 ++++++++++++++ .../placement/SchematicPlacementUnloaded.java | 39 +++++++++++++++++++ 7 files changed, 147 insertions(+), 7 deletions(-) create mode 100644 src/main/java/fi/dy/masa/litematica/Litematica.java create mode 100644 src/main/java/fi/dy/masa/litematica/data/DataManager.java create mode 100644 src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java create mode 100644 src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java create mode 100644 src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 437c2c8d9..cd1a19b8b 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -50,7 +50,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import fi.dy.masa.litematica.data.DataManager; import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; -import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import net.minecraft.block.*; import net.minecraft.block.properties.IProperty; @@ -182,9 +181,8 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public void buildOpenLitematic() { - if (LitematicaHelper.isLitematicaPresent()) { - SchematicPlacementManager placementManager = DataManager.getSchematicPlacementManager(); - List placementList = placementManager.getAllSchematicsPlacements(); + if (LitematicaHelper.isLitematicaPresent()) { //TODO Investigate why true even without litematica being present + List placementList = DataManager.getSchematicPlacementManager().getAllSchematicPlacements(); if (placementList.size()>0) { String name = LitematicaHelper.getName(placementList,0); File schemFile = LitematicaHelper.getSchematicFile(placementList,0); @@ -194,6 +192,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } else { logDirect("No schematic currently open"); } + } else { logDirect("Litematica is not present"); } } diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java index 825332583..c97a46b71 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -17,9 +17,8 @@ package baritone.utils.schematic.litematica; -import com.github.lunatrius.schematica.Schematica; +import fi.dy.masa.litematica.Litematica; import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; -import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager; import net.minecraft.util.math.Vec3i; import java.io.File; @@ -28,7 +27,7 @@ import java.util.List; public enum LitematicaHelper { ; public static boolean isLitematicaPresent() { try { - Class.forName(Schematica.class.getName()); + Class.forName(Litematica.class.getName()); return true; } catch (ClassNotFoundException | NoClassDefFoundError ex) { return false; diff --git a/src/main/java/fi/dy/masa/litematica/Litematica.java b/src/main/java/fi/dy/masa/litematica/Litematica.java new file mode 100644 index 000000000..46f4e02ae --- /dev/null +++ b/src/main/java/fi/dy/masa/litematica/Litematica.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 . + */ + +package fi.dy.masa.litematica; + +public class Litematica { +} diff --git a/src/main/java/fi/dy/masa/litematica/data/DataManager.java b/src/main/java/fi/dy/masa/litematica/data/DataManager.java new file mode 100644 index 000000000..b590eb2e8 --- /dev/null +++ b/src/main/java/fi/dy/masa/litematica/data/DataManager.java @@ -0,0 +1,31 @@ +/* + * 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 fi.dy.masa.litematica.data; + +import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager; + +public class DataManager { + public static final DataManager INSTANCE = new DataManager(); + private final SchematicPlacementManager schematicPlacementManager = new SchematicPlacementManager(); + private static DataManager getInstance() { + return INSTANCE; + } + public static SchematicPlacementManager getSchematicPlacementManager() { + return getInstance().schematicPlacementManager; + } +} diff --git a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java new file mode 100644 index 000000000..0407dff09 --- /dev/null +++ b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java @@ -0,0 +1,22 @@ +/* + * 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 fi.dy.masa.litematica.schematic.placement; + +public class SchematicPlacement extends SchematicPlacementUnloaded { + +} diff --git a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java new file mode 100644 index 000000000..c30ab149d --- /dev/null +++ b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java @@ -0,0 +1,29 @@ +/* + * 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 fi.dy.masa.litematica.schematic.placement; + +import java.util.ArrayList; +import java.util.List; + +public class SchematicPlacementManager { + private final List schematicPlacements = new ArrayList<>(); + + public List getAllSchematicPlacements() { + return schematicPlacements; + } +} diff --git a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java new file mode 100644 index 000000000..707aaf78c --- /dev/null +++ b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java @@ -0,0 +1,39 @@ +/* + * 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 fi.dy.masa.litematica.schematic.placement; + +import net.minecraft.util.math.BlockPos; + +import javax.annotation.Nullable; +import java.io.File; + +public class SchematicPlacementUnloaded { + protected String name = "?"; + @Nullable protected File schematicFile; + protected BlockPos origin = BlockPos.ORIGIN; + public String getName() { + return this.name; + } + @Nullable + public File getSchematicFile() { + return this.schematicFile; + } + public BlockPos getOrigin() { + return this.origin; + } +} From 5ff274f040c6bd568857730144a8e22e1402399a Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Thu, 29 Sep 2022 19:58:05 +0200 Subject: [PATCH 51/78] Change requests part one --- .../launch/mixins/MixinNBTTagLongArray.java | 2 - src/launch/resources/mixins.baritone.json | 4 +- .../format/DefaultSchematicFormats.java | 2 +- .../format/defaults/LitematicaSchematic.java | 73 ++++++++----------- 4 files changed, 35 insertions(+), 46 deletions(-) diff --git a/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java b/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java index a4cd739ac..2c05e5442 100644 --- a/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java +++ b/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java @@ -32,6 +32,4 @@ public abstract class MixinNBTTagLongArray implements INBTTagLongArray { @Accessor("data") @Override public abstract long[] getLongArray(); - - } \ No newline at end of file diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index c4b88481c..982736635 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -23,6 +23,7 @@ "MixinItemStack", "MixinItemTool", "MixinMinecraft", + "MixinNBTTagLongArray", "MixinNetHandlerPlayClient", "MixinNetworkManager", "MixinPlayerControllerMP", @@ -31,7 +32,6 @@ "MixinStateImplementation", "MixinTabCompleter", "MixinVboRenderList", - "MixinWorldClient", - "MixinNBTTagLongArray" + "MixinWorldClient" ] } \ No newline at end of file diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index de142b391..d8049ce4a 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -71,7 +71,7 @@ public enum DefaultSchematicFormats implements ISchematicFormat { /** * The Litematica schematic specification. Commonly denoted by the ".litematic" file extension. */ - Litematica("litematic") { + LITEMATICA("litematic") { @Override public IStaticSchematic parse(InputStream input) throws IOException { NBTTagCompound nbt = CompressedStreamTools.readCompressed(input); diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 37d132fb3..4cccecee6 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -37,27 +37,30 @@ import java.util.*; * */ public final class LitematicaSchematic extends StaticSchematic { - int minX=0; - int minY=0; - int minZ=0; - private static final String reg = "Regions"; - private static final String meta = "Metadata"; - private static final String schemSize = "EnclosingSize"; - private static final String blSt = "BlockStates"; - private static final String blStPl = "BlockStatePalette"; - private static final String pos = "Position"; - private static final String size = "Size"; + private final int minX; + private final int minY; + private final int minZ; public LitematicaSchematic(NBTTagCompound nbt) { - getMinimumCorner(nbt); + int x=0; + int y=0; + int z=0; + for (String subReg : getRegions(nbt)) { + x = Math.min(x, getMinimumCord(nbt, subReg,"x")); + y = Math.min(y, getMinimumCord(nbt, subReg,"y")); + z = Math.min(z, getMinimumCord(nbt, subReg,"z")); + } + this.minX = x; + this.minY = y; + this.minZ = z; - this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); - this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y")); - this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z")); + this.x = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("x")); + this.y = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("y")); + this.z = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; for (String subReg : getRegions(nbt)) { - NBTTagList usedBlockTypes = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); + NBTTagList usedBlockTypes = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getTagList("BlockStatePalette", 10); IBlockState[] blockList = getBlockList(usedBlockTypes); int bitsPerBlock = getBitsPerBlock(usedBlockTypes.tagCount()); @@ -74,28 +77,16 @@ public final class LitematicaSchematic extends StaticSchematic { * @return Array of subregion names. */ private static String[] getRegions(NBTTagCompound nbt) { - return nbt.getCompoundTag(reg).getKeySet().toArray(new String[0]); - } - - /** - * Calculates the minimum cords/origin of the schematic as litematica schematics - * can have a non-minimum origin. - */ - private void getMinimumCorner(NBTTagCompound nbt) { - for (String subReg : getRegions(nbt)) { - this.minX = Math.min(this.minX, getMinimumCord(nbt, subReg,"x")); - this.minY = Math.min(this.minY, getMinimumCord(nbt, subReg,"y")); - this.minZ = Math.min(this.minZ, getMinimumCord(nbt, subReg,"z")); - } + return nbt.getCompoundTag("Regions").getKeySet().toArray(new String[0]); } /** * @param s axis that should be read. - * @return the lower cord of the requested axis. + * @return the lower coord of the requested axis. */ private static int getMinimumCord(NBTTagCompound nbt, String subReg, String s) { - int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); - int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); + int a = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Position").getInteger(s); + int b = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger(s); if (b < 0) { b++; } @@ -167,16 +158,16 @@ public final class LitematicaSchematic extends StaticSchematic { */ private static long getVolume(NBTTagCompound nbt, String subReg) { return Math.abs( - nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x") * - nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * - nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); + nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("x") * + nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y") * + nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); } /** * @return array of Long values. */ private static long[] getBlockStates(NBTTagCompound nbt, String subReg) { - return ((INBTTagLongArray) nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt)).getLongArray(); + return ((INBTTagLongArray) nbt.getCompoundTag("Regions").getCompoundTag(subReg).getTag("BlockStates")).getLongArray(); } /** @@ -201,16 +192,16 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param x cord of the schematic. - * @param y cord of the schematic. - * @param z cord of the schematic. + * @param x coord of the schematic. + * @param y coord of the schematic. + * @param z coord of the schematic. * @return if the current block is inside the subregion. */ private static boolean inSubregion(NBTTagCompound nbt, String subReg, int x, int y, int z) { return - x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && - y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && - z < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); + x < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("x")) && + y < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y")) && + z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); } /** LitematicaBitArray class from litematica */ From 7ba3de57d02e34962af3b4f610cee446b7b30196 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Thu, 29 Sep 2022 20:20:38 +0200 Subject: [PATCH 52/78] credits LitematicaBitArray --- .../schematic/format/defaults/LitematicaSchematic.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 4cccecee6..df8c82ee3 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -204,7 +204,11 @@ public final class LitematicaSchematic extends StaticSchematic { z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); } - /** LitematicaBitArray class from litematica */ + /** + * @author maruohon + * Class from the Litematica mod by maruohon + * https://github.com/maruohon/litematica + */ private static class LitematicaBitArray { /** The long array that is used to store the data for this BitArray. */ From e99fcbbe36450f414d98f860c461973a7ee20b07 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Thu, 29 Sep 2022 21:47:42 +0200 Subject: [PATCH 53/78] Change requests part two --- .../format/DefaultSchematicFormats.java | 8 +- .../format/defaults/LitematicaSchematic.java | 180 +++++++++--------- 2 files changed, 89 insertions(+), 99 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index d8049ce4a..699f87bc3 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -77,11 +77,11 @@ public enum DefaultSchematicFormats implements ISchematicFormat { NBTTagCompound nbt = CompressedStreamTools.readCompressed(input); int version = nbt.getInteger("Version"); switch (version) { - case 4: + case 4: //1.12 return new LitematicaSchematic(nbt); - case 5: - case 6: - throw new UnsupportedOperationException("This Schematic Verion is to new."); + case 5: //1.13-1.17 + case 6: //1.18+ + throw new UnsupportedOperationException("This litematic Verion is to new."); default: throw new UnsupportedOperationException("Unsuported Version of a Litematica Schematic"); } diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index df8c82ee3..3f0e165f1 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -17,24 +17,24 @@ package baritone.utils.schematic.format.defaults; -import baritone.utils.schematic.StaticSchematic; import baritone.utils.accessor.INBTTagLongArray; -import net.minecraft.block.*; +import baritone.utils.schematic.StaticSchematic; +import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; -import net.minecraft.nbt.*; -import net.minecraft.util.ResourceLocation; import net.minecraft.block.state.IBlockState; - +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ResourceLocation; import org.apache.commons.lang3.Validate; + import javax.annotation.Nullable; -import java.util.*; +import java.util.Optional; /** * @author Emerson * @since 12/27/2020 * @author rycbar * @since 22.09.2022 - * */ public final class LitematicaSchematic extends StaticSchematic { private final int minX; @@ -42,13 +42,13 @@ public final class LitematicaSchematic extends StaticSchematic { private final int minZ; public LitematicaSchematic(NBTTagCompound nbt) { - int x=0; - int y=0; - int z=0; + int x = 0; + int y = 0; + int z = 0; for (String subReg : getRegions(nbt)) { - x = Math.min(x, getMinimumCord(nbt, subReg,"x")); - y = Math.min(y, getMinimumCord(nbt, subReg,"y")); - z = Math.min(z, getMinimumCord(nbt, subReg,"z")); + x = Math.min(x, getMinimumCoord(nbt, subReg, "x")); + y = Math.min(y, getMinimumCoord(nbt, subReg, "y")); + z = Math.min(z, getMinimumCoord(nbt, subReg, "z")); } this.minX = x; this.minY = y; @@ -81,16 +81,17 @@ public final class LitematicaSchematic extends StaticSchematic { } /** + * Gets both ends from schematic box for a given axis and returns the lower one. * @param s axis that should be read. * @return the lower coord of the requested axis. */ - private static int getMinimumCord(NBTTagCompound nbt, String subReg, String s) { + private static int getMinimumCoord(NBTTagCompound nbt, String subReg, String s) { int a = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Position").getInteger(s); int b = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger(s); if (b < 0) { b++; } - return Math.min(a,a+b); + return Math.min(a, a + b); } @@ -101,7 +102,7 @@ public final class LitematicaSchematic extends StaticSchematic { private static IBlockState[] getBlockList(NBTTagList blockStatePalette) { IBlockState[] blockList = new IBlockState[blockStatePalette.tagCount()]; - for (int i = 0; i< blockStatePalette.tagCount(); i++) { + for (int i = 0; i < blockStatePalette.tagCount(); i++) { Block block = Block.REGISTRY.getObject(new ResourceLocation((((NBTTagCompound) blockStatePalette.get(i)).getString("Name")))); NBTTagCompound properties = ((NBTTagCompound) blockStatePalette.get(i)).getCompoundTag("Properties"); @@ -111,7 +112,7 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param block block. + * @param block block. * @param properties List of Properties the block has. * @return A blockState. */ @@ -129,12 +130,7 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * i haven't written this and i wont try to decode it. - * @param state . - * @param property . - * @param value . - * @return . - * @param . + * @author Emerson */ private static > IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { Optional parsed = property.parseValue(value).toJavaUtil(); @@ -150,10 +146,12 @@ public final class LitematicaSchematic extends StaticSchematic { * @return amount of bits used to encode a block. */ private static int getBitsPerBlock(int amountOfBlockTypes) { - return (int) Math.floor((Math.log(amountOfBlockTypes)) / Math.log(2))+1; + return (int) Math.floor((Math.log(amountOfBlockTypes)) / Math.log(2)) + 1; } /** + * Calculates the volume of the subregion. As size can be a negative value we take the absolute value of the + * multiplication as the volume still holds a positive amount of blocks. * @return the volume of the subregion. */ private static long getVolume(NBTTagCompound nbt, String subReg) { @@ -171,19 +169,36 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param blockList list with the different block types used in the schematic - * @param bitArray bit array that holds the placement pattern + * Subregion don't have to be the same size as the enclosing size of the schematic. If they are smaller we check here if the current block is part of the subregion. + * @param x coord of the block relative to the minimum corner. + * @param y coord of the block relative to the minimum corner. + * @param z coord of the block relative to the minimum corner. + * @return if the current block is part of the subregion. */ + private static boolean inSubregion(NBTTagCompound nbt, String subReg, int x, int y, int z) { + return + x < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("x")) && + y < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y")) && + z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); + } + + /** + * @param blockList list with the different block types used in the schematic + * @param bitArray bit array that holds the placement pattern + */ + //x,y,z are the releative positons to the minimum corner of the enclosing box + //minX,minY,minZ are correction terms if the schematic origin isn't the minimum corner + //posX,posY,posZ are the subregions offset relative to the minimum corner private void writeSubregionIntoSchematic(NBTTagCompound nbt, String subReg, IBlockState[] blockList, LitematicaBitArray bitArray) { - int posX = getMinimumCord(nbt, subReg,"x"); - int posY = getMinimumCord(nbt, subReg,"y"); - int posZ = getMinimumCord(nbt, subReg,"z"); + int posX = getMinimumCoord(nbt, subReg, "x"); + int posY = getMinimumCoord(nbt, subReg, "y"); + int posZ = getMinimumCoord(nbt, subReg, "z"); int index = 0; for (int y = 0; y < this.y; y++) { for (int z = 0; z < this.z; z++) { for (int x = 0; x < this.x; x++) { if (inSubregion(nbt, subReg, x, y, z)) { - this.states[x-(minX- posX)][z-(minZ- posZ)][y-(minY- posY)] = blockList[bitArray.getAt(index)]; + this.states[x - (minX - posX)][z - (minZ - posZ)][y - (minY - posY)] = blockList[bitArray.getAt(index)]; index++; } } @@ -191,95 +206,51 @@ public final class LitematicaSchematic extends StaticSchematic { } } - /** - * @param x coord of the schematic. - * @param y coord of the schematic. - * @param z coord of the schematic. - * @return if the current block is inside the subregion. - */ - private static boolean inSubregion(NBTTagCompound nbt, String subReg, int x, int y, int z) { - return - x < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("x")) && - y < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y")) && - z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); - } - /** * @author maruohon * Class from the Litematica mod by maruohon - * https://github.com/maruohon/litematica + * ... */ - private static class LitematicaBitArray - { - /** The long array that is used to store the data for this BitArray. */ + private static class LitematicaBitArray { + /** + * The long array that is used to store the data for this BitArray. + */ private final long[] longArray; - /** Number of bits a single entry takes up */ + /** + * Number of bits a single entry takes up + */ private final int bitsPerEntry; /** * The maximum value for a single entry. This also works as a bitmask for a single entry. * For instance, if bitsPerEntry were 5, this value would be 31 (ie, {@code 0b00011111}). */ private final long maxEntryValue; - /** Number of entries in this array (not the length of the long array that internally backs this array) */ + /** + * Number of entries in this array (not the length of the long array that internally backs this array) + */ private final long arraySize; - public LitematicaBitArray(int bitsPerEntryIn, long arraySizeIn, @Nullable long[] longArrayIn) - { - Validate.inclusiveBetween(1L, 32L, (long) bitsPerEntryIn); + public LitematicaBitArray(int bitsPerEntryIn, long arraySizeIn, @Nullable long[] longArrayIn) { + Validate.inclusiveBetween(1L, 32L, bitsPerEntryIn); this.arraySize = arraySizeIn; this.bitsPerEntry = bitsPerEntryIn; this.maxEntryValue = (1L << bitsPerEntryIn) - 1L; - if (longArrayIn != null) - { + if (longArrayIn != null) { this.longArray = longArrayIn; - } - else - { - this.longArray = new long[(int) (roundUp((long) arraySizeIn * (long) bitsPerEntryIn, 64L) / 64L)]; + } else { + this.longArray = new long[(int) (roundUp(arraySizeIn * (long) bitsPerEntryIn, 64L) / 64L)]; } } - public int getAt(long index) - { - Validate.inclusiveBetween(0L, this.arraySize - 1L, (long) index); - long startOffset = index * (long) this.bitsPerEntry; - int startArrIndex = (int) (startOffset >> 6); // startOffset / 64 - int endArrIndex = (int) (((index + 1L) * (long) this.bitsPerEntry - 1L) >> 6); - int startBitOffset = (int) (startOffset & 0x3F); // startOffset % 64 - - if (startArrIndex == endArrIndex) - { - return (int) (this.longArray[startArrIndex] >>> startBitOffset & this.maxEntryValue); - } - else - { - int endOffset = 64 - startBitOffset; - return (int) ((this.longArray[startArrIndex] >>> startBitOffset | this.longArray[endArrIndex] << endOffset) & this.maxEntryValue); - } - } - - - public long size() - { - return this.arraySize; - } - - public static long roundUp(long number, long interval) - { + public static long roundUp(long number, long interval) { int sign = 1; - if (interval == 0) - { + if (interval == 0) { return 0; - } - else if (number == 0) - { + } else if (number == 0) { return interval; - } - else - { - if (number < 0) - { + } else { + if (number < 0) { sign = -1; } @@ -287,5 +258,24 @@ public final class LitematicaSchematic extends StaticSchematic { return i == 0 ? number : number + (interval * sign) - i; } } + + public int getAt(long index) { + Validate.inclusiveBetween(0L, this.arraySize - 1L, index); + long startOffset = index * (long) this.bitsPerEntry; + int startArrIndex = (int) (startOffset >> 6); // startOffset / 64 + int endArrIndex = (int) (((index + 1L) * (long) this.bitsPerEntry - 1L) >> 6); + int startBitOffset = (int) (startOffset & 0x3F); // startOffset % 64 + + if (startArrIndex == endArrIndex) { + return (int) (this.longArray[startArrIndex] >>> startBitOffset & this.maxEntryValue); + } else { + int endOffset = 64 - startBitOffset; + return (int) ((this.longArray[startArrIndex] >>> startBitOffset | this.longArray[endArrIndex] << endOffset) & this.maxEntryValue); + } + } + + public long size() { + return this.arraySize; + } } } \ No newline at end of file From 484b3326c77c92d749cc24d919888d726ab05dc4 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Thu, 29 Sep 2022 21:52:15 +0200 Subject: [PATCH 54/78] auto-format all files I touched --- .../utils/schematic/format/DefaultSchematicFormats.java | 2 +- .../utils/schematic/format/defaults/LitematicaSchematic.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index 699f87bc3..faabe57b3 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -19,9 +19,9 @@ package baritone.utils.schematic.format; import baritone.api.schematic.IStaticSchematic; import baritone.api.schematic.format.ISchematicFormat; +import baritone.utils.schematic.format.defaults.LitematicaSchematic; import baritone.utils.schematic.format.defaults.MCEditSchematic; import baritone.utils.schematic.format.defaults.SpongeSchematic; -import baritone.utils.schematic.format.defaults.LitematicaSchematic; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import org.apache.commons.io.FilenameUtils; diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 3f0e165f1..12b3264fe 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -82,6 +82,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * Gets both ends from schematic box for a given axis and returns the lower one. + * * @param s axis that should be read. * @return the lower coord of the requested axis. */ @@ -152,6 +153,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * Calculates the volume of the subregion. As size can be a negative value we take the absolute value of the * multiplication as the volume still holds a positive amount of blocks. + * * @return the volume of the subregion. */ private static long getVolume(NBTTagCompound nbt, String subReg) { @@ -170,6 +172,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * Subregion don't have to be the same size as the enclosing size of the schematic. If they are smaller we check here if the current block is part of the subregion. + * * @param x coord of the block relative to the minimum corner. * @param y coord of the block relative to the minimum corner. * @param z coord of the block relative to the minimum corner. From 4ba3c883e6d49d194c2e31f3e527ac5df10c2ec7 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Fri, 30 Sep 2022 13:32:31 +0200 Subject: [PATCH 55/78] something is fishy with the getAllSchematicPlacements() methode but i want my progress saved --- scripts/proguard.pro | 2 ++ .../java/baritone/process/BuilderProcess.java | 26 ++++++++++------- .../litematica/LitematicaHelper.java | 29 +++++++++++++------ .../fi/dy/masa/litematica/Litematica.java | 0 .../dy/masa/litematica/data/DataManager.java | 0 .../placement/SchematicPlacement.java | 0 .../placement/SchematicPlacementManager.java | 0 .../placement/SchematicPlacementUnloaded.java | 0 8 files changed, 38 insertions(+), 19 deletions(-) rename src/{main => schematica_api}/java/fi/dy/masa/litematica/Litematica.java (100%) rename src/{main => schematica_api}/java/fi/dy/masa/litematica/data/DataManager.java (100%) rename src/{main => schematica_api}/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java (100%) rename src/{main => schematica_api}/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java (100%) rename src/{main => schematica_api}/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java (100%) diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 517494f46..cc3130081 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -42,8 +42,10 @@ #try to keep usage of schematica in separate classes -keep class baritone.utils.schematic.schematica.** +-keep class baritone.utils.schematic.litematica.** #proguard doesnt like it when it cant find our fake schematica classes -dontwarn baritone.utils.schematic.schematica.** +-dontwarn baritone.utils.schematic.litematica.** # copy all necessary libraries into tempLibraries to build diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index cd1a19b8b..a3ee785d9 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -48,8 +48,6 @@ import baritone.utils.schematic.litematica.LitematicaHelper; import baritone.utils.schematic.schematica.SchematicaHelper; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import fi.dy.masa.litematica.data.DataManager; -import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import net.minecraft.block.*; import net.minecraft.block.properties.IProperty; @@ -181,16 +179,24 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public void buildOpenLitematic() { - if (LitematicaHelper.isLitematicaPresent()) { //TODO Investigate why true even without litematica being present - List placementList = DataManager.getSchematicPlacementManager().getAllSchematicPlacements(); - if (placementList.size()>0) { - String name = LitematicaHelper.getName(placementList,0); - File schemFile = LitematicaHelper.getSchematicFile(placementList,0); - Vec3i origin = LitematicaHelper.getOrigin(placementList,0); + logDirect("start building open litematic"); + if (LitematicaHelper.isLitematicaPresent()) { + logDirect("litematica is present"); //TODO debug line remove + if (LitematicaHelper.hasLoadedSchematic()) { + logDirect("a schematic is present"); //TODO debug line remove + String name = LitematicaHelper.getName(0); + File schemFile = LitematicaHelper.getSchematicFile(0); + Vec3i origin = LitematicaHelper.getOrigin(0); - build(name, schemFile, origin); + boolean success = build(name, schemFile, origin); + if (success) { + logDirect(String.format("Building Schematic: %s\nOrigion: %s",name,origin)); + } else { + logDirect("Couldn't load the schematic. That is strange."); + //this should happen as invalid schematics should not be abel to be loaded in litematica in the first place + } } else { - logDirect("No schematic currently open"); + logDirect("No schematic currently loaded"); } } else { logDirect("Litematica is not present"); diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java index c97a46b71..3692b8b04 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -18,13 +18,15 @@ package baritone.utils.schematic.litematica; import fi.dy.masa.litematica.Litematica; +import fi.dy.masa.litematica.data.DataManager; import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; +import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager; import net.minecraft.util.math.Vec3i; import java.io.File; import java.util.List; -public enum LitematicaHelper { ; +public final class LitematicaHelper { public static boolean isLitematicaPresent() { try { Class.forName(Litematica.class.getName()); @@ -33,18 +35,27 @@ public enum LitematicaHelper { ; return false; } } - public static String getName(List placementList, int i) { - return placementList.get(i).getName(); + //TODO compact into one line when debugging is done + public static boolean hasLoadedSchematic() { + System.out.println("start checking for schematic"); //TODO debug line remove + SchematicPlacementManager a = DataManager.getSchematicPlacementManager(); + System.out.println("manager aquired"); //TODO debug line remove + List< SchematicPlacement> b = a.getAllSchematicPlacements(); + System.out.println("list aquired"); //TODO debug line remove + return b.size()>0; } - public static Vec3i getOrigin(List placementList, int i) { + public static String getName(int i) { + return DataManager.getSchematicPlacementManager().getAllSchematicPlacements().get(i).getName(); + } + public static Vec3i getOrigin(int i) { int x,y,z; - x=placementList.get(i).getOrigin().getX(); - y=placementList.get(i).getOrigin().getY(); - z=placementList.get(i).getOrigin().getZ(); + x=DataManager.getSchematicPlacementManager().getAllSchematicPlacements().get(i).getOrigin().getX(); + y=DataManager.getSchematicPlacementManager().getAllSchematicPlacements().get(i).getOrigin().getY(); + z=DataManager.getSchematicPlacementManager().getAllSchematicPlacements().get(i).getOrigin().getZ(); return new Vec3i(x,y,z); } - public static File getSchematicFile(List placementList, int i) { - return placementList.get(i).getSchematicFile(); + public static File getSchematicFile(int i) { + return DataManager.getSchematicPlacementManager().getAllSchematicPlacements().get(i).getSchematicFile(); } } diff --git a/src/main/java/fi/dy/masa/litematica/Litematica.java b/src/schematica_api/java/fi/dy/masa/litematica/Litematica.java similarity index 100% rename from src/main/java/fi/dy/masa/litematica/Litematica.java rename to src/schematica_api/java/fi/dy/masa/litematica/Litematica.java diff --git a/src/main/java/fi/dy/masa/litematica/data/DataManager.java b/src/schematica_api/java/fi/dy/masa/litematica/data/DataManager.java similarity index 100% rename from src/main/java/fi/dy/masa/litematica/data/DataManager.java rename to src/schematica_api/java/fi/dy/masa/litematica/data/DataManager.java diff --git a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java b/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java similarity index 100% rename from src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java rename to src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java diff --git a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java b/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java similarity index 100% rename from src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java rename to src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java diff --git a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java b/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java similarity index 100% rename from src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java rename to src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java From 025f6235f9eaa678088a0d595dcd9306f8d4188b Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Fri, 30 Sep 2022 17:53:31 +0200 Subject: [PATCH 56/78] litematica command works and added schematic selection if more than 1 schematic is loaded bug: if schematic origin isnt minimum corner schematic is built in the wrong place --- .../baritone/api/process/IBuilderProcess.java | 2 +- .../command/defaults/LitematicaCommand.java | 19 +++++++++++++---- .../java/baritone/process/BuilderProcess.java | 11 ++++------ .../litematica/LitematicaHelper.java | 21 ++++++------------- .../placement/SchematicPlacementManager.java | 4 +++- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/api/java/baritone/api/process/IBuilderProcess.java b/src/api/java/baritone/api/process/IBuilderProcess.java index dc17d0419..c63113cdd 100644 --- a/src/api/java/baritone/api/process/IBuilderProcess.java +++ b/src/api/java/baritone/api/process/IBuilderProcess.java @@ -58,7 +58,7 @@ public interface IBuilderProcess extends IBaritoneProcess { void buildOpenSchematic(); - void buildOpenLitematic(); + void buildOpenLitematic(int i); void pause(); diff --git a/src/main/java/baritone/command/defaults/LitematicaCommand.java b/src/main/java/baritone/command/defaults/LitematicaCommand.java index 56360331e..eecab07de 100644 --- a/src/main/java/baritone/command/defaults/LitematicaCommand.java +++ b/src/main/java/baritone/command/defaults/LitematicaCommand.java @@ -34,8 +34,18 @@ public class LitematicaCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { - args.requireMax(0); - baritone.getBuilderProcess().buildOpenLitematic(); + int schematic = 0; + if(args.hasAny()) { + args.requireMax(1); + if (args.is(Integer.class)) { + schematic = args.getAs(Integer.class)-1; + } + } + try { + baritone.getBuilderProcess().buildOpenLitematic(schematic); + } catch (IndexOutOfBoundsException e) { + logDirect("Pleas provide a valid index."); + } } @Override @@ -51,10 +61,11 @@ public class LitematicaCommand extends Command { @Override public List getLongDesc() { return Arrays.asList( - "Builds the schematic currently open in Litematica.", + "Build a schematic currently open in Litematica.", "", "Usage:", - "> litematica" + "> litematica", + "> litematica <#>" ); } } \ No newline at end of file diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index a3ee785d9..bb62ab769 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -178,15 +178,12 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } @Override - public void buildOpenLitematic() { - logDirect("start building open litematic"); + public void buildOpenLitematic(int i) { if (LitematicaHelper.isLitematicaPresent()) { - logDirect("litematica is present"); //TODO debug line remove if (LitematicaHelper.hasLoadedSchematic()) { - logDirect("a schematic is present"); //TODO debug line remove - String name = LitematicaHelper.getName(0); - File schemFile = LitematicaHelper.getSchematicFile(0); - Vec3i origin = LitematicaHelper.getOrigin(0); + String name = LitematicaHelper.getName(i); + File schemFile = LitematicaHelper.getSchematicFile(i); + Vec3i origin = LitematicaHelper.getOrigin(i); boolean success = build(name, schemFile, origin); if (success) { diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java index 3692b8b04..9f5f19fb1 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -19,12 +19,9 @@ package baritone.utils.schematic.litematica; import fi.dy.masa.litematica.Litematica; import fi.dy.masa.litematica.data.DataManager; -import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; -import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager; import net.minecraft.util.math.Vec3i; import java.io.File; -import java.util.List; public final class LitematicaHelper { public static boolean isLitematicaPresent() { @@ -35,27 +32,21 @@ public final class LitematicaHelper { return false; } } - //TODO compact into one line when debugging is done public static boolean hasLoadedSchematic() { - System.out.println("start checking for schematic"); //TODO debug line remove - SchematicPlacementManager a = DataManager.getSchematicPlacementManager(); - System.out.println("manager aquired"); //TODO debug line remove - List< SchematicPlacement> b = a.getAllSchematicPlacements(); - System.out.println("list aquired"); //TODO debug line remove - return b.size()>0; + return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().size()>0; } public static String getName(int i) { - return DataManager.getSchematicPlacementManager().getAllSchematicPlacements().get(i).getName(); + return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getName(); } public static Vec3i getOrigin(int i) { int x,y,z; - x=DataManager.getSchematicPlacementManager().getAllSchematicPlacements().get(i).getOrigin().getX(); - y=DataManager.getSchematicPlacementManager().getAllSchematicPlacements().get(i).getOrigin().getY(); - z=DataManager.getSchematicPlacementManager().getAllSchematicPlacements().get(i).getOrigin().getZ(); + x=DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getOrigin().getX(); + y=DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getOrigin().getY(); + z=DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getOrigin().getZ(); return new Vec3i(x,y,z); } public static File getSchematicFile(int i) { - return DataManager.getSchematicPlacementManager().getAllSchematicPlacements().get(i).getSchematicFile(); + return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getSchematicFile(); } } diff --git a/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java b/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java index c30ab149d..9391330d3 100644 --- a/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java +++ b/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java @@ -23,7 +23,9 @@ import java.util.List; public class SchematicPlacementManager { private final List schematicPlacements = new ArrayList<>(); - public List getAllSchematicPlacements() { + //in case of a java.lang.NoSuchMethodError try change the name of this method to getAllSchematicPlacements() + // there are inconsistencies in the litematica mod about the naming of this method + public List getAllSchematicsPlacements() { return schematicPlacements; } } From 76404c8af671bb59e31c5480363310665606b1e7 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Sat, 1 Oct 2022 02:01:46 +0200 Subject: [PATCH 57/78] it works but its spaghetti --- .../java/baritone/process/BuilderProcess.java | 73 +++++++++++++++++-- .../format/defaults/LitematicaSchematic.java | 17 +++++ .../litematica/LitematicaHelper.java | 9 +++ .../placement/SchematicPlacement.java | 11 +++ 4 files changed, 104 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index bb62ab769..e18f7aea0 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -44,6 +44,7 @@ import baritone.utils.PathingCommandContext; import baritone.utils.schematic.MapArtSchematic; import baritone.utils.schematic.SelectionSchematic; import baritone.utils.schematic.SchematicSystem; +import baritone.utils.schematic.format.defaults.LitematicaSchematic; import baritone.utils.schematic.litematica.LitematicaHelper; import baritone.utils.schematic.schematica.SchematicaHelper; import com.google.common.collect.ImmutableMap; @@ -55,12 +56,15 @@ 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.util.EnumFacing; +import net.minecraft.util.Mirror; 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 java.util.stream.Collectors; @@ -180,18 +184,75 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public void buildOpenLitematic(int i) { if (LitematicaHelper.isLitematicaPresent()) { + //if java.lang.NoSuchMethodError is thrown see comment in SchematicPlacementManager if (LitematicaHelper.hasLoadedSchematic()) { String name = LitematicaHelper.getName(i); File schemFile = LitematicaHelper.getSchematicFile(i); Vec3i origin = LitematicaHelper.getOrigin(i); - boolean success = build(name, schemFile, origin); - if (success) { - logDirect(String.format("Building Schematic: %s\nOrigion: %s",name,origin)); - } else { - logDirect("Couldn't load the schematic. That is strange."); - //this should happen as invalid schematics should not be abel to be loaded in litematica in the first place + + + + try { + LitematicaSchematic herbert = new LitematicaSchematic(CompressedStreamTools.readCompressed(new FileInputStream(schemFile))); + LitematicaSchematic volker_rainer_fahrenhorst = new LitematicaSchematic(CompressedStreamTools.readCompressed(new FileInputStream(schemFile))); + + net.minecraft.util.Rotation rotation = LitematicaHelper.getRotation(i); + net.minecraft.util.Mirror mirror = LitematicaHelper.getMirror(i); + + + Vec3i gustav = herbert.getMinimumCorner(); + Vec3i martin = new Vec3i(origin.getX()+gustav.getX(),origin.getY()+gustav.getY(),origin.getZ()+gustav.getZ()); + int xena = herbert.getX(); + int yvonne = herbert.getY(); + int zuse = herbert.getZ(); + + for (int brian=0; brian Date: Sat, 1 Oct 2022 05:27:02 +0200 Subject: [PATCH 58/78] remove spaghetti --- .../java/baritone/process/BuilderProcess.java | 69 ++----------------- .../format/defaults/LitematicaSchematic.java | 7 +- .../litematica/LitematicaHelper.java | 60 +++++++++------- 3 files changed, 46 insertions(+), 90 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index e18f7aea0..da56bdf91 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -58,13 +58,13 @@ import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.util.EnumFacing; -import net.minecraft.util.Mirror; import net.minecraft.util.Tuple; import net.minecraft.util.math.*; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.Files; import java.util.*; import java.util.stream.Collectors; @@ -187,72 +187,15 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil //if java.lang.NoSuchMethodError is thrown see comment in SchematicPlacementManager if (LitematicaHelper.hasLoadedSchematic()) { String name = LitematicaHelper.getName(i); - File schemFile = LitematicaHelper.getSchematicFile(i); - Vec3i origin = LitematicaHelper.getOrigin(i); - - - - try { - LitematicaSchematic herbert = new LitematicaSchematic(CompressedStreamTools.readCompressed(new FileInputStream(schemFile))); - LitematicaSchematic volker_rainer_fahrenhorst = new LitematicaSchematic(CompressedStreamTools.readCompressed(new FileInputStream(schemFile))); + LitematicaSchematic schematic = new LitematicaSchematic(CompressedStreamTools.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath()))); + schematic = LitematicaHelper.blackMagicFuckery(schematic, i); + Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(LitematicaHelper.getOrigin(i), schematic.getMinimumCorner()); - net.minecraft.util.Rotation rotation = LitematicaHelper.getRotation(i); - net.minecraft.util.Mirror mirror = LitematicaHelper.getMirror(i); - - - Vec3i gustav = herbert.getMinimumCorner(); - Vec3i martin = new Vec3i(origin.getX()+gustav.getX(),origin.getY()+gustav.getY(),origin.getZ()+gustav.getZ()); - int xena = herbert.getX(); - int yvonne = herbert.getY(); - int zuse = herbert.getZ(); - - for (int brian=0; brian Date: Sat, 1 Oct 2022 17:14:05 +0200 Subject: [PATCH 59/78] debugging mirroring and rotating as well as refactoring --- .../java/baritone/process/BuilderProcess.java | 8 +-- .../format/DefaultSchematicFormats.java | 2 +- .../format/defaults/LitematicaSchematic.java | 52 +++++++++++-------- .../litematica/LitematicaHelper.java | 11 +++- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index da56bdf91..3b9ba2dd5 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -188,11 +188,11 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (LitematicaHelper.hasLoadedSchematic()) { String name = LitematicaHelper.getName(i); try { - LitematicaSchematic schematic = new LitematicaSchematic(CompressedStreamTools.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath()))); - schematic = LitematicaHelper.blackMagicFuckery(schematic, i); - Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(LitematicaHelper.getOrigin(i), schematic.getMinimumCorner()); + LitematicaSchematic schematic1 = new LitematicaSchematic(CompressedStreamTools.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath())),false); + LitematicaSchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i); + Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(LitematicaHelper.getOrigin(i), schematic2.getMinimumCorner()); - build(name, schematic, correctedOrigin); + build(name, schematic2, correctedOrigin); } catch (IOException e) { logDirect("Schematic File could not be loaded"); } diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index faabe57b3..2ca9e1485 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -78,7 +78,7 @@ public enum DefaultSchematicFormats implements ISchematicFormat { int version = nbt.getInteger("Version"); switch (version) { case 4: //1.12 - return new LitematicaSchematic(nbt); + return new LitematicaSchematic(nbt, false); case 5: //1.13-1.17 case 6: //1.18+ throw new UnsupportedOperationException("This litematic Verion is to new."); diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 5f3c6e855..40ff37e73 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -43,25 +43,33 @@ public final class LitematicaSchematic extends StaticSchematic { private final int minZ; private final NBTTagCompound nbt; - public LitematicaSchematic(NBTTagCompound nbtTagCompound) { + public LitematicaSchematic(NBTTagCompound nbtTagCompound, boolean rotated) { this.nbt = nbtTagCompound; - int x = 0; - int y = 0; - int z = 0; - for (String subReg : getRegions(nbt)) { - x = Math.min(x, getMinimumCoord(nbt, subReg, "x")); - y = Math.min(y, getMinimumCoord(nbt, subReg, "y")); - z = Math.min(z, getMinimumCoord(nbt, subReg, "z")); - } - this.minX = x; - this.minY = y; - this.minZ = z; - - this.x = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("x")); + this.minX = getMinOfSchematic("x"); + this.minY = getMinOfSchematic("y"); + this.minZ = getMinOfSchematic("z"); this.y = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("y")); - this.z = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("z")); - this.states = new IBlockState[this.x][this.z][this.y]; + if (rotated) { + this.x = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("z")); + this.z = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("x")); + } else { + this.x = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("x")); + this.z = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("z")); + } + this.states = new IBlockState[this.x][this.z][this.y]; + fillInSchematic(); + } + + private int getMinOfSchematic(String s) { + int n = 0; + for (String subReg : getRegions(nbt)) { + n = Math.min(n, getMinOfSubregion(nbt, subReg, s)); + } + return n; + } + + private void fillInSchematic() { for (String subReg : getRegions(nbt)) { NBTTagList usedBlockTypes = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getTagList("BlockStatePalette", 10); IBlockState[] blockList = getBlockList(usedBlockTypes); @@ -89,7 +97,7 @@ public final class LitematicaSchematic extends StaticSchematic { * @param s axis that should be read. * @return the lower coord of the requested axis. */ - private static int getMinimumCoord(NBTTagCompound nbt, String subReg, String s) { + private static int getMinOfSubregion(NBTTagCompound nbt, String subReg, String s) { int a = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Position").getInteger(s); int b = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger(s); if (b < 0) { @@ -196,9 +204,9 @@ public final class LitematicaSchematic extends StaticSchematic { //minX,minY,minZ are correction terms if the schematic origin isn't the minimum corner //posX,posY,posZ are the subregions offset relative to the minimum corner private void writeSubregionIntoSchematic(NBTTagCompound nbt, String subReg, IBlockState[] blockList, LitematicaBitArray bitArray) { - int posX = getMinimumCoord(nbt, subReg, "x"); - int posY = getMinimumCoord(nbt, subReg, "y"); - int posZ = getMinimumCoord(nbt, subReg, "z"); + int posX = getMinOfSubregion(nbt, subReg, "x"); + int posY = getMinOfSubregion(nbt, subReg, "y"); + int posZ = getMinOfSubregion(nbt, subReg, "z"); int index = 0; for (int y = 0; y < this.y; y++) { for (int z = 0; z < this.z; z++) { @@ -227,8 +235,8 @@ public final class LitematicaSchematic extends StaticSchematic { public void setDirect(int x,int y,int z,IBlockState blockState) { this.states[x][z][y] = blockState; } - public LitematicaSchematic getCopy() { - return new LitematicaSchematic(nbt); + public LitematicaSchematic getCopy(boolean rotated) { + return new LitematicaSchematic(nbt, rotated); } /** diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java index c19ae5a74..47d3fe242 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -74,14 +74,21 @@ public final class LitematicaHelper { return new Vec3i(sizeX - (sizeX - sizeZ) - in.getZ(), in.getY(), in.getX()); } public static LitematicaSchematic blackMagicFuckery(LitematicaSchematic schemIn, int i) { - LitematicaSchematic tempSchem = schemIn.getCopy(); + LitematicaSchematic tempSchem = schemIn.getCopy(LitematicaHelper.getRotation(i).ordinal()%2==1); for (int yCounter=0; yCounter Date: Sat, 1 Oct 2022 22:51:36 +0200 Subject: [PATCH 60/78] getCorrectedOrigin returns the correct origin --- .../java/baritone/process/BuilderProcess.java | 2 +- .../litematica/LitematicaHelper.java | 46 ++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 3b9ba2dd5..65f97543f 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -190,7 +190,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil try { LitematicaSchematic schematic1 = new LitematicaSchematic(CompressedStreamTools.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath())),false); LitematicaSchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i); - Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(LitematicaHelper.getOrigin(i), schematic2.getMinimumCorner()); + Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(schematic2, i); build(name, schematic2, correctedOrigin); } catch (IOException e) { diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java index 47d3fe242..5e42ba999 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -57,8 +57,50 @@ public final class LitematicaHelper { public static Mirror getMirror(int i) { return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getMirror(); } - public static Vec3i getCorrectedOrigin(Vec3i origin, Vec3i correction) { - return new Vec3i(origin.getX()+ correction.getX(), origin.getY() + correction.getY(), origin.getZ() + correction.getZ()); + public static Vec3i getCorrectedOrigin(LitematicaSchematic schematic, int i) { + int x = LitematicaHelper.getOrigin(i).getX() + schematic.getMinimumCorner().getX(); + int y = LitematicaHelper.getOrigin(i).getY() + schematic.getMinimumCorner().getY(); + int z = LitematicaHelper.getOrigin(i).getZ() + schematic.getMinimumCorner().getZ(); + Vec3i correctedOrigin; + Mirror mirror = LitematicaHelper.getMirror(i); + Rotation rotation = LitematicaHelper.getRotation(i); + + //todo there has to be a better way to do this but i cant finde it atm + switch (mirror) { + case FRONT_BACK: + case LEFT_RIGHT: + switch ((mirror.ordinal()*2+rotation.ordinal())%4) { + case 1: + correctedOrigin = new Vec3i(x - schematic.getX()+1, y, z - schematic.getZ()+1); + break; + case 2: + correctedOrigin = new Vec3i(x, y, z - schematic.getZ()+1); + break; + case 3: + correctedOrigin = new Vec3i(x, y, z); + break; + default: + correctedOrigin = new Vec3i(x - schematic.getX()+1, y, z); + break; + } + break; + default: + switch (rotation) { + case CLOCKWISE_90: + correctedOrigin = new Vec3i(x - schematic.getX()+1, y, z); + break; + case CLOCKWISE_180: + correctedOrigin = new Vec3i(x - schematic.getX()+1, y, z - schematic.getZ()+1); + break; + case COUNTERCLOCKWISE_90: + correctedOrigin = new Vec3i(x, y, z - schematic.getZ()+1); + break; + default: + correctedOrigin = new Vec3i(x, y, z); + break; + } + } + return correctedOrigin; } public static Vec3i doMirroring(Vec3i in, int sizeX, int sizeZ, Mirror mirror) { int xOut = in.getX(); From 3e75cc7408fc299149c32e71c2114c307a4b9bc4 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Sat, 1 Oct 2022 22:59:47 +0200 Subject: [PATCH 61/78] block mirroring and rotation --- .../baritone/utils/schematic/litematica/LitematicaHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java index 5e42ba999..14b984c49 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -20,6 +20,7 @@ package baritone.utils.schematic.litematica; import baritone.utils.schematic.format.defaults.LitematicaSchematic; import fi.dy.masa.litematica.Litematica; import fi.dy.masa.litematica.data.DataManager; +import net.minecraft.block.state.IBlockState; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.Vec3i; @@ -132,7 +133,8 @@ public final class LitematicaHelper { } //System.out.println(String.format("Turned: %s, sizeX=%S, sizeZ=%s",xyzHolder,schemIn.getX(),schemIn.getZ())); } - tempSchem.setDirect(xyzHolder.getX(), xyzHolder.getY(), xyzHolder.getZ(), schemIn.getDirect(xCounter, yCounter, zCounter)); + IBlockState state = schemIn.getDirect(xCounter, yCounter, zCounter).withMirror(LitematicaHelper.getMirror(i)).withRotation(LitematicaHelper.getRotation(i)); + tempSchem.setDirect(xyzHolder.getX(), xyzHolder.getY(), xyzHolder.getZ(), state); } } } From fdfeeb2ffafc7b5b9be867e2a5e7f3f1d7e1a18e Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 3 Oct 2022 02:35:25 +0200 Subject: [PATCH 62/78] need stronger pesticides, bugs keep multiplying --- .../java/baritone/process/BuilderProcess.java | 11 +++-- .../format/defaults/LitematicaSchematic.java | 2 +- .../litematica/LitematicaHelper.java | 40 ++++++++++++------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 65f97543f..74d9f95c0 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -189,10 +189,15 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil String name = LitematicaHelper.getName(i); try { LitematicaSchematic schematic1 = new LitematicaSchematic(CompressedStreamTools.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath())),false); - LitematicaSchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i); - Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(schematic2, i); + try { + LitematicaSchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i); + Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(schematic2, i); + //Vec3i correctedOrigin = new Vec3i(0,4,0); - build(name, schematic2, correctedOrigin); + build(name, schematic2, correctedOrigin); + } catch (IndexOutOfBoundsException e) { + logDirect("BlackMagicFuckery summoned a Balrog. This foe is beyond any of you. "); + } } catch (IOException e) { logDirect("Schematic File could not be loaded"); } diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 40ff37e73..fb2f36ebf 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -62,7 +62,7 @@ public final class LitematicaSchematic extends StaticSchematic { } private int getMinOfSchematic(String s) { - int n = 0; + int n = Integer.MAX_VALUE; for (String subReg : getRegions(nbt)) { n = Math.min(n, getMinOfSubregion(nbt, subReg, s)); } diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java index 14b984c49..ea9b711b3 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -59,9 +59,14 @@ public final class LitematicaHelper { return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getMirror(); } public static Vec3i getCorrectedOrigin(LitematicaSchematic schematic, int i) { - int x = LitematicaHelper.getOrigin(i).getX() + schematic.getMinimumCorner().getX(); - int y = LitematicaHelper.getOrigin(i).getY() + schematic.getMinimumCorner().getY(); - int z = LitematicaHelper.getOrigin(i).getZ() + schematic.getMinimumCorner().getZ(); + int x = LitematicaHelper.getOrigin(i).getX(); + int y = LitematicaHelper.getOrigin(i).getY(); + int z = LitematicaHelper.getOrigin(i).getZ(); + int mx = schematic.getMinimumCorner().getX(); + int my = schematic.getMinimumCorner().getY(); + int mz = schematic.getMinimumCorner().getZ(); + int sx = (schematic.getX() - 1) * -1; + int sz = (schematic.getZ() - 1) * -1; Vec3i correctedOrigin; Mirror mirror = LitematicaHelper.getMirror(i); Rotation rotation = LitematicaHelper.getRotation(i); @@ -72,32 +77,32 @@ public final class LitematicaHelper { case LEFT_RIGHT: switch ((mirror.ordinal()*2+rotation.ordinal())%4) { case 1: - correctedOrigin = new Vec3i(x - schematic.getX()+1, y, z - schematic.getZ()+1); + correctedOrigin = new Vec3i(x + (sz - mz), y + my, z + (sx - mx)); break; case 2: - correctedOrigin = new Vec3i(x, y, z - schematic.getZ()+1); + correctedOrigin = new Vec3i(x + mx, y + my, z + (sz - mz)); break; case 3: - correctedOrigin = new Vec3i(x, y, z); + correctedOrigin = new Vec3i(x + mz, y + my, z + mx); break; default: - correctedOrigin = new Vec3i(x - schematic.getX()+1, y, z); + correctedOrigin = new Vec3i(x + (sx - mx), y + my, z + mz); break; } break; default: switch (rotation) { case CLOCKWISE_90: - correctedOrigin = new Vec3i(x - schematic.getX()+1, y, z); + correctedOrigin = new Vec3i(x + (sz - mz), y + my, z + mz); break; case CLOCKWISE_180: - correctedOrigin = new Vec3i(x - schematic.getX()+1, y, z - schematic.getZ()+1); + correctedOrigin = new Vec3i(x + (sx - mx), y + my, z + (sz - mz)); break; case COUNTERCLOCKWISE_90: - correctedOrigin = new Vec3i(x, y, z - schematic.getZ()+1); + correctedOrigin = new Vec3i(x + mz, y + my, z + (sx - mx)); break; default: - correctedOrigin = new Vec3i(x, y, z); + correctedOrigin = new Vec3i(x + mx, y + my, z + mz); break; } } @@ -122,18 +127,23 @@ public final class LitematicaHelper { for (int zCounter=0; zCounter Date: Mon, 3 Oct 2022 17:44:15 +0200 Subject: [PATCH 63/78] a fucking x and z mixup --- src/main/java/baritone/process/BuilderProcess.java | 4 +--- .../baritone/utils/schematic/litematica/LitematicaHelper.java | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 74d9f95c0..110df3dee 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -189,11 +189,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil String name = LitematicaHelper.getName(i); try { LitematicaSchematic schematic1 = new LitematicaSchematic(CompressedStreamTools.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath())),false); + Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(schematic1, i); try { LitematicaSchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i); - Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(schematic2, i); - //Vec3i correctedOrigin = new Vec3i(0,4,0); - build(name, schematic2, correctedOrigin); } catch (IndexOutOfBoundsException e) { logDirect("BlackMagicFuckery summoned a Balrog. This foe is beyond any of you. "); diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java index ea9b711b3..f63c8eb3c 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -67,6 +67,7 @@ public final class LitematicaHelper { int mz = schematic.getMinimumCorner().getZ(); int sx = (schematic.getX() - 1) * -1; int sz = (schematic.getZ() - 1) * -1; + Vec3i correctedOrigin; Mirror mirror = LitematicaHelper.getMirror(i); Rotation rotation = LitematicaHelper.getRotation(i); @@ -93,7 +94,7 @@ public final class LitematicaHelper { default: switch (rotation) { case CLOCKWISE_90: - correctedOrigin = new Vec3i(x + (sz - mz), y + my, z + mz); + correctedOrigin = new Vec3i(x + (sz - mz), y + my, z + mx); break; case CLOCKWISE_180: correctedOrigin = new Vec3i(x + (sx - mx), y + my, z + (sz - mz)); From fc65f22febd6cd75fa7b9cd236685ffcfeb7772a Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 3 Oct 2022 19:59:07 +0200 Subject: [PATCH 64/78] clean up and adding javadoc --- .../java/baritone/process/BuilderProcess.java | 14 ++-- .../format/defaults/LitematicaSchematic.java | 67 +++++++++++----- .../litematica/LitematicaHelper.java | 79 +++++++++++++++++-- .../placement/SchematicPlacementManager.java | 2 +- 4 files changed, 129 insertions(+), 33 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 110df3dee..124547ee1 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -181,6 +181,10 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } } + /** + * Builds the with index 'i' given schematic placement. + * @param i index reference to the schematic placement list. + */ @Override public void buildOpenLitematic(int i) { if (LitematicaHelper.isLitematicaPresent()) { @@ -190,14 +194,10 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil try { LitematicaSchematic schematic1 = new LitematicaSchematic(CompressedStreamTools.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath())),false); Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(schematic1, i); - try { - LitematicaSchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i); - build(name, schematic2, correctedOrigin); - } catch (IndexOutOfBoundsException e) { - logDirect("BlackMagicFuckery summoned a Balrog. This foe is beyond any of you. "); - } + LitematicaSchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i); + build(name, schematic2, correctedOrigin); } catch (IOException e) { - logDirect("Schematic File could not be loaded"); + logDirect("Schematic File could not be loaded."); } } else { logDirect("No schematic currently loaded"); diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index fb2f36ebf..f55f9212d 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -38,16 +38,16 @@ import java.util.Optional; * @since 22.09.2022 */ public final class LitematicaSchematic extends StaticSchematic { - private final int minX; - private final int minY; - private final int minZ; + private final Vec3i offsetMinCorner; private final NBTTagCompound nbt; + /** + * @param nbtTagCompound a decompressed file stream aka nbt data. + * @param rotated if the schematic is rotated by 90° aka x and z size are switched. + */ public LitematicaSchematic(NBTTagCompound nbtTagCompound, boolean rotated) { this.nbt = nbtTagCompound; - this.minX = getMinOfSchematic("x"); - this.minY = getMinOfSchematic("y"); - this.minZ = getMinOfSchematic("z"); + this.offsetMinCorner = new Vec3i(getMinOfSchematic("x"),getMinOfSchematic("y"),getMinOfSchematic("z")); this.y = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("y")); if (rotated) { @@ -61,6 +61,10 @@ public final class LitematicaSchematic extends StaticSchematic { fillInSchematic(); } + /** + * @param s axis. + * @return the lowest coordinate of that axis of the schematic. + */ private int getMinOfSchematic(String s) { int n = Integer.MAX_VALUE; for (String subReg : getRegions(nbt)) { @@ -69,6 +73,9 @@ public final class LitematicaSchematic extends StaticSchematic { return n; } + /** + * reads the file data. + */ private void fillInSchematic() { for (String subReg : getRegions(nbt)) { NBTTagList usedBlockTypes = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getTagList("BlockStatePalette", 10); @@ -92,7 +99,7 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * Gets both ends from schematic box for a given axis and returns the lower one. + * Gets both ends from a region box for a given axis and returns the lower one. * * @param s axis that should be read. * @return the lower coord of the requested axis. @@ -197,22 +204,19 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param blockList list with the different block types used in the schematic - * @param bitArray bit array that holds the placement pattern + * Writes the file data in to the IBlockstate array. + * + * @param blockList list with the different block types used in the schematic. + * @param bitArray bit array that holds the placement pattern. */ - //x,y,z are the releative positons to the minimum corner of the enclosing box - //minX,minY,minZ are correction terms if the schematic origin isn't the minimum corner - //posX,posY,posZ are the subregions offset relative to the minimum corner private void writeSubregionIntoSchematic(NBTTagCompound nbt, String subReg, IBlockState[] blockList, LitematicaBitArray bitArray) { - int posX = getMinOfSubregion(nbt, subReg, "x"); - int posY = getMinOfSubregion(nbt, subReg, "y"); - int posZ = getMinOfSubregion(nbt, subReg, "z"); + Vec3i offsetSubregion = new Vec3i(getMinOfSubregion(nbt, subReg, "x"), getMinOfSubregion(nbt, subReg, "y"), getMinOfSubregion(nbt, subReg, "z")); int index = 0; for (int y = 0; y < this.y; y++) { for (int z = 0; z < this.z; z++) { for (int x = 0; x < this.x; x++) { if (inSubregion(nbt, subReg, x, y, z)) { - this.states[x - (minX - posX)][z - (minZ - posZ)][y - (minY - posY)] = blockList[bitArray.getAt(index)]; + this.states[x - (offsetMinCorner.getX() - offsetSubregion.getX())][z - (offsetMinCorner.getZ() - offsetSubregion.getZ())][y - (offsetMinCorner.getY() - offsetSubregion.getY())] = blockList[bitArray.getAt(index)]; index++; } } @@ -220,21 +224,48 @@ public final class LitematicaSchematic extends StaticSchematic { } } - public Vec3i getMinimumCorner() { - return new Vec3i(this.minX, this.minY, this.minZ); + /** + * @return offset from the schematic origin to the minimum Corner as a Vec3i. + */ + public Vec3i getOffsetMinCorner() { + return offsetMinCorner; } + + /** + * @return x size of the schematic. + */ public int getX() { return this.x; } + + /** + * @return y size of the schematic. + */ public int getY() { return this.y; } + + /** + * @return z size of the schematic. + */ public int getZ() { return this.z; } + + /** + * @param x position relative to the minimum corner of the schematic. + * @param y position relative to the minimum corner of the schematic. + * @param z position relative to the minimum corner of the schematic. + * @param blockState new blockstate of the block at this position. + */ public void setDirect(int x,int y,int z,IBlockState blockState) { this.states[x][z][y] = blockState; } + + /** + * @param rotated if the schematic is rotated by 90°. + * @return a copy of the schematic. + */ public LitematicaSchematic getCopy(boolean rotated) { return new LitematicaSchematic(nbt, rotated); } diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java index f63c8eb3c..be437624d 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -27,7 +27,17 @@ import net.minecraft.util.math.Vec3i; import java.io.File; +/** + * Helper class that provides access or processes data related to Litmatica schematics. + * + * @author rycbar + * @since 28.09.2022 + */ public final class LitematicaHelper { + + /** + * @return if Litmatica is installed. + */ public static boolean isLitematicaPresent() { try { Class.forName(Litematica.class.getName()); @@ -36,12 +46,26 @@ public final class LitematicaHelper { return false; } } + + /** + * @return if there are loaded schematics. + */ public static boolean hasLoadedSchematic() { return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().size()>0; } + + /** + * @param i index of the Schematic in the schematic placement list. + * @return the name of the requested schematic. + */ public static String getName(int i) { return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getName(); } + + /** + * @param i index of the Schematic in the schematic placement list. + * @return the world coordinates of the schematic origin. This can but does not have to be the minimum corner. + */ public static Vec3i getOrigin(int i) { int x,y,z; x=DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getOrigin().getX(); @@ -49,22 +73,43 @@ public final class LitematicaHelper { z=DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getOrigin().getZ(); return new Vec3i(x,y,z); } + + /** + * @param i index of the Schematic in the schematic placement list. + * @return Filepath of the schematic file. + */ public static File getSchematicFile(int i) { return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getSchematicFile(); } + + /** + * @param i index of the Schematic in the schematic placement list. + * @return rotation of the schematic placement. + */ public static Rotation getRotation(int i) { return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getRotation(); } + + /** + * @param i index of the Schematic in the schematic placement list. + * @return the mirroring of the schematic placement. + */ public static Mirror getMirror(int i) { return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getMirror(); } + + /** + * @param schematic original schematic. + * @param i index of the Schematic in the schematic placement list. + * @return the minimum corner coordinates of the schematic, after the original schematic got rotated and mirrored. + */ public static Vec3i getCorrectedOrigin(LitematicaSchematic schematic, int i) { int x = LitematicaHelper.getOrigin(i).getX(); int y = LitematicaHelper.getOrigin(i).getY(); int z = LitematicaHelper.getOrigin(i).getZ(); - int mx = schematic.getMinimumCorner().getX(); - int my = schematic.getMinimumCorner().getY(); - int mz = schematic.getMinimumCorner().getZ(); + int mx = schematic.getOffsetMinCorner().getX(); + int my = schematic.getOffsetMinCorner().getY(); + int mz = schematic.getOffsetMinCorner().getZ(); int sx = (schematic.getX() - 1) * -1; int sz = (schematic.getZ() - 1) * -1; @@ -109,6 +154,14 @@ public final class LitematicaHelper { } return correctedOrigin; } + + /** + * @param in the xyz offsets of the block relative to the schematic minimum corner. + * @param sizeX size of the schematic in the x-axis direction. + * @param sizeZ size of the schematic in the z-axis direction. + * @param mirror the mirroring of the schematic placement. + * @return the corresponding xyz coordinates after mirroring them according to the given mirroring. + */ public static Vec3i doMirroring(Vec3i in, int sizeX, int sizeZ, Mirror mirror) { int xOut = in.getX(); int zOut = in.getZ(); @@ -119,31 +172,43 @@ public final class LitematicaHelper { } return new Vec3i(xOut, in.getY(), zOut); } + + /** + * @param in the xyz offsets of the block relative to the schematic minimum corner. + * @param sizeX size of the schematic in the x-axis direction. + * @param sizeZ size of the schematic in the z-axis direction. + * @return the corresponding xyz coordinates after rotation them 90° clockwise. + */ public static Vec3i rotate(Vec3i in, int sizeX, int sizeZ) { return new Vec3i(sizeX - (sizeX - sizeZ) - in.getZ(), in.getY(), in.getX()); } + + /** + * IDFK this just grew and it somehow works. If you understand how, pls tell me. + * + * @param schemIn give in the original schematic. + * @param i index of the Schematic in the schematic placement list. + * @return get it out rotated and mirrored. + */ public static LitematicaSchematic blackMagicFuckery(LitematicaSchematic schemIn, int i) { LitematicaSchematic tempSchem = schemIn.getCopy(LitematicaHelper.getRotation(i).ordinal()%2==1); for (int yCounter=0; yCounter schematicPlacements = new ArrayList<>(); //in case of a java.lang.NoSuchMethodError try change the name of this method to getAllSchematicPlacements() - // there are inconsistencies in the litematica mod about the naming of this method + //there are inconsistencies in the litematica mod about the naming of this method public List getAllSchematicsPlacements() { return schematicPlacements; } From 3a5608566e3c46f61b888065675fa586791db807 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 3 Oct 2022 20:13:11 +0200 Subject: [PATCH 65/78] auto formatting --- .../java/baritone/process/BuilderProcess.java | 7 +- .../format/defaults/LitematicaSchematic.java | 72 +++++++++---------- .../litematica/LitematicaHelper.java | 36 +++++----- .../dy/masa/litematica/data/DataManager.java | 2 + .../placement/SchematicPlacement.java | 2 + .../placement/SchematicPlacementUnloaded.java | 6 +- 6 files changed, 65 insertions(+), 60 deletions(-) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 124547ee1..c1c0cb1d9 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -26,9 +26,9 @@ import baritone.api.process.IBuilderProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.api.schematic.FillSchematic; -import baritone.api.schematic.SubstituteSchematic; import baritone.api.schematic.ISchematic; import baritone.api.schematic.IStaticSchematic; +import baritone.api.schematic.SubstituteSchematic; import baritone.api.schematic.format.ISchematicFormat; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.RayTraceUtils; @@ -42,8 +42,8 @@ import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import baritone.utils.PathingCommandContext; import baritone.utils.schematic.MapArtSchematic; -import baritone.utils.schematic.SelectionSchematic; import baritone.utils.schematic.SchematicSystem; +import baritone.utils.schematic.SelectionSchematic; import baritone.utils.schematic.format.defaults.LitematicaSchematic; import baritone.utils.schematic.litematica.LitematicaHelper; import baritone.utils.schematic.schematica.SchematicaHelper; @@ -183,6 +183,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil /** * Builds the with index 'i' given schematic placement. + * * @param i index reference to the schematic placement list. */ @Override @@ -192,7 +193,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (LitematicaHelper.hasLoadedSchematic()) { String name = LitematicaHelper.getName(i); try { - LitematicaSchematic schematic1 = new LitematicaSchematic(CompressedStreamTools.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath())),false); + LitematicaSchematic schematic1 = new LitematicaSchematic(CompressedStreamTools.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath())), false); Vec3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(schematic1, i); LitematicaSchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i); build(name, schematic2, correctedOrigin); diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index f55f9212d..dc1c1d5bd 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -43,11 +43,11 @@ public final class LitematicaSchematic extends StaticSchematic { /** * @param nbtTagCompound a decompressed file stream aka nbt data. - * @param rotated if the schematic is rotated by 90° aka x and z size are switched. + * @param rotated if the schematic is rotated by 90° aka x and z size are switched. */ public LitematicaSchematic(NBTTagCompound nbtTagCompound, boolean rotated) { this.nbt = nbtTagCompound; - this.offsetMinCorner = new Vec3i(getMinOfSchematic("x"),getMinOfSchematic("y"),getMinOfSchematic("z")); + this.offsetMinCorner = new Vec3i(getMinOfSchematic("x"), getMinOfSchematic("y"), getMinOfSchematic("z")); this.y = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("y")); if (rotated) { @@ -61,36 +61,6 @@ public final class LitematicaSchematic extends StaticSchematic { fillInSchematic(); } - /** - * @param s axis. - * @return the lowest coordinate of that axis of the schematic. - */ - private int getMinOfSchematic(String s) { - int n = Integer.MAX_VALUE; - for (String subReg : getRegions(nbt)) { - n = Math.min(n, getMinOfSubregion(nbt, subReg, s)); - } - return n; - } - - /** - * reads the file data. - */ - private void fillInSchematic() { - for (String subReg : getRegions(nbt)) { - NBTTagList usedBlockTypes = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getTagList("BlockStatePalette", 10); - IBlockState[] blockList = getBlockList(usedBlockTypes); - - int bitsPerBlock = getBitsPerBlock(usedBlockTypes.tagCount()); - long regionVolume = getVolume(nbt, subReg); - long[] blockStateArray = getBlockStates(nbt, subReg); - - LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, blockStateArray); - - writeSubregionIntoSchematic(nbt, subReg, blockList, bitArray); - } - } - /** * @return Array of subregion names. */ @@ -203,6 +173,36 @@ public final class LitematicaSchematic extends StaticSchematic { z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); } + /** + * @param s axis. + * @return the lowest coordinate of that axis of the schematic. + */ + private int getMinOfSchematic(String s) { + int n = Integer.MAX_VALUE; + for (String subReg : getRegions(nbt)) { + n = Math.min(n, getMinOfSubregion(nbt, subReg, s)); + } + return n; + } + + /** + * reads the file data. + */ + private void fillInSchematic() { + for (String subReg : getRegions(nbt)) { + NBTTagList usedBlockTypes = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getTagList("BlockStatePalette", 10); + IBlockState[] blockList = getBlockList(usedBlockTypes); + + int bitsPerBlock = getBitsPerBlock(usedBlockTypes.tagCount()); + long regionVolume = getVolume(nbt, subReg); + long[] blockStateArray = getBlockStates(nbt, subReg); + + LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, blockStateArray); + + writeSubregionIntoSchematic(nbt, subReg, blockList, bitArray); + } + } + /** * Writes the file data in to the IBlockstate array. * @@ -253,12 +253,12 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param x position relative to the minimum corner of the schematic. - * @param y position relative to the minimum corner of the schematic. - * @param z position relative to the minimum corner of the schematic. + * @param x position relative to the minimum corner of the schematic. + * @param y position relative to the minimum corner of the schematic. + * @param z position relative to the minimum corner of the schematic. * @param blockState new blockstate of the block at this position. */ - public void setDirect(int x,int y,int z,IBlockState blockState) { + public void setDirect(int x, int y, int z, IBlockState blockState) { this.states[x][z][y] = blockState; } diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java index be437624d..b6ba681fa 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -51,7 +51,7 @@ public final class LitematicaHelper { * @return if there are loaded schematics. */ public static boolean hasLoadedSchematic() { - return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().size()>0; + return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().size() > 0; } /** @@ -67,11 +67,7 @@ public final class LitematicaHelper { * @return the world coordinates of the schematic origin. This can but does not have to be the minimum corner. */ public static Vec3i getOrigin(int i) { - int x,y,z; - x=DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getOrigin().getX(); - y=DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getOrigin().getY(); - z=DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getOrigin().getZ(); - return new Vec3i(x,y,z); + return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getOrigin(); } /** @@ -100,7 +96,7 @@ public final class LitematicaHelper { /** * @param schematic original schematic. - * @param i index of the Schematic in the schematic placement list. + * @param i index of the Schematic in the schematic placement list. * @return the minimum corner coordinates of the schematic, after the original schematic got rotated and mirrored. */ public static Vec3i getCorrectedOrigin(LitematicaSchematic schematic, int i) { @@ -121,7 +117,7 @@ public final class LitematicaHelper { switch (mirror) { case FRONT_BACK: case LEFT_RIGHT: - switch ((mirror.ordinal()*2+rotation.ordinal())%4) { + switch ((mirror.ordinal() * 2 + rotation.ordinal()) % 4) { case 1: correctedOrigin = new Vec3i(x + (sz - mz), y + my, z + (sx - mx)); break; @@ -156,16 +152,16 @@ public final class LitematicaHelper { } /** - * @param in the xyz offsets of the block relative to the schematic minimum corner. - * @param sizeX size of the schematic in the x-axis direction. - * @param sizeZ size of the schematic in the z-axis direction. + * @param in the xyz offsets of the block relative to the schematic minimum corner. + * @param sizeX size of the schematic in the x-axis direction. + * @param sizeZ size of the schematic in the z-axis direction. * @param mirror the mirroring of the schematic placement. * @return the corresponding xyz coordinates after mirroring them according to the given mirroring. */ public static Vec3i doMirroring(Vec3i in, int sizeX, int sizeZ, Mirror mirror) { int xOut = in.getX(); int zOut = in.getZ(); - if(mirror == Mirror.LEFT_RIGHT) { + if (mirror == Mirror.LEFT_RIGHT) { zOut = sizeZ - in.getZ(); } else if (mirror == Mirror.FRONT_BACK) { xOut = sizeX - in.getX(); @@ -174,31 +170,31 @@ public final class LitematicaHelper { } /** - * @param in the xyz offsets of the block relative to the schematic minimum corner. + * @param in the xyz offsets of the block relative to the schematic minimum corner. * @param sizeX size of the schematic in the x-axis direction. * @param sizeZ size of the schematic in the z-axis direction. * @return the corresponding xyz coordinates after rotation them 90° clockwise. */ public static Vec3i rotate(Vec3i in, int sizeX, int sizeZ) { - return new Vec3i(sizeX - (sizeX - sizeZ) - in.getZ(), in.getY(), in.getX()); + return new Vec3i(sizeX - (sizeX - sizeZ) - in.getZ(), in.getY(), in.getX()); } /** * IDFK this just grew and it somehow works. If you understand how, pls tell me. * * @param schemIn give in the original schematic. - * @param i index of the Schematic in the schematic placement list. + * @param i index of the Schematic in the schematic placement list. * @return get it out rotated and mirrored. */ public static LitematicaSchematic blackMagicFuckery(LitematicaSchematic schemIn, int i) { - LitematicaSchematic tempSchem = schemIn.getCopy(LitematicaHelper.getRotation(i).ordinal()%2==1); - for (int yCounter=0; yCounter Date: Mon, 3 Oct 2022 20:32:56 +0200 Subject: [PATCH 66/78] made a oopsie --- .../baritone/utils/schematic/litematica/LitematicaHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java index b6ba681fa..ec9fcc735 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -202,7 +202,7 @@ public final class LitematicaHelper { } IBlockState state = schemIn.getDirect(xCounter, yCounter, zCounter); try { - state.withMirror(LitematicaHelper.getMirror(i)).withRotation(LitematicaHelper.getRotation(i)); + state = state.withMirror(LitematicaHelper.getMirror(i)).withRotation(LitematicaHelper.getRotation(i)); } catch (NullPointerException e) { //nothing to worry about it's just a hole in the schematic. } From f9c5386e7ada3c732aeec9f436a07828ae9de68f Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 3 Oct 2022 21:39:53 +0200 Subject: [PATCH 67/78] final changes --- .../command/defaults/LitematicaCommand.java | 4 ++-- .../schematic/format/DefaultSchematicFormats.java | 2 +- .../format/defaults/LitematicaSchematic.java | 14 ++++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/baritone/command/defaults/LitematicaCommand.java b/src/main/java/baritone/command/defaults/LitematicaCommand.java index eecab07de..bfe0079b3 100644 --- a/src/main/java/baritone/command/defaults/LitematicaCommand.java +++ b/src/main/java/baritone/command/defaults/LitematicaCommand.java @@ -35,10 +35,10 @@ public class LitematicaCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { int schematic = 0; - if(args.hasAny()) { + if (args.hasAny()) { args.requireMax(1); if (args.is(Integer.class)) { - schematic = args.getAs(Integer.class)-1; + schematic = args.getAs(Integer.class) - 1; } } try { diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index 2ca9e1485..cd38433ad 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -81,7 +81,7 @@ public enum DefaultSchematicFormats implements ISchematicFormat { return new LitematicaSchematic(nbt, false); case 5: //1.13-1.17 case 6: //1.18+ - throw new UnsupportedOperationException("This litematic Verion is to new."); + throw new UnsupportedOperationException("This litematic Verion is too new."); default: throw new UnsupportedOperationException("Unsuported Version of a Litematica Schematic"); } diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index dc1c1d5bd..84b9b86e2 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -32,8 +32,9 @@ import javax.annotation.Nullable; import java.util.Optional; /** - * @author Emerson - * @since 12/27/2020 + * Based on EmersonDove's work + * ... + * * @author rycbar * @since 22.09.2022 */ @@ -43,7 +44,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * @param nbtTagCompound a decompressed file stream aka nbt data. - * @param rotated if the schematic is rotated by 90° aka x and z size are switched. + * @param rotated if the schematic is rotated by 90°. */ public LitematicaSchematic(NBTTagCompound nbtTagCompound, boolean rotated) { this.nbt = nbtTagCompound; @@ -167,10 +168,10 @@ public final class LitematicaSchematic extends StaticSchematic { * @return if the current block is part of the subregion. */ private static boolean inSubregion(NBTTagCompound nbt, String subReg, int x, int y, int z) { - return + return x >= 0 && y >= 0 && z >= 0 && x < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("x")) && - y < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y")) && - z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); + y < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y")) && + z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); } /** @@ -273,6 +274,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * @author maruohon * Class from the Litematica mod by maruohon + * Usage under LGPLv3 with the permission of the author. * ... */ private static class LitematicaBitArray { From ba3ca47f8c454a8c9ed34d6da66d1b63bf7acf37 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sun, 23 Oct 2022 01:42:31 +0200 Subject: [PATCH 68/78] =?UTF-8?q?=E2=9C=A8=20Add=20buildIgnoreProperties?= =?UTF-8?q?=20setting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/java/baritone/api/Settings.java | 6 ++++++ src/main/java/baritone/process/BuilderProcess.java | 13 ++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 897182898..267fe7822 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -279,6 +279,12 @@ public final class Settings { */ public final Setting buildIgnoreDirection = new Setting<>(false); + /** + * A list of names of block properties the builder will ignore. + */ + public final Setting> buildIgnoreProperties = new Setting<>(new ArrayList<>(Arrays.asList( + ))); + /** * If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block. *

diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index c1c0cb1d9..2d7714d9e 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -874,14 +874,21 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil BlockTrapDoor.OPEN, BlockTrapDoor.HALF ); - private boolean sameWithoutOrientation(IBlockState first, IBlockState second) { + private boolean sameBlockstate(IBlockState first, IBlockState second) { if (first.getBlock() != second.getBlock()) { return false; } + boolean ignoreDirection = Baritone.settings().buildIgnoreDirection.value; + List ignoredProps = Baritone.settings().buildIgnoreProperties.value; + if (!ignoreDirection && ignoredProps.isEmpty()) { + return first.equals(second); // early return if no properties are being ignored + } ImmutableMap, Comparable> map1 = first.getProperties(); ImmutableMap, Comparable> map2 = second.getProperties(); for (IProperty prop : map1.keySet()) { - if (map1.get(prop) != map2.get(prop) && !orientationProps.contains(prop)) { + if (map1.get(prop) != map2.get(prop) + && !(ignoreDirection && orientationProps.contains(prop)) + && !ignoredProps.contains(prop.getName())) { return false; } } @@ -913,7 +920,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (current.equals(desired)) { return true; } - return Baritone.settings().buildIgnoreDirection.value && sameWithoutOrientation(current, desired); + return sameBlockstate(current, desired); } public class BuilderCalculationContext extends CalculationContext { From 1cd2fb5b18203b7fee4f8e1c71a53326e6b7e2ea Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Mon, 24 Oct 2022 22:49:12 +0200 Subject: [PATCH 69/78] Reliably clear keys when paused --- .../java/baritone/command/defaults/ExecutionControlCommands.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java index eaab75286..6f6293ccd 100644 --- a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java +++ b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java @@ -56,6 +56,7 @@ public class ExecutionControlCommands { @Override public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { + baritone.getInputOverrideHandler().clearAllKeys(); return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); } From 3cef7a7911d45c94a1344239ab6895b5c7578bb8 Mon Sep 17 00:00:00 2001 From: rycbar0 <100363533+rycbar0@users.noreply.github.com> Date: Wed, 26 Oct 2022 23:09:23 +0200 Subject: [PATCH 70/78] formula error --- .../utils/schematic/format/defaults/LitematicaSchematic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 84b9b86e2..c2857bc2d 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -136,7 +136,7 @@ public final class LitematicaSchematic extends StaticSchematic { * @return amount of bits used to encode a block. */ private static int getBitsPerBlock(int amountOfBlockTypes) { - return (int) Math.floor((Math.log(amountOfBlockTypes)) / Math.log(2)) + 1; + return (int) Math.max(2,Math.ceil(Math.log(amountOfBlockTypes) / Math.log(2))); } /** From e1095962a1b2854dd65003959e17e5f812fad7e3 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Mon, 28 Nov 2022 23:07:30 +0100 Subject: [PATCH 71/78] Fix Registry.unregister --- src/api/java/baritone/api/command/registry/Registry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/command/registry/Registry.java b/src/api/java/baritone/api/command/registry/Registry.java index 067791690..b571484b7 100644 --- a/src/api/java/baritone/api/command/registry/Registry.java +++ b/src/api/java/baritone/api/command/registry/Registry.java @@ -84,7 +84,7 @@ public class Registry { * @param entry The entry to unregister. */ public void unregister(V entry) { - if (registered(entry)) { + if (!registered(entry)) { return; } _entries.remove(entry); From e09127eadf3efe6aee9afd56183c902181737c57 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sat, 10 Dec 2022 16:35:51 -0700 Subject: [PATCH 72/78] allowBreakAnyway should let mining happen --- .../java/baritone/process/MineProcess.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 1ec47cd92..08a6791b6 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -102,10 +102,17 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return null; } } + if (!Baritone.settings().allowBreak.value) { - logDirect("Unable to mine when allowBreak is false!"); - cancel(); - return null; + this.filter = new BlockOptionalMetaLookup(filter.blocks() + .stream() + .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) + .toArray(BlockOptionalMeta[]::new)); + if (this.filter.blocks().isEmpty()) { + logDirect("Unable to mine when allowBreak is false!"); + cancel(); + return null; + } } updateLoucaSystem(); int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; @@ -467,9 +474,15 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro public void mine(int quantity, BlockOptionalMetaLookup filter) { this.filter = filter; if (filter != null && !Baritone.settings().allowBreak.value) { - logDirect("Unable to mine when allowBreak is false!"); - this.mine(quantity, (BlockOptionalMetaLookup) null); - return; + this.filter = new BlockOptionalMetaLookup(filter.blocks() + .stream() + .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) + .toArray(BlockOptionalMeta[]::new)); + if (this.filter.blocks().isEmpty()) { + logDirect("Unable to mine when allowBreak is false!"); + this.mine(quantity, (BlockOptionalMetaLookup) null); + return; + } } this.desiredQuantity = quantity; this.knownOreLocations = new ArrayList<>(); From 85087ce04a9130a92059732ca7046be3d39c9f29 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sat, 10 Dec 2022 19:25:57 -0700 Subject: [PATCH 73/78] smarter filter filtering --- .../java/baritone/process/MineProcess.java | 59 +++++++++++-------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 08a6791b6..7666ec7c5 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -103,17 +103,6 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } } - if (!Baritone.settings().allowBreak.value) { - this.filter = new BlockOptionalMetaLookup(filter.blocks() - .stream() - .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) - .toArray(BlockOptionalMeta[]::new)); - if (this.filter.blocks().isEmpty()) { - logDirect("Unable to mine when allowBreak is false!"); - cancel(); - return null; - } - } updateLoucaSystem(); int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; List curr = new ArrayList<>(knownOreLocations); @@ -122,7 +111,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro Baritone.getExecutor().execute(() -> rescan(curr, context)); } if (Baritone.settings().legitMine.value) { - addNearby(); + if (!addNearby()) return null; } Optional shaft = curr.stream() .filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ()) @@ -183,6 +172,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } private PathingCommand updateGoal() { + BlockOptionalMetaLookup filter = filterFilter(); + if (filter == null) { + return null; + } + boolean legit = Baritone.settings().legitMine.value; List locs = knownOreLocations; if (!locs.isEmpty()) { @@ -227,6 +221,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } private void rescan(List already, CalculationContext context) { + BlockOptionalMetaLookup filter = filterFilter(); if (filter == null) { return; } @@ -376,11 +371,18 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return prune(ctx, locs, filter, max, blacklist, dropped); } - private void addNearby() { + private boolean addNearby() { List dropped = droppedItemsScan(); knownOreLocations.addAll(dropped); BlockPos playerFeet = ctx.playerFeet(); BlockStateInterface bsi = new BlockStateInterface(ctx); + + + BlockOptionalMetaLookup filter = filterFilter(); + if (filter == null) { + return false; + } + int searchDist = 10; double fakedBlockReachDistance = 20; // at least 10 * sqrt(3) with some extra space to account for positioning within the block for (int x = playerFeet.getX() - searchDist; x <= playerFeet.getX() + searchDist; x++) { @@ -398,6 +400,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } } knownOreLocations = prune(new CalculationContext(baritone), knownOreLocations, filter, ORE_LOCATIONS_COUNT, blacklist, dropped); + return true; } private static List prune(CalculationContext ctx, List locs2, BlockOptionalMetaLookup filter, int max, List blacklist, List dropped) { @@ -473,16 +476,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro @Override public void mine(int quantity, BlockOptionalMetaLookup filter) { this.filter = filter; - if (filter != null && !Baritone.settings().allowBreak.value) { - this.filter = new BlockOptionalMetaLookup(filter.blocks() - .stream() - .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) - .toArray(BlockOptionalMeta[]::new)); - if (this.filter.blocks().isEmpty()) { - logDirect("Unable to mine when allowBreak is false!"); - this.mine(quantity, (BlockOptionalMetaLookup) null); - return; - } + if (this.filterFilter() == null) { + this.filter = null; } this.desiredQuantity = quantity; this.knownOreLocations = new ArrayList<>(); @@ -494,4 +489,22 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro rescan(new ArrayList<>(), new CalculationContext(baritone)); } } + + private BlockOptionalMetaLookup filterFilter() { + if (this.filter == null) { + return null; + } + if (!Baritone.settings().allowBreak.value) { + BlockOptionalMetaLookup f = new BlockOptionalMetaLookup(this.filter.blocks() + .stream() + .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) + .toArray(BlockOptionalMeta[]::new)); + if (f.blocks().isEmpty()) { + logDirect("Unable to mine when allowBreak is false and target block is not in allowBreakAnyway!"); + return null; + } + return f; + } + return filter; + } } From ea1914a24816ae57daa925132cafce4f7007edc8 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sat, 10 Dec 2022 20:12:51 -0700 Subject: [PATCH 74/78] missed a spot --- src/main/java/baritone/process/MineProcess.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 7666ec7c5..395e99d9a 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -111,7 +111,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro Baritone.getExecutor().execute(() -> rescan(curr, context)); } if (Baritone.settings().legitMine.value) { - if (!addNearby()) return null; + if (!addNearby()) { + cancel(); + return null; + } } Optional shaft = curr.stream() .filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ()) From d157756d9438566da4250eb3f26923f7b2d8e639 Mon Sep 17 00:00:00 2001 From: Warpten Date: Mon, 12 Dec 2022 01:08:49 +0100 Subject: [PATCH 75/78] Improve handling spaces in paths during proguard pass --- .../java/baritone/gradle/task/ProguardTask.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index 01e561775..1789435f7 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -209,8 +209,8 @@ public class ProguardTask extends BaritoneGradleTask { // Setup the template that will be used to derive the API and Standalone configs List template = Files.readAllLines(getTemporaryFile(PROGUARD_CONFIG_DEST)); - template.add(0, "-injars " + this.artifactPath.toString()); - template.add(1, "-outjars " + this.getTemporaryFile(PROGUARD_EXPORT_PATH)); + template.add(0, "-injars '" + this.artifactPath.toString() + "'"); + 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(this.getJavaBinPathForProguard(), "-verbose").start(); @@ -405,9 +405,15 @@ public class ProguardTask extends BaritoneGradleTask { Files.delete(this.proguardOut); } - Path proguardJar = getTemporaryFile(PROGUARD_JAR); + // 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. + Process p = new ProcessBuilder("java", "-jar", proguardJar.toString(), "@" + config.toString()) - .directory(getTemporaryFile("").toFile()) // Set the working directory to the temporary folder] + .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 From 41968546d1efb9559b172e4a1d0f66f64bd4c927 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Fri, 6 Jan 2023 04:09:56 +0100 Subject: [PATCH 76/78] Update workflows --- .github/workflows/gradle_build.yml | 8 ++++---- .github/workflows/run_tests.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/gradle_build.yml b/.github/workflows/gradle_build.yml index 34e93bff2..6a800e98e 100644 --- a/.github/workflows/gradle_build.yml +++ b/.github/workflows/gradle_build.yml @@ -13,9 +13,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up JDK 8 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: '8' distribution: 'adopt' @@ -27,13 +27,13 @@ jobs: run: ./gradlew build - name: Archive Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: Artifacts path: dist/ - name: Archive mapping.txt - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: Mappings path: build/tmp/proguard/mapping.txt diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 1af26a476..08fd28ef6 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -11,9 +11,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up JDK 9 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: '8' distribution: 'adopt' From 678f8bc77fa5a3f22b364faf29401c62a2e1500c Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Fri, 6 Jan 2023 04:25:03 +0100 Subject: [PATCH 77/78] Use Temurin JDK --- .github/workflows/gradle_build.yml | 2 +- .github/workflows/run_tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gradle_build.yml b/.github/workflows/gradle_build.yml index 6a800e98e..d69498bc3 100644 --- a/.github/workflows/gradle_build.yml +++ b/.github/workflows/gradle_build.yml @@ -18,7 +18,7 @@ jobs: uses: actions/setup-java@v3 with: java-version: '8' - distribution: 'adopt' + distribution: 'temurin' - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 08fd28ef6..18eac5e2e 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -16,7 +16,7 @@ jobs: uses: actions/setup-java@v3 with: java-version: '8' - distribution: 'adopt' + distribution: 'temurin' - name: Grant execute permission for gradlew run: chmod +x gradlew From a1a94ec0d154dd519b09443f0cb486aeb9ed15b6 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Fri, 6 Jan 2023 04:26:03 +0100 Subject: [PATCH 78/78] Fix step name --- .github/workflows/run_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 18eac5e2e..d2d849fb7 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -12,7 +12,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 9 + - name: Set up JDK 8 uses: actions/setup-java@v3 with: java-version: '8'