Atomic NBT List

This commit is contained in:
cyberpwn 2021-08-24 04:09:26 -04:00
parent 617066340b
commit 6dc3e74607
2 changed files with 11 additions and 3 deletions

View File

@ -58,6 +58,7 @@ public class Section {
putValueIndexedPalette(data, i); putValueIndexedPalette(data, i);
} }
palette.makeAtomic();
ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight"); ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight");
LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates"); LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates");
ByteArrayTag skyLight = sectionRoot.getByteArrayTag("SkyLight"); ByteArrayTag skyLight = sectionRoot.getByteArrayTag("SkyLight");
@ -171,9 +172,9 @@ public class Section {
* This option should only be used moderately to avoid unnecessary recalculation of the palette indices. * This option should only be used moderately to avoid unnecessary recalculation of the palette indices.
* Recalculating the Palette should only be executed once right before saving the Section to file. * Recalculating the Palette should only be executed once right before saving the Section to file.
*/ */
public synchronized void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) { public void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) {
int paletteSizeBefore = palette.size();
int paletteIndex = addToPalette(state); int paletteIndex = addToPalette(state);
int paletteSizeBefore = palette.size();
//power of 2 --> bits must increase, but only if the palette size changed //power of 2 --> bits must increase, but only if the palette size changed
//otherwise we would attempt to update all blockstates and the entire palette //otherwise we would attempt to update all blockstates and the entire palette
//every time an existing blockstate was added while having 2^x blockstates in the palette //every time an existing blockstate was added while having 2^x blockstates in the palette
@ -377,7 +378,7 @@ public class Section {
* @throws NullPointerException If <code>blockStates</code> is <code>null</code> * @throws NullPointerException If <code>blockStates</code> is <code>null</code>
* @throws IllegalArgumentException When <code>blockStates</code>' length is &lt; 256 or &gt; 4096 and is not a multiple of 64 * @throws IllegalArgumentException When <code>blockStates</code>' length is &lt; 256 or &gt; 4096 and is not a multiple of 64
*/ */
public synchronized void setBlockStates(AtomicLongArray blockStates) { public void setBlockStates(AtomicLongArray blockStates) {
if (blockStates == null) { if (blockStates == null) {
throw new NullPointerException("BlockStates cannot be null"); throw new NullPointerException("BlockStates cannot be null");
} else if (blockStates.length() % 64 != 0 || blockStates.length() < 256 || blockStates.length() > 4096) { } else if (blockStates.length() % 64 != 0 || blockStates.length() < 256 || blockStates.length() > 4096) {

View File

@ -22,6 +22,7 @@ import com.volmit.iris.engine.data.io.MaxDepthIO;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer; import java.util.function.Consumer;
/** /**
@ -42,6 +43,12 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
super(createEmptyValue(3)); super(createEmptyValue(3));
} }
public ListTag<T> makeAtomic()
{
setValue(new CopyOnWriteArrayList<>(getValue()));
return this;
}
@Override @Override
public byte getID() { public byte getID() {
return ID; return ID;