codacy issue #2,#3 and #4 fix

This commit is contained in:
rycbar0 2022-09-26 22:32:25 +02:00
parent 8aa8918124
commit 7a48824ced

View File

@ -47,39 +47,33 @@ public final class LitematicaSchematic extends StaticSchematic {
private static final String blStPl = "BlockStatePalette"; private static final String blStPl = "BlockStatePalette";
private static final String pos = "Position"; private static final String pos = "Position";
private static final String size = "Size"; private static final String size = "Size";
private static String subReg;
private static String[] regNames;
private static NBTTagCompound nbt;
public LitematicaSchematic(NBTTagCompound nbtCompound) { public LitematicaSchematic(NBTTagCompound nbt) {
nbt = nbtCompound; getMinimumCorner(nbt);
regNames = getRegions();
getMinimumCorner();
this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x")); this.x = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("x"));
this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y")); this.y = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("y"));
this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z")); this.z = Math.abs(nbt.getCompoundTag(meta).getCompoundTag(schemSize).getInteger("z"));
this.states = new IBlockState[this.x][this.z][this.y]; this.states = new IBlockState[this.x][this.z][this.y];
for (String subRegion : regNames) { for (String subReg : getRegions(nbt)) {
subReg = subRegion;
NBTTagList usedBlockTypes = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); NBTTagList usedBlockTypes = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10);
IBlockState[] blockList = getBlockList(usedBlockTypes); IBlockState[] blockList = getBlockList(usedBlockTypes);
int bitsPerBlock = getBitsPerBlock(usedBlockTypes.tagCount()); int bitsPerBlock = getBitsPerBlock(usedBlockTypes.tagCount());
long regionVolume = getVolume(); long regionVolume = getVolume(nbt, subReg);
long[] blockStateArray = getBlockStates(); long[] blockStateArray = getBlockStates(nbt, subReg);
LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, blockStateArray); LitematicaBitArray bitArray = new LitematicaBitArray(bitsPerBlock, regionVolume, blockStateArray);
writeSubregionIntoSchematic(blockList, bitArray); writeSubregionIntoSchematic(nbt, subReg, blockList, bitArray);
} }
} }
/** /**
* @return Array of subregion names. * @return Array of subregion names.
*/ */
private static String[] getRegions() { private static String[] getRegions(NBTTagCompound nbt) {
return nbt.getCompoundTag(reg).getKeySet().toArray(new String[0]); 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 * 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 getMinimumCorner() { private void getMinimumCorner(NBTTagCompound nbt) {
for (String subRegion : regNames) { for (String subReg : getRegions(nbt)) {
subReg = subRegion; this.minX = Math.min(this.minX, getMinimumCord(nbt, subReg,"x"));
this.minX = Math.min(this.minX, getMinimumCord("x")); this.minY = Math.min(this.minY, getMinimumCord(nbt, subReg,"y"));
this.minY = Math.min(this.minY, getMinimumCord("y")); this.minZ = Math.min(this.minZ, getMinimumCord(nbt, subReg,"z"));
this.minZ = Math.min(this.minZ, getMinimumCord("z"));
} }
} }
@ -100,7 +93,7 @@ public final class LitematicaSchematic extends StaticSchematic {
* @param s axis that should be read. * @param s axis that should be read.
* @return the lower cord of the requested axis. * @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 a = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(pos).getInteger(s);
int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s); int b = nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger(s);
if (b < 0) { if (b < 0) {
@ -172,7 +165,7 @@ public final class LitematicaSchematic extends StaticSchematic {
/** /**
* @return the volume of the subregion. * @return the volume of the subregion.
*/ */
private static long getVolume() { private static long getVolume(NBTTagCompound nbt, String subReg) {
return Math.abs( return Math.abs(
nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x") * 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("y") *
@ -182,7 +175,7 @@ public final class LitematicaSchematic extends StaticSchematic {
/** /**
* @return array of Long values. * @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(); 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 blockList list with the different block types used in the schematic
* @param bitArray bit array that holds the placement pattern * @param bitArray bit array that holds the placement pattern
*/ */
private void writeSubregionIntoSchematic(IBlockState[] blockList, LitematicaBitArray bitArray) { private void writeSubregionIntoSchematic(NBTTagCompound nbt, String subReg, IBlockState[] blockList, LitematicaBitArray bitArray) {
int posX = getMinimumCord("x"); int posX = getMinimumCord(nbt, subReg,"x");
int posY = getMinimumCord("y"); int posY = getMinimumCord(nbt, subReg,"y");
int posZ = getMinimumCord("z"); int posZ = getMinimumCord(nbt, subReg,"z");
int index = 0; int index = 0;
for (int y = 0; y < this.y; y++) { for (int y = 0; y < this.y; y++) {
for (int z = 0; z < this.z; z++) { for (int z = 0; z < this.z; z++) {
for (int x = 0; x < this.x; x++) { 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)]; this.states[x-(minX- posX)][z-(minZ- posZ)][y-(minY- posY)] = blockList[bitArray.getAt(index)];
index++; index++;
} }
@ -213,7 +206,7 @@ public final class LitematicaSchematic extends StaticSchematic {
* @param z cord of the schematic. * @param z cord of the schematic.
* @return if the current block is inside the subregion. * @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 return
x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) && x < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("x")) &&
y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) && y < Math.abs(nbt.getCompoundTag(reg).getCompoundTag(subReg).getCompoundTag(size).getInteger("y")) &&