From 21534d1c0bafb5d27dadb97ae1144a54e9a2d19f Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Thu, 18 Nov 2021 00:21:12 +0100 Subject: [PATCH 01/80] Fix chat error messages being obfuscated for block type arguments --- scripts/proguard.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 9adc5174c..6f797771f 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -22,6 +22,7 @@ -keep class baritone.api.IBaritoneProvider -keep class baritone.api.utils.MyChunkPos { *; } # even in standalone we need to keep this for gson reflect +-keepname class baritone.api.utils.BlockOptionalMeta # this name is exposed to the user, so we need to keep it in all builds # Keep any class or member annotated with @KeepName so we dont have to put everything in the script -keep,allowobfuscation @interface baritone.KeepName From 74ea803651c2e4d73c813ea38d2c790e26c209e0 Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Wed, 2 Feb 2022 20:33:47 +0000 Subject: [PATCH 02/80] Add world border checks to MovementHelper --- .../java/baritone/pathing/movement/CalculationContext.java | 1 - src/main/java/baritone/pathing/movement/MovementHelper.java | 6 ++++++ src/main/java/baritone/utils/BlockStateInterface.java | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 124e6f109..fca6bc990 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -143,7 +143,6 @@ public class CalculationContext { return COST_INF; } if (!worldBorder.canPlaceAt(x, z)) { - // TODO perhaps MovementHelper.canPlaceAgainst could also use this? return COST_INF; } return placeBlockCost; diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index f5f565e39..23c261446 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -49,6 +49,9 @@ import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____S public interface MovementHelper extends ActionCosts, Helper { static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { + if (!bsi.worldBorder.canPlaceAt(x, y)) { + return false; + } Block b = state.getBlock(); return Baritone.settings().blocksToDisallowBreaking.value.contains(b) || b == Blocks.ICE // ice becomes water, and water can mess up the path @@ -368,6 +371,9 @@ public interface MovementHelper extends ActionCosts, Helper { } static boolean canPlaceAgainst(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { + if (!bsi.worldBorder.canPlaceAt(x, z)) { + return false; + } // can we look at the center of a side face of this block and likely be able to place? // (thats how this check is used) // therefore dont include weird things that we technically could place against (like carpet) but practically can't diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 4f5f26899..f451c2f1d 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -22,6 +22,7 @@ import baritone.api.utils.IPlayerContext; import baritone.cache.CachedRegion; import baritone.cache.WorldData; import baritone.utils.accessor.IChunkProviderClient; +import baritone.utils.pathing.BetterWorldBorder; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import net.minecraft.block.Block; @@ -46,6 +47,7 @@ public class BlockStateInterface { protected final IBlockAccess world; public final BlockPos.MutableBlockPos isPassableBlockPos; public final IBlockAccess access; + public final BetterWorldBorder worldBorder; private Chunk prev = null; private CachedRegion prevCached = null; @@ -64,6 +66,7 @@ public class BlockStateInterface { public BlockStateInterface(World world, WorldData worldData, boolean copyLoadedChunks) { this.world = world; + this.worldBorder = new BetterWorldBorder(world.getWorldBorder()); this.worldData = worldData; Long2ObjectMap worldLoaded = ((IChunkProviderClient) world.getChunkProvider()).loadedChunks(); if (copyLoadedChunks) { From 2d0f10c79fe4441d40bdefbc54a599037e543e5b Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 2 Feb 2022 15:53:09 -0800 Subject: [PATCH 03/80] link to branches --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 86aab720b..eec452ba4 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@

- Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft - Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft + Minecraft

From 25de3324920fa375dad903f9386eabe496d291a6 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 2 Feb 2022 15:53:43 -0800 Subject: [PATCH 04/80] mfw this also needs to be in master --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 84a7e4319..d4c25ad90 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ baritone_Client.launch # Copyright Files !/.idea/copyright/Baritone.xml !/.idea/copyright/profiles_settings.xml + +.vscode/launch.json + From e0a53144db0889eb9d279ce248b7a279600ccc8c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 2 Feb 2022 16:10:14 -0800 Subject: [PATCH 05/80] bump most recent jars --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eec452ba4..381e3f126 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,9 @@ For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see de For 1.16.5, [click here](https://www.youtube.com/watch?v=_4eVJ9Qz2J8) and see description. If you need Forge or Fabric 1.16.5, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.6.3) and get the `api-forge` or `api-fabric` jar. **For 1.16.5 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.6.3/baritone-api-fabric-1.6.3.jar)**. -If you need Forge or Fabric 1.17.1, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.7.1) and get the `api-forge` or `api-fabric` jar. **For 1.17.1 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.7.1/baritone-api-fabric-1.7.1.jar)**. +If you need Forge or Fabric 1.17.1, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.7.2) and get the `api-forge` or `api-fabric` jar. **For 1.17.1 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.7.2/baritone-api-fabric-1.7.2.jar)**. -If you need Forge or Fabric 1.18.1, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.8.1) and get the `api-forge` or `api-fabric` jar. **For 1.18.1 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.8.1/baritone-api-fabric-1.8.1.jar)**. +If you need Forge or Fabric 1.18.1, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.8.2) and get the `api-forge` or `api-fabric` jar. **For 1.18.1 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.8.2/baritone-api-fabric-1.8.2.jar)**. This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 onwards. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). From 9b70ace1807baef93782bc34cfb37ab01359e091 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Wed, 2 Feb 2022 22:04:15 -0700 Subject: [PATCH 06/80] fix getting stuck on cauldrons (fixes #3099) --- src/main/java/baritone/pathing/movement/MovementHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index f5f565e39..48ebd3c28 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -134,7 +134,9 @@ public interface MovementHelper extends ActionCosts, Helper { } 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)); } From 49357790f1e48186949b82f97d27b842e5ffd3e9 Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Thu, 3 Feb 2022 08:06:01 +0000 Subject: [PATCH 07/80] fix world border checks Signed-off-by: scorbett123 <50634068+scorbett123@users.noreply.github.com> --- 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 23c261446..2990b7f20 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -50,7 +50,7 @@ public interface MovementHelper extends ActionCosts, Helper { static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { if (!bsi.worldBorder.canPlaceAt(x, y)) { - return false; + return true; } Block b = state.getBlock(); return Baritone.settings().blocksToDisallowBreaking.value.contains(b) From 7052fe62250c48bf4021857ceb8b44066887dc58 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 7 Feb 2022 22:03:31 -0800 Subject: [PATCH 08/80] put this on its own line --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 381e3f126..b125edf6e 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,9 @@ A Minecraft pathfinder bot. [**Baritone Discord Server**](http://discord.gg/s6fRBAUpmr) -Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do. [Tutorial playlist](https://www.youtube.com/playlist?list=PLnwnJ1qsS7CoQl9Si-RTluuzCo_4Oulpa) +Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do. + +[Tutorial playlist](https://www.youtube.com/playlist?list=PLnwnJ1qsS7CoQl9Si-RTluuzCo_4Oulpa) The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* `api-forge` jar from [releases](https://github.com/cabaletta/baritone/releases). **For 1.12.2 Forge, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.2.15/baritone-api-forge-1.2.15.jar)**. Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. From 0ade37f14f8af914c50046a5d681f1ffff3635c0 Mon Sep 17 00:00:00 2001 From: ehylo <1487662ehylo@gmail.com> Date: Tue, 8 Feb 2022 21:13:51 -0800 Subject: [PATCH 09/80] Update Setup and Usage guides Also fix 2 settings that just don't have a description for some reason, and add some information to the find command because that also for some reason did not have anything there. The descriptions I put may not be detailed enough so please let me know if things should change --- README.md | 2 +- SETUP.md | 21 ++++++++++++------- USAGE.md | 16 ++++++++++---- src/api/java/baritone/api/Settings.java | 6 ++++++ .../command/defaults/FindCommand.java | 4 ++-- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b125edf6e..7222e4d89 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ jar. Below is an example of basic usage for changing some settings, and then pathing to an X/Z goal. -``` +```java BaritoneAPI.getSettings().allowSprint.value = true; BaritoneAPI.getSettings().primaryTimeoutMS.value = 2000L; diff --git a/SETUP.md b/SETUP.md index 7a43faa62..57866b192 100644 --- a/SETUP.md +++ b/SETUP.md @@ -11,7 +11,7 @@ These releases are not always completely up to date with latest features, and ar Link to the releases page: [Releases](https://github.com/cabaletta/baritone/releases) -v1.2.* is for 1.12.2, v1.3.* is for 1.13.2, v1.4.* is for 1.14.4, v1.5.* is for 1.15.2, v1.6.* is for 1.16.2 or 1.16.4 or 1.16.5 (LOL) +v1.2.* is for 1.12.2, v1.3.* is for 1.13.2, v1.4.* is for 1.14.4, v1.5.* is for 1.15.2, v1.6.* is for 1.16.5, v1.7.* is for 1.17.1, v1.8.* is for 1.18.1 Any official release will be GPG signed by leijurv (44A3EA646EADAC6A). Please verify that the hash of the file you download is in `checksums.txt` and that `checksums_signed.asc` is a valid signature by that public keys of `checksums.txt`. @@ -22,15 +22,16 @@ The build is fully deterministic and reproducible, and you can verify Travis did Building Baritone will result in 5 artifacts created in the ``dist`` directory. These are the same as the artifacts created in the [releases](https://github.com/cabaletta/baritone/releases). -**The Forge release can simply be added as a Forge mod.** +**The Forge and Fabric releases can simply be added as a Forge/Fabric mods.** If another one of your Forge mods has a Baritone integration, you want `baritone-api-forge-VERSION.jar`. Otherwise, you want `baritone-standalone-forge-VERSION.jar` - **API**: Only the non-api packages are obfuscated. This should be used in environments where other mods would like to use Baritone's features. -- **Forge API**: Same as API, but packaged for Forge. This should be used where another mod has a Baritone integration. +- **Forge/Fabric API**: Same as API, but packaged for Forge/Fabric. This should be used where another mod has a Baritone integration. - **Standalone**: Everything is obfuscated. This should be used in environments where there are no other mods present that would like to use Baritone's features. -- **Forge Standalone**: Same as Standalone, but packaged for Forge. This should be used when Baritone is your only Forge mod, or none of your other Forge mods integrate with Baritone. +- **Forge/Fabric Standalone**: Same as Standalone, but packaged for Forge/Fabric. This should be used when Baritone is your only Forge/Fabric mod, or none of your other Forge/Fabric mods integrate with Baritone. - **Unoptimized**: Nothing is obfuscated. This shouldn't be used ever in production. +- **Forge/Fabric Unoptimized**: Same as Unoptimized, but packaged for Forge/Fabric. ## Build it yourself - Clone or download Baritone @@ -42,13 +43,13 @@ If another one of your Forge mods has a Baritone integration, you want `baritone ## Command Line On Mac OSX and Linux, use `./gradlew` instead of `gradlew`. -If you have errors with a package missing please make sure you have setup your environment, and are using Oracle JDK 8. +If you have errors with a package missing please make sure you have setup your environment, and are using Oracle JDK 8 for 1.12.2-1.16.5, JDK 16 for 1.17.1, and JDK 17 for 1.18.1. To check which java you are using do `java -version` in a command prompt or terminal. -If you are using anything above OpenJDK 8, it might not work because the Java distributions above JDK 8 using may not have the needed javax classes. +If you are using anything above OpenJDK 8 for 1.12.2-1.16.5, it might not work because the Java distributions above JDK 8 using may not have the needed javax classes. -Open JDK 8 download: https://openjdk.java.net/install/ +Open JDK download: https://openjdk.java.net/install/ #### macOS guide In order to get JDK 8, Try running the following command: `% /usr/libexec/java_home -V` @@ -84,6 +85,12 @@ For minecraft 1.15.2+, run the following instead to include the Forge jars: $ gradlew build -Pbaritone.forge_build ``` +Do this instead for Fabric jars: + +``` +$ gradlew build -Pbaritone.fabric_build +``` + Running Baritone: ``` diff --git a/USAGE.md b/USAGE.md index f896ad012..46241e3fe 100644 --- a/USAGE.md +++ b/USAGE.md @@ -32,13 +32,13 @@ Watch this [showcase video](https://youtu.be/CZkLXWo4Fg4)! To toggle a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `primaryTimeoutMS 250`). It's case insensitive. To reset a setting to its default value, say `acceptableThrowawayItems reset`. To reset all settings, say `reset`. To see all settings that have been modified from their default values, say `modified`. -Some common examples: +Commands in Baritone: - `thisway 1000` then `path` to go in the direction you're facing for a thousand blocks - `goal x y z` or `goal x z` or `goal y`, then `path` to set a goal to a certain coordinate then path to it - `goto x y z` or `goto x z` or `goto y` to go to a certain coordinate (in a single step, starts going immediately) - `goal` to set the goal to your player's feet - `goal clear` to clear the goal -- `cancel` or `stop` to stop everything +- `cancel` or `stop` to stop everything, `forcecancel` is also an option - `goto portal` or `goto ender_chest` or `goto block_type` to go to a block. (in Impact, `.goto` is an alias for `.b goto` for the most part) - `mine diamond_ore iron_ore` to mine diamond ore or iron ore (turn on the setting `legitMine` to only mine ores that it can actually see. It will explore randomly around y=11 until it finds them.) An amount of blocks can also be specified, for example, `mine 64 diamond_ore`. - `click` to click your destination on the screen. Right click path to on top of the block, left click to path into it (either at foot level or eye level), and left click and drag to select an area (`#help sel` to see what you can do with that selection). @@ -51,11 +51,19 @@ Some common examples: - `axis` to go to an axis or diagonal axis at y=120 (`axisHeight` is a configurable setting, defaults to 120). - `explore x z` to explore the world from the origin of x,z. Leave out x and z to default to player feet. This will continually path towards the closest chunk to the origin that it's never seen before. `explorefilter filter.json` with optional invert can be used to load in a list of chunks to load. - `invert` to invert the current goal and path. This gets as far away from it as possible, instead of as close as possible. For example, do `goal` then `invert` to run as far as possible from where you're standing at the start. +- `come` tells Baritone to head towards your camera, useful when freecam doesn't move your player position. +- `blacklist` will stop baritone from going to the closest block so it won't attempt to get to it. +- `eta` to get information about the estimated time until the next segment and the goal, be aware that the ETA to your goal is really unprecise. +- `proc` to view miscellaneous information about the process currently controlling Baritone. +- `repack` to re-cache the chunks around you. +- `gc` to call `System.gc()` which may free up some memory. +- `render` to fix glitched chunk rendering without having to reload all of them. +- `reloadall` to reload Baritone's world cache or `saveall` to save Baritone's world cache. +- `find` to search through Baritone's cache and attempt to find the location of the block. +- `surface` or `top` to tell Baritone to head towards the closest surface-like area, this can be the surface or highest available air space. - `version` to get the version of Baritone you're running - `damn` daniel -For the rest of the commands, you can take a look at the code [here](https://baritone.leijurv.com/baritone/api/Settings.html). - All the settings and documentation are here. If you find HTML easier to read than Javadoc, you can look here. There are about a hundred settings, but here are some fun / interesting / important ones that you might want to look at changing in normal usage of Baritone. The documentation for each can be found at the above links. diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index c3ea4225a..b0eda7489 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -385,6 +385,9 @@ public final class Settings { */ public final Setting mobSpawnerAvoidanceCoefficient = new Setting<>(2.0); + /** + * Distance to avoid mob spawners. + */ public final Setting mobSpawnerAvoidanceRadius = new Setting<>(16); /** @@ -394,6 +397,9 @@ public final class Settings { */ public final Setting mobAvoidanceCoefficient = new Setting<>(1.5); + /** + * Distance to avoid mobs. + */ public final Setting mobAvoidanceRadius = new Setting<>(8); /** diff --git a/src/main/java/baritone/command/defaults/FindCommand.java b/src/main/java/baritone/command/defaults/FindCommand.java index 22e6815be..65eb9b5c3 100644 --- a/src/main/java/baritone/command/defaults/FindCommand.java +++ b/src/main/java/baritone/command/defaults/FindCommand.java @@ -71,10 +71,10 @@ public class FindCommand extends Command { @Override public List getLongDesc() { return Arrays.asList( - "", + "The find command searches through Baritone's cache and attempts to find the location of the block.", "", "Usage:", - "> " + "> find - Find positions of a certain block" ); } } 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 10/80] 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 11/80] 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 dc6c87b58de8fad7dd86fe3951fd207833083000 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Mon, 7 Mar 2022 15:50:42 -0700 Subject: [PATCH 12/80] fix modded toolmaterials --- .../baritone/launch/mixins/MixinItemTool.java | 35 +++++++++++++++++++ src/launch/resources/mixins.baritone.json | 1 + src/main/java/baritone/utils/ToolSet.java | 8 +++-- .../baritone/utils/accessor/IItemTool.java | 24 +++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/launch/java/baritone/launch/mixins/MixinItemTool.java create mode 100644 src/main/java/baritone/utils/accessor/IItemTool.java diff --git a/src/launch/java/baritone/launch/mixins/MixinItemTool.java b/src/launch/java/baritone/launch/mixins/MixinItemTool.java new file mode 100644 index 000000000..4f5d025bf --- /dev/null +++ b/src/launch/java/baritone/launch/mixins/MixinItemTool.java @@ -0,0 +1,35 @@ +/* + * 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.IItemTool; +import net.minecraft.item.Item; +import net.minecraft.item.ItemTool; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(ItemTool.class) +public class MixinItemTool implements IItemTool { + @Shadow protected Item.ToolMaterial toolMaterial; + + @Override + public int getHarvestLevel() { + return toolMaterial.getHarvestLevel(); + } + +} diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index eb31a2e76..fdcd14b92 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -21,6 +21,7 @@ "MixinEntityRenderer", "MixinGuiScreen", "MixinItemStack", + "MixinItemTool", "MixinMinecraft", "MixinNetHandlerPlayClient", "MixinNetworkManager", diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index 4d17b4ea1..0ad4665d6 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -18,6 +18,7 @@ package baritone.utils; import baritone.Baritone; +import baritone.utils.accessor.IItemTool; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.entity.EntityPlayerSP; @@ -78,15 +79,16 @@ public class ToolSet { /** * Evaluate the material cost of a possible tool. The priority matches the - * listed order in the Item.ToolMaterial enum. + * harvest level order; there is a chance for multiple at the same with modded tools + * but in that case we don't really care. * * @param itemStack a possibly empty ItemStack - * @return values range from -1 to 4 + * @return values from 0 up */ private int getMaterialCost(ItemStack itemStack) { if (itemStack.getItem() instanceof ItemTool) { ItemTool tool = (ItemTool) itemStack.getItem(); - return ToolMaterial.valueOf(tool.getToolMaterialName()).ordinal(); + return ((IItemTool) tool).getHarvestLevel(); } else { return -1; } diff --git a/src/main/java/baritone/utils/accessor/IItemTool.java b/src/main/java/baritone/utils/accessor/IItemTool.java new file mode 100644 index 000000000..990cb672b --- /dev/null +++ b/src/main/java/baritone/utils/accessor/IItemTool.java @@ -0,0 +1,24 @@ +/* + * 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; + +public interface IItemTool { + + int getHarvestLevel(); + +} From 8aba97b577f49992894ec4a933be4587a7b00aa5 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 8 Mar 2022 15:00:14 -0800 Subject: [PATCH 13/80] update for 1.8.3 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7222e4d89..e2acc7d83 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ For 1.16.5, [click here](https://www.youtube.com/watch?v=_4eVJ9Qz2J8) and see de If you need Forge or Fabric 1.17.1, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.7.2) and get the `api-forge` or `api-fabric` jar. **For 1.17.1 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.7.2/baritone-api-fabric-1.7.2.jar)**. -If you need Forge or Fabric 1.18.1, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.8.2) and get the `api-forge` or `api-fabric` jar. **For 1.18.1 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.8.2/baritone-api-fabric-1.8.2.jar)**. +If you need Forge or Fabric 1.18.2, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.8.3) and get the `api-forge` or `api-fabric` jar. **For 1.18.2 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.8.3/baritone-api-fabric-1.8.3.jar)**. **For 1.18.2 Forge, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.8.3/baritone-api-forge-1.8.3.jar)**. This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 onwards. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). From 10430f8142374153f5f443b140b191f92874f5ce Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 8 Mar 2022 15:01:48 -0800 Subject: [PATCH 14/80] bump to 1.18.2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e2acc7d83..2687c2291 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Minecraft Minecraft Minecraft - Minecraft + Minecraft

From 25d418e96bf854d597d68dbdc00b64f827f4ffa3 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 8 Mar 2022 15:04:34 -0800 Subject: [PATCH 15/80] 1.15 is deprecated --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 2687c2291..75c04553d 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,6 @@ Baritone is the pathfinding system used in [Impact](https://impactclient.net/) s The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* `api-forge` jar from [releases](https://github.com/cabaletta/baritone/releases). **For 1.12.2 Forge, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.2.15/baritone-api-forge-1.2.15.jar)**. Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. -For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. If you need Forge 1.15.2, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.5.3), follow the instructions, and get the `api-forge` jar. - For 1.16.5, [click here](https://www.youtube.com/watch?v=_4eVJ9Qz2J8) and see description. If you need Forge or Fabric 1.16.5, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.6.3) and get the `api-forge` or `api-fabric` jar. **For 1.16.5 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.6.3/baritone-api-fabric-1.6.3.jar)**. If you need Forge or Fabric 1.17.1, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.7.2) and get the `api-forge` or `api-fabric` jar. **For 1.17.1 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.7.2/baritone-api-fabric-1.7.2.jar)**. From 02711a73ed6db6ee22c4943efc77cc7222ed30ed Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 8 Mar 2022 15:14:00 -0800 Subject: [PATCH 16/80] fix codacy --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75c04553d..c50caf56a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Build Status Release License - Codacy Badge + Codacy Badge Code of Conduct Known Vulnerabilities Contributions welcome From e58220e2c4b33278991e063cf7d2d4e192ed19a3 Mon Sep 17 00:00:00 2001 From: wagyourtail Date: Tue, 8 Mar 2022 19:45:05 -0700 Subject: [PATCH 17/80] fix inner class attribute being stripped --- scripts/proguard.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/proguard.pro b/scripts/proguard.pro index eea6fc23d..517494f46 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -1,5 +1,6 @@ -keepattributes Signature -keepattributes *Annotation* +-keepattributes InnerClasses -optimizationpasses 5 -verbose From 511941c7146135f28bde29dbe48f8459cd5efccb Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Tue, 15 Mar 2022 18:39:19 -0700 Subject: [PATCH 18/80] reimplement death and bed waypoints --- src/api/java/baritone/api/Settings.java | 11 +++ src/main/java/baritone/Baritone.java | 2 + .../baritone/behavior/WaypointBehavior.java | 92 +++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 src/main/java/baritone/behavior/WaypointBehavior.java diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index b0eda7489..0637f859c 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -550,6 +550,17 @@ public final class Settings { */ public final Setting slowPathTimeoutMS = new Setting<>(40000L); + + /** + * allows baritone to save bed waypoints when interacting with beds + */ + public final Setting doBedWaypoints = new Setting<>(true); + + /** + * allows baritone to save death waypoints + */ + public final Setting doDeathWaypoints = new Setting<>(true); + /** * The big one. Download all chunks in simplified 2-bit format and save them for better very-long-distance pathing. */ diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 82451514f..71c2c455a 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -69,6 +69,7 @@ public class Baritone implements IBaritone { private PathingBehavior pathingBehavior; private LookBehavior lookBehavior; private InventoryBehavior inventoryBehavior; + private WaypointBehavior waypointBehavior; private InputOverrideHandler inputOverrideHandler; private FollowProcess followProcess; @@ -101,6 +102,7 @@ public class Baritone implements IBaritone { lookBehavior = new LookBehavior(this); inventoryBehavior = new InventoryBehavior(this); inputOverrideHandler = new InputOverrideHandler(this); + waypointBehavior = new WaypointBehavior(this); } this.pathingControlManager = new PathingControlManager(this); diff --git a/src/main/java/baritone/behavior/WaypointBehavior.java b/src/main/java/baritone/behavior/WaypointBehavior.java new file mode 100644 index 000000000..b21e080e7 --- /dev/null +++ b/src/main/java/baritone/behavior/WaypointBehavior.java @@ -0,0 +1,92 @@ +/* + * 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.behavior; + +import baritone.Baritone; +import baritone.api.cache.IWaypoint; +import baritone.api.cache.Waypoint; +import baritone.api.event.events.BlockInteractEvent; +import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.Helper; +import baritone.utils.BlockStateInterface; +import net.minecraft.block.BlockBed; +import net.minecraft.block.state.IBlockState; +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.Set; + +import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; + +public class WaypointBehavior extends Behavior { + + + public WaypointBehavior(Baritone baritone) { + super(baritone); + } + + @Override + public void onBlockInteract(BlockInteractEvent event) { + if (!Baritone.settings().doBedWaypoints.value) + return; + if (event.getType() == BlockInteractEvent.Type.USE) { + BetterBlockPos pos = BetterBlockPos.from(event.getPos()); + IBlockState state = BlockStateInterface.get(ctx, pos); + if (state.getBlock() instanceof BlockBed) { + if (state.getValue(BlockBed.PART) == BlockBed.EnumPartType.FOOT) { + pos = pos.offset(state.getValue(BlockBed.FACING)); + } + Set waypoints = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getByTag(IWaypoint.Tag.BED); + boolean exists = waypoints.stream().map(IWaypoint::getLocation).filter(pos::equals).findFirst().isPresent(); + if (!exists) { + baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, pos)); + } + } + } + } + + @Override + public void onPlayerDeath() { + if (!Baritone.settings().doDeathWaypoints.value) + return; + Waypoint deathWaypoint = new Waypoint("death", Waypoint.Tag.DEATH, ctx.playerFeet()); + baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(deathWaypoint); + ITextComponent component = new TextComponentString("Death position saved."); + component.getStyle() + .setColor(TextFormatting.WHITE) + .setHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + new TextComponentString("Click to goto death") + )) + .setClickEvent(new ClickEvent( + ClickEvent.Action.RUN_COMMAND, + String.format( + "%s%s goto %s @ %d", + FORCE_COMMAND_PREFIX, + "wp", + deathWaypoint.getTag().getName(), + deathWaypoint.getCreationTimestamp() + ) + )); + Helper.HELPER.logDirect(component); + } + +} From e036f5360c49819c3fa4c83649bff5a8ad5dc542 Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Wed, 16 Mar 2022 20:12:56 +0000 Subject: [PATCH 19/80] If context.player() returns none we don't want to use its position for pruning. --- src/main/java/baritone/cache/CachedWorld.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index 1d1132465..6b3959fe3 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -209,7 +209,7 @@ public final class CachedWorld implements ICachedWorld, Helper { private BlockPos guessPosition() { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { IWorldData data = ibaritone.getWorldProvider().getCurrentWorld(); - if (data != null && data.getCachedWorld() == this) { + if (data != null && data.getCachedWorld() == this && ibaritone.getPlayerContext().player() != null) { return ibaritone.getPlayerContext().playerFeet(); } } From 6aadd00e72af1b55a750eb47566a0ef4418497ba Mon Sep 17 00:00:00 2001 From: PhlegethonAcheron <53194290+PhlegethonAcheron@users.noreply.github.com> Date: Sun, 20 Mar 2022 15:41:25 -0400 Subject: [PATCH 20/80] Added usage syntax to the documentation for buildValidSubstitutes and buildSubstitutes --- src/api/java/baritone/api/Settings.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 0637f859c..99ffcea20 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -234,6 +234,8 @@ public final class Settings { * A mapping of blocks to blocks treated as correct in their position *

* If a schematic asks for a block on this mapping, all blocks on the mapped list will be accepted at that location as well + *

+ * Syntax same as buildSubstitutes */ public final Setting>> buildValidSubstitutes = new Setting<>(new HashMap<>()); @@ -241,6 +243,15 @@ public final class Settings { * A mapping of blocks to blocks to be built instead *

* If a schematic asks for a block on this mapping, Baritone will place the first placeable block in the mapped list + *

+ * Usage Syntax: + *

+     *      sourceblockA->blockToSubstituteA1,blockToSubstituteA2,...blockToSubstituteAN,sourceBlockB->blockToSubstituteB1,blockToSubstituteB2,...blockToSubstituteBN,...sourceBlockX->blockToSubstituteX1,blockToSubstituteX2...blockToSubstituteXN
+     * 
+ * Example: + *
+     *     stone->cobblestone,andesite,oak_planks->birch_planks,acacia_planks,glass
+     * 
*/ public final Setting>> buildSubstitutes = new Setting<>(new HashMap<>()); From 4e6b6d97ce785341f6471520cd4f91b545386f38 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Thu, 24 Mar 2022 17:33:33 -0700 Subject: [PATCH 21/80] add forceAllowBreak setting --- src/api/java/baritone/api/Settings.java | 5 +++++ .../baritone/pathing/movement/CalculationContext.java | 9 ++++++++- src/main/java/baritone/process/BuilderProcess.java | 7 ++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 0637f859c..f8dc196cc 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -49,6 +49,11 @@ public final class Settings { */ public final Setting allowBreak = new Setting<>(true); + /** + * Blocks that baritone will be allowed to break even with allowBreak set to false + */ + public final Setting> forceAllowBreak = new Setting<>(new ArrayList<>()); + /** * Allow Baritone to sprint */ diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index fca6bc990..02e5557b7 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -34,6 +34,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import java.util.ArrayList; +import java.util.List; + import static baritone.api.pathing.movement.ActionCosts.COST_INF; /** @@ -55,6 +58,7 @@ public class CalculationContext { public final boolean canSprint; protected final double placeBlockCost; // protected because you should call the function instead public final boolean allowBreak; + public final List forceAllowBreak; public final boolean allowParkour; public final boolean allowParkourPlace; public final boolean allowJumpAt256; @@ -89,6 +93,7 @@ public class CalculationContext { this.canSprint = Baritone.settings().allowSprint.value && player.getFoodStats().getFoodLevel() > 6; this.placeBlockCost = Baritone.settings().blockPlacementPenalty.value; this.allowBreak = Baritone.settings().allowBreak.value; + this.forceAllowBreak = new ArrayList<>(Baritone.settings().forceAllowBreak.value); this.allowParkour = Baritone.settings().allowParkour.value; this.allowParkourPlace = Baritone.settings().allowParkourPlace.value; this.allowJumpAt256 = Baritone.settings().allowJumpAt256.value; @@ -150,7 +155,9 @@ public class CalculationContext { public double breakCostMultiplierAt(int x, int y, int z, IBlockState current) { if (!allowBreak) { - return COST_INF; + if (!forceAllowBreak.contains(current.getBlock())) { + return COST_INF; + } } if (isPossiblyProtected(x, y, z)) { return COST_INF; diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 604dbb2bc..3d98a710e 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -947,7 +947,12 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public double breakCostMultiplierAt(int x, int y, int z, IBlockState current) { - if (!allowBreak || isPossiblyProtected(x, y, z)) { + if (!allowBreak) { + if (!forceAllowBreak.contains(current.getBlock())) { + return COST_INF; + } + } + if (isPossiblyProtected(x, y, z)) { return COST_INF; } IBlockState sch = getSchematic(x, y, z, current); From bf450b7d68ac1dba9703cfc36809a2f475dcf105 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Thu, 24 Mar 2022 17:34:31 -0700 Subject: [PATCH 22/80] rename to allowBreakAnyway --- src/api/java/baritone/api/Settings.java | 2 +- .../java/baritone/pathing/movement/CalculationContext.java | 6 +++--- src/main/java/baritone/process/BuilderProcess.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index f8dc196cc..c883413b3 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -52,7 +52,7 @@ public final class Settings { /** * Blocks that baritone will be allowed to break even with allowBreak set to false */ - public final Setting> forceAllowBreak = new Setting<>(new ArrayList<>()); + public final Setting> allowBreakAnyway = new Setting<>(new ArrayList<>()); /** * Allow Baritone to sprint diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 02e5557b7..7a67acffe 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -58,7 +58,7 @@ public class CalculationContext { public final boolean canSprint; protected final double placeBlockCost; // protected because you should call the function instead public final boolean allowBreak; - public final List forceAllowBreak; + public final List allowBreakAnyway; public final boolean allowParkour; public final boolean allowParkourPlace; public final boolean allowJumpAt256; @@ -93,7 +93,7 @@ public class CalculationContext { this.canSprint = Baritone.settings().allowSprint.value && player.getFoodStats().getFoodLevel() > 6; this.placeBlockCost = Baritone.settings().blockPlacementPenalty.value; this.allowBreak = Baritone.settings().allowBreak.value; - this.forceAllowBreak = new ArrayList<>(Baritone.settings().forceAllowBreak.value); + this.allowBreakAnyway = new ArrayList<>(Baritone.settings().allowBreakAnyway.value); this.allowParkour = Baritone.settings().allowParkour.value; this.allowParkourPlace = Baritone.settings().allowParkourPlace.value; this.allowJumpAt256 = Baritone.settings().allowJumpAt256.value; @@ -155,7 +155,7 @@ public class CalculationContext { public double breakCostMultiplierAt(int x, int y, int z, IBlockState current) { if (!allowBreak) { - if (!forceAllowBreak.contains(current.getBlock())) { + if (!allowBreakAnyway.contains(current.getBlock())) { return COST_INF; } } diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 3d98a710e..751900df6 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -948,7 +948,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public double breakCostMultiplierAt(int x, int y, int z, IBlockState current) { if (!allowBreak) { - if (!forceAllowBreak.contains(current.getBlock())) { + if (!allowBreakAnyway.contains(current.getBlock())) { return COST_INF; } } From 2953e2c522b9c37d59d1407f79a5ee7b581f5676 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Thu, 24 Mar 2022 18:16:19 -0700 Subject: [PATCH 23/80] make codacy happy --- .../java/baritone/pathing/movement/CalculationContext.java | 6 ++---- src/main/java/baritone/process/BuilderProcess.java | 7 +------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 7a67acffe..d5d6c93c8 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -154,10 +154,8 @@ public class CalculationContext { } public double breakCostMultiplierAt(int x, int y, int z, IBlockState current) { - if (!allowBreak) { - if (!allowBreakAnyway.contains(current.getBlock())) { - return COST_INF; - } + if (!allowBreak && !allowBreakAnyway.contains(current.getBlock())) { + return COST_INF; } if (isPossiblyProtected(x, y, z)) { return COST_INF; diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 751900df6..e3ff4fbd9 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -947,12 +947,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil @Override public double breakCostMultiplierAt(int x, int y, int z, IBlockState current) { - if (!allowBreak) { - if (!allowBreakAnyway.contains(current.getBlock())) { - return COST_INF; - } - } - if (isPossiblyProtected(x, y, z)) { + if ((!allowBreak && !allowBreakAnyway.contains(current.getBlock())) || isPossiblyProtected(x, y, z)) { return COST_INF; } IBlockState sch = getSchematic(x, y, z, current); From ef4c2bbc98cefc8bd935748816fe214ae69ca71c Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Thu, 31 Mar 2022 23:53:58 +0200 Subject: [PATCH 24/80] Remove false information from `#help mine` Baritone no longer caches ores on Minecraft 1.13+ Metadata values were removed in Minecraft 1.13 lit_redstone_ore was merged into redstone_ore in Minecraft 1.13 --- src/main/java/baritone/command/defaults/MineCommand.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/baritone/command/defaults/MineCommand.java b/src/main/java/baritone/command/defaults/MineCommand.java index 63712fe3e..5351af54e 100644 --- a/src/main/java/baritone/command/defaults/MineCommand.java +++ b/src/main/java/baritone/command/defaults/MineCommand.java @@ -65,14 +65,12 @@ public class MineCommand extends Command { return Arrays.asList( "The mine command allows you to tell Baritone to search for and mine individual blocks.", "", - "The specified blocks can be ores (which are commonly cached), or any other block.", + "The specified blocks can be ores, or any other block.", "", "Also see the legitMine settings (see #set l legitMine).", "", "Usage:", "> mine diamond_ore - Mines all diamonds it can find.", - "> mine redstone_ore lit_redstone_ore - Mines redstone ore.", - "> mine log:0 - Mines only oak logs." ); } } From 2908c7499c070d21509bd1eb5895634b19ad0c5c Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Fri, 1 Apr 2022 00:33:27 +0200 Subject: [PATCH 25/80] Fix syntax That's why you shouldn't make changes on Github --- src/main/java/baritone/command/defaults/MineCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/MineCommand.java b/src/main/java/baritone/command/defaults/MineCommand.java index 5351af54e..98a2e264d 100644 --- a/src/main/java/baritone/command/defaults/MineCommand.java +++ b/src/main/java/baritone/command/defaults/MineCommand.java @@ -70,7 +70,7 @@ public class MineCommand extends Command { "Also see the legitMine settings (see #set l legitMine).", "", "Usage:", - "> mine diamond_ore - Mines all diamonds it can find.", + "> mine diamond_ore - Mines all diamonds it can find." ); } } From adc88d1fb9af5b2fb4ea98ef20d3b20b5993f8c9 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sat, 2 Apr 2022 23:44:29 +0200 Subject: [PATCH 26/80] Fix dynamic mixin dependency to 0.8.3 Newer Mixin versions use a class file format Proguard can't handle. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 59d8edef6..798b5b354 100755 --- a/build.gradle +++ b/build.gradle @@ -198,7 +198,7 @@ dependencies { } runtime launchCompile('org.ow2.asm:asm-debug-all:5.2') runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2') - runtime launchCompile('org.spongepowered:mixin:0.8.+') { + runtime launchCompile('org.spongepowered:mixin:0.8.3') { // Mixin includes a lot of dependencies that are too up-to-date exclude module: 'launchwrapper' exclude module: 'guava' From 65974e15ba5efc0ea8d7a5b2388b5ca77dfd3a5a Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Mon, 11 Apr 2022 18:36:48 +0100 Subject: [PATCH 27/80] Improve output to user in eta command --- .../baritone/command/defaults/ETACommand.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/command/defaults/ETACommand.java b/src/main/java/baritone/command/defaults/ETACommand.java index 3c16bd113..6905610f6 100644 --- a/src/main/java/baritone/command/defaults/ETACommand.java +++ b/src/main/java/baritone/command/defaults/ETACommand.java @@ -28,6 +28,7 @@ import baritone.api.command.argument.IArgConsumer; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.stream.Stream; public class ETACommand extends Command { @@ -45,12 +46,22 @@ public class ETACommand extends Command { throw new CommandInvalidStateException("No process in control"); } IPathingBehavior pathingBehavior = baritone.getPathingBehavior(); - logDirect(String.format( - "Next segment: %.2f\n" + - "Goal: %.2f", - pathingBehavior.ticksRemainingInSegment().orElse(-1.0), - pathingBehavior.estimatedTicksToGoal().orElse(-1.0) - )); + + Optional ticksRemainingInSegment = pathingBehavior.ticksRemainingInSegment(); + Optional ticksRemainingInGoal = pathingBehavior.estimatedTicksToGoal(); + + if (ticksRemainingInGoal.isPresent() && ticksRemainingInSegment.isPresent()) { + logDirect(String.format( + "Next segment: %.1fs (%.0f ticks)\n" + + "Goal: %.1fs (%.0f ticks)", + ticksRemainingInSegment.get() / 20, // we just assume tps is 20, it isn't worth the effort that is needed to calculate it exactly + ticksRemainingInSegment.get(), + ticksRemainingInGoal.get() / 20, + ticksRemainingInGoal.get() + )); + } else { + logDirect("Not currently pathing"); + } } @Override From 2cf973809a2fc277c8a8507565131d49e3e11e6b Mon Sep 17 00:00:00 2001 From: scorbett123 <50634068+scorbett123@users.noreply.github.com> Date: Tue, 12 Apr 2022 12:15:42 +0100 Subject: [PATCH 28/80] eta command should default to NaN not just not showing the eta as suggested by ZacSharp --- .../baritone/command/defaults/ETACommand.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/command/defaults/ETACommand.java b/src/main/java/baritone/command/defaults/ETACommand.java index 6905610f6..47b6ae9fa 100644 --- a/src/main/java/baritone/command/defaults/ETACommand.java +++ b/src/main/java/baritone/command/defaults/ETACommand.java @@ -47,21 +47,17 @@ public class ETACommand extends Command { } IPathingBehavior pathingBehavior = baritone.getPathingBehavior(); - Optional ticksRemainingInSegment = pathingBehavior.ticksRemainingInSegment(); - Optional ticksRemainingInGoal = pathingBehavior.estimatedTicksToGoal(); + double ticksRemainingInSegment = pathingBehavior.ticksRemainingInSegment().orElse(Double.NaN); + double ticksRemainingInGoal = pathingBehavior.estimatedTicksToGoal().orElse(Double.NaN); - if (ticksRemainingInGoal.isPresent() && ticksRemainingInSegment.isPresent()) { - logDirect(String.format( - "Next segment: %.1fs (%.0f ticks)\n" + - "Goal: %.1fs (%.0f ticks)", - ticksRemainingInSegment.get() / 20, // we just assume tps is 20, it isn't worth the effort that is needed to calculate it exactly - ticksRemainingInSegment.get(), - ticksRemainingInGoal.get() / 20, - ticksRemainingInGoal.get() - )); - } else { - logDirect("Not currently pathing"); - } + logDirect(String.format( + "Next segment: %.1fs (%.0f ticks)\n" + + "Goal: %.1fs (%.0f ticks)", + ticksRemainingInSegment / 20, // we just assume tps is 20, it isn't worth the effort that is needed to calculate it exactly + ticksRemainingInSegment, + ticksRemainingInGoal / 20, + ticksRemainingInGoal + )); } @Override From 4dcf260059d63ed12de94b7f1adeb6f26d1fbae8 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Thu, 14 Apr 2022 19:08:42 +0200 Subject: [PATCH 29/80] Fix mistakes made while merging upwards --- .github/workflows/gradle_build.yml | 6 ++++++ .../command/defaults/WaypointsCommand.java | 20 +++++++++---------- src/main/java/baritone/utils/GuiClick.java | 4 ++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.github/workflows/gradle_build.yml b/.github/workflows/gradle_build.yml index 34e93bff2..2ad00904b 100644 --- a/.github/workflows/gradle_build.yml +++ b/.github/workflows/gradle_build.yml @@ -26,6 +26,12 @@ jobs: - name: Build with Gradle run: ./gradlew build + - name: Build (fabric) with Gradle + run: ./gradlew build -Pbaritone.fabric_build + + - name: Build (forge) with Gradle + run: ./gradlew build -Pbaritone.forge_build + - name: Archive Artifacts uses: actions/upload-artifact@v2 with: diff --git a/src/main/java/baritone/command/defaults/WaypointsCommand.java b/src/main/java/baritone/command/defaults/WaypointsCommand.java index 035ddd02e..671caf574 100644 --- a/src/main/java/baritone/command/defaults/WaypointsCommand.java +++ b/src/main/java/baritone/command/defaults/WaypointsCommand.java @@ -156,8 +156,8 @@ public class WaypointsCommand extends Command { ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint); } deletedWaypoints.computeIfAbsent(baritone.getWorldProvider().getCurrentWorld(), k -> new ArrayList<>()).addAll(Arrays.asList(waypoints)); - ITextComponent textComponent = new StringTextComponent(String.format("Cleared %d waypoints, click to restore them", waypoints.length)); - textComponent.getStyle().setClickEvent(new ClickEvent( + TextComponent textComponent = new StringTextComponent(String.format("Cleared %d waypoints, click to restore them", waypoints.length)); + textComponent.setStyle(textComponent.getStyle().setClickEvent(new ClickEvent( ClickEvent.Action.RUN_COMMAND, String.format( "%s%s restore @ %s", @@ -165,7 +165,7 @@ public class WaypointsCommand extends Command { label, Stream.of(waypoints).map(wp -> Long.toString(wp.getCreationTimestamp())).collect(Collectors.joining(" ")) ) - )); + ))); logDirect(textComponent); } else if (action == Action.RESTORE) { List waypoints = new ArrayList<>(); @@ -260,7 +260,7 @@ public class WaypointsCommand extends Command { ) ))); TextComponent recreateComponent = new StringTextComponent("Click to show a command to recreate this waypoint"); - recreateComponent.getStyle().setClickEvent(new ClickEvent( + recreateComponent.setStyle(recreateComponent.getStyle().setClickEvent(new ClickEvent( ClickEvent.Action.SUGGEST_COMMAND, String.format( "%s%s save %s %s %s %s %s", @@ -272,16 +272,16 @@ public class WaypointsCommand extends Command { waypoint.getLocation().y, waypoint.getLocation().z ) - )); + ))); TextComponent backComponent = new StringTextComponent("Click to return to the waypoints list"); - backComponent.getStyle().setClickEvent(new ClickEvent( + backComponent.setStyle(backComponent.getStyle().setClickEvent(new ClickEvent( ClickEvent.Action.RUN_COMMAND, String.format( "%s%s list", FORCE_COMMAND_PREFIX, label ) - )); + ))); logDirect(deleteComponent); logDirect(goalComponent); logDirect(recreateComponent); @@ -289,8 +289,8 @@ public class WaypointsCommand extends Command { } else if (action == Action.DELETE) { ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint); deletedWaypoints.computeIfAbsent(baritone.getWorldProvider().getCurrentWorld(), k -> new ArrayList<>()).add(waypoint); - ITextComponent textComponent = new StringTextComponent("That waypoint has successfully been deleted, click to restore it"); - textComponent.getStyle().setClickEvent(new ClickEvent( + TextComponent textComponent = new StringTextComponent("That waypoint has successfully been deleted, click to restore it"); + textComponent.setStyle(textComponent.getStyle().setClickEvent(new ClickEvent( ClickEvent.Action.RUN_COMMAND, String.format( "%s%s restore @ %s", @@ -298,7 +298,7 @@ public class WaypointsCommand extends Command { label, waypoint.getCreationTimestamp() ) - )); + ))); logDirect(textComponent); } else if (action == Action.GOAL) { Goal goal = new GoalBlock(waypoint.getLocation()); diff --git a/src/main/java/baritone/utils/GuiClick.java b/src/main/java/baritone/utils/GuiClick.java index 07b4093e7..56953ceef 100644 --- a/src/main/java/baritone/utils/GuiClick.java +++ b/src/main/java/baritone/utils/GuiClick.java @@ -88,12 +88,12 @@ public class GuiClick extends Screen implements Helper { BaritoneAPI.getProvider().getPrimaryBaritone().getSelectionManager().removeAllSelections(); BaritoneAPI.getProvider().getPrimaryBaritone().getSelectionManager().addSelection(BetterBlockPos.from(clickStart), BetterBlockPos.from(currentMouseOver)); TextComponent component = new StringTextComponent("Selection made! For usage: " + Baritone.settings().prefix.value + "help sel"); - component.getStyle() + component.setStyle(component.getStyle() .setFormatting(TextFormatting.WHITE) .setClickEvent(new ClickEvent( ClickEvent.Action.RUN_COMMAND, FORCE_COMMAND_PREFIX + "help sel" - )); + ))); Helper.HELPER.logDirect(component); clickStart = null; } else { From bf7c840ea381ebdcb0e67817d4654552a9e18486 Mon Sep 17 00:00:00 2001 From: wagyourtail Date: Fri, 22 Apr 2022 19:00:43 -0700 Subject: [PATCH 30/80] backport 3308 --- .../baritone/pathing/movement/MovementHelper.java | 4 +++- src/main/java/baritone/process/BuilderProcess.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 4d4f1887b..7f84ab0e0 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -96,7 +96,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block instanceof AirBlock) { // early return for most common case return true; } - if (block instanceof AbstractFireBlock || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof AbstractSkullBlock || block == Blocks.BUBBLE_COLUMN || block instanceof ShulkerBoxBlock || block instanceof SlabBlock || block instanceof TrapDoorBlock || block == Blocks.HONEY_BLOCK || block == Blocks.END_ROD) { + if (block instanceof BaseFireBlock || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof AbstractSkullBlock || block == Blocks.BUBBLE_COLUMN || block instanceof ShulkerBoxBlock || block instanceof SlabBlock || block instanceof TrapDoorBlock || block == Blocks.HONEY_BLOCK || block == Blocks.END_ROD || block == Blocks.SWEET_BERRY_BUSH) { return false; } if (Baritone.settings().blocksToAvoid.value.contains(block)) { @@ -283,6 +283,8 @@ public interface MovementHelper extends ActionCosts, Helper { return !state.getFluidState().isEmpty() || block == Blocks.MAGMA_BLOCK || block == Blocks.CACTUS + || block == Blocks.SWEET_BERRY_BUSH + || block instanceof BaseFireBlock || block instanceof AbstractFireBlock || block == Blocks.END_PORTAL || block == Blocks.COBWEB diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 186412cea..f473b4cf8 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -847,7 +847,18 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil continue; } // - result.add(((BlockItem) stack.getItem()).getBlock().getStateForPlacement(new BlockItemUseContext(new ItemUseContext(ctx.world(), ctx.player(), Hand.MAIN_HAND, stack, new BlockRayTraceResult(new Vector3d(ctx.player().getPositionVec().x, ctx.player().getPositionVec().y, ctx.player().getPositionVec().z), Direction.UP, ctx.playerFeet(), false)) {}))); + BlockState itemState = ((BlockItem) stack.getItem()) + .getBlock() + .getStateForPlacement( + new BlockItemUseOnContext( + new ItemUseContext(ctx.world(), ctx.player(), InteractionHand.MAIN_HAND, stack, new BlockRayTraceResult(new Vector3d(ctx.player().position().x, ctx.player().position().y, ctx.player().position().z), Direction.UP, ctx.playerFeet(), false)) {} + ) + ); + if (itemState != null) { + result.add(itemState); + } else { + result.add(Blocks.AIR.defaultBlockState()); + } // } return result; From 25e8e1b5fe8c1cc03da9194ed37569aade533253 Mon Sep 17 00:00:00 2001 From: wagyourtail Date: Fri, 22 Apr 2022 19:23:39 -0700 Subject: [PATCH 31/80] fix --- src/main/java/baritone/pathing/movement/MovementHelper.java | 3 +-- src/main/java/baritone/process/BuilderProcess.java | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 7f84ab0e0..e67bd5638 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -96,7 +96,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block instanceof AirBlock) { // early return for most common case return true; } - if (block instanceof BaseFireBlock || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof AbstractSkullBlock || block == Blocks.BUBBLE_COLUMN || block instanceof ShulkerBoxBlock || block instanceof SlabBlock || block instanceof TrapDoorBlock || block == Blocks.HONEY_BLOCK || block == Blocks.END_ROD || block == Blocks.SWEET_BERRY_BUSH) { + if (block instanceof AbstractFireBlock || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof AbstractSkullBlock || block == Blocks.BUBBLE_COLUMN || block instanceof ShulkerBoxBlock || block instanceof SlabBlock || block instanceof TrapDoorBlock || block == Blocks.HONEY_BLOCK || block == Blocks.END_ROD || block == Blocks.SWEET_BERRY_BUSH) { return false; } if (Baritone.settings().blocksToAvoid.value.contains(block)) { @@ -284,7 +284,6 @@ public interface MovementHelper extends ActionCosts, Helper { || block == Blocks.MAGMA_BLOCK || block == Blocks.CACTUS || block == Blocks.SWEET_BERRY_BUSH - || block instanceof BaseFireBlock || block instanceof AbstractFireBlock || block == Blocks.END_PORTAL || block == Blocks.COBWEB diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index f473b4cf8..828cb0874 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -850,14 +850,14 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil BlockState itemState = ((BlockItem) stack.getItem()) .getBlock() .getStateForPlacement( - new BlockItemUseOnContext( - new ItemUseContext(ctx.world(), ctx.player(), InteractionHand.MAIN_HAND, stack, new BlockRayTraceResult(new Vector3d(ctx.player().position().x, ctx.player().position().y, ctx.player().position().z), Direction.UP, ctx.playerFeet(), false)) {} + new BlockItemUseContext( + new ItemUseContext(ctx.world(), ctx.player(), Hand.MAIN_HAND, stack, new BlockRayTraceResult(new Vector3d(ctx.player().getPositionVec().x, ctx.player().getPositionVec().y, ctx.player().getPositionVec().z), Direction.UP, ctx.playerFeet(), false)) {} ) ); if (itemState != null) { result.add(itemState); } else { - result.add(Blocks.AIR.defaultBlockState()); + result.add(Blocks.AIR.getDefaultState()); } // } From ad40a9225e18559e1ec71571f14040f914df8853 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Tue, 3 May 2022 23:25:01 +0200 Subject: [PATCH 32/80] Fix leaking incorrect positions It was only cleared when the previous one was canceled, not when it was directly replaced by the next one. --- src/main/java/baritone/process/BuilderProcess.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index e3ff4fbd9..1766af623 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -108,6 +108,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil this.layer = Baritone.settings().startAtLayer.value; this.numRepeats = 0; this.observedCompleted = new LongOpenHashSet(); + this.incorrectPositions = null; } public void resume() { From 221eba11dd1d41d523e2e2b9603bf4a75055f148 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Fri, 20 May 2022 01:31:09 +0200 Subject: [PATCH 33/80] Deal with others replacing the chat gui --- src/api/java/baritone/api/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index e488a9199..897182898 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -1124,7 +1124,7 @@ public final class Settings { * via {@link Consumer#andThen(Consumer)} or it can completely be overriden via setting * {@link Setting#value}; */ - public final Setting> logger = new Setting<>(Minecraft.getMinecraft().ingameGUI.getChatGUI()::printChatMessage); + public final Setting> logger = new Setting<>(msg -> Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(msg)); /** * The function that is called when Baritone will send a desktop notification. This function can be added to From 2741fc2683be6f49edbd4fdfdfce6ab5d3593217 Mon Sep 17 00:00:00 2001 From: Echocage Date: Mon, 27 Jun 2022 15:06:27 -0500 Subject: [PATCH 34/80] 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 35/80] 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 36/80] 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 51275b3a65c83851f0d9177408bc896a25e31df8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 9 Jul 2022 22:06:39 -0700 Subject: [PATCH 37/80] 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 38/80] 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 d7fc916d20e6f8d2abdc3f83953ebb2d0565ee99 Mon Sep 17 00:00:00 2001 From: Lucas Arden Date: Sun, 24 Jul 2022 21:37:45 -0700 Subject: [PATCH 39/80] 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 40/80] 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 8803c618b1cf8ece9adbc9c53a50f6cdd3d366a9 Mon Sep 17 00:00:00 2001 From: wagyourtail Date: Wed, 31 Aug 2022 18:20:51 -0700 Subject: [PATCH 41/80] remove schematica command because it doesn't work anyway on 1.13+ since sechematica doesn't exist past 1.12.2 --- src/main/java/baritone/command/defaults/DefaultCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/DefaultCommands.java b/src/main/java/baritone/command/defaults/DefaultCommands.java index e998dcc97..5af4d158e 100644 --- a/src/main/java/baritone/command/defaults/DefaultCommands.java +++ b/src/main/java/baritone/command/defaults/DefaultCommands.java @@ -42,7 +42,7 @@ public final class DefaultCommands { new VersionCommand(baritone), new RepackCommand(baritone), new BuildCommand(baritone), - new SchematicaCommand(baritone), + //new SchematicaCommand(baritone), new ComeCommand(baritone), new AxisCommand(baritone), new ForceCancelCommand(baritone), From 96ba589d4d12152ebb1441a564b9abf9ffe691af Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sat, 17 Sep 2022 01:56:23 +0200 Subject: [PATCH 42/80] Fix yet another cave air bug --- 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 e67bd5638..51a451ff2 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -603,7 +603,7 @@ public interface MovementHelper extends ActionCosts, Helper { static boolean isTransparent(Block b) { - return b == Blocks.AIR || + return b instanceof AirBlock || b == Blocks.LAVA || b == Blocks.WATER; } From 40449400d3270ccb91560c939b04197414625e32 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Sun, 25 Sep 2022 16:55:08 +0200 Subject: [PATCH 43/80] 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 44/80] 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 45/80] 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 46/80] 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 47/80] 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 48/80] 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 49/80] 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 50/80] 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 51/80] 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 52/80] 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 53/80] 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 54/80] 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 55/80] 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 56/80] 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 57/80] 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 58/80] 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 59/80] 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 60/80] 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 61/80] 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 62/80] 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 63/80] 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 64/80] 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 65/80] 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 66/80] 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 67/80] 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 68/80] 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 69/80] 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 70/80] 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 71/80] 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 72/80] 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 73/80] 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 74/80] 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 75/80] 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 76/80] 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 d91abd5e45fc2352c4c2b96e2fcd0fcf1f2c4240 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Tue, 4 Oct 2022 02:09:07 +0200 Subject: [PATCH 77/80] Litematica support for 1.16.5 --- scripts/proguard.pro | 2 + .../baritone/api/process/IBuilderProcess.java | 2 + .../launch/mixins/MixinLongArrayNBT.java | 35 ++ src/launch/resources/mixins.baritone.json | 1 + .../command/defaults/DefaultCommands.java | 1 + .../command/defaults/LitematicaCommand.java | 71 ++++ .../java/baritone/process/BuilderProcess.java | 26 ++ .../utils/accessor/ILongArrayNBT.java | 27 ++ .../format/DefaultSchematicFormats.java | 21 ++ .../format/defaults/LitematicaSchematic.java | 348 ++++++++++++++++++ .../litematica/LitematicaHelper.java | 215 +++++++++++ .../fi/dy/masa/litematica/Litematica.java | 21 ++ .../dy/masa/litematica/data/DataManager.java | 33 ++ .../placement/SchematicPlacement.java | 35 ++ .../placement/SchematicPlacementManager.java | 31 ++ .../placement/SchematicPlacementUnloaded.java | 43 +++ 16 files changed, 912 insertions(+) create mode 100644 src/launch/java/baritone/launch/mixins/MixinLongArrayNBT.java create mode 100644 src/main/java/baritone/command/defaults/LitematicaCommand.java create mode 100644 src/main/java/baritone/utils/accessor/ILongArrayNBT.java create mode 100644 src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java create mode 100644 src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java create mode 100644 src/schematica_api/java/fi/dy/masa/litematica/Litematica.java create mode 100644 src/schematica_api/java/fi/dy/masa/litematica/data/DataManager.java create mode 100644 src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java create mode 100644 src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java create mode 100644 src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 8c0627112..d9b0c497c 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -47,8 +47,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.** # Keep - Applications. Keep all application classes, along with their 'main' # methods. diff --git a/src/api/java/baritone/api/process/IBuilderProcess.java b/src/api/java/baritone/api/process/IBuilderProcess.java index 67255d7e8..17a559798 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(int i); + void pause(); boolean isPaused(); diff --git a/src/launch/java/baritone/launch/mixins/MixinLongArrayNBT.java b/src/launch/java/baritone/launch/mixins/MixinLongArrayNBT.java new file mode 100644 index 000000000..738bdecc6 --- /dev/null +++ b/src/launch/java/baritone/launch/mixins/MixinLongArrayNBT.java @@ -0,0 +1,35 @@ +/* + * 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.ILongArrayNBT; +import net.minecraft.nbt.LongArrayNBT; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +/** + * @author rycbar + * @since 26.09.2022 + */ +@Mixin(LongArrayNBT.class) +public abstract class MixinLongArrayNBT implements ILongArrayNBT { + + @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 6ef809b0b..dc109abe3 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -19,6 +19,7 @@ "MixinLivingEntity", "MixinLootContext", "MixinMinecraft", + "MixinLongArrayNBT", "MixinNetworkManager", "MixinPlayerController", "MixinScreen", diff --git a/src/main/java/baritone/command/defaults/DefaultCommands.java b/src/main/java/baritone/command/defaults/DefaultCommands.java index 5af4d158e..c2118ebe8 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..bfe0079b3 --- /dev/null +++ b/src/main/java/baritone/command/defaults/LitematicaCommand.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.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 { + 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 + 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( + "Build a schematic currently open in Litematica.", + "", + "Usage:", + "> 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 411a841b8..ca61ab9a6 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -44,6 +44,8 @@ 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; import com.google.common.collect.ImmutableSet; @@ -53,6 +55,7 @@ import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; +import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.state.Property; import net.minecraft.util.Direction; import net.minecraft.util.Hand; @@ -67,6 +70,7 @@ import net.minecraft.util.math.vector.Vector3i; import java.io.File; import java.io.FileInputStream; +import java.nio.file.Files; import java.util.*; import java.util.stream.Collectors; @@ -183,6 +187,28 @@ 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); + try { + LitematicaSchematic schematic1 = new LitematicaSchematic(CompressedStreamTools.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath())), false); + Vector3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(schematic1, i); + LitematicaSchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i); + build(name, schematic2, correctedOrigin); + } catch (Exception e) { + logDirect("Schematic File could not be loaded."); + } + } else { + logDirect("No schematic currently loaded"); + } + } else { + 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/accessor/ILongArrayNBT.java b/src/main/java/baritone/utils/accessor/ILongArrayNBT.java new file mode 100644 index 000000000..df5ec72d0 --- /dev/null +++ b/src/main/java/baritone/utils/accessor/ILongArrayNBT.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 ILongArrayNBT { + + long[] getLongArray(); +} \ 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 15aa281a9..092ff8f2a 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -19,6 +19,7 @@ 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 net.minecraft.nbt.CompoundNBT; @@ -65,6 +66,26 @@ 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 { + CompoundNBT nbt = CompressedStreamTools.readCompressed(input); + int version = nbt.getInt("Version"); + switch (version) { + case 4: //1.12 + return new LitematicaSchematic(nbt, false); + case 5: //1.13-1.17 + case 6: //1.18+ + throw new UnsupportedOperationException("This litematic Verion is too new."); + default: + throw new UnsupportedOperationException("Unsuported Version of a Litematica Schematic"); + } + } }; 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..16a8f9711 --- /dev/null +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -0,0 +1,348 @@ +/* + * 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.accessor.ILongArrayNBT; +import baritone.utils.schematic.StaticSchematic; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.state.Property; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.vector.Vector3i; +import net.minecraft.util.registry.Registry; +import org.apache.commons.lang3.Validate; + +import javax.annotation.Nullable; +import java.util.Optional; + +/** + * Based on EmersonDove's work + * ... + * + * @author rycbar + * @since 22.09.2022 + */ +public final class LitematicaSchematic extends StaticSchematic { + private final Vector3i offsetMinCorner; + private final CompoundNBT nbt; + + /** + * @param nbtTagCompound a decompressed file stream aka nbt data. + * @param rotated if the schematic is rotated by 90°. + */ + public LitematicaSchematic(CompoundNBT nbtTagCompound, boolean rotated) { + this.nbt = nbtTagCompound; + this.offsetMinCorner = new Vector3i(getMinOfSchematic("x"), getMinOfSchematic("y"), getMinOfSchematic("z")); + this.y = Math.abs(nbt.getCompound("Metadata").getCompound("EnclosingSize").getInt("y")); + + if (rotated) { + this.x = Math.abs(nbt.getCompound("Metadata").getCompound("EnclosingSize").getInt("z")); + this.z = Math.abs(nbt.getCompound("Metadata").getCompound("EnclosingSize").getInt("x")); + } else { + this.x = Math.abs(nbt.getCompound("Metadata").getCompound("EnclosingSize").getInt("x")); + this.z = Math.abs(nbt.getCompound("Metadata").getCompound("EnclosingSize").getInt("z")); + } + this.states = new BlockState[this.x][this.z][this.y]; + fillInSchematic(); + } + + /** + * @return Array of subregion names. + */ + private static String[] getRegions(CompoundNBT nbt) { + return nbt.getCompound("Regions").keySet().toArray(new String[0]); + } + + /** + * 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. + */ + private static int getMinOfSubregion(CompoundNBT nbt, String subReg, String s) { + int a = nbt.getCompound("Regions").getCompound(subReg).getCompound("Position").getInt(s); + int b = nbt.getCompound("Regions").getCompound(subReg).getCompound("Size").getInt(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 BlockState[] getBlockList(ListNBT blockStatePalette) { + BlockState[] blockList = new BlockState[blockStatePalette.size()]; + + for (int i = 0; i < blockStatePalette.size(); i++) { + Block block = Registry.BLOCK.getOrDefault(new ResourceLocation((((CompoundNBT) blockStatePalette.get(i)).getString("Name")))); + CompoundNBT properties = ((CompoundNBT) blockStatePalette.get(i)).getCompound("Properties"); + + blockList[i] = getBlockState(block, properties); + } + return blockList; + } + + /** + * @param block block. + * @param properties List of Properties the block has. + * @return A blockState. + */ + private static BlockState getBlockState(Block block, CompoundNBT properties) { + BlockState blockState = block.getDefaultState(); + + for (Object key : properties.keySet().toArray()) { + Property property = block.getStateContainer().getProperty((String) key); + String propertyValue = properties.getString((String) key); + if (property != null) { + blockState = setPropertyValue(blockState, property, propertyValue); + } + } + return blockState; + } + + /** + * @author Emerson + */ + private static > BlockState setPropertyValue(BlockState state, Property property, String value) { + Optional parsed = property.parseValue(value); + if (parsed.isPresent()) { + return state.with(property, parsed.get()); + } else { + throw new IllegalArgumentException("Invalid value for property " + property); + } + } + + /** + * @param amountOfBlockTypes amount of block types in the schematic. + * @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; + } + + /** + * 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(CompoundNBT nbt, String subReg) { + return Math.abs( + nbt.getCompound("Regions").getCompound(subReg).getCompound("Size").getInt("x") * + nbt.getCompound("Regions").getCompound(subReg).getCompound("Size").getInt("y") * + nbt.getCompound("Regions").getCompound(subReg).getCompound("Size").getInt("z")); + } + + /** + * @return array of Long values. + */ + private static long[] getBlockStates(CompoundNBT nbt, String subReg) { + return ((ILongArrayNBT) nbt.getCompound("Regions").getCompound(subReg).get("BlockStates")).getLongArray(); + } + + /** + * 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(CompoundNBT nbt, String subReg, int x, int y, int z) { + return x >= 0 && y >= 0 && z >= 0 && + x < Math.abs(nbt.getCompound("Regions").getCompound(subReg).getCompound("Size").getInt("x")) && + y < Math.abs(nbt.getCompound("Regions").getCompound(subReg).getCompound("Size").getInt("y")) && + z < Math.abs(nbt.getCompound("Regions").getCompound(subReg).getCompound("Size").getInt("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)) { + ListNBT usedBlockTypes = nbt.getCompound("Regions").getCompound(subReg).getList("BlockStatePalette", 10); + BlockState[] blockList = getBlockList(usedBlockTypes); + + int bitsPerBlock = getBitsPerBlock(usedBlockTypes.size()); + 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. + * + * @param blockList list with the different block types used in the schematic. + * @param bitArray bit array that holds the placement pattern. + */ + private void writeSubregionIntoSchematic(CompoundNBT nbt, String subReg, BlockState[] blockList, LitematicaBitArray bitArray) { + Vector3i offsetSubregion = new Vector3i(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 - (offsetMinCorner.getX() - offsetSubregion.getX())][z - (offsetMinCorner.getZ() - offsetSubregion.getZ())][y - (offsetMinCorner.getY() - offsetSubregion.getY())] = blockList[bitArray.getAt(index)]; + index++; + } + } + } + } + } + + /** + * @return offset from the schematic origin to the minimum Corner as a Vec3i. + */ + public Vector3i 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, BlockState 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); + } + + /** + * @author maruohon + * Class from the Litematica mod by maruohon + * Usage under LGPLv3 with the permission of the author. + * ... + */ + 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, 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(arraySizeIn * (long) bitsPerEntryIn, 64L) / 64L)]; + } + } + + public static long roundUp(long number, long interval) { + int sign = 1; + if (interval == 0) { + return 0; + } else if (number == 0) { + return interval; + } else { + if (number < 0) { + sign = -1; + } + + long i = number % (interval * sign); + 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 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..1396e5bed --- /dev/null +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -0,0 +1,215 @@ +/* + * 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 baritone.utils.schematic.format.defaults.LitematicaSchematic; +import fi.dy.masa.litematica.Litematica; +import fi.dy.masa.litematica.data.DataManager; +import net.minecraft.block.BlockState; +import net.minecraft.util.Mirror; +import net.minecraft.util.Rotation; +import net.minecraft.util.math.vector.Vector3i; + +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()); + return true; + } catch (ClassNotFoundException | NoClassDefFoundError ex) { + 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 Vector3i getOrigin(int i) { + return DataManager.getSchematicPlacementManager().getAllSchematicsPlacements().get(i).getOrigin(); + } + + /** + * @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 Vector3i 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.getOffsetMinCorner().getX(); + int my = schematic.getOffsetMinCorner().getY(); + int mz = schematic.getOffsetMinCorner().getZ(); + int sx = (schematic.getX() - 1) * -1; + int sz = (schematic.getZ() - 1) * -1; + + Vector3i 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 Vector3i(x + (sz - mz), y + my, z + (sx - mx)); + break; + case 2: + correctedOrigin = new Vector3i(x + mx, y + my, z + (sz - mz)); + break; + case 3: + correctedOrigin = new Vector3i(x + mz, y + my, z + mx); + break; + default: + correctedOrigin = new Vector3i(x + (sx - mx), y + my, z + mz); + break; + } + break; + default: + switch (rotation) { + case CLOCKWISE_90: + correctedOrigin = new Vector3i(x + (sz - mz), y + my, z + mx); + break; + case CLOCKWISE_180: + correctedOrigin = new Vector3i(x + (sx - mx), y + my, z + (sz - mz)); + break; + case COUNTERCLOCKWISE_90: + correctedOrigin = new Vector3i(x + mz, y + my, z + (sx - mx)); + break; + default: + correctedOrigin = new Vector3i(x + mx, y + my, z + mz); + break; + } + } + 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 Vector3i doMirroring(Vector3i in, int sizeX, int sizeZ, Mirror mirror) { + int xOut = in.getX(); + int zOut = in.getZ(); + if (mirror == Mirror.LEFT_RIGHT) { + zOut = sizeZ - in.getZ(); + } else if (mirror == Mirror.FRONT_BACK) { + xOut = sizeX - in.getX(); + } + return new Vector3i(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 Vector3i rotate(Vector3i in, int sizeX, int sizeZ) { + return new Vector3i(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 < schemIn.getY(); yCounter++) { + for (int zCounter = 0; zCounter < schemIn.getZ(); zCounter++) { + for (int xCounter = 0; xCounter < schemIn.getX(); xCounter++) { + Vector3i xyzHolder = new Vector3i(xCounter, yCounter, zCounter); + xyzHolder = LitematicaHelper.doMirroring(xyzHolder, schemIn.getX() - 1, schemIn.getZ() - 1, LitematicaHelper.getMirror(i)); + for (int turns = 0; turns < LitematicaHelper.getRotation(i).ordinal(); turns++) { + if ((turns % 2) == 0) { + xyzHolder = LitematicaHelper.rotate(xyzHolder, schemIn.getX() - 1, schemIn.getZ() - 1); + } else { + xyzHolder = LitematicaHelper.rotate(xyzHolder, schemIn.getZ() - 1, schemIn.getX() - 1); + } + } + BlockState state = schemIn.getDirect(xCounter, yCounter, zCounter); + try { + state = state.mirror(LitematicaHelper.getMirror(i)).rotate(LitematicaHelper.getRotation(i)); + } catch (NullPointerException e) { + //nothing to worry about it's just a hole in the schematic. + } + tempSchem.setDirect(xyzHolder.getX(), xyzHolder.getY(), xyzHolder.getZ(), state); + } + } + } + return tempSchem; + } +} \ No newline at end of file diff --git a/src/schematica_api/java/fi/dy/masa/litematica/Litematica.java b/src/schematica_api/java/fi/dy/masa/litematica/Litematica.java new file mode 100644 index 000000000..c10d5b38e --- /dev/null +++ b/src/schematica_api/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 { +} \ No newline at end of file diff --git a/src/schematica_api/java/fi/dy/masa/litematica/data/DataManager.java b/src/schematica_api/java/fi/dy/masa/litematica/data/DataManager.java new file mode 100644 index 000000000..4941e7cf3 --- /dev/null +++ b/src/schematica_api/java/fi/dy/masa/litematica/data/DataManager.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 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; + } +} \ No newline at end of file diff --git a/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java b/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java new file mode 100644 index 000000000..ce3f09c70 --- /dev/null +++ b/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java @@ -0,0 +1,35 @@ +/* + * 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.Mirror; +import net.minecraft.util.Rotation; + +public class SchematicPlacement extends SchematicPlacementUnloaded { + private Rotation rotation; + private Mirror mirror; + + public Rotation getRotation() { + return this.rotation; + } + + public Mirror getMirror() { + return this.mirror; + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..ab60e27fa --- /dev/null +++ b/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.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.schematic.placement; + +import java.util.ArrayList; +import java.util.List; + +public class SchematicPlacementManager { + private final List 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 + public List getAllSchematicsPlacements() { + return schematicPlacements; + } +} \ No newline at end of file diff --git a/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java b/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java new file mode 100644 index 000000000..e5eaaffc9 --- /dev/null +++ b/src/schematica_api/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java @@ -0,0 +1,43 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +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.ZERO; + + public String getName() { + return this.name; + } + + @Nullable + public File getSchematicFile() { + return this.schematicFile; + } + + public BlockPos getOrigin() { + return this.origin; + } +} \ No newline at end of file From 9d620f8137e06cb33916f92b836cb568abd23fe8 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Tue, 4 Oct 2022 03:35:49 +0200 Subject: [PATCH 78/80] merging main into 1.16.5 --- .../java/baritone/command/defaults/FindCommand.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/baritone/command/defaults/FindCommand.java b/src/main/java/baritone/command/defaults/FindCommand.java index b45f7050e..1bc454b82 100644 --- a/src/main/java/baritone/command/defaults/FindCommand.java +++ b/src/main/java/baritone/command/defaults/FindCommand.java @@ -27,8 +27,7 @@ import baritone.api.utils.BetterBlockPos; import baritone.cache.CachedChunk; import net.minecraft.block.Block; import net.minecraft.util.registry.Registry; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.*; import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.HoverEvent; @@ -76,10 +75,10 @@ public class FindCommand extends Command { 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"); + ITextComponent baseComponent = new StringTextComponent(pos.toString()); + ITextComponent hoverComponent = new StringTextComponent("Click to set goal to this position"); baseComponent.getStyle() - .setColor(TextFormatting.GRAY) + .setColor(Color.fromTextFormatting(TextFormatting.GRAY)) .setInsertion(positionText) .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)) .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent)); @@ -91,7 +90,7 @@ public class FindCommand extends Command { return new TabCompleteHelper() .append( CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.stream() - .map(Registry.BLOCK::getNameForObject) + .map(Registry.BLOCK::getKey) .map(Object::toString) ) .filterPrefixNamespaced(args.getString()) From c2a857f4d683057eee833096cb3bf942b39aead8 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Tue, 4 Oct 2022 03:41:38 +0200 Subject: [PATCH 79/80] merging main into 1.16.5 --- .../launch/mixins/MixinNBTTagLongArray.java | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java diff --git a/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java b/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java deleted file mode 100644 index 2c05e5442..000000000 --- a/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java +++ /dev/null @@ -1,35 +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.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 From 44c1438541b4656e24ac397e462f448a9cb9d1c9 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Tue, 4 Oct 2022 19:38:16 +0200 Subject: [PATCH 80/80] forgot to adjust version check --- .../utils/schematic/format/DefaultSchematicFormats.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index 092ff8f2a..9cb5bb90b 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -78,10 +78,11 @@ public enum DefaultSchematicFormats implements ISchematicFormat { int version = nbt.getInt("Version"); switch (version) { case 4: //1.12 - return new LitematicaSchematic(nbt, false); + throw new UnsupportedOperationException("This litematic Version is too old."); case 5: //1.13-1.17 + return new LitematicaSchematic(nbt, false); case 6: //1.18+ - throw new UnsupportedOperationException("This litematic Verion is too new."); + throw new UnsupportedOperationException("This litematic Version is too new."); default: throw new UnsupportedOperationException("Unsuported Version of a Litematica Schematic"); }