From 40449400d3270ccb91560c939b04197414625e32 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Sun, 25 Sep 2022 16:55:08 +0200 Subject: [PATCH 01/34] State of Emerson --- .../format/DefaultSchematicFormats.java | 11 + .../format/defaults/LitematicaSchematic.java | 217 ++++++++++++++++++ 2 files changed, 228 insertions(+) create mode 100644 src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index fb20164b..6cea77fe 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -21,6 +21,7 @@ import baritone.api.schematic.IStaticSchematic; import baritone.api.schematic.format.ISchematicFormat; import baritone.utils.schematic.format.defaults.MCEditSchematic; import baritone.utils.schematic.format.defaults.SpongeSchematic; +import baritone.utils.schematic.format.defaults.LitematicaSchematic; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import org.apache.commons.io.FilenameUtils; @@ -65,6 +66,16 @@ public enum DefaultSchematicFormats implements ISchematicFormat { throw new UnsupportedOperationException("Unsupported Version of a Sponge Schematic"); } } + }, + + /** + * The Litematica schematic specification. Commonly denoted by the ".litematic" file extension. + */ + Litematica("litematic") { + @Override + public IStaticSchematic parse(InputStream input) throws IOException { + return new LitematicaSchematic(CompressedStreamTools.readCompressed(input)); + } }; private final String extension; diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java new file mode 100644 index 00000000..9c647a0b --- /dev/null +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -0,0 +1,217 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils.schematic.format.defaults; + +import baritone.utils.schematic.StaticSchematic; +import net.minecraft.block.*; +import net.minecraft.block.properties.IProperty; +import net.minecraft.nbt.*; +import net.minecraft.util.ResourceLocation; +import net.minecraft.block.state.IBlockState; + +import org.apache.commons.lang3.Validate; +import javax.annotation.Nullable; +import java.util.*; + +/** + * @author Emerson + * @since 12/27/2020 + */ +public final class LitematicaSchematic extends StaticSchematic { + + public LitematicaSchematic(NBTTagCompound nbt) { + String regionName = (String) nbt.getCompoundTag("Regions").getKeySet().toArray()[0]; + this.x = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("x")); + this.y = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("y")); + this.z = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("z")); + this.states = new IBlockState[this.x][this.z][this.y]; + + + NBTTagList paletteTag = nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTagList("BlockStatePalette",10); + // ListNBT paletteTag = nbt.getCompound("Regions").getCompound(regionName).getList("BlockStatePalette",10); + + // Create the block states array + IBlockState[] paletteBlockStates = new IBlockState[paletteTag.tagCount()]; + // For every part of the array + for (int i = 0; i propertiesMap = new HashMap<>(); + // Create a map for each state + for (int j = 0; j property = block.getBlockState().getProperty(keys[j].toString()); + if (property != null) { + blockState = setPropertyValue(blockState, property, propertiesMap.get(keys[j])); + } + } + paletteBlockStates[i] = blockState; + } + + + // BlockData is stored as an NBT long[] + int paletteSize = (int) Math.floor(log2(paletteTag.tagCount()))+1; + long litematicSize = (long) this.x*this.y*this.z; + + // In 1.12, the long array isn't exposed by the libraries so parsing has to be done manually + String rawBlockString = (nbt.getCompoundTag("Regions").getCompoundTag(regionName)).getTag("BlockStates").toString(); + rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); + String[] rawBlockArrayString = rawBlockString.split(","); + long[] rawBlockData = new long[rawBlockArrayString.length]; + for (int i = 0; i < rawBlockArrayString.length; i++) { + rawBlockData[i] = Long.parseLong(rawBlockArrayString[i].substring(0,rawBlockArrayString[i].length()-1)); + } + + + LitematicaBitArray bitArray = new LitematicaBitArray(paletteSize, litematicSize, rawBlockData); + if (paletteSize > 32) { + throw new IllegalStateException("Too many blocks in schematic to handle"); + } + + int[] serializedBlockStates = new int[(int) litematicSize]; + for (int i = 0; i> IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { + Optional parsed = property.parseValue(value).toJavaUtil(); + if (parsed.isPresent()) { + return state.withProperty(property, parsed.get()); + } else { + throw new IllegalArgumentException("Invalid value for property " + property); + } + } + + /** LitematicaBitArray class from litematica */ + private static class LitematicaBitArray + { + /** The long array that is used to store the data for this BitArray. */ + private final long[] longArray; + /** Number of bits a single entry takes up */ + private final int bitsPerEntry; + /** + * The maximum value for a single entry. This also works as a bitmask for a single entry. + * For instance, if bitsPerEntry were 5, this value would be 31 (ie, {@code 0b00011111}). + */ + private final long maxEntryValue; + /** Number of entries in this array (not the length of the long array that internally backs this array) */ + private final long arraySize; + + public LitematicaBitArray(int bitsPerEntryIn, long arraySizeIn, @Nullable long[] longArrayIn) + { + Validate.inclusiveBetween(1L, 32L, (long) bitsPerEntryIn); + this.arraySize = arraySizeIn; + this.bitsPerEntry = bitsPerEntryIn; + this.maxEntryValue = (1L << bitsPerEntryIn) - 1L; + + if (longArrayIn != null) + { + this.longArray = longArrayIn; + } + else + { + this.longArray = new long[(int) (roundUp((long) arraySizeIn * (long) bitsPerEntryIn, 64L) / 64L)]; + } + } + + public void setAt(long index, int value) + { + Validate.inclusiveBetween(0L, this.arraySize - 1L, (long) index); + Validate.inclusiveBetween(0L, this.maxEntryValue, (long) value); + long startOffset = index * (long) this.bitsPerEntry; + int startArrIndex = (int) (startOffset >> 6); // startOffset / 64 + int endArrIndex = (int) (((index + 1L) * (long) this.bitsPerEntry - 1L) >> 6); + int startBitOffset = (int) (startOffset & 0x3F); // startOffset % 64 + this.longArray[startArrIndex] = this.longArray[startArrIndex] & ~(this.maxEntryValue << startBitOffset) | ((long) value & this.maxEntryValue) << startBitOffset; + + if (startArrIndex != endArrIndex) + { + int endOffset = 64 - startBitOffset; + int j1 = this.bitsPerEntry - endOffset; + this.longArray[endArrIndex] = this.longArray[endArrIndex] >>> j1 << j1 | ((long) value & this.maxEntryValue) >> endOffset; + } + } + + public int getAt(long index) + { + Validate.inclusiveBetween(0L, this.arraySize - 1L, (long) index); + long startOffset = index * (long) this.bitsPerEntry; + int startArrIndex = (int) (startOffset >> 6); // startOffset / 64 + int endArrIndex = (int) (((index + 1L) * (long) this.bitsPerEntry - 1L) >> 6); + int startBitOffset = (int) (startOffset & 0x3F); // startOffset % 64 + + if (startArrIndex == endArrIndex) + { + return (int) (this.longArray[startArrIndex] >>> startBitOffset & this.maxEntryValue); + } + else + { + int endOffset = 64 - startBitOffset; + return (int) ((this.longArray[startArrIndex] >>> startBitOffset | this.longArray[endArrIndex] << endOffset) & this.maxEntryValue); + } + } + + + public long size() + { + return this.arraySize; + } + + public static long roundUp(long number, long interval) + { + if (interval == 0) + { + return 0; + } + else if (number == 0) + { + return interval; + } + else + { + if (number < 0) + { + interval *= -1; + } + + long i = number % interval; + return i == 0 ? number : number + interval - i; + } + } + } +} \ No newline at end of file From 240e81a9e0cfbb45529ba88fd130664a97bcd03f Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Sun, 25 Sep 2022 18:22:59 +0200 Subject: [PATCH 02/34] Refactoring --- .../format/defaults/LitematicaSchematic.java | 194 ++++++++++++------ 1 file changed, 132 insertions(+), 62 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 9c647a0b..23704045 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -31,6 +31,9 @@ import java.util.*; /** * @author Emerson * @since 12/27/2020 + * @author rycbar + * @since 22.09.2022 + * */ public final class LitematicaSchematic extends StaticSchematic { @@ -41,80 +44,147 @@ public final class LitematicaSchematic extends StaticSchematic { this.z = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; + NBTTagList blockStatePalette = nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTagList("BlockStatePalette", 10); + // ListTag blockStatePalette = nbt.getCompound("Regions").getCompound(regionName).getList("BlockStatePalette",10); + IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); + // BlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); - NBTTagList paletteTag = nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTagList("BlockStatePalette",10); - // ListNBT paletteTag = nbt.getCompound("Regions").getCompound(regionName).getList("BlockStatePalette",10); + int bitsPerBlock = bitsPerBlock(blockStatePalette); + long schematicVolume = schematicVolume(); + long[] rawBlockData = rawBlockData(rawBlockArrayString(nbt, regionName)); - // Create the block states array - IBlockState[] paletteBlockStates = new IBlockState[paletteTag.tagCount()]; - // For every part of the array - for (int i = 0; i propertiesMap = new HashMap<>(); - // Create a map for each state - for (int j = 0; j property = block.getBlockState().getProperty(keys[j].toString()); - if (property != null) { - blockState = setPropertyValue(blockState, property, propertiesMap.get(keys[j])); - } - } - paletteBlockStates[i] = blockState; + LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, schematicVolume, rawBlockData); + + if (bitsPerBlock > 32) { + throw new IllegalStateException("Too many blocks in schematic to handle"); } + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + this.states[x][y][z] = paletteBlockStates[bitArray.getAt((y * this.z + z) * this.x + x)]; + } + } + } + } - // BlockData is stored as an NBT long[] - int paletteSize = (int) Math.floor(log2(paletteTag.tagCount()))+1; - long litematicSize = (long) this.x*this.y*this.z; + /** + * @param blockStatePalette List of all different block types used in the schematic. + * @return Array of BlockStates. + */ + private static IBlockState[] paletteBlockStates(NBTTagList blockStatePalette) { + // private static BlockState[] paletteBlockStates(TagList blockStatePalette) { + IBlockState[] paletteBlockStates = new IBlockState[blockStatePalette.tagCount()]; + //BlockState[] paletteBlockState = new BlockState[blockStatePalette.tagCount()]; - // In 1.12, the long array isn't exposed by the libraries so parsing has to be done manually - String rawBlockString = (nbt.getCompoundTag("Regions").getCompoundTag(regionName)).getTag("BlockStates").toString(); - rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); - String[] rawBlockArrayString = rawBlockString.split(","); + for (int i = 0; i< blockStatePalette.tagCount(); i++) { + Block block = Block.REGISTRY.getObject(new ResourceLocation((((NBTTagCompound) blockStatePalette.get(i)).getString("Name")))); + //Block block = Registry.BLOCK.get(new ResourceLocation((((CompoundTag) blockStatePalette.get(i)).getString("Name")))); + NBTTagCompound properties = ((NBTTagCompound) blockStatePalette.get(i)).getCompoundTag("Properties"); + //CompoundTag properties = ((CompoundTag) blockStatePalette.get(i)).getCompound("Properties"); + + paletteBlockStates[i] = getBlockState(block, properties); + } + return paletteBlockStates; + } + + /** + * @param block block. + * @param properties List of Properties the block has. + * @return A blockState. + */ + private static IBlockState getBlockState(Block block, NBTTagCompound properties) { + //private static BlockState getBlockState(Block block, CompoundTag properties) { + IBlockState blockState = block.getDefaultState(); + //BlockState blockState = block.defaultBlockState(); + + for (Object key : properties.getKeySet().toArray()) { + //for (Object key : properties.getAllKeys().toArray()) { + IProperty property = block.getBlockState().getProperty(key.toString()); + //Property property = block.getStateDefinition().getProperty(key.toString()); + if (property != null) { + blockState = setPropertyValue(blockState, property, propertiesMap(properties).get(key)); + } + } + return blockState; + } + + /** + * i haven't written this and i wont try to decode it. + * @param state + * @param property + * @param value + * @return + * @param + */ + private static > IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { + //private static > BlockState setPropertyValue(BlockState state, Property property, String value) { + Optional parsed = property.parseValue(value).toJavaUtil(); + //Optional parsed = property.getValue(value); + if (parsed.isPresent()) { + return state.withProperty(property, parsed.get()); + //return state.setValue(property, parsed.get()); + } else { + throw new IllegalArgumentException("Invalid value for property " + property); + } + } + + /** + * @param properties properties a block has. + * @return properties as map. + */ + private static Map propertiesMap(NBTTagCompound properties) { + //private static Map propertiesMap(CompoundTag properties) { + Map propertiesMap = new HashMap<>(); + + for (Object key : properties.getKeySet().toArray()) { + //for (Object key : properties.getAllKeys().toArray()) { + propertiesMap.put((String) key, (properties.getString((String) key))); + } + return propertiesMap; + } + + /** + * @param blockStatePalette List of all different block types used in the schematic. + * @return amount of bits used to encode a block. + */ + private static int bitsPerBlock(NBTTagList blockStatePalette) { + //private static int bitsPerBlock(ListTag blockStatePalette) { + return (int) Math.floor((Math.log(blockStatePalette.tagCount())) / Math.log(2))+1; + //return (int) Math.floor((Math.log(blockStatePalette.size())) / Math.log(2))+1; + } + + /** + * @return the amount of blocks in the schematic, including air blocks. + */ + private long schematicVolume() { + return (long) this.x*this.y*this.z; + } + + /** + * @param rawBlockArrayString String Array holding Long values as text. + * @return array of Long values. + */ + private static long[] rawBlockData(String[] rawBlockArrayString) { long[] rawBlockData = new long[rawBlockArrayString.length]; for (int i = 0; i < rawBlockArrayString.length; i++) { rawBlockData[i] = Long.parseLong(rawBlockArrayString[i].substring(0,rawBlockArrayString[i].length()-1)); } - - - LitematicaBitArray bitArray = new LitematicaBitArray(paletteSize, litematicSize, rawBlockData); - if (paletteSize > 32) { - throw new IllegalStateException("Too many blocks in schematic to handle"); - } - - int[] serializedBlockStates = new int[(int) litematicSize]; - for (int i = 0; i> IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { - Optional parsed = property.parseValue(value).toJavaUtil(); - if (parsed.isPresent()) { - return state.withProperty(property, parsed.get()); - } else { - throw new IllegalArgumentException("Invalid value for property " + property); - } + /** + * @param nbt schematic file. + * @param regionName Name of the region the schematic is in. + * @return String Array holding Long values as text. + */ + private static String[] rawBlockArrayString(NBTTagCompound nbt, String regionName) { + //private static String[] rawBlockArrayString(CompoundTag nbt, String regionName) { + + String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTag("BlockStates"))).toString(); + //String rawBlockString = Objects.requireNonNull((nbt.getCompound("Regions").getCompound(regionName).get("BlockStates"))).toString(); + rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); + return rawBlockString.split(","); } /** LitematicaBitArray class from litematica */ From 3cd8ce83236f4d2f27bc4d8c6c8b1f192f11a9e4 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 00:58:32 +0200 Subject: [PATCH 03/34] Multiple Sub-region support --- .../format/defaults/LitematicaSchematic.java | 110 +++++++++++++----- 1 file changed, 83 insertions(+), 27 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 23704045..5a9f6d90 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -36,38 +36,92 @@ import java.util.*; * */ public final class LitematicaSchematic extends StaticSchematic { + int minX=0,minY=0,minZ=0; + private static String reg = "Regions"; + private static String meta = "Metadata"; + private static String schemSize = "EnclosingSize"; + private static String[] regNames; + private static String blSt = "BlockStates"; + private static String blStPl = "BlockStatePalette"; + private static String pos = "Position"; + private static String size = "Size"; + private static NBTTagCompound nbt; public LitematicaSchematic(NBTTagCompound nbt) { - String regionName = (String) nbt.getCompoundTag("Regions").getKeySet().toArray()[0]; - this.x = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("x")); - this.y = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("y")); - this.z = Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(regionName).getCompoundTag("Size").getInteger("z")); + this.nbt = nbt; + regNames = getRegions(); + + this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); + this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y")); + this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; - NBTTagList blockStatePalette = nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTagList("BlockStatePalette", 10); - // ListTag blockStatePalette = nbt.getCompound("Regions").getCompound(regionName).getList("BlockStatePalette",10); - IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); - // BlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); + minCord(); - int bitsPerBlock = bitsPerBlock(blockStatePalette); - long schematicVolume = schematicVolume(); - long[] rawBlockData = rawBlockData(rawBlockArrayString(nbt, regionName)); + for (String subReg : regNames) { + NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); + // ListTag blockStatePalette = nbt.getCompound(reg).getCompound(subReg).getList(blStPl,10); + IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); + // BlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); + int posX = getMin(subReg,"x"); + int posY = getMin(subReg,"y"); + int posZ = getMin(subReg,"z"); - LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, schematicVolume, rawBlockData); + int bitsPerBlock = bitsPerBlock(blockStatePalette); + long regionVolume = getVolume(subReg); + long[] rawBlockData = rawBlockData(rawBlockArrayString(subReg)); - if (bitsPerBlock > 32) { - throw new IllegalStateException("Too many blocks in schematic to handle"); - } + LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, rawBlockData); - for (int y = 0; y < this.y; y++) { - for (int z = 0; z < this.z; z++) { - for (int x = 0; x < this.x; x++) { - this.states[x][y][z] = paletteBlockStates[bitArray.getAt((y * this.z + z) * this.x + x)]; + if (bitsPerBlock > 32) { + throw new IllegalStateException("Too many blocks in schematic to handle"); + } + + int index = 0; + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + if (inSubregion(x, y, z, subReg)) { + int paletteIndex = bitArray.getAt(index); + this.states[x-(minX-posX)][z-(minZ-posZ)][y-(minY-posY)] = paletteBlockStates[paletteIndex]; + index++; + } + } } } } } + private static boolean inSubregion(int x, int y, int z, String subReg) { + boolean inspect = + x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && + y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && + z < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); + return inspect; + } + + private static int getMin(String subReg,String s) { + int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); + int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); + if (b < 0) { + b++; + } + return Math.min(a,a+b); + + } + + private void minCord() { + for (String subReg : regNames) { + this.minX = Math.min(this.minX,getMin(subReg,"x")); + this.minY = Math.min(this.minY,getMin(subReg,"y")); + this.minZ = Math.min(this.minZ,getMin(subReg,"z")); + } + } + + private static String[] getRegions() { + return nbt.getCompoundTag(reg).getKeySet().toArray(new String[0]); + } + /** * @param blockStatePalette List of all different block types used in the schematic. * @return Array of BlockStates. @@ -157,8 +211,11 @@ public final class LitematicaSchematic extends StaticSchematic { /** * @return the amount of blocks in the schematic, including air blocks. */ - private long schematicVolume() { - return (long) this.x*this.y*this.z; + private static long getVolume(String subReg) { + return Math.abs( + nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x") * + nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * + nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); } /** @@ -174,15 +231,14 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param nbt schematic file. - * @param regionName Name of the region the schematic is in. + * @param subReg Name of the region the schematic is in. * @return String Array holding Long values as text. */ - private static String[] rawBlockArrayString(NBTTagCompound nbt, String regionName) { - //private static String[] rawBlockArrayString(CompoundTag nbt, String regionName) { + private static String[] rawBlockArrayString(String subReg) { + //private static String[] rawBlockArrayString(String regionName) { - String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag("Regions").getCompoundTag(regionName).getTag("BlockStates"))).toString(); - //String rawBlockString = Objects.requireNonNull((nbt.getCompound("Regions").getCompound(regionName).get("BlockStates"))).toString(); + String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt))).toString(); + //String rawBlockString = Objects.requireNonNull((nbt.getCompound(reg).getCompound(subReg).get(blSt))).toString(); rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); return rawBlockString.split(","); } From 75a3fc699ebbc8903510999d685d175f35db97c0 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 01:18:56 +0200 Subject: [PATCH 04/34] Code clean up --- .../format/defaults/LitematicaSchematic.java | 74 +++++++++---------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 5a9f6d90..a312b020 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -37,27 +37,26 @@ import java.util.*; */ public final class LitematicaSchematic extends StaticSchematic { int minX=0,minY=0,minZ=0; - private static String reg = "Regions"; - private static String meta = "Metadata"; - private static String schemSize = "EnclosingSize"; + private static final String reg = "Regions"; + private static final String meta = "Metadata"; + private static final String schemSize = "EnclosingSize"; + private static final String blSt = "BlockStates"; + private static final String blStPl = "BlockStatePalette"; + private static final String pos = "Position"; + private static final String size = "Size"; private static String[] regNames; - private static String blSt = "BlockStates"; - private static String blStPl = "BlockStatePalette"; - private static String pos = "Position"; - private static String size = "Size"; private static NBTTagCompound nbt; public LitematicaSchematic(NBTTagCompound nbt) { - this.nbt = nbt; regNames = getRegions(); + LitematicaSchematic.nbt = nbt; + minCord(); this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y")); this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; - minCord(); - for (String subReg : regNames) { NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); // ListTag blockStatePalette = nbt.getCompound(reg).getCompound(subReg).getList(blStPl,10); @@ -82,8 +81,7 @@ public final class LitematicaSchematic extends StaticSchematic { for (int z = 0; z < this.z; z++) { for (int x = 0; x < this.x; x++) { if (inSubregion(x, y, z, subReg)) { - int paletteIndex = bitArray.getAt(index); - this.states[x-(minX-posX)][z-(minZ-posZ)][y-(minY-posY)] = paletteBlockStates[paletteIndex]; + this.states[x-(minX-posX)][z-(minZ-posZ)][y-(minY-posY)] = paletteBlockStates[bitArray.getAt(index)]; index++; } } @@ -92,14 +90,25 @@ public final class LitematicaSchematic extends StaticSchematic { } } + /** + * @param x cord of the schematic. + * @param y cord of the schematic. + * @param z cord of the schematic. + * @param subReg name of the subregion. + * @return if the current block is inside the subregion. + */ private static boolean inSubregion(int x, int y, int z, String subReg) { - boolean inspect = + return x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && z < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); - return inspect; } + /** + * @param subReg name of the subregion. + * @param s axis that should be read. + * @return the lower cord of the requested axis. + */ private static int getMin(String subReg,String s) { int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); @@ -110,6 +119,10 @@ public final class LitematicaSchematic extends StaticSchematic { } + /** + * Calculates the minimum cords/origin of the schematic as litematica schematics + * can have a non minimum origin. + */ private void minCord() { for (String subReg : regNames) { this.minX = Math.min(this.minX,getMin(subReg,"x")); @@ -118,6 +131,9 @@ public final class LitematicaSchematic extends StaticSchematic { } } + /** + * @return Array of subregion names. + */ private static String[] getRegions() { return nbt.getCompoundTag(reg).getKeySet().toArray(new String[0]); } @@ -165,11 +181,11 @@ public final class LitematicaSchematic extends StaticSchematic { /** * i haven't written this and i wont try to decode it. - * @param state - * @param property - * @param value - * @return - * @param + * @param state . + * @param property . + * @param value . + * @return . + * @param . */ private static > IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { //private static > BlockState setPropertyValue(BlockState state, Property property, String value) { @@ -209,7 +225,7 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @return the amount of blocks in the schematic, including air blocks. + * @return the volume of the subregion. */ private static long getVolume(String subReg) { return Math.abs( @@ -275,24 +291,6 @@ public final class LitematicaSchematic extends StaticSchematic { } } - public void setAt(long index, int value) - { - Validate.inclusiveBetween(0L, this.arraySize - 1L, (long) index); - Validate.inclusiveBetween(0L, this.maxEntryValue, (long) value); - long startOffset = index * (long) this.bitsPerEntry; - int startArrIndex = (int) (startOffset >> 6); // startOffset / 64 - int endArrIndex = (int) (((index + 1L) * (long) this.bitsPerEntry - 1L) >> 6); - int startBitOffset = (int) (startOffset & 0x3F); // startOffset % 64 - this.longArray[startArrIndex] = this.longArray[startArrIndex] & ~(this.maxEntryValue << startBitOffset) | ((long) value & this.maxEntryValue) << startBitOffset; - - if (startArrIndex != endArrIndex) - { - int endOffset = 64 - startBitOffset; - int j1 = this.bitsPerEntry - endOffset; - this.longArray[endArrIndex] = this.longArray[endArrIndex] >>> j1 << j1 | ((long) value & this.maxEntryValue) >> endOffset; - } - } - public int getAt(long index) { Validate.inclusiveBetween(0L, this.arraySize - 1L, (long) index); From 325aa7201bd549ba5ba8b8f544148b1194f1fb47 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 02:51:06 +0200 Subject: [PATCH 05/34] bug fix --- .../utils/schematic/format/defaults/LitematicaSchematic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index a312b020..d19362c0 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -48,8 +48,8 @@ public final class LitematicaSchematic extends StaticSchematic { private static NBTTagCompound nbt; public LitematicaSchematic(NBTTagCompound nbt) { + this.nbt = nbt; regNames = getRegions(); - LitematicaSchematic.nbt = nbt; minCord(); this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); From 70303634f548f0aaf9a7657a2f1f69ebc920a22a Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 15:59:55 +0200 Subject: [PATCH 06/34] ref files added --- .../schematic/format/schemfiles/1.12.0.litematic | Bin 0 -> 369 bytes .../schematic/format/schemfiles/1.12.1.litematic | Bin 0 -> 372 bytes .../schematic/format/schemfiles/1.12.2.litematic | Bin 0 -> 373 bytes .../schematic/format/schemfiles/1.14.2.litematic | Bin 0 -> 348 bytes .../schematic/format/schemfiles/1.14.3.litematic | Bin 0 -> 349 bytes .../schematic/format/schemfiles/1.14.4.litematic | Bin 0 -> 348 bytes .../schematic/format/schemfiles/1.15.0.litematic | Bin 0 -> 349 bytes .../schematic/format/schemfiles/1.15.1.litematic | Bin 0 -> 350 bytes .../schematic/format/schemfiles/1.15.2.litematic | Bin 0 -> 353 bytes .../schematic/format/schemfiles/1.16.0.litematic | Bin 0 -> 351 bytes .../schematic/format/schemfiles/1.16.1.litematic | Bin 0 -> 350 bytes .../schematic/format/schemfiles/1.16.2.litematic | Bin 0 -> 351 bytes .../schematic/format/schemfiles/1.16.3.litematic | Bin 0 -> 351 bytes .../schematic/format/schemfiles/1.16.4.litematic | Bin 0 -> 347 bytes .../schematic/format/schemfiles/1.16.5.litematic | Bin 0 -> 351 bytes .../schematic/format/schemfiles/1.17.1.litematic | Bin 0 -> 351 bytes .../schematic/format/schemfiles/1.18.2.litematic | Bin 0 -> 342 bytes .../schematic/format/schemfiles/1.19.2.litematic | Bin 0 -> 350 bytes 18 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.2.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.0.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.3.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.17.1.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.18.2.litematic create mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic new file mode 100644 index 0000000000000000000000000000000000000000..d2154182cb4921a0725eb584122702d7859f80df GIT binary patch literal 369 zcmV-%0gnD3iwFP!000000G(1zPr^VDeYJ&_7W@ha{VUuQIM!4_u4ZWm+)#GOb}_=$ z|Lje1TE3!*7xpqcZ|A+4H`x$y(T=5})QE}g2`ffq3aJ&~6)yZk1}{VqlNA})c!-8_ zPF+L7QU*95tItmCp;@A_&g4WM;SjC9N^@OEH66$`xp3ZD&*iw{c*b#E<_Hk=s7Q@m z*s7(A=!vF$?dqknT;eb?)K=v8xlU&VBj*9?cT4-K4Scgo$HKhqYeqU>&WUTT19%UD zul}=A95aOQx57nu0Go&^)q!P8rL=>aas9U6er(_>A(ip;Rl!hhTZ3hSgk6=x?mS`V z$=P{21Cx)kiO9)X3i+kBAF4IqFTW$CVa+fxdO^lYDgyX#!brj9YlYQ{uxDKyS=)#I zc>dG~CG9E9Olory)74^jU|k+ri(DvPT?p^*H`r`8-{s0Ue(}oq8|BnjR+hrmsv8J? P<$Qhsq@|#=y8-|J&E>W- literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic new file mode 100644 index 0000000000000000000000000000000000000000..04a225e5c3ac62d2a242ebcceab5825308565367 GIT binary patch literal 372 zcmV-)0gL`0iwFP!000000G(3HQo=wG?2tf00=|la{)#sRj#wzj)moAPw+Oq`X0e2; zU+Kxu@T52i1WK#Cu$RfqPWMcAHUwO>dQwqr#Kd-l6(cg4)C%z4UHJP9UWlMaRwUfx zAsWg#wG9bN3E;e~K0g{B8hN#+6FHHGa)@SE#i`DunhxZeTsW`H=W<+etZ-cCIRZo- z%3>oIwixLmdY~zPw)Ik3ZgKLt+KTix)$uID_M8N$-7M|1Ht@|V9t-nS_KkG9oYSuF zB7k=%IQ1Wu;+PNhJP@c~Ef*6rzb2_A;H>d2i;uZV0$&^`xT2h_USmD~4opsTEMYcH!?ccp-uwS&?#& zhiD*Y)HWn6rGWFc{P=wL&?u@soyxI1ltVPTD#>&%)ub<1;l?Pg)0wSjMz$w-)|vTvxf#f)}+ z=K;Js!KweK6vq@H{Oy1|+!q^&Htc=N(uxrdE=IM>ZtK2|vzS!MDmD!RS+2mw#H_AZ zdZ!ILZO%?x1q?pW#v&tYDdd}Kxm0sj{)8(b4ReOE(Q`6ZQXas65k?9&p_*H*2qo&| zfZAUChw~>!C~1#Drc#@ukggWfJ?iv;nrA|>bs@aJ&tbh@e;1Z<{9?=aIc3yURu;q? TtLq4U<$QhsBc*4+!vX*R{jjpx literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic new file mode 100644 index 0000000000000000000000000000000000000000..3382eb96c0b36fa76cccddc5a9b1582a95995093 GIT binary patch literal 348 zcmV-i0i*sOiwFP!000000BuphQo=A4+|o)*3pzL)^jEwo;0*@_y?9_k`@jq#VbU-o zT>WmvSD;i!dwF@g+s)g&81T^vYxNqSS)c=x$(gL+7_GiemC2=^kK~qoc<=1zbKP*QaorX@A|yS^Q!7_) zf2EJ)iROIlnzeQ;@faB!C)AxX=^|(3JVO0;?cR(1Xe)?7vi9t0o5 zXRWzrh!Gx)^Y{cdk?dVZjw2P;9wf34f%cGe#?$WwV|ln5Y!eMRRWa-_Q|*`u z$4mhKT-gqVBIhVBUb7skwJab1Mo5bizNp~b8BHgmT@iCDv~>ScnKbq%)u|{W7L%0{ unnT10%7yH9yU#xhsgmETwalvIjbhV^`r2`NDzWHS&)+x4OUPng0ssJnpr$bZ literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic new file mode 100644 index 0000000000000000000000000000000000000000..ac61c3aae708ac0b5b62a5232a409f927de913b2 GIT binary patch literal 349 zcmV-j0iymNiwFP!000000BuoCPr^VHoYG253mOau{VU$&!y5(#y^^JU;D)kGw%bIw zdiE!q`U;e4w3oMUW;*+3UkJG9jisX4h@~A0D_+TDQY)Z2cj2EqT!aY5WJSUn57A6+ zXkbWKN&x3$SA6z8v`ciX6S2s5uVuR6^)#G2~>-lO27 z|DqJv1R?yRaTcDzHll;;)N-WK+QH4Dc{}Powa}fAN_hH%U?z`OgKdHdrz(d%Won!< z;gkvBpKIHRNXc3X%h#-i>TIgVzZ24+g0E^gvs%%a=+?x_2qo>mR3f$cN%d+iPQyVU(YoUIG9B%qggW literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic new file mode 100644 index 0000000000000000000000000000000000000000..1ea4bd2e38d0fb3de6a919c0bf884e9f0f8b7792 GIT binary patch literal 348 zcmV-i0i*sOiwFP!000000BuphPQpMGoYG253mOau{S|Ktc*CF|*Jf!SxS{Nl?KTmv z{-(cT@D(W4XfJQy%yjn6z7TNH8%afp5eqvIR?NucQY)YtyYSB)E8w~2Ypw%$PlAvB zt5RH3gz%5Xd3Xlfhz_n3%aKZJ2RHNP?XdUULU&9m<>?QCsXSf{wh6|ZsvP!|sd37L zQzn3au5HI6BWo!vU$Yvjv#uWhPDq0azN+EeYDH(FTN6tol(hd+snq5t)vGBjR`Dhi uibI6(s)g+L`>#I>sgplug-q+@t#Z>D4VC5eRAIrdp1*HVXg}m$0ssKn#i*tL literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic new file mode 100644 index 0000000000000000000000000000000000000000..ea6ca5ae1d77f518071bd828bdb4ca27733ab60f GIT binary patch literal 349 zcmV-j0iymNiwFP!000000BuphPQpMGoYD%V1r3IS{)0Df-W2eLK|!u$X&<;@*(KX; zqFnuMgRelTMtgbtW~Q@m_CL5j+V# zHeR*nnj%8uV4OuKu!VT8ZrRUp;@{&h{CxUIG9BAgior literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic new file mode 100644 index 0000000000000000000000000000000000000000..53df63aab72aefedea1eec60e5969362e4139c48 GIT binary patch literal 350 zcmV-k0ipgMiwFP!000000BuphPQpMGoZ3oD3mOau{S|Ktc*CF|SF*GZ+_3DD?UD#r z|H+RtG589UYP6TPZ)Q6CW?u~WX!oV2)QXww3Ma;7b7?eCoA?M%9nND!eR3jWO@L%1 zm(;N&9A$v_zV$vo0yGM=Z!$TP6&$14)2TAK)bpX-k`M2V{d}$)u4i1gMUMzcm-5ug zmD^wGBYCDdA3J8P9ZNh$M#c$suS~kg8M%m1yIZ?gV-ea-Iu&+OYQ{#bm&BT@2*IP^ zWB8&q*9(Fte!rH_2w06^LKh@D1kj{AeylT{YkYe%812e wrG(}XF@ka-yWQ^V&qAu?4{9y5DtW!ww4$DNoSsT7`qlII4I@*PY+eEY0DBXs3jhEB literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic new file mode 100644 index 0000000000000000000000000000000000000000..dfdcac5589a46e5d99030f7736ba6cbb7e76c36c GIT binary patch literal 353 zcmV-n0iOOJiwFP!000000Buo0Qo=wG?2t%80$Nxc^ef&J@P>tgT&X1)aEq`@Z8lZH z)sOfJzvT-ooB$zOn#=5TcY3FHLcm35AQi<%%xzCtF(H#lt$^Ueg@5XB79tps6$xuR zL}R(4t|4J50i3sO?fuh3vp@$rk#kwWAzFPEr#h2rF_K$y;k>e+%XP!G#&uit2oUus zi;Y~{{gp1FCtC2at8-;p;xIDSR-|{Sj+YrD=K<=sxqZKqSJgutho%} zJqSMf&q{Gk5W+tgXW~>9R8hD7A1UH!MQV(4?e=a1Q1rIqt~vFVI@+Oc~ovFKOM=NqwGb=_V9006T+uIc~) literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic new file mode 100644 index 0000000000000000000000000000000000000000..b671b1f9fd521a386334a77119e44799ee3d8bcd GIT binary patch literal 350 zcmV-k0ipgMiwFP!000000BuphPQpMCeWlfw1vD5A`YRqx6!3;YL9S$J2i#D0$#$Cv zSAWi*GB^cFHM*DCdGq$|ycq%b=nRym*vh%{Gi5X&LLcEN!o-kI2uX#X-hU}_n_UNg0 z^n{})fFD<~Lz$9uB#LR4O|@3#@NcEEDB;Tr&YaP7DzvM@!b+{&zokSO`?J)kN=7cH w>r`qsArO=c+3j{;e-=_Xe@t_gRL<+grc>%`$L^`bqF*_mZy>g4hh72z019oXnE(I) literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic new file mode 100644 index 0000000000000000000000000000000000000000..f3d137028149266913fb7183b9d8a824c13e1597 GIT binary patch literal 351 zcmV-l0igaLiwFP!000000BuphQo=A0eWit#6m(!X=&yKFz#9$cSVi}@jzsW zl^b{X(ntIxmUQi#Tsxw8giMX&>Q0$tl@W3gp>dnLS7Q;{Z8GO}R&rj9%GZK8-3Y-0 zr)&7EHN_MR;ZZnaXRw9%pgM76sgU+?HE&!Gdyh?Y#zLpm{edu*$FFHXh{oiqX!hi( zcJhRiCx9MTvSY45SWH#hDmYtORkcA_R|| zuHlQ;6f-b{2jQHZz!u`Y>d29$Qrg4ytZ~y%o|@lU(mT{3(* xT`R811Vd0QWVhRW{aHxu{6Q5mtDQH?O)JsYj@*k1i+<&Fz5%sbBC%cq006`_svQ6T literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic new file mode 100644 index 0000000000000000000000000000000000000000..a0ff6107aa675fdbd70db69ad2ba6d0a69a21fff GIT binary patch literal 347 zcmV-h0i^yPiwFP!000000BuphQo=A0eWlfw6m)Pn;ID8~z#9$z#vKy-YBmkd_|(U6=>nG+zMs5SL0 zNk=K*eeNUI4bUjip-I(3Rj@#Fpp(qxN-xK1Pd>a4*7G^;IMz7siyRT+KIMs38+ZKD zNBl}lzV^&kJEnMyOpKG+V`h?7&d5!K>xZp-Hx{AYC39(KC1+}~?V6Z#7a@3-d=1~U z=9oetJPGIG0yYpIRmYAk71AC$^XvOT`=yT7h;+)`9|;q6`kDuXXvD6HX3w5#XHPhL z0{C$yJCYeWN1~W!*;I2~4!PA`BS!4Y300LY&xTXcI=)?Ec%u6`38fMs7hV}007LgrYisd literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic new file mode 100644 index 0000000000000000000000000000000000000000..46aead9a275c48aa290e1ac2c1590027a791c385 GIT binary patch literal 351 zcmV-l0igaLiwFP!000000BuphQo=A0eWjI_6m)Pns6XP2HwC=mpdeQ!v;i}Ogh|sG z;pzwY#SU(PQXS1@vu|Hs_U$sjM`s|lNGzYb9(Q~qY$lBc*o}|yl;Mma8VJWz;sl7t zawWP}a3@m0``9*aKLa!ibYN0Bmle#=>gzx_?WlH1=nyQWBENz5=B>)wR{+7&u7xm?NyPS6?ZOqoLJ)kN;dhxg8YKGzSfXIytxj~MBIip6B_1PFM#! oIYffs-w$b$KdMsZP4ZUt(~5@LaeAt;_*c*C8{2wM-d+L#0L)3J&j0`b literal 0 HcmV?d00001 diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic new file mode 100644 index 0000000000000000000000000000000000000000..e3514b035da95b90a213587572ebfcc7371e66c5 GIT binary patch literal 350 zcmV-k0ipgMiwFP!00000|7}shPQpMGoZ3oD3mOau{R_|D6!3;YL9S$JAGl%JCEFzt zuKtIAYVZ{()o3qo-^}dno4y$E(e6u4sTDKV6;6!F=F(`OaqA;Ib*RON`s75$ngGd2 zE~#TlILZL;W83=l0yGM=Z!$TP6&$14)2TAK)bpX-k`M2l{d}$)u4i1gMUMzcm-5ug zmD@k*BYB}YA3J8P9ZNh$M#c&CpiH{R8M%m1yI;FEV-ea-Iu&+OYQ{#bm&BT@2*H!! zWB95y*9(Fte!rH_2w06^LKiAP3kj{Aey&%YDWqJ%FiICnlT{YkYe%812e wrG(}XF@ka-yWQ^V&qAu?k7_NmDtW!ww4$DNoSsT7`qlII4KBSA0$u_D03nR5`v3p{ literal 0 HcmV?d00001 From c89d8b69e5d50c5aa1dd7c6f03179492d3147c8b Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 16:08:37 +0200 Subject: [PATCH 07/34] ref files removed --- .../schematic/format/schemfiles/1.12.0.litematic | Bin 369 -> 0 bytes .../schematic/format/schemfiles/1.12.1.litematic | Bin 372 -> 0 bytes .../schematic/format/schemfiles/1.12.2.litematic | Bin 373 -> 0 bytes .../schematic/format/schemfiles/1.14.2.litematic | Bin 348 -> 0 bytes .../schematic/format/schemfiles/1.14.3.litematic | Bin 349 -> 0 bytes .../schematic/format/schemfiles/1.14.4.litematic | Bin 348 -> 0 bytes .../schematic/format/schemfiles/1.15.0.litematic | Bin 349 -> 0 bytes .../schematic/format/schemfiles/1.15.1.litematic | Bin 350 -> 0 bytes .../schematic/format/schemfiles/1.15.2.litematic | Bin 353 -> 0 bytes .../schematic/format/schemfiles/1.16.0.litematic | Bin 351 -> 0 bytes .../schematic/format/schemfiles/1.16.1.litematic | Bin 350 -> 0 bytes .../schematic/format/schemfiles/1.16.2.litematic | Bin 351 -> 0 bytes .../schematic/format/schemfiles/1.16.3.litematic | Bin 351 -> 0 bytes .../schematic/format/schemfiles/1.16.4.litematic | Bin 347 -> 0 bytes .../schematic/format/schemfiles/1.16.5.litematic | Bin 351 -> 0 bytes .../schematic/format/schemfiles/1.17.1.litematic | Bin 351 -> 0 bytes .../schematic/format/schemfiles/1.18.2.litematic | Bin 342 -> 0 bytes .../schematic/format/schemfiles/1.19.2.litematic | Bin 350 -> 0 bytes 18 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.12.2.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.0.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.3.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.17.1.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.18.2.litematic delete mode 100644 src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.0.litematic deleted file mode 100644 index d2154182cb4921a0725eb584122702d7859f80df..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 369 zcmV-%0gnD3iwFP!000000G(1zPr^VDeYJ&_7W@ha{VUuQIM!4_u4ZWm+)#GOb}_=$ z|Lje1TE3!*7xpqcZ|A+4H`x$y(T=5})QE}g2`ffq3aJ&~6)yZk1}{VqlNA})c!-8_ zPF+L7QU*95tItmCp;@A_&g4WM;SjC9N^@OEH66$`xp3ZD&*iw{c*b#E<_Hk=s7Q@m z*s7(A=!vF$?dqknT;eb?)K=v8xlU&VBj*9?cT4-K4Scgo$HKhqYeqU>&WUTT19%UD zul}=A95aOQx57nu0Go&^)q!P8rL=>aas9U6er(_>A(ip;Rl!hhTZ3hSgk6=x?mS`V z$=P{21Cx)kiO9)X3i+kBAF4IqFTW$CVa+fxdO^lYDgyX#!brj9YlYQ{uxDKyS=)#I zc>dG~CG9E9Olory)74^jU|k+ri(DvPT?p^*H`r`8-{s0Ue(}oq8|BnjR+hrmsv8J? P<$Qhsq@|#=y8-|J&E>W- diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.12.1.litematic deleted file mode 100644 index 04a225e5c3ac62d2a242ebcceab5825308565367..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 372 zcmV-)0gL`0iwFP!000000G(3HQo=wG?2tf00=|la{)#sRj#wzj)moAPw+Oq`X0e2; zU+Kxu@T52i1WK#Cu$RfqPWMcAHUwO>dQwqr#Kd-l6(cg4)C%z4UHJP9UWlMaRwUfx zAsWg#wG9bN3E;e~K0g{B8hN#+6FHHGa)@SE#i`DunhxZeTsW`H=W<+etZ-cCIRZo- z%3>oIwixLmdY~zPw)Ik3ZgKLt+KTix)$uID_M8N$-7M|1Ht@|V9t-nS_KkG9oYSuF zB7k=%IQ1Wu;+PNhJP@c~Ef*6rzb2_A;H>d2i;uZV0$&^`xT2h_USmD~4opsTEMYcH!?ccp-uwS&?#& zhiD*Y)HWn6rGWFc{P=wL&?u@soyxI1ltVPTD#>&%)ub<1;l?Pg)0wSjMz$w-)|vTvxf#f)}+ z=K;Js!KweK6vq@H{Oy1|+!q^&Htc=N(uxrdE=IM>ZtK2|vzS!MDmD!RS+2mw#H_AZ zdZ!ILZO%?x1q?pW#v&tYDdd}Kxm0sj{)8(b4ReOE(Q`6ZQXas65k?9&p_*H*2qo&| zfZAUChw~>!C~1#Drc#@ukggWfJ?iv;nrA|>bs@aJ&tbh@e;1Z<{9?=aIc3yURu;q? TtLq4U<$QhsBc*4+!vX*R{jjpx diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.2.litematic deleted file mode 100644 index 3382eb96c0b36fa76cccddc5a9b1582a95995093..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 348 zcmV-i0i*sOiwFP!000000BuphQo=A4+|o)*3pzL)^jEwo;0*@_y?9_k`@jq#VbU-o zT>WmvSD;i!dwF@g+s)g&81T^vYxNqSS)c=x$(gL+7_GiemC2=^kK~qoc<=1zbKP*QaorX@A|yS^Q!7_) zf2EJ)iROIlnzeQ;@faB!C)AxX=^|(3JVO0;?cR(1Xe)?7vi9t0o5 zXRWzrh!Gx)^Y{cdk?dVZjw2P;9wf34f%cGe#?$WwV|ln5Y!eMRRWa-_Q|*`u z$4mhKT-gqVBIhVBUb7skwJab1Mo5bizNp~b8BHgmT@iCDv~>ScnKbq%)u|{W7L%0{ unnT10%7yH9yU#xhsgmETwalvIjbhV^`r2`NDzWHS&)+x4OUPng0ssJnpr$bZ diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.3.litematic deleted file mode 100644 index ac61c3aae708ac0b5b62a5232a409f927de913b2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 349 zcmV-j0iymNiwFP!000000BuoCPr^VHoYG253mOau{VU$&!y5(#y^^JU;D)kGw%bIw zdiE!q`U;e4w3oMUW;*+3UkJG9jisX4h@~A0D_+TDQY)Z2cj2EqT!aY5WJSUn57A6+ zXkbWKN&x3$SA6z8v`ciX6S2s5uVuR6^)#G2~>-lO27 z|DqJv1R?yRaTcDzHll;;)N-WK+QH4Dc{}Powa}fAN_hH%U?z`OgKdHdrz(d%Won!< z;gkvBpKIHRNXc3X%h#-i>TIgVzZ24+g0E^gvs%%a=+?x_2qo>mR3f$cN%d+iPQyVU(YoUIG9B%qggW diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.14.4.litematic deleted file mode 100644 index 1ea4bd2e38d0fb3de6a919c0bf884e9f0f8b7792..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 348 zcmV-i0i*sOiwFP!000000BuphPQpMGoYG253mOau{S|Ktc*CF|*Jf!SxS{Nl?KTmv z{-(cT@D(W4XfJQy%yjn6z7TNH8%afp5eqvIR?NucQY)YtyYSB)E8w~2Ypw%$PlAvB zt5RH3gz%5Xd3Xlfhz_n3%aKZJ2RHNP?XdUULU&9m<>?QCsXSf{wh6|ZsvP!|sd37L zQzn3au5HI6BWo!vU$Yvjv#uWhPDq0azN+EeYDH(FTN6tol(hd+snq5t)vGBjR`Dhi uibI6(s)g+L`>#I>sgplug-q+@t#Z>D4VC5eRAIrdp1*HVXg}m$0ssKn#i*tL diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.0.litematic deleted file mode 100644 index ea6ca5ae1d77f518071bd828bdb4ca27733ab60f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 349 zcmV-j0iymNiwFP!000000BuphPQpMGoYD%V1r3IS{)0Df-W2eLK|!u$X&<;@*(KX; zqFnuMgRelTMtgbtW~Q@m_CL5j+V# zHeR*nnj%8uV4OuKu!VT8ZrRUp;@{&h{CxUIG9BAgior diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.1.litematic deleted file mode 100644 index 53df63aab72aefedea1eec60e5969362e4139c48..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 350 zcmV-k0ipgMiwFP!000000BuphPQpMGoZ3oD3mOau{S|Ktc*CF|SF*GZ+_3DD?UD#r z|H+RtG589UYP6TPZ)Q6CW?u~WX!oV2)QXww3Ma;7b7?eCoA?M%9nND!eR3jWO@L%1 zm(;N&9A$v_zV$vo0yGM=Z!$TP6&$14)2TAK)bpX-k`M2V{d}$)u4i1gMUMzcm-5ug zmD^wGBYCDdA3J8P9ZNh$M#c$suS~kg8M%m1yIZ?gV-ea-Iu&+OYQ{#bm&BT@2*IP^ zWB8&q*9(Fte!rH_2w06^LKh@D1kj{AeylT{YkYe%812e wrG(}XF@ka-yWQ^V&qAu?4{9y5DtW!ww4$DNoSsT7`qlII4I@*PY+eEY0DBXs3jhEB diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.15.2.litematic deleted file mode 100644 index dfdcac5589a46e5d99030f7736ba6cbb7e76c36c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 353 zcmV-n0iOOJiwFP!000000Buo0Qo=wG?2t%80$Nxc^ef&J@P>tgT&X1)aEq`@Z8lZH z)sOfJzvT-ooB$zOn#=5TcY3FHLcm35AQi<%%xzCtF(H#lt$^Ueg@5XB79tps6$xuR zL}R(4t|4J50i3sO?fuh3vp@$rk#kwWAzFPEr#h2rF_K$y;k>e+%XP!G#&uit2oUus zi;Y~{{gp1FCtC2at8-;p;xIDSR-|{Sj+YrD=K<=sxqZKqSJgutho%} zJqSMf&q{Gk5W+tgXW~>9R8hD7A1UH!MQV(4?e=a1Q1rIqt~vFVI@+Oc~ovFKOM=NqwGb=_V9006T+uIc~) diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.1.litematic deleted file mode 100644 index b671b1f9fd521a386334a77119e44799ee3d8bcd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 350 zcmV-k0ipgMiwFP!000000BuphPQpMCeWlfw1vD5A`YRqx6!3;YL9S$J2i#D0$#$Cv zSAWi*GB^cFHM*DCdGq$|ycq%b=nRym*vh%{Gi5X&LLcEN!o-kI2uX#X-hU}_n_UNg0 z^n{})fFD<~Lz$9uB#LR4O|@3#@NcEEDB;Tr&YaP7DzvM@!b+{&zokSO`?J)kN=7cH w>r`qsArO=c+3j{;e-=_Xe@t_gRL<+grc>%`$L^`bqF*_mZy>g4hh72z019oXnE(I) diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.2.litematic deleted file mode 100644 index f3d137028149266913fb7183b9d8a824c13e1597..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 351 zcmV-l0igaLiwFP!000000BuphQo=A0eWit#6m(!X=&yKFz#9$cSVi}@jzsW zl^b{X(ntIxmUQi#Tsxw8giMX&>Q0$tl@W3gp>dnLS7Q;{Z8GO}R&rj9%GZK8-3Y-0 zr)&7EHN_MR;ZZnaXRw9%pgM76sgU+?HE&!Gdyh?Y#zLpm{edu*$FFHXh{oiqX!hi( zcJhRiCx9MTvSY45SWH#hDmYtORkcA_R|| zuHlQ;6f-b{2jQHZz!u`Y>d29$Qrg4ytZ~y%o|@lU(mT{3(* xT`R811Vd0QWVhRW{aHxu{6Q5mtDQH?O)JsYj@*k1i+<&Fz5%sbBC%cq006`_svQ6T diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.4.litematic deleted file mode 100644 index a0ff6107aa675fdbd70db69ad2ba6d0a69a21fff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 347 zcmV-h0i^yPiwFP!000000BuphQo=A0eWlfw6m)Pn;ID8~z#9$z#vKy-YBmkd_|(U6=>nG+zMs5SL0 zNk=K*eeNUI4bUjip-I(3Rj@#Fpp(qxN-xK1Pd>a4*7G^;IMz7siyRT+KIMs38+ZKD zNBl}lzV^&kJEnMyOpKG+V`h?7&d5!K>xZp-Hx{AYC39(KC1+}~?V6Z#7a@3-d=1~U z=9oetJPGIG0yYpIRmYAk71AC$^XvOT`=yT7h;+)`9|;q6`kDuXXvD6HX3w5#XHPhL z0{C$yJCYeWN1~W!*;I2~4!PA`BS!4Y300LY&xTXcI=)?Ec%u6`38fMs7hV}007LgrYisd diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.16.5.litematic deleted file mode 100644 index 46aead9a275c48aa290e1ac2c1590027a791c385..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 351 zcmV-l0igaLiwFP!000000BuphQo=A0eWjI_6m)Pns6XP2HwC=mpdeQ!v;i}Ogh|sG z;pzwY#SU(PQXS1@vu|Hs_U$sjM`s|lNGzYb9(Q~qY$lBc*o}|yl;Mma8VJWz;sl7t zawWP}a3@m0``9*aKLa!ibYN0Bmle#=>gzx_?WlH1=nyQWBENz5=B>)wR{+7&u7xm?NyPS6?ZOqoLJ)kN;dhxg8YKGzSfXIytxj~MBIip6B_1PFM#! oIYffs-w$b$KdMsZP4ZUt(~5@LaeAt;_*c*C8{2wM-d+L#0L)3J&j0`b diff --git a/src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic b/src/main/java/baritone/utils/schematic/format/schemfiles/1.19.2.litematic deleted file mode 100644 index e3514b035da95b90a213587572ebfcc7371e66c5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 350 zcmV-k0ipgMiwFP!00000|7}shPQpMGoZ3oD3mOau{R_|D6!3;YL9S$JAGl%JCEFzt zuKtIAYVZ{()o3qo-^}dno4y$E(e6u4sTDKV6;6!F=F(`OaqA;Ib*RON`s75$ngGd2 zE~#TlILZL;W83=l0yGM=Z!$TP6&$14)2TAK)bpX-k`M2l{d}$)u4i1gMUMzcm-5ug zmD@k*BYB}YA3J8P9ZNh$M#c&CpiH{R8M%m1yI;FEV-ea-Iu&+OYQ{#bm&BT@2*H!! zWB95y*9(Fte!rH_2w06^LKiAP3kj{Aey&%YDWqJ%FiICnlT{YkYe%812e wrG(}XF@ka-yWQ^V&qAu?k7_NmDtW!ww4$DNoSsT7`qlII4KBSA0$u_D03nR5`v3p{ From 113e340474c3c33da94f885b81a029a07b33aa60 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 16:09:41 +0200 Subject: [PATCH 08/34] version check added --- .../schematic/format/DefaultSchematicFormats.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index 6cea77fe..de142b39 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -74,7 +74,17 @@ public enum DefaultSchematicFormats implements ISchematicFormat { Litematica("litematic") { @Override public IStaticSchematic parse(InputStream input) throws IOException { - return new LitematicaSchematic(CompressedStreamTools.readCompressed(input)); + NBTTagCompound nbt = CompressedStreamTools.readCompressed(input); + int version = nbt.getInteger("Version"); + switch (version) { + case 4: + return new LitematicaSchematic(nbt); + case 5: + case 6: + throw new UnsupportedOperationException("This Schematic Verion is to new."); + default: + throw new UnsupportedOperationException("Unsuported Version of a Litematica Schematic"); + } } }; From 376d6422ec2c3f602dc2225c9008b2832ba8175e Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 16:18:43 +0200 Subject: [PATCH 09/34] refactoring --- .../format/defaults/LitematicaSchematic.java | 72 ++++++++++--------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index d19362c0..f0e9d174 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -44,6 +44,7 @@ public final class LitematicaSchematic extends StaticSchematic { private static final String blStPl = "BlockStatePalette"; private static final String pos = "Position"; private static final String size = "Size"; + private static String subReg; private static String[] regNames; private static NBTTagCompound nbt; @@ -57,33 +58,42 @@ public final class LitematicaSchematic extends StaticSchematic { this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; - for (String subReg : regNames) { + for (String subRegion : regNames) { + subReg = subRegion; NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); // ListTag blockStatePalette = nbt.getCompound(reg).getCompound(subReg).getList(blStPl,10); IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); // BlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); - int posX = getMin(subReg,"x"); - int posY = getMin(subReg,"y"); - int posZ = getMin(subReg,"z"); - int bitsPerBlock = bitsPerBlock(blockStatePalette); - long regionVolume = getVolume(subReg); - long[] rawBlockData = rawBlockData(rawBlockArrayString(subReg)); + int bitsPerBlock = bitsPerBlock(blockStatePalette.tagCount()); + long regionVolume = getVolume(); + long[] blockStateArray = getBlockStates(); - LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, rawBlockData); + LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, blockStateArray); if (bitsPerBlock > 32) { throw new IllegalStateException("Too many blocks in schematic to handle"); } - int index = 0; - for (int y = 0; y < this.y; y++) { - for (int z = 0; z < this.z; z++) { - for (int x = 0; x < this.x; x++) { - if (inSubregion(x, y, z, subReg)) { - this.states[x-(minX-posX)][z-(minZ-posZ)][y-(minY-posY)] = paletteBlockStates[bitArray.getAt(index)]; - index++; - } + createSchematicOfSubRegion(paletteBlockStates, bitArray); + } + } + + /** + * @param paletteBlockStates list with the different block types used in the schematic + * @param bitArray bit array that holds the placement pattern + */ + private void createSchematicOfSubRegion(IBlockState[] paletteBlockStates, LitematicaBitArray bitArray) { + int posX = getMin("x"); + int posY = getMin("y"); + int posZ = getMin("z"); + int index = 0; + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + if (inSubregion(x, y, z)) { + this.states[x-(minX- posX)][z-(minZ- posZ)][y-(minY- posY)] = paletteBlockStates[bitArray.getAt(index)]; + index++; } } } @@ -94,10 +104,9 @@ public final class LitematicaSchematic extends StaticSchematic { * @param x cord of the schematic. * @param y cord of the schematic. * @param z cord of the schematic. - * @param subReg name of the subregion. * @return if the current block is inside the subregion. */ - private static boolean inSubregion(int x, int y, int z, String subReg) { + private static boolean inSubregion(int x, int y, int z) { return x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && @@ -105,11 +114,10 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param subReg name of the subregion. * @param s axis that should be read. * @return the lower cord of the requested axis. */ - private static int getMin(String subReg,String s) { + private static int getMin(String s) { int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); if (b < 0) { @@ -124,10 +132,11 @@ public final class LitematicaSchematic extends StaticSchematic { * can have a non minimum origin. */ private void minCord() { - for (String subReg : regNames) { - this.minX = Math.min(this.minX,getMin(subReg,"x")); - this.minY = Math.min(this.minY,getMin(subReg,"y")); - this.minZ = Math.min(this.minZ,getMin(subReg,"z")); + for (String subRegion : regNames) { + subReg = subRegion; + this.minX = Math.min(this.minX,getMin("x")); + this.minY = Math.min(this.minY,getMin("y")); + this.minZ = Math.min(this.minZ,getMin("z")); } } @@ -215,19 +224,19 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param blockStatePalette List of all different block types used in the schematic. + * @param amountOfBlockTypes amount of block types in the schematic. * @return amount of bits used to encode a block. */ - private static int bitsPerBlock(NBTTagList blockStatePalette) { + private static int bitsPerBlock(int amountOfBlockTypes) { //private static int bitsPerBlock(ListTag blockStatePalette) { - return (int) Math.floor((Math.log(blockStatePalette.tagCount())) / Math.log(2))+1; + return (int) Math.floor((Math.log(amountOfBlockTypes)) / Math.log(2))+1; //return (int) Math.floor((Math.log(blockStatePalette.size())) / Math.log(2))+1; } /** * @return the volume of the subregion. */ - private static long getVolume(String subReg) { + private static long getVolume() { return Math.abs( nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x") * nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * @@ -235,10 +244,10 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param rawBlockArrayString String Array holding Long values as text. * @return array of Long values. */ - private static long[] rawBlockData(String[] rawBlockArrayString) { + private static long[] getBlockStates() { + String[] rawBlockArrayString = rawBlockArrayString(); long[] rawBlockData = new long[rawBlockArrayString.length]; for (int i = 0; i < rawBlockArrayString.length; i++) { rawBlockData[i] = Long.parseLong(rawBlockArrayString[i].substring(0,rawBlockArrayString[i].length()-1)); @@ -247,10 +256,9 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param subReg Name of the region the schematic is in. * @return String Array holding Long values as text. */ - private static String[] rawBlockArrayString(String subReg) { + private static String[] rawBlockArrayString() { //private static String[] rawBlockArrayString(String regionName) { String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt))).toString(); From 295265c2618a0e519117a17102358964d01cebb8 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 17:43:54 +0200 Subject: [PATCH 10/34] refactoring --- .../format/defaults/LitematicaSchematic.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index f0e9d174..55723faf 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -247,7 +247,9 @@ public final class LitematicaSchematic extends StaticSchematic { * @return array of Long values. */ private static long[] getBlockStates() { - String[] rawBlockArrayString = rawBlockArrayString(); + String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt))).toString(); + rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); + String[] rawBlockArrayString = rawBlockString.split(","); long[] rawBlockData = new long[rawBlockArrayString.length]; for (int i = 0; i < rawBlockArrayString.length; i++) { rawBlockData[i] = Long.parseLong(rawBlockArrayString[i].substring(0,rawBlockArrayString[i].length()-1)); @@ -255,17 +257,15 @@ public final class LitematicaSchematic extends StaticSchematic { return rawBlockData; } + // will only work after 1.12. will replace the getBlockStates() above. + /* /** - * @return String Array holding Long values as text. + * @return array of Long values. */ - private static String[] rawBlockArrayString() { - //private static String[] rawBlockArrayString(String regionName) { - - String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt))).toString(); - //String rawBlockString = Objects.requireNonNull((nbt.getCompound(reg).getCompound(subReg).get(blSt))).toString(); - rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); - return rawBlockString.split(","); - } + /* + private static long[] getBlockStates() { + return nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt).getLongArray(); + }*/ /** LitematicaBitArray class from litematica */ private static class LitematicaBitArray From 3d8eddc4e161e9fca6bfa7661125d55f4b3868f8 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 19:23:09 +0200 Subject: [PATCH 11/34] cleanup --- .../format/defaults/LitematicaSchematic.java | 51 +++---------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 55723faf..4c8ce4c6 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -48,8 +48,8 @@ public final class LitematicaSchematic extends StaticSchematic { private static String[] regNames; private static NBTTagCompound nbt; - public LitematicaSchematic(NBTTagCompound nbt) { - this.nbt = nbt; + public LitematicaSchematic(NBTTagCompound nbtCompound) { + nbt = nbtCompound; regNames = getRegions(); minCord(); @@ -61,9 +61,7 @@ public final class LitematicaSchematic extends StaticSchematic { for (String subRegion : regNames) { subReg = subRegion; NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); - // ListTag blockStatePalette = nbt.getCompound(reg).getCompound(subReg).getList(blStPl,10); IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); - // BlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); int bitsPerBlock = bitsPerBlock(blockStatePalette.tagCount()); long regionVolume = getVolume(); @@ -129,7 +127,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * Calculates the minimum cords/origin of the schematic as litematica schematics - * can have a non minimum origin. + * can have a non-minimum origin. */ private void minCord() { for (String subRegion : regNames) { @@ -152,15 +150,11 @@ public final class LitematicaSchematic extends StaticSchematic { * @return Array of BlockStates. */ private static IBlockState[] paletteBlockStates(NBTTagList blockStatePalette) { - // private static BlockState[] paletteBlockStates(TagList blockStatePalette) { IBlockState[] paletteBlockStates = new IBlockState[blockStatePalette.tagCount()]; - //BlockState[] paletteBlockState = new BlockState[blockStatePalette.tagCount()]; for (int i = 0; i< blockStatePalette.tagCount(); i++) { Block block = Block.REGISTRY.getObject(new ResourceLocation((((NBTTagCompound) blockStatePalette.get(i)).getString("Name")))); - //Block block = Registry.BLOCK.get(new ResourceLocation((((CompoundTag) blockStatePalette.get(i)).getString("Name")))); NBTTagCompound properties = ((NBTTagCompound) blockStatePalette.get(i)).getCompoundTag("Properties"); - //CompoundTag properties = ((CompoundTag) blockStatePalette.get(i)).getCompound("Properties"); paletteBlockStates[i] = getBlockState(block, properties); } @@ -173,16 +167,13 @@ public final class LitematicaSchematic extends StaticSchematic { * @return A blockState. */ private static IBlockState getBlockState(Block block, NBTTagCompound properties) { - //private static BlockState getBlockState(Block block, CompoundTag properties) { IBlockState blockState = block.getDefaultState(); - //BlockState blockState = block.defaultBlockState(); + for (Object key : properties.getKeySet().toArray()) { - //for (Object key : properties.getAllKeys().toArray()) { - IProperty property = block.getBlockState().getProperty(key.toString()); - //Property property = block.getStateDefinition().getProperty(key.toString()); + IProperty property = block.getBlockState().getProperty((String) key); if (property != null) { - blockState = setPropertyValue(blockState, property, propertiesMap(properties).get(key)); + blockState = setPropertyValue(blockState, property, properties.getString((String) key)); } } return blockState; @@ -197,40 +188,20 @@ public final class LitematicaSchematic extends StaticSchematic { * @param . */ private static > IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { - //private static > BlockState setPropertyValue(BlockState state, Property property, String value) { Optional parsed = property.parseValue(value).toJavaUtil(); - //Optional parsed = property.getValue(value); if (parsed.isPresent()) { return state.withProperty(property, parsed.get()); - //return state.setValue(property, parsed.get()); } else { throw new IllegalArgumentException("Invalid value for property " + property); } } - /** - * @param properties properties a block has. - * @return properties as map. - */ - private static Map propertiesMap(NBTTagCompound properties) { - //private static Map propertiesMap(CompoundTag properties) { - Map propertiesMap = new HashMap<>(); - - for (Object key : properties.getKeySet().toArray()) { - //for (Object key : properties.getAllKeys().toArray()) { - propertiesMap.put((String) key, (properties.getString((String) key))); - } - return propertiesMap; - } - /** * @param amountOfBlockTypes amount of block types in the schematic. * @return amount of bits used to encode a block. */ private static int bitsPerBlock(int amountOfBlockTypes) { - //private static int bitsPerBlock(ListTag blockStatePalette) { return (int) Math.floor((Math.log(amountOfBlockTypes)) / Math.log(2))+1; - //return (int) Math.floor((Math.log(blockStatePalette.size())) / Math.log(2))+1; } /** @@ -257,16 +228,6 @@ public final class LitematicaSchematic extends StaticSchematic { return rawBlockData; } - // will only work after 1.12. will replace the getBlockStates() above. - /* - /** - * @return array of Long values. - */ - /* - private static long[] getBlockStates() { - return nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt).getLongArray(); - }*/ - /** LitematicaBitArray class from litematica */ private static class LitematicaBitArray { From 52aa0d9b8a111ad51cb073757a641650297848bf Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 20:04:57 +0200 Subject: [PATCH 12/34] more cleanup --- .../format/defaults/LitematicaSchematic.java | 154 +++++++++--------- 1 file changed, 75 insertions(+), 79 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 4c8ce4c6..411e1988 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -51,7 +51,7 @@ public final class LitematicaSchematic extends StaticSchematic { public LitematicaSchematic(NBTTagCompound nbtCompound) { nbt = nbtCompound; regNames = getRegions(); - minCord(); + getMinimumCorner(); this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y")); @@ -60,81 +60,16 @@ public final class LitematicaSchematic extends StaticSchematic { for (String subRegion : regNames) { subReg = subRegion; - NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); - IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); + NBTTagList usedBlockTypes = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); + IBlockState[] blockList = getBlockList(usedBlockTypes); - int bitsPerBlock = bitsPerBlock(blockStatePalette.tagCount()); + int bitsPerBlock = getBitsPerBlock(usedBlockTypes.tagCount()); long regionVolume = getVolume(); long[] blockStateArray = getBlockStates(); LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, blockStateArray); - if (bitsPerBlock > 32) { - throw new IllegalStateException("Too many blocks in schematic to handle"); - } - - createSchematicOfSubRegion(paletteBlockStates, bitArray); - } - } - - /** - * @param paletteBlockStates list with the different block types used in the schematic - * @param bitArray bit array that holds the placement pattern - */ - private void createSchematicOfSubRegion(IBlockState[] paletteBlockStates, LitematicaBitArray bitArray) { - int posX = getMin("x"); - int posY = getMin("y"); - int posZ = getMin("z"); - int index = 0; - for (int y = 0; y < this.y; y++) { - for (int z = 0; z < this.z; z++) { - for (int x = 0; x < this.x; x++) { - if (inSubregion(x, y, z)) { - this.states[x-(minX- posX)][z-(minZ- posZ)][y-(minY- posY)] = paletteBlockStates[bitArray.getAt(index)]; - index++; - } - } - } - } - } - - /** - * @param x cord of the schematic. - * @param y cord of the schematic. - * @param z cord of the schematic. - * @return if the current block is inside the subregion. - */ - private static boolean inSubregion(int x, int y, int z) { - return - x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && - y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && - z < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); - } - - /** - * @param s axis that should be read. - * @return the lower cord of the requested axis. - */ - private static int getMin(String s) { - int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); - int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); - if (b < 0) { - b++; - } - return Math.min(a,a+b); - - } - - /** - * Calculates the minimum cords/origin of the schematic as litematica schematics - * can have a non-minimum origin. - */ - private void minCord() { - for (String subRegion : regNames) { - subReg = subRegion; - this.minX = Math.min(this.minX,getMin("x")); - this.minY = Math.min(this.minY,getMin("y")); - this.minZ = Math.min(this.minZ,getMin("z")); + writeSubregionIntoSchematic(blockList, bitArray); } } @@ -145,20 +80,47 @@ public final class LitematicaSchematic extends StaticSchematic { return nbt.getCompoundTag(reg).getKeySet().toArray(new String[0]); } + /** + * Calculates the minimum cords/origin of the schematic as litematica schematics + * can have a non-minimum origin. + */ + private void getMinimumCorner() { + for (String subRegion : regNames) { + subReg = subRegion; + this.minX = Math.min(this.minX, getMinimumCord("x")); + this.minY = Math.min(this.minY, getMinimumCord("y")); + this.minZ = Math.min(this.minZ, getMinimumCord("z")); + } + } + + /** + * @param s axis that should be read. + * @return the lower cord of the requested axis. + */ + private static int getMinimumCord(String s) { + int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); + int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); + if (b < 0) { + b++; + } + return Math.min(a,a+b); + + } + /** * @param blockStatePalette List of all different block types used in the schematic. * @return Array of BlockStates. */ - private static IBlockState[] paletteBlockStates(NBTTagList blockStatePalette) { - IBlockState[] paletteBlockStates = new IBlockState[blockStatePalette.tagCount()]; + private static IBlockState[] getBlockList(NBTTagList blockStatePalette) { + IBlockState[] blockList = new IBlockState[blockStatePalette.tagCount()]; for (int i = 0; i< blockStatePalette.tagCount(); i++) { Block block = Block.REGISTRY.getObject(new ResourceLocation((((NBTTagCompound) blockStatePalette.get(i)).getString("Name")))); NBTTagCompound properties = ((NBTTagCompound) blockStatePalette.get(i)).getCompoundTag("Properties"); - paletteBlockStates[i] = getBlockState(block, properties); + blockList[i] = getBlockState(block, properties); } - return paletteBlockStates; + return blockList; } /** @@ -169,11 +131,11 @@ public final class LitematicaSchematic extends StaticSchematic { private static IBlockState getBlockState(Block block, NBTTagCompound properties) { IBlockState blockState = block.getDefaultState(); - for (Object key : properties.getKeySet().toArray()) { IProperty property = block.getBlockState().getProperty((String) key); + String propertyValue = properties.getString((String) key); if (property != null) { - blockState = setPropertyValue(blockState, property, properties.getString((String) key)); + blockState = setPropertyValue(blockState, property, propertyValue); } } return blockState; @@ -200,7 +162,7 @@ public final class LitematicaSchematic extends StaticSchematic { * @param amountOfBlockTypes amount of block types in the schematic. * @return amount of bits used to encode a block. */ - private static int bitsPerBlock(int amountOfBlockTypes) { + private static int getBitsPerBlock(int amountOfBlockTypes) { return (int) Math.floor((Math.log(amountOfBlockTypes)) / Math.log(2))+1; } @@ -210,8 +172,8 @@ public final class LitematicaSchematic extends StaticSchematic { private static long getVolume() { return Math.abs( nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x") * - nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * - nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); + nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * + nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); } /** @@ -228,6 +190,40 @@ public final class LitematicaSchematic extends StaticSchematic { return rawBlockData; } + /** + * @param blockList list with the different block types used in the schematic + * @param bitArray bit array that holds the placement pattern + */ + private void writeSubregionIntoSchematic(IBlockState[] blockList, LitematicaBitArray bitArray) { + int posX = getMinimumCord("x"); + int posY = getMinimumCord("y"); + int posZ = getMinimumCord("z"); + int index = 0; + for (int y = 0; y < this.y; y++) { + for (int z = 0; z < this.z; z++) { + for (int x = 0; x < this.x; x++) { + if (inSubregion(x, y, z)) { + this.states[x-(minX- posX)][z-(minZ- posZ)][y-(minY- posY)] = blockList[bitArray.getAt(index)]; + index++; + } + } + } + } + } + + /** + * @param x cord of the schematic. + * @param y cord of the schematic. + * @param z cord of the schematic. + * @return if the current block is inside the subregion. + */ + private static boolean inSubregion(int x, int y, int z) { + return + x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && + y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && + z < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); + } + /** LitematicaBitArray class from litematica */ private static class LitematicaBitArray { From a091c17b83cd7f97e9dff2b87823c99ad4cfad55 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 21:04:09 +0200 Subject: [PATCH 13/34] Added mixin to properly handle Long Arrays --- .../launch/mixins/MixinNBTTagLongArray.java | 37 +++++++++++++++++++ src/launch/resources/mixins.baritone.json | 3 +- .../utils/accessor/INBTTagLongArray.java | 27 ++++++++++++++ .../format/defaults/LitematicaSchematic.java | 10 +---- 4 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java create mode 100644 src/main/java/baritone/utils/accessor/INBTTagLongArray.java diff --git a/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java b/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java new file mode 100644 index 00000000..a4cd739a --- /dev/null +++ b/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java @@ -0,0 +1,37 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.launch.mixins; + +import baritone.utils.accessor.INBTTagLongArray; +import net.minecraft.nbt.NBTTagLongArray; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +/** + * @author rycbar + * @since 26.09.2022 + */ +@Mixin(NBTTagLongArray.class) +public abstract class MixinNBTTagLongArray implements INBTTagLongArray { + + @Accessor("data") + @Override + public abstract long[] getLongArray(); + + +} \ No newline at end of file diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index fdcd14b9..c4b88481 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -31,6 +31,7 @@ "MixinStateImplementation", "MixinTabCompleter", "MixinVboRenderList", - "MixinWorldClient" + "MixinWorldClient", + "MixinNBTTagLongArray" ] } \ No newline at end of file diff --git a/src/main/java/baritone/utils/accessor/INBTTagLongArray.java b/src/main/java/baritone/utils/accessor/INBTTagLongArray.java new file mode 100644 index 00000000..fe4f0bd8 --- /dev/null +++ b/src/main/java/baritone/utils/accessor/INBTTagLongArray.java @@ -0,0 +1,27 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.utils.accessor; + +/** + * @author rycbar + * @since 26.09.2022 + */ +public interface INBTTagLongArray { + + long[] getLongArray(); +} \ No newline at end of file diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 411e1988..defbd3ea 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -18,6 +18,7 @@ package baritone.utils.schematic.format.defaults; import baritone.utils.schematic.StaticSchematic; +import baritone.utils.accessor.INBTTagLongArray; import net.minecraft.block.*; import net.minecraft.block.properties.IProperty; import net.minecraft.nbt.*; @@ -180,14 +181,7 @@ public final class LitematicaSchematic extends StaticSchematic { * @return array of Long values. */ private static long[] getBlockStates() { - String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt))).toString(); - rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1); - String[] rawBlockArrayString = rawBlockString.split(","); - long[] rawBlockData = new long[rawBlockArrayString.length]; - for (int i = 0; i < rawBlockArrayString.length; i++) { - rawBlockData[i] = Long.parseLong(rawBlockArrayString[i].substring(0,rawBlockArrayString[i].length()-1)); - } - return rawBlockData; + return ((INBTTagLongArray) nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt)).getLongArray(); } /** From 8aa891812473ef67a62ed4ab15d4fcf53abc7124 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 22:23:38 +0200 Subject: [PATCH 14/34] codacy issue #1 and #5 fix --- .../format/defaults/LitematicaSchematic.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index defbd3ea..8aea77a5 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -37,7 +37,9 @@ import java.util.*; * */ public final class LitematicaSchematic extends StaticSchematic { - int minX=0,minY=0,minZ=0; + int minX=0; + int minY=0; + int minZ=0; private static final String reg = "Regions"; private static final String meta = "Metadata"; private static final String schemSize = "EnclosingSize"; @@ -277,6 +279,7 @@ public final class LitematicaSchematic extends StaticSchematic { public static long roundUp(long number, long interval) { + int sign = 1; if (interval == 0) { return 0; @@ -289,11 +292,11 @@ public final class LitematicaSchematic extends StaticSchematic { { if (number < 0) { - interval *= -1; + sign = -1; } - long i = number % interval; - return i == 0 ? number : number + interval - i; + long i = number % (interval * sign); + return i == 0 ? number : number + (interval * sign) - i; } } } From 7a48824ced82e8b7e7dfd12a169cd378e3bd1356 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 26 Sep 2022 22:32:25 +0200 Subject: [PATCH 15/34] codacy issue #2,#3 and #4 fix --- .../format/defaults/LitematicaSchematic.java | 49 ++++++++----------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 8aea77a5..37d132fb 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -47,39 +47,33 @@ public final class LitematicaSchematic extends StaticSchematic { private static final String blStPl = "BlockStatePalette"; private static final String pos = "Position"; private static final String size = "Size"; - private static String subReg; - private static String[] regNames; - private static NBTTagCompound nbt; - public LitematicaSchematic(NBTTagCompound nbtCompound) { - nbt = nbtCompound; - regNames = getRegions(); - getMinimumCorner(); + public LitematicaSchematic(NBTTagCompound nbt) { + getMinimumCorner(nbt); this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y")); this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; - for (String subRegion : regNames) { - subReg = subRegion; + for (String subReg : getRegions(nbt)) { NBTTagList usedBlockTypes = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); IBlockState[] blockList = getBlockList(usedBlockTypes); int bitsPerBlock = getBitsPerBlock(usedBlockTypes.tagCount()); - long regionVolume = getVolume(); - long[] blockStateArray = getBlockStates(); + long regionVolume = getVolume(nbt, subReg); + long[] blockStateArray = getBlockStates(nbt, subReg); LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, blockStateArray); - writeSubregionIntoSchematic(blockList, bitArray); + writeSubregionIntoSchematic(nbt, subReg, blockList, bitArray); } } /** * @return Array of subregion names. */ - private static String[] getRegions() { + private static String[] getRegions(NBTTagCompound nbt) { return nbt.getCompoundTag(reg).getKeySet().toArray(new String[0]); } @@ -87,12 +81,11 @@ public final class LitematicaSchematic extends StaticSchematic { * Calculates the minimum cords/origin of the schematic as litematica schematics * can have a non-minimum origin. */ - private void getMinimumCorner() { - for (String subRegion : regNames) { - subReg = subRegion; - this.minX = Math.min(this.minX, getMinimumCord("x")); - this.minY = Math.min(this.minY, getMinimumCord("y")); - this.minZ = Math.min(this.minZ, getMinimumCord("z")); + private void getMinimumCorner(NBTTagCompound nbt) { + for (String subReg : getRegions(nbt)) { + this.minX = Math.min(this.minX, getMinimumCord(nbt, subReg,"x")); + this.minY = Math.min(this.minY, getMinimumCord(nbt, subReg,"y")); + this.minZ = Math.min(this.minZ, getMinimumCord(nbt, subReg,"z")); } } @@ -100,7 +93,7 @@ public final class LitematicaSchematic extends StaticSchematic { * @param s axis that should be read. * @return the lower cord of the requested axis. */ - private static int getMinimumCord(String s) { + private static int getMinimumCord(NBTTagCompound nbt, String subReg, String s) { int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); if (b < 0) { @@ -172,7 +165,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * @return the volume of the subregion. */ - private static long getVolume() { + private static long getVolume(NBTTagCompound nbt, String subReg) { return Math.abs( nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x") * nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * @@ -182,7 +175,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * @return array of Long values. */ - private static long[] getBlockStates() { + private static long[] getBlockStates(NBTTagCompound nbt, String subReg) { return ((INBTTagLongArray) nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt)).getLongArray(); } @@ -190,15 +183,15 @@ public final class LitematicaSchematic extends StaticSchematic { * @param blockList list with the different block types used in the schematic * @param bitArray bit array that holds the placement pattern */ - private void writeSubregionIntoSchematic(IBlockState[] blockList, LitematicaBitArray bitArray) { - int posX = getMinimumCord("x"); - int posY = getMinimumCord("y"); - int posZ = getMinimumCord("z"); + private void writeSubregionIntoSchematic(NBTTagCompound nbt, String subReg, IBlockState[] blockList, LitematicaBitArray bitArray) { + int posX = getMinimumCord(nbt, subReg,"x"); + int posY = getMinimumCord(nbt, subReg,"y"); + int posZ = getMinimumCord(nbt, subReg,"z"); int index = 0; for (int y = 0; y < this.y; y++) { for (int z = 0; z < this.z; z++) { for (int x = 0; x < this.x; x++) { - if (inSubregion(x, y, z)) { + if (inSubregion(nbt, subReg, x, y, z)) { this.states[x-(minX- posX)][z-(minZ- posZ)][y-(minY- posY)] = blockList[bitArray.getAt(index)]; index++; } @@ -213,7 +206,7 @@ public final class LitematicaSchematic extends StaticSchematic { * @param z cord of the schematic. * @return if the current block is inside the subregion. */ - private static boolean inSubregion(int x, int y, int z) { + private static boolean inSubregion(NBTTagCompound nbt, String subReg, int x, int y, int z) { return x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && From d928e705b91f7cb19f38e8b193721e781422a7d3 Mon Sep 17 00:00:00 2001 From: schmar03 Date: Wed, 28 Sep 2022 12:09:38 +0200 Subject: [PATCH 16/34] 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 9063b990..dc17d041 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 e998dcc9..901fda71 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 00000000..56360331 --- /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 1766af62..437c2c8d 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 00000000..82533258 --- /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 17/34] 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 437c2c8d..cd1a19b8 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 82533258..c97a46b7 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 00000000..46f4e02a --- /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 00000000..b590eb2e --- /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 00000000..0407dff0 --- /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 00000000..c30ab149 --- /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 00000000..707aaf78 --- /dev/null +++ b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementUnloaded.java @@ -0,0 +1,39 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package fi.dy.masa.litematica.schematic.placement; + +import net.minecraft.util.math.BlockPos; + +import javax.annotation.Nullable; +import java.io.File; + +public class SchematicPlacementUnloaded { + protected String name = "?"; + @Nullable protected File schematicFile; + protected BlockPos origin = BlockPos.ORIGIN; + public String getName() { + return this.name; + } + @Nullable + public File getSchematicFile() { + return this.schematicFile; + } + public BlockPos getOrigin() { + return this.origin; + } +} From 5ff274f040c6bd568857730144a8e22e1402399a Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Thu, 29 Sep 2022 19:58:05 +0200 Subject: [PATCH 18/34] Change requests part one --- .../launch/mixins/MixinNBTTagLongArray.java | 2 - src/launch/resources/mixins.baritone.json | 4 +- .../format/DefaultSchematicFormats.java | 2 +- .../format/defaults/LitematicaSchematic.java | 73 ++++++++----------- 4 files changed, 35 insertions(+), 46 deletions(-) diff --git a/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java b/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java index a4cd739a..2c05e544 100644 --- a/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java +++ b/src/launch/java/baritone/launch/mixins/MixinNBTTagLongArray.java @@ -32,6 +32,4 @@ public abstract class MixinNBTTagLongArray implements INBTTagLongArray { @Accessor("data") @Override public abstract long[] getLongArray(); - - } \ No newline at end of file diff --git a/src/launch/resources/mixins.baritone.json b/src/launch/resources/mixins.baritone.json index c4b88481..98273663 100644 --- a/src/launch/resources/mixins.baritone.json +++ b/src/launch/resources/mixins.baritone.json @@ -23,6 +23,7 @@ "MixinItemStack", "MixinItemTool", "MixinMinecraft", + "MixinNBTTagLongArray", "MixinNetHandlerPlayClient", "MixinNetworkManager", "MixinPlayerControllerMP", @@ -31,7 +32,6 @@ "MixinStateImplementation", "MixinTabCompleter", "MixinVboRenderList", - "MixinWorldClient", - "MixinNBTTagLongArray" + "MixinWorldClient" ] } \ No newline at end of file diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index de142b39..d8049ce4 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -71,7 +71,7 @@ public enum DefaultSchematicFormats implements ISchematicFormat { /** * The Litematica schematic specification. Commonly denoted by the ".litematic" file extension. */ - Litematica("litematic") { + LITEMATICA("litematic") { @Override public IStaticSchematic parse(InputStream input) throws IOException { NBTTagCompound nbt = CompressedStreamTools.readCompressed(input); diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 37d132fb..4cccecee 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -37,27 +37,30 @@ import java.util.*; * */ public final class LitematicaSchematic extends StaticSchematic { - int minX=0; - int minY=0; - int minZ=0; - private static final String reg = "Regions"; - private static final String meta = "Metadata"; - private static final String schemSize = "EnclosingSize"; - private static final String blSt = "BlockStates"; - private static final String blStPl = "BlockStatePalette"; - private static final String pos = "Position"; - private static final String size = "Size"; + private final int minX; + private final int minY; + private final int minZ; public LitematicaSchematic(NBTTagCompound nbt) { - getMinimumCorner(nbt); + int x=0; + int y=0; + int z=0; + for (String subReg : getRegions(nbt)) { + x = Math.min(x, getMinimumCord(nbt, subReg,"x")); + y = Math.min(y, getMinimumCord(nbt, subReg,"y")); + z = Math.min(z, getMinimumCord(nbt, subReg,"z")); + } + this.minX = x; + this.minY = y; + this.minZ = z; - this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); - this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y")); - this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z")); + this.x = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("x")); + this.y = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("y")); + this.z = Math.abs(nbt.getCompoundTag("Metadata").getCompoundTag("EnclosingSize").getInteger("z")); this.states = new IBlockState[this.x][this.z][this.y]; for (String subReg : getRegions(nbt)) { - NBTTagList usedBlockTypes = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); + NBTTagList usedBlockTypes = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getTagList("BlockStatePalette", 10); IBlockState[] blockList = getBlockList(usedBlockTypes); int bitsPerBlock = getBitsPerBlock(usedBlockTypes.tagCount()); @@ -74,28 +77,16 @@ public final class LitematicaSchematic extends StaticSchematic { * @return Array of subregion names. */ private static String[] getRegions(NBTTagCompound nbt) { - return nbt.getCompoundTag(reg).getKeySet().toArray(new String[0]); - } - - /** - * Calculates the minimum cords/origin of the schematic as litematica schematics - * can have a non-minimum origin. - */ - private void getMinimumCorner(NBTTagCompound nbt) { - for (String subReg : getRegions(nbt)) { - this.minX = Math.min(this.minX, getMinimumCord(nbt, subReg,"x")); - this.minY = Math.min(this.minY, getMinimumCord(nbt, subReg,"y")); - this.minZ = Math.min(this.minZ, getMinimumCord(nbt, subReg,"z")); - } + return nbt.getCompoundTag("Regions").getKeySet().toArray(new String[0]); } /** * @param s axis that should be read. - * @return the lower cord of the requested axis. + * @return the lower coord of the requested axis. */ private static int getMinimumCord(NBTTagCompound nbt, String subReg, String s) { - int a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s); - int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); + int a = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Position").getInteger(s); + int b = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger(s); if (b < 0) { b++; } @@ -167,16 +158,16 @@ public final class LitematicaSchematic extends StaticSchematic { */ private static long getVolume(NBTTagCompound nbt, String subReg) { return Math.abs( - nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x") * - nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y") * - nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); + nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("x") * + nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y") * + nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); } /** * @return array of Long values. */ private static long[] getBlockStates(NBTTagCompound nbt, String subReg) { - return ((INBTTagLongArray) nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt)).getLongArray(); + return ((INBTTagLongArray) nbt.getCompoundTag("Regions").getCompoundTag(subReg).getTag("BlockStates")).getLongArray(); } /** @@ -201,16 +192,16 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param x cord of the schematic. - * @param y cord of the schematic. - * @param z cord of the schematic. + * @param x coord of the schematic. + * @param y coord of the schematic. + * @param z coord of the schematic. * @return if the current block is inside the subregion. */ private static boolean inSubregion(NBTTagCompound nbt, String subReg, int x, int y, int z) { return - x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && - y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && - z < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("z")); + x < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("x")) && + y < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y")) && + z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); } /** LitematicaBitArray class from litematica */ From 7ba3de57d02e34962af3b4f610cee446b7b30196 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Thu, 29 Sep 2022 20:20:38 +0200 Subject: [PATCH 19/34] credits LitematicaBitArray --- .../schematic/format/defaults/LitematicaSchematic.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 4cccecee..df8c82ee 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -204,7 +204,11 @@ public final class LitematicaSchematic extends StaticSchematic { z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); } - /** LitematicaBitArray class from litematica */ + /** + * @author maruohon + * Class from the Litematica mod by maruohon + * https://github.com/maruohon/litematica + */ private static class LitematicaBitArray { /** The long array that is used to store the data for this BitArray. */ From e99fcbbe36450f414d98f860c461973a7ee20b07 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Thu, 29 Sep 2022 21:47:42 +0200 Subject: [PATCH 20/34] Change requests part two --- .../format/DefaultSchematicFormats.java | 8 +- .../format/defaults/LitematicaSchematic.java | 180 +++++++++--------- 2 files changed, 89 insertions(+), 99 deletions(-) diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index d8049ce4..699f87bc 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -77,11 +77,11 @@ public enum DefaultSchematicFormats implements ISchematicFormat { NBTTagCompound nbt = CompressedStreamTools.readCompressed(input); int version = nbt.getInteger("Version"); switch (version) { - case 4: + case 4: //1.12 return new LitematicaSchematic(nbt); - case 5: - case 6: - throw new UnsupportedOperationException("This Schematic Verion is to new."); + case 5: //1.13-1.17 + case 6: //1.18+ + throw new UnsupportedOperationException("This litematic Verion is to new."); default: throw new UnsupportedOperationException("Unsuported Version of a Litematica Schematic"); } diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index df8c82ee..3f0e165f 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -17,24 +17,24 @@ package baritone.utils.schematic.format.defaults; -import baritone.utils.schematic.StaticSchematic; import baritone.utils.accessor.INBTTagLongArray; -import net.minecraft.block.*; +import baritone.utils.schematic.StaticSchematic; +import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; -import net.minecraft.nbt.*; -import net.minecraft.util.ResourceLocation; import net.minecraft.block.state.IBlockState; - +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ResourceLocation; import org.apache.commons.lang3.Validate; + import javax.annotation.Nullable; -import java.util.*; +import java.util.Optional; /** * @author Emerson * @since 12/27/2020 * @author rycbar * @since 22.09.2022 - * */ public final class LitematicaSchematic extends StaticSchematic { private final int minX; @@ -42,13 +42,13 @@ public final class LitematicaSchematic extends StaticSchematic { private final int minZ; public LitematicaSchematic(NBTTagCompound nbt) { - int x=0; - int y=0; - int z=0; + int x = 0; + int y = 0; + int z = 0; for (String subReg : getRegions(nbt)) { - x = Math.min(x, getMinimumCord(nbt, subReg,"x")); - y = Math.min(y, getMinimumCord(nbt, subReg,"y")); - z = Math.min(z, getMinimumCord(nbt, subReg,"z")); + x = Math.min(x, getMinimumCoord(nbt, subReg, "x")); + y = Math.min(y, getMinimumCoord(nbt, subReg, "y")); + z = Math.min(z, getMinimumCoord(nbt, subReg, "z")); } this.minX = x; this.minY = y; @@ -81,16 +81,17 @@ public final class LitematicaSchematic extends StaticSchematic { } /** + * Gets both ends from schematic box for a given axis and returns the lower one. * @param s axis that should be read. * @return the lower coord of the requested axis. */ - private static int getMinimumCord(NBTTagCompound nbt, String subReg, String s) { + private static int getMinimumCoord(NBTTagCompound nbt, String subReg, String s) { int a = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Position").getInteger(s); int b = nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger(s); if (b < 0) { b++; } - return Math.min(a,a+b); + return Math.min(a, a + b); } @@ -101,7 +102,7 @@ public final class LitematicaSchematic extends StaticSchematic { private static IBlockState[] getBlockList(NBTTagList blockStatePalette) { IBlockState[] blockList = new IBlockState[blockStatePalette.tagCount()]; - for (int i = 0; i< blockStatePalette.tagCount(); i++) { + for (int i = 0; i < blockStatePalette.tagCount(); i++) { Block block = Block.REGISTRY.getObject(new ResourceLocation((((NBTTagCompound) blockStatePalette.get(i)).getString("Name")))); NBTTagCompound properties = ((NBTTagCompound) blockStatePalette.get(i)).getCompoundTag("Properties"); @@ -111,7 +112,7 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param block block. + * @param block block. * @param properties List of Properties the block has. * @return A blockState. */ @@ -129,12 +130,7 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * i haven't written this and i wont try to decode it. - * @param state . - * @param property . - * @param value . - * @return . - * @param . + * @author Emerson */ private static > IBlockState setPropertyValue(IBlockState state, IProperty property, String value) { Optional parsed = property.parseValue(value).toJavaUtil(); @@ -150,10 +146,12 @@ public final class LitematicaSchematic extends StaticSchematic { * @return amount of bits used to encode a block. */ private static int getBitsPerBlock(int amountOfBlockTypes) { - return (int) Math.floor((Math.log(amountOfBlockTypes)) / Math.log(2))+1; + return (int) Math.floor((Math.log(amountOfBlockTypes)) / Math.log(2)) + 1; } /** + * Calculates the volume of the subregion. As size can be a negative value we take the absolute value of the + * multiplication as the volume still holds a positive amount of blocks. * @return the volume of the subregion. */ private static long getVolume(NBTTagCompound nbt, String subReg) { @@ -171,19 +169,36 @@ public final class LitematicaSchematic extends StaticSchematic { } /** - * @param blockList list with the different block types used in the schematic - * @param bitArray bit array that holds the placement pattern + * Subregion don't have to be the same size as the enclosing size of the schematic. If they are smaller we check here if the current block is part of the subregion. + * @param x coord of the block relative to the minimum corner. + * @param y coord of the block relative to the minimum corner. + * @param z coord of the block relative to the minimum corner. + * @return if the current block is part of the subregion. */ + private static boolean inSubregion(NBTTagCompound nbt, String subReg, int x, int y, int z) { + return + x < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("x")) && + y < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y")) && + z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); + } + + /** + * @param blockList list with the different block types used in the schematic + * @param bitArray bit array that holds the placement pattern + */ + //x,y,z are the releative positons to the minimum corner of the enclosing box + //minX,minY,minZ are correction terms if the schematic origin isn't the minimum corner + //posX,posY,posZ are the subregions offset relative to the minimum corner private void writeSubregionIntoSchematic(NBTTagCompound nbt, String subReg, IBlockState[] blockList, LitematicaBitArray bitArray) { - int posX = getMinimumCord(nbt, subReg,"x"); - int posY = getMinimumCord(nbt, subReg,"y"); - int posZ = getMinimumCord(nbt, subReg,"z"); + int posX = getMinimumCoord(nbt, subReg, "x"); + int posY = getMinimumCoord(nbt, subReg, "y"); + int posZ = getMinimumCoord(nbt, subReg, "z"); int index = 0; for (int y = 0; y < this.y; y++) { for (int z = 0; z < this.z; z++) { for (int x = 0; x < this.x; x++) { if (inSubregion(nbt, subReg, x, y, z)) { - this.states[x-(minX- posX)][z-(minZ- posZ)][y-(minY- posY)] = blockList[bitArray.getAt(index)]; + this.states[x - (minX - posX)][z - (minZ - posZ)][y - (minY - posY)] = blockList[bitArray.getAt(index)]; index++; } } @@ -191,95 +206,51 @@ public final class LitematicaSchematic extends StaticSchematic { } } - /** - * @param x coord of the schematic. - * @param y coord of the schematic. - * @param z coord of the schematic. - * @return if the current block is inside the subregion. - */ - private static boolean inSubregion(NBTTagCompound nbt, String subReg, int x, int y, int z) { - return - x < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("x")) && - y < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y")) && - z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); - } - /** * @author maruohon * Class from the Litematica mod by maruohon - * https://github.com/maruohon/litematica + * ... */ - private static class LitematicaBitArray - { - /** The long array that is used to store the data for this BitArray. */ + private static class LitematicaBitArray { + /** + * The long array that is used to store the data for this BitArray. + */ private final long[] longArray; - /** Number of bits a single entry takes up */ + /** + * Number of bits a single entry takes up + */ private final int bitsPerEntry; /** * The maximum value for a single entry. This also works as a bitmask for a single entry. * For instance, if bitsPerEntry were 5, this value would be 31 (ie, {@code 0b00011111}). */ private final long maxEntryValue; - /** Number of entries in this array (not the length of the long array that internally backs this array) */ + /** + * Number of entries in this array (not the length of the long array that internally backs this array) + */ private final long arraySize; - public LitematicaBitArray(int bitsPerEntryIn, long arraySizeIn, @Nullable long[] longArrayIn) - { - Validate.inclusiveBetween(1L, 32L, (long) bitsPerEntryIn); + public LitematicaBitArray(int bitsPerEntryIn, long arraySizeIn, @Nullable long[] longArrayIn) { + Validate.inclusiveBetween(1L, 32L, bitsPerEntryIn); this.arraySize = arraySizeIn; this.bitsPerEntry = bitsPerEntryIn; this.maxEntryValue = (1L << bitsPerEntryIn) - 1L; - if (longArrayIn != null) - { + if (longArrayIn != null) { this.longArray = longArrayIn; - } - else - { - this.longArray = new long[(int) (roundUp((long) arraySizeIn * (long) bitsPerEntryIn, 64L) / 64L)]; + } else { + this.longArray = new long[(int) (roundUp(arraySizeIn * (long) bitsPerEntryIn, 64L) / 64L)]; } } - public int getAt(long index) - { - Validate.inclusiveBetween(0L, this.arraySize - 1L, (long) index); - long startOffset = index * (long) this.bitsPerEntry; - int startArrIndex = (int) (startOffset >> 6); // startOffset / 64 - int endArrIndex = (int) (((index + 1L) * (long) this.bitsPerEntry - 1L) >> 6); - int startBitOffset = (int) (startOffset & 0x3F); // startOffset % 64 - - if (startArrIndex == endArrIndex) - { - return (int) (this.longArray[startArrIndex] >>> startBitOffset & this.maxEntryValue); - } - else - { - int endOffset = 64 - startBitOffset; - return (int) ((this.longArray[startArrIndex] >>> startBitOffset | this.longArray[endArrIndex] << endOffset) & this.maxEntryValue); - } - } - - - public long size() - { - return this.arraySize; - } - - public static long roundUp(long number, long interval) - { + public static long roundUp(long number, long interval) { int sign = 1; - if (interval == 0) - { + if (interval == 0) { return 0; - } - else if (number == 0) - { + } else if (number == 0) { return interval; - } - else - { - if (number < 0) - { + } else { + if (number < 0) { sign = -1; } @@ -287,5 +258,24 @@ public final class LitematicaSchematic extends StaticSchematic { return i == 0 ? number : number + (interval * sign) - i; } } + + public int getAt(long index) { + Validate.inclusiveBetween(0L, this.arraySize - 1L, index); + long startOffset = index * (long) this.bitsPerEntry; + int startArrIndex = (int) (startOffset >> 6); // startOffset / 64 + int endArrIndex = (int) (((index + 1L) * (long) this.bitsPerEntry - 1L) >> 6); + int startBitOffset = (int) (startOffset & 0x3F); // startOffset % 64 + + if (startArrIndex == endArrIndex) { + return (int) (this.longArray[startArrIndex] >>> startBitOffset & this.maxEntryValue); + } else { + int endOffset = 64 - startBitOffset; + return (int) ((this.longArray[startArrIndex] >>> startBitOffset | this.longArray[endArrIndex] << endOffset) & this.maxEntryValue); + } + } + + public long size() { + return this.arraySize; + } } } \ No newline at end of file From 484b3326c77c92d749cc24d919888d726ab05dc4 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Thu, 29 Sep 2022 21:52:15 +0200 Subject: [PATCH 21/34] auto-format all files I touched --- .../utils/schematic/format/DefaultSchematicFormats.java | 2 +- .../utils/schematic/format/defaults/LitematicaSchematic.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index 699f87bc..faabe57b 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -19,9 +19,9 @@ package baritone.utils.schematic.format; import baritone.api.schematic.IStaticSchematic; import baritone.api.schematic.format.ISchematicFormat; +import baritone.utils.schematic.format.defaults.LitematicaSchematic; import baritone.utils.schematic.format.defaults.MCEditSchematic; import baritone.utils.schematic.format.defaults.SpongeSchematic; -import baritone.utils.schematic.format.defaults.LitematicaSchematic; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import org.apache.commons.io.FilenameUtils; diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index 3f0e165f..12b3264f 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -82,6 +82,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * Gets both ends from schematic box for a given axis and returns the lower one. + * * @param s axis that should be read. * @return the lower coord of the requested axis. */ @@ -152,6 +153,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * Calculates the volume of the subregion. As size can be a negative value we take the absolute value of the * multiplication as the volume still holds a positive amount of blocks. + * * @return the volume of the subregion. */ private static long getVolume(NBTTagCompound nbt, String subReg) { @@ -170,6 +172,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * Subregion don't have to be the same size as the enclosing size of the schematic. If they are smaller we check here if the current block is part of the subregion. + * * @param x coord of the block relative to the minimum corner. * @param y coord of the block relative to the minimum corner. * @param z coord of the block relative to the minimum corner. From 4ba3c883e6d49d194c2e31f3e527ac5df10c2ec7 Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Fri, 30 Sep 2022 13:32:31 +0200 Subject: [PATCH 22/34] 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 517494f4..cc313008 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 cd1a19b8..a3ee785d 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 c97a46b7..3692b8b0 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 23/34] 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 dc17d041..c63113cd 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 56360331..eecab07d 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 a3ee785d..bb62ab76 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 3692b8b0..9f5f19fb 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 c30ab149..9391330d 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 24/34] 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 bb62ab76..e18f7aea 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 25/34] 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 e18f7aea..da56bdf9 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 26/34] 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 da56bdf9..3b9ba2dd 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 faabe57b..2ca9e148 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 5f3c6e85..40ff37e7 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 c19ae5a7..47d3fe24 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 27/34] 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 3b9ba2dd..65f97543 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 47d3fe24..5e42ba99 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 28/34] 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 5e42ba99..14b984c4 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 29/34] 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 65f97543..74d9f95c 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 40ff37e7..fb2f36eb 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 14b984c4..ea9b711b 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 30/34] 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 74d9f95c..110df3de 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 ea9b711b..f63c8eb3 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 31/34] 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 110df3de..124547ee 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 fb2f36eb..f55f9212 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 f63c8eb3..be437624 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 32/34] 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 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 Date: Mon, 3 Oct 2022 20:32:56 +0200 Subject: [PATCH 33/34] 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 b6ba681f..ec9fcc73 100644 --- a/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java +++ b/src/main/java/baritone/utils/schematic/litematica/LitematicaHelper.java @@ -202,7 +202,7 @@ public final class LitematicaHelper { } IBlockState state = schemIn.getDirect(xCounter, yCounter, zCounter); try { - state.withMirror(LitematicaHelper.getMirror(i)).withRotation(LitematicaHelper.getRotation(i)); + state = state.withMirror(LitematicaHelper.getMirror(i)).withRotation(LitematicaHelper.getRotation(i)); } catch (NullPointerException e) { //nothing to worry about it's just a hole in the schematic. } From f9c5386e7ada3c732aeec9f436a07828ae9de68f Mon Sep 17 00:00:00 2001 From: rycbar0 Date: Mon, 3 Oct 2022 21:39:53 +0200 Subject: [PATCH 34/34] final changes --- .../command/defaults/LitematicaCommand.java | 4 ++-- .../schematic/format/DefaultSchematicFormats.java | 2 +- .../format/defaults/LitematicaSchematic.java | 14 ++++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/baritone/command/defaults/LitematicaCommand.java b/src/main/java/baritone/command/defaults/LitematicaCommand.java index eecab07d..bfe0079b 100644 --- a/src/main/java/baritone/command/defaults/LitematicaCommand.java +++ b/src/main/java/baritone/command/defaults/LitematicaCommand.java @@ -35,10 +35,10 @@ public class LitematicaCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { int schematic = 0; - if(args.hasAny()) { + if (args.hasAny()) { args.requireMax(1); if (args.is(Integer.class)) { - schematic = args.getAs(Integer.class)-1; + schematic = args.getAs(Integer.class) - 1; } } try { diff --git a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java index 2ca9e148..cd38433a 100644 --- a/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java +++ b/src/main/java/baritone/utils/schematic/format/DefaultSchematicFormats.java @@ -81,7 +81,7 @@ public enum DefaultSchematicFormats implements ISchematicFormat { return new LitematicaSchematic(nbt, false); case 5: //1.13-1.17 case 6: //1.18+ - throw new UnsupportedOperationException("This litematic Verion is to new."); + throw new UnsupportedOperationException("This litematic Verion is too new."); default: throw new UnsupportedOperationException("Unsuported Version of a Litematica Schematic"); } diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index dc1c1d5b..84b9b86e 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -32,8 +32,9 @@ import javax.annotation.Nullable; import java.util.Optional; /** - * @author Emerson - * @since 12/27/2020 + * Based on EmersonDove's work + * ... + * * @author rycbar * @since 22.09.2022 */ @@ -43,7 +44,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * @param nbtTagCompound a decompressed file stream aka nbt data. - * @param rotated if the schematic is rotated by 90° aka x and z size are switched. + * @param rotated if the schematic is rotated by 90°. */ public LitematicaSchematic(NBTTagCompound nbtTagCompound, boolean rotated) { this.nbt = nbtTagCompound; @@ -167,10 +168,10 @@ public final class LitematicaSchematic extends StaticSchematic { * @return if the current block is part of the subregion. */ private static boolean inSubregion(NBTTagCompound nbt, String subReg, int x, int y, int z) { - return + return x >= 0 && y >= 0 && z >= 0 && x < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("x")) && - y < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y")) && - z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); + y < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("y")) && + z < Math.abs(nbt.getCompoundTag("Regions").getCompoundTag(subReg).getCompoundTag("Size").getInteger("z")); } /** @@ -273,6 +274,7 @@ public final class LitematicaSchematic extends StaticSchematic { /** * @author maruohon * Class from the Litematica mod by maruohon + * Usage under LGPLv3 with the permission of the author. * ... */ private static class LitematicaBitArray {