This commit is contained in:
cyberpwn
2021-09-08 08:46:25 -04:00
parent 0c8c7157f6
commit d25633e213
233 changed files with 5791 additions and 5553 deletions

View File

@@ -48,6 +48,16 @@ public class IrisMatter implements Matter {
this.sliceMap = new KMap<>();
}
private static KMap<Class<?>, MatterSlice<?>> buildSlicers() {
KMap<Class<?>, MatterSlice<?>> c = new KMap<>();
for (Object i : Iris.initialize("com.volmit.iris.util.matter.slices", Sliced.class)) {
MatterSlice<?> s = (MatterSlice<?>) i;
c.put(s.getType(), s);
}
return c;
}
@Override
public <T> MatterSlice<T> createSlice(Class<T> type, Matter m) {
MatterSlice<?> slice = slicers.get(type);
@@ -64,14 +74,4 @@ public class IrisMatter implements Matter {
return null;
}
private static KMap<Class<?>, MatterSlice<?>> buildSlicers() {
KMap<Class<?>, MatterSlice<?>> c = new KMap<>();
for (Object i : Iris.initialize("com.volmit.iris.util.matter.slices", Sliced.class)) {
MatterSlice<?> s = (MatterSlice<?>) i;
c.put(s.getType(), s);
}
return c;
}
}

View File

@@ -27,7 +27,14 @@ import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Entity;
import java.io.*;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
@@ -50,6 +57,51 @@ import java.util.function.Function;
public interface Matter {
int VERSION = 1;
static Matter read(File f) throws IOException, ClassNotFoundException {
FileInputStream in = new FileInputStream(f);
Matter m = read(in);
in.close();
return m;
}
static Matter read(InputStream in) throws IOException, ClassNotFoundException {
return read(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ()));
}
/**
* Reads the input stream into a matter object using a matter factory.
* Does not close the input stream. Be a man, close it yourself.
*
* @param in the input stream
* @param matterFactory the matter factory (size) -> new MatterImpl(size);
* @return the matter object
* @throws IOException shit happens yo
*/
static Matter read(InputStream in, Function<BlockPosition, Matter> matterFactory) throws IOException, ClassNotFoundException {
DataInputStream din = new DataInputStream(in);
Matter matter = matterFactory.apply(new BlockPosition(
Varint.readUnsignedVarInt(din),
Varint.readUnsignedVarInt(din),
Varint.readUnsignedVarInt(din)));
int sliceCount = din.readByte();
matter.getHeader().read(din);
while (sliceCount-- > 0) {
String cn = din.readUTF();
try {
Class<?> type = Class.forName(cn);
MatterSlice<?> slice = matter.createSlice(type, matter);
slice.read(din);
matter.putSlice(type, slice);
} catch (Throwable e) {
e.printStackTrace();
throw new IOException("Can't read class '" + cn + "' (slice count reverse at " + sliceCount + ")");
}
}
return matter;
}
/**
* Get the header information
*
@@ -313,51 +365,6 @@ public interface Matter {
}
}
static Matter read(File f) throws IOException, ClassNotFoundException {
FileInputStream in = new FileInputStream(f);
Matter m = read(in);
in.close();
return m;
}
static Matter read(InputStream in) throws IOException, ClassNotFoundException {
return read(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ()));
}
/**
* Reads the input stream into a matter object using a matter factory.
* Does not close the input stream. Be a man, close it yourself.
*
* @param in the input stream
* @param matterFactory the matter factory (size) -> new MatterImpl(size);
* @return the matter object
* @throws IOException shit happens yo
*/
static Matter read(InputStream in, Function<BlockPosition, Matter> matterFactory) throws IOException, ClassNotFoundException {
DataInputStream din = new DataInputStream(in);
Matter matter = matterFactory.apply(new BlockPosition(
Varint.readUnsignedVarInt(din),
Varint.readUnsignedVarInt(din),
Varint.readUnsignedVarInt(din)));
int sliceCount = din.readByte();
matter.getHeader().read(din);
while (sliceCount-- > 0) {
String cn = din.readUTF();
try {
Class<?> type = Class.forName(cn);
MatterSlice<?> slice = matter.createSlice(type, matter);
slice.read(din);
matter.putSlice(type, slice);
} catch (Throwable e) {
e.printStackTrace();
throw new IOException("Can't read class '" + cn + "' (slice count reverse at " + sliceCount + ")");
}
}
return matter;
}
default int getTotalCount() {
int m = 0;

View File

@@ -27,10 +27,6 @@ import java.io.IOException;
@Sliced
public class CavernMatter extends RawMatter<MatterCavern> {
public static MatterCavern get(String customBiome, int liquid) {
return new MatterCavern(true, customBiome, (byte) liquid);
}
public CavernMatter() {
this(1, 1, 1);
}
@@ -39,6 +35,10 @@ public class CavernMatter extends RawMatter<MatterCavern> {
super(width, height, depth, MatterCavern.class);
}
public static MatterCavern get(String customBiome, int liquid) {
return new MatterCavern(true, customBiome, (byte) liquid);
}
@Override
public void writeNode(MatterCavern b, DataOutputStream dos) throws IOException {
dos.writeBoolean(b.isCavern());

View File

@@ -27,10 +27,6 @@ import java.io.IOException;
@Sliced
public class FluidBodyMatter extends RawMatter<MatterFluidBody> {
public static MatterFluidBody get(String customBiome, boolean lava) {
return new MatterFluidBody(true, customBiome, lava);
}
public FluidBodyMatter() {
this(1, 1, 1);
}
@@ -39,6 +35,10 @@ public class FluidBodyMatter extends RawMatter<MatterFluidBody> {
super(width, height, depth, MatterFluidBody.class);
}
public static MatterFluidBody get(String customBiome, boolean lava) {
return new MatterFluidBody(true, customBiome, lava);
}
@Override
public void writeNode(MatterFluidBody b, DataOutputStream dos) throws IOException {
dos.writeBoolean(b.isBody());

View File

@@ -28,9 +28,9 @@ import java.io.IOException;
@Sliced
public class MarkerMatter extends RawMatter<MatterMarker> {
private static final KMap<String, MatterMarker> markers = new KMap<>();
public static final MatterMarker CAVE_FLOOR = new MatterMarker("cave_floor");
public static final MatterMarker CAVE_CEILING = new MatterMarker("cave_ceiling");
private static final KMap<String, MatterMarker> markers = new KMap<>();
public MarkerMatter() {
this(1, 1, 1);

View File

@@ -30,10 +30,10 @@ import java.io.DataOutputStream;
import java.io.IOException;
public abstract class RawMatter<T> extends MappedHunk<T> implements MatterSlice<T> {
@Getter
private final Class<T> type;
protected final KMap<Class<?>, MatterWriter<?, T>> writers;
protected final KMap<Class<?>, MatterReader<?, T>> readers;
@Getter
private final Class<T> type;
public RawMatter(int width, int height, int depth, Class<T> type) {
super(width, height, depth);