Mantle fixes

This commit is contained in:
Daniel Mills
2021-08-08 03:44:25 -04:00
parent 1781ff36c6
commit 366c903f84
4 changed files with 119 additions and 3 deletions
@@ -18,6 +18,9 @@
package com.volmit.iris.util.mantle;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.matter.IrisMatter;
@@ -33,6 +36,7 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
* Mantle Chunks are fully atomic & thread safe
*/
public class MantleChunk {
private final KSet<String> flags;
private final AtomicReferenceArray<Matter> sections;
/**
@@ -43,6 +47,7 @@ public class MantleChunk {
@ChunkCoordinates
public MantleChunk(int sectionHeight) {
sections = new AtomicReferenceArray<>(sectionHeight);
flags = new KSet<>();
}
/**
@@ -55,7 +60,13 @@ public class MantleChunk {
*/
public MantleChunk(int sectionHeight, DataInputStream din) throws IOException, ClassNotFoundException {
this(sectionHeight);
int s = Varint.readUnsignedVarInt(din);
int s = din.readByte();
int f = din.readByte();
for(int i = 0; i < f; i++)
{
flags.add(din.readUTF());
}
for (int i = 0; i < s; i++) {
if (din.readBoolean()) {
@@ -64,6 +75,24 @@ public class MantleChunk {
}
}
public void flag(String s, boolean f)
{
if(f)
{
flags.add(s);
}
else
{
flags.remove(s);
}
}
public boolean isFlagged(String s)
{
return flags.contains(s);
}
/**
* Check if a section exists (same as get(section) != null)
*
@@ -130,7 +159,13 @@ public class MantleChunk {
* @throws IOException shit happens
*/
public void write(DataOutputStream dos) throws IOException {
Varint.writeUnsignedVarInt(sections.length(), dos);
dos.writeByte(sections.length());
dos.writeByte(flags.size());
for(String i : flags)
{
dos.writeUTF(i);
}
for (int i = 0; i < sections.length(); i++) {
if (exists(i)) {