diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 124547ee..c1c0cb1d 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 f55f9212..dc1c1d5b 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 be437624..b6ba681f 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