This commit is contained in:
rycbar0 2022-09-26 19:23:09 +02:00
parent 295265c261
commit 3d8eddc4e1

View File

@ -48,8 +48,8 @@ public final class LitematicaSchematic extends StaticSchematic {
private static String[] regNames; private static String[] regNames;
private static NBTTagCompound nbt; private static NBTTagCompound nbt;
public LitematicaSchematic(NBTTagCompound nbt) { public LitematicaSchematic(NBTTagCompound nbtCompound) {
this.nbt = nbt; nbt = nbtCompound;
regNames = getRegions(); regNames = getRegions();
minCord(); minCord();
@ -61,9 +61,7 @@ public final class LitematicaSchematic extends StaticSchematic {
for (String subRegion : regNames) { for (String subRegion : regNames) {
subReg = subRegion; subReg = subRegion;
NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10); NBTTagList blockStatePalette = nbt.getCompoundTag(reg).getCompoundTag(subReg).getTagList(blStPl, 10);
// ListTag blockStatePalette = nbt.getCompound(reg).getCompound(subReg).getList(blStPl,10);
IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette); IBlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette);
// BlockState[] paletteBlockStates = paletteBlockStates(blockStatePalette);
int bitsPerBlock = bitsPerBlock(blockStatePalette.tagCount()); int bitsPerBlock = bitsPerBlock(blockStatePalette.tagCount());
long regionVolume = getVolume(); long regionVolume = getVolume();
@ -129,7 +127,7 @@ 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 minCord() { private void minCord() {
for (String subRegion : regNames) { for (String subRegion : regNames) {
@ -152,15 +150,11 @@ public final class LitematicaSchematic extends StaticSchematic {
* @return Array of BlockStates. * @return Array of BlockStates.
*/ */
private static IBlockState[] paletteBlockStates(NBTTagList blockStatePalette) { private static IBlockState[] paletteBlockStates(NBTTagList blockStatePalette) {
// private static BlockState[] paletteBlockStates(TagList blockStatePalette) {
IBlockState[] paletteBlockStates = new IBlockState[blockStatePalette.tagCount()]; IBlockState[] paletteBlockStates = new IBlockState[blockStatePalette.tagCount()];
//BlockState[] paletteBlockState = new BlockState[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")))); 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"); NBTTagCompound properties = ((NBTTagCompound) blockStatePalette.get(i)).getCompoundTag("Properties");
//CompoundTag properties = ((CompoundTag) blockStatePalette.get(i)).getCompound("Properties");
paletteBlockStates[i] = getBlockState(block, properties); paletteBlockStates[i] = getBlockState(block, properties);
} }
@ -173,16 +167,13 @@ public final class LitematicaSchematic extends StaticSchematic {
* @return A blockState. * @return A blockState.
*/ */
private static IBlockState getBlockState(Block block, NBTTagCompound properties) { private static IBlockState getBlockState(Block block, NBTTagCompound properties) {
//private static BlockState getBlockState(Block block, CompoundTag properties) {
IBlockState blockState = block.getDefaultState(); IBlockState blockState = block.getDefaultState();
//BlockState blockState = block.defaultBlockState();
for (Object key : properties.getKeySet().toArray()) { for (Object key : properties.getKeySet().toArray()) {
//for (Object key : properties.getAllKeys().toArray()) { IProperty<?> property = block.getBlockState().getProperty((String) key);
IProperty<?> property = block.getBlockState().getProperty(key.toString());
//Property<?> property = block.getStateDefinition().getProperty(key.toString());
if (property != null) { if (property != null) {
blockState = setPropertyValue(blockState, property, propertiesMap(properties).get(key)); blockState = setPropertyValue(blockState, property, properties.getString((String) key));
} }
} }
return blockState; return blockState;
@ -197,40 +188,20 @@ public final class LitematicaSchematic extends StaticSchematic {
* @param <T> . * @param <T> .
*/ */
private static <T extends Comparable<T>> IBlockState setPropertyValue(IBlockState state, IProperty<T> property, String value) { private static <T extends Comparable<T>> IBlockState setPropertyValue(IBlockState state, IProperty<T> property, String value) {
//private static <T extends Comparable<T>> BlockState setPropertyValue(BlockState state, Property<T> property, String value) {
Optional<T> parsed = property.parseValue(value).toJavaUtil(); Optional<T> parsed = property.parseValue(value).toJavaUtil();
//Optional<T> parsed = property.getValue(value);
if (parsed.isPresent()) { if (parsed.isPresent()) {
return state.withProperty(property, parsed.get()); return state.withProperty(property, parsed.get());
//return state.setValue(property, parsed.get());
} else { } else {
throw new IllegalArgumentException("Invalid value for property " + property); throw new IllegalArgumentException("Invalid value for property " + property);
} }
} }
/**
* @param properties properties a block has.
* @return properties as map.
*/
private static Map<String, String> propertiesMap(NBTTagCompound properties) {
//private static Map<String, String> propertiesMap(CompoundTag properties) {
Map<String, String> 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. * @param amountOfBlockTypes amount of block types in the schematic.
* @return amount of bits used to encode a block. * @return amount of bits used to encode a block.
*/ */
private static int bitsPerBlock(int amountOfBlockTypes) { 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(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; 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 */ /** LitematicaBitArray class from litematica */
private static class LitematicaBitArray private static class LitematicaBitArray
{ {