From d928e705b91f7cb19f38e8b193721e781422a7d3 Mon Sep 17 00:00:00 2001 From: schmar03 Date: Wed, 28 Sep 2022 12:09:38 +0200 Subject: [PATCH 01/14] 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 02/14] 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 4ba3c883e6d49d194c2e31f3e527ac5df10c2ec7 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Fri, 30 Sep 2022 13:32:31 +0200 Subject: [PATCH 03/14] 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 04/14] 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 05/14] 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 06/14] 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 07/14] 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 08/14] 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 09/14] 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 10/14] 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 11/14] 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 12/14] 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 13/14] 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 14/14] 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. }