Fix palettes

This commit is contained in:
cyberpwn 2021-08-25 03:55:47 -04:00
parent 1dce68212f
commit ca228ca23e

View File

@ -27,7 +27,7 @@ import com.volmit.iris.util.nbt.tag.LongArrayTag;
public class Section {
private CompoundTag data;
private DataPaletteBlock<CompoundTag> palette;
private DataPaletteBlock palette;
private byte[] blockLight;
private byte[] skyLight;
private int dataVersion;
@ -43,7 +43,7 @@ public class Section {
if (rawPalette == null) {
return;
}
palette = new DataPaletteBlock<>();
palette = new DataPaletteBlock();
LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates");
palette.load((ListTag<CompoundTag>) rawPalette, blockStates.getValue());
ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight");
@ -74,8 +74,11 @@ public class Section {
* @return The block state data of this block.
*/
public synchronized CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) {
synchronized (palette)
{
return palette.getBlock(blockX&15, blockY&15, blockZ&15);
}
}
/**
* Attempts to add a block state for a specific block location in this Section.
@ -86,8 +89,11 @@ public class Section {
* @param state The block state to be set
*/
public synchronized void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) {
synchronized (palette)
{
palette.setBlock(blockX&15, blockY&15, blockZ&15, state);
}
}
/**
* This method recalculates the palette and its indices.
@ -145,7 +151,7 @@ public class Section {
*/
public static Section newSection() {
Section s = new Section();
s.palette = new DataPaletteBlock<>();
s.palette = new DataPaletteBlock();
s.data = new CompoundTag();
return s;
}
@ -162,8 +168,11 @@ public class Section {
data.putByte("Y", (byte) y);
if (palette != null) {
synchronized (palette)
{
palette.save(data, "Palette", "BlockStates");
}
}
if (blockLight != null) {
data.putByteArray("BlockLight", blockLight);
}