mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-12 02:36:05 +00:00
Mantle & Debugging
This commit is contained in:
@@ -24,6 +24,7 @@ import com.volmit.iris.util.data.Varint;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.BlockPosition;
|
||||
|
||||
import javax.xml.crypto.Data;
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -87,7 +88,7 @@ public interface Matter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a slice from the given type
|
||||
* Create a slice from the given type (full is false)
|
||||
*
|
||||
* @param type the type class
|
||||
* @param matter the matter this slice will go into (size provider)
|
||||
@@ -248,7 +249,7 @@ public interface Matter {
|
||||
Set<Class<?>> drop = null;
|
||||
|
||||
for (Class<?> i : getSliceTypes()) {
|
||||
if (getSlice(i).getCount() == 0) {
|
||||
if (getSlice(i).getEntryCount() == 0) {
|
||||
if (drop == null) {
|
||||
drop = new KSet<>();
|
||||
}
|
||||
@@ -272,8 +273,11 @@ public interface Matter {
|
||||
* @throws IOException shit happens yo
|
||||
*/
|
||||
default void write(OutputStream out) throws IOException {
|
||||
writeDos(new DataOutputStream(out));
|
||||
}
|
||||
|
||||
default void writeDos(DataOutputStream dos) throws IOException {
|
||||
trimSlices();
|
||||
DataOutputStream dos = new DataOutputStream(out);
|
||||
Varint.writeUnsignedVarInt(getWidth(), dos);
|
||||
Varint.writeUnsignedVarInt(getHeight(), dos);
|
||||
Varint.writeUnsignedVarInt(getDepth(), dos);
|
||||
@@ -283,8 +287,6 @@ public interface Matter {
|
||||
for (Class<?> i : getSliceTypes()) {
|
||||
getSlice(i).write(dos);
|
||||
}
|
||||
|
||||
dos.flush();
|
||||
}
|
||||
|
||||
static Matter read(File f) throws IOException, ClassNotFoundException {
|
||||
@@ -339,7 +341,7 @@ public interface Matter {
|
||||
|
||||
for(MatterSlice<?> i : getSliceMap().values())
|
||||
{
|
||||
m+= i.getCount();
|
||||
m+= i.getEntryCount();
|
||||
}
|
||||
|
||||
return m;
|
||||
|
||||
@@ -99,14 +99,6 @@ public interface MatterSlice<T> extends Hunk<T> {
|
||||
return true;
|
||||
}
|
||||
|
||||
// BlockMatter<T>
|
||||
// RawMatter<T> ex MappedHunk<T>
|
||||
// IMatterSlice<T> ex Hunk<T>
|
||||
|
||||
default int getCount() {
|
||||
return ((MappedHunk<?>) this).getEntryCount();
|
||||
}
|
||||
|
||||
default boolean canWrite(Class<?> mediumType) {
|
||||
return writeInto(mediumType) != null;
|
||||
}
|
||||
@@ -122,24 +114,41 @@ public interface MatterSlice<T> extends Hunk<T> {
|
||||
MatterPalette<T> palette = new MatterPalette<T>(this);
|
||||
iterateSync((x, y, z, b) -> palette.assign(b));
|
||||
palette.writePalette(dos);
|
||||
Varint.writeUnsignedVarInt(getCount(), dos);
|
||||
iterateSyncIO((x, y, z, b) -> {
|
||||
Varint.writeUnsignedVarInt(Cache.to1D(x, y, z, w, h), dos);
|
||||
palette.writeNode(b, dos);
|
||||
});
|
||||
dos.writeBoolean(isMapped());
|
||||
|
||||
if(isMapped())
|
||||
{
|
||||
Varint.writeUnsignedVarInt(getEntryCount(), dos);
|
||||
iterateSyncIO((x, y, z, b) -> {
|
||||
Varint.writeUnsignedVarInt(Cache.to1D(x, y, z, w, h), dos);
|
||||
palette.writeNode(b, dos);
|
||||
});
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
iterateSyncIO((x, y, z, b) -> palette.writeNode(b, dos));
|
||||
}
|
||||
}
|
||||
|
||||
default void read(DataInputStream din) throws IOException {
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
|
||||
MatterPalette<T> palette = new MatterPalette<T>(this, din);
|
||||
int nodes = Varint.readUnsignedVarInt(din);
|
||||
int[] pos;
|
||||
if(din.readBoolean())
|
||||
{
|
||||
int nodes = Varint.readUnsignedVarInt(din);
|
||||
int[] pos;
|
||||
|
||||
while (nodes-- > 0) {
|
||||
pos = Cache.to3D(Varint.readUnsignedVarInt(din), w, h);
|
||||
setRaw(pos[0], pos[1], pos[2], palette.readNode(din));
|
||||
while (nodes-- > 0) {
|
||||
pos = Cache.to3D(Varint.readUnsignedVarInt(din), w, h);
|
||||
setRaw(pos[0], pos[1], pos[2], palette.readNode(din));
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
iterateSyncIO((x, y, z, b) -> setRaw(x, y, z, palette.readNode(din)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,12 +38,10 @@ public class BlockMatter extends RawMatter<BlockData> {
|
||||
public BlockMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, BlockData.class);
|
||||
registerWriter(World.class, ((w, d, x, y, z) -> w.getBlockAt(x, y, z).setBlockData(d)));
|
||||
registerWriter(ParallaxWorld.class, (w, d, x, y, z) -> w.setBlock(x, y, z, d));
|
||||
registerReader(World.class, (w, x, y, z) -> {
|
||||
BlockData d = w.getBlockAt(x, y, z).getBlockData();
|
||||
return d.getMaterial().isAir() ? null : d;
|
||||
});
|
||||
registerReader(ParallaxWorld.class, ParallaxAccess::getBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user