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