debugging mirroring and rotating as well as refactoring

This commit is contained in:
rycbar0 2022-10-01 17:14:05 +02:00
parent de1256cc80
commit 144a534bb3
4 changed files with 44 additions and 29 deletions

View File

@ -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");
}

View File

@ -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.");

View File

@ -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);
}
/**

View File

@ -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<schemIn.getY(); yCounter++) {
for (int zCounter=0; zCounter<schemIn.getZ(); zCounter++) {
for (int xCounter=0; xCounter<schemIn.getX(); xCounter++) {
Vec3i xyzHolder = new Vec3i(xCounter, yCounter, zCounter);
//System.out.println(String.format("In: %s, sizeX=%S, sizeZ=%s",xyzHolder,schemIn.getX(),schemIn.getZ()));
xyzHolder = LitematicaHelper.doMirroring(xyzHolder, schemIn.getX() - 1, schemIn.getZ() - 1, LitematicaHelper.getMirror(i));
//System.out.println(String.format("Mirror: %s, sizeX=%S, sizeZ=%s",xyzHolder,schemIn.getX(),schemIn.getZ()));
for (int turns = 0; turns < LitematicaHelper.getRotation(i).ordinal(); turns++) {
xyzHolder = LitematicaHelper.rotate(xyzHolder, schemIn.getX() - 1, schemIn.getZ() - 1);
if ((turns%2)==0) {
xyzHolder = LitematicaHelper.rotate(xyzHolder, schemIn.getX() - 1, schemIn.getZ() - 1);
} else {
xyzHolder = LitematicaHelper.rotate(xyzHolder, schemIn.getZ() - 1, schemIn.getX() - 1);
}
//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));
}