This commit is contained in:
cyberpwn
2022-01-12 01:47:38 -05:00
parent 8c00499e76
commit 2dde426df6
463 changed files with 11845 additions and 10159 deletions

View File

@@ -44,8 +44,7 @@ public class IrisMatter extends IrisRegistrant implements Matter {
private final KMap<Class<?>, MatterSlice<?>> sliceMap;
public IrisMatter(int width, int height, int depth) {
if(width < 1 || height < 1 || depth < 1)
{
if(width < 1 || height < 1 || depth < 1) {
throw new RuntimeException("Invalid Matter Size " + width + "x" + height + "x" + depth);
}
@@ -58,7 +57,7 @@ public class IrisMatter extends IrisRegistrant implements Matter {
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)) {
for(Object i : Iris.initialize("com.volmit.iris.util.matter.slices", Sliced.class)) {
MatterSlice<?> s = (MatterSlice<?>) i;
c.put(s.getType(), s);
}
@@ -70,13 +69,13 @@ public class IrisMatter extends IrisRegistrant implements Matter {
public <T> MatterSlice<T> createSlice(Class<T> type, Matter m) {
MatterSlice<?> slice = slicers.get(type);
if (slice == null) {
if(slice == null) {
return null;
}
try {
return slice.getClass().getConstructor(int.class, int.class, int.class).newInstance(getWidth(), getHeight(), getDepth());
} catch (Throwable e) {
} catch(Throwable e) {
e.printStackTrace();
}

View File

@@ -22,7 +22,6 @@ import com.volmit.iris.Iris;
import com.volmit.iris.engine.object.IrisObject;
import com.volmit.iris.engine.object.IrisPosition;
import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.math.BlockPosition;
import org.bukkit.World;
@@ -66,13 +65,13 @@ public interface Matter {
BlockVector min = new BlockVector();
Matter m = new IrisMatter(object.getW(), object.getH(), object.getD());
for (BlockVector i : object.getBlocks().keySet()) {
for(BlockVector i : object.getBlocks().keySet()) {
min.setX(Math.min(min.getX(), i.getX()));
min.setY(Math.min(min.getY(), i.getY()));
min.setZ(Math.min(min.getZ(), i.getZ()));
}
for (BlockVector i : object.getBlocks().keySet()) {
for(BlockVector i : object.getBlocks().keySet()) {
m.slice(BlockData.class).set(i.getBlockX() - min.getBlockX(), i.getBlockY() - min.getBlockY(), i.getBlockZ() - min.getBlockZ(), object.getBlocks().get(i));
}
@@ -104,10 +103,13 @@ public interface Matter {
* 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);
* @param in
* the input stream
* @param matterFactory
* the matter factory (size) -> new MatterImpl(size);
* @return the matter object
* @throws IOException shit happens yo
* @throws IOException
* shit happens yo
*/
static Matter read(InputStream in, Function<BlockPosition, Matter> matterFactory) throws IOException, ClassNotFoundException {
return readDin(new DataInputStream(in), matterFactory);
@@ -115,9 +117,9 @@ public interface Matter {
static Matter readDin(DataInputStream din, Function<BlockPosition, Matter> matterFactory) throws IOException, ClassNotFoundException {
Matter matter = matterFactory.apply(new BlockPosition(
din.readInt(),
din.readInt(),
din.readInt()));
din.readInt(),
din.readInt(),
din.readInt()));
Iris.addPanic("read.matter.size", matter.getWidth() + "x" + matter.getHeight() + "x" + matter.getDepth());
int sliceCount = din.readByte();
Iris.addPanic("read.matter.slicecount", sliceCount + "");
@@ -125,8 +127,7 @@ public interface Matter {
matter.getHeader().read(din);
Iris.addPanic("read.matter.header", matter.getHeader().toString());
for(int i = 0; i < sliceCount; i++)
{
for(int i = 0; i < sliceCount; i++) {
Iris.addPanic("read.matter.slice", i + "");
String cn = din.readUTF();
Iris.addPanic("read.matter.slice.class", cn);
@@ -135,7 +136,7 @@ public interface Matter {
MatterSlice<?> slice = matter.createSlice(type, matter);
slice.read(din);
matter.putSlice(type, slice);
} catch (Throwable e) {
} catch(Throwable e) {
e.printStackTrace();
throw new IOException("Can't read class '" + cn + "' (slice count reverse at " + sliceCount + ")");
}
@@ -184,9 +185,12 @@ public interface Matter {
/**
* 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)
* @param <T> the type
* @param type
* the type class
* @param matter
* the matter this slice will go into (size provider)
* @param <T>
* the type
* @return the slice (or null if not supported)
*/
<T> MatterSlice<T> createSlice(Class<T> type, Matter matter);
@@ -230,8 +234,10 @@ public interface Matter {
/**
* Return the slice for the given type
*
* @param t the type class
* @param <T> the type
* @param t
* the type class
* @param <T>
* the type
* @return the slice or null
*/
default <T> MatterSlice<T> getSlice(Class<T> t) {
@@ -241,8 +247,10 @@ public interface Matter {
/**
* Delete the slice for the given type
*
* @param c the type class
* @param <T> the type
* @param c
* the type class
* @param <T>
* the type
* @return the deleted slice, or null if it diddn't exist
*/
default <T> MatterSlice<T> deleteSlice(Class<?> c) {
@@ -252,9 +260,12 @@ public interface Matter {
/**
* Put a given slice type
*
* @param c the slice type class
* @param slice the slice to assign to the type
* @param <T> the slice type
* @param c
* the slice type class
* @param slice
* the slice to assign to the type
* @param <T>
* the slice type
* @return the overwritten slice if there was an existing slice of that type
*/
default <T> MatterSlice<T> putSlice(Class<?> c, MatterSlice<T> slice) {
@@ -264,11 +275,11 @@ public interface Matter {
default Class<?> getClass(Object w) {
Class<?> c = w.getClass();
if (w instanceof World) {
if(w instanceof World) {
c = World.class;
} else if (w instanceof BlockData) {
} else if(w instanceof BlockData) {
c = BlockData.class;
} else if (w instanceof Entity) {
} else if(w instanceof Entity) {
c = Entity.class;
}
@@ -277,13 +288,13 @@ public interface Matter {
default <T> MatterSlice<T> slice(Class<?> c) {
MatterSlice<T> slice = (MatterSlice<T>) getSlice(c);
if (slice == null) {
if(slice == null) {
slice = (MatterSlice<T>) createSlice(c, this);
if (slice == null) {
if(slice == null) {
try {
throw new RuntimeException("Bad slice " + c.getCanonicalName());
} catch (Throwable e) {
} catch(Throwable e) {
e.printStackTrace();
}
@@ -299,9 +310,12 @@ public interface Matter {
/**
* Rotate a matter object into a new object
*
* @param x the x rotation (degrees)
* @param y the y rotation (degrees)
* @param z the z rotation (degrees)
* @param x
* the x rotation (degrees)
* @param y
* the y rotation (degrees)
* @param z
* the z rotation (degrees)
* @return the new rotated matter object
*/
default Matter rotate(double x, double y, double z) {
@@ -310,7 +324,7 @@ public interface Matter {
n.getHeader().setAuthor(getHeader().getAuthor());
n.getHeader().setCreatedAt(getHeader().getCreatedAt());
for (Class<?> i : getSliceTypes()) {
for(Class<?> i : getSliceTypes()) {
getSlice(i).rotateSliceInto(n, x, y, z);
}
@@ -320,7 +334,8 @@ public interface Matter {
/**
* Check if a slice exists for a given type
*
* @param c the slice class type
* @param c
* the slice class type
* @return true if it exists
*/
default boolean hasSlice(Class<?> c) {
@@ -362,9 +377,9 @@ public interface Matter {
default void trimSlices() {
Set<Class<?>> drop = null;
for (Class<?> i : getSliceTypes()) {
if (getSlice(i).getEntryCount() == 0) {
if (drop == null) {
for(Class<?> i : getSliceTypes()) {
if(getSlice(i).getEntryCount() == 0) {
if(drop == null) {
drop = new KSet<>();
}
@@ -372,8 +387,8 @@ public interface Matter {
}
}
if (drop != null) {
for (Class<?> i : drop) {
if(drop != null) {
for(Class<?> i : drop) {
deleteSlice(i);
}
}
@@ -383,8 +398,10 @@ public interface Matter {
* Writes the data to the output stream. The data will be flushed to the provided output
* stream however the provided stream will NOT BE CLOSED, so be sure to actually close it
*
* @param out the output stream
* @throws IOException shit happens yo
* @param out
* the output stream
* @throws IOException
* shit happens yo
*/
default void write(OutputStream out) throws IOException {
writeDos(new DataOutputStream(out));
@@ -398,7 +415,7 @@ public interface Matter {
dos.writeByte(getSliceTypes().size());
getHeader().write(dos);
for (Class<?> i : getSliceTypes()) {
for(Class<?> i : getSliceTypes()) {
getSlice(i).write(dos);
}
}
@@ -406,7 +423,7 @@ public interface Matter {
default int getTotalCount() {
int m = 0;
for (MatterSlice<?> i : getSliceMap().values()) {
for(MatterSlice<?> i : getSliceMap().values()) {
m += i.getEntryCount();
}

View File

@@ -18,7 +18,6 @@
package com.volmit.iris.util.matter;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.math.M;
import lombok.Data;

View File

@@ -34,7 +34,7 @@ public interface MatterPlacer {
}
default void set(int x, int y, int z, Matter matter) {
for (MatterSlice<?> i : matter.getSliceMap().values()) {
for(MatterSlice<?> i : matter.getSliceMap().values()) {
set(x, y, z, i);
}
}

View File

@@ -18,7 +18,6 @@
package com.volmit.iris.util.matter;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.data.palette.Palette;
@@ -85,11 +84,11 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
default Class<?> getClass(Object w) {
Class<?> c = w.getClass();
if (w instanceof World) {
if(w instanceof World) {
c = World.class;
} else if (w instanceof BlockData) {
} else if(w instanceof BlockData) {
c = BlockData.class;
} else if (w instanceof Entity) {
} else if(w instanceof Entity) {
c = Entity.class;
}
@@ -103,7 +102,7 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
default <W> boolean writeInto(W w, int x, int y, int z) {
MatterWriter<W, T> injector = (MatterWriter<W, T>) writeInto(getClass(w));
if (injector == null) {
if(injector == null) {
return false;
}
@@ -119,16 +118,16 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
default <W> boolean readFrom(W w, int x, int y, int z) {
MatterReader<W, T> ejector = (MatterReader<W, T>) readFrom(getClass(w));
if (ejector == null) {
if(ejector == null) {
return false;
}
for (int i = x; i < x + getWidth(); i++) {
for (int j = y; j < y + getHeight(); j++) {
for (int k = z; k < z + getDepth(); k++) {
for(int i = x; i < x + getWidth(); i++) {
for(int j = y; j < y + getHeight(); j++) {
for(int k = z; k < z + getDepth(); k++) {
T v = ejector.readMatter(w, i, j, k);
if (v != null) {
if(v != null) {
set(i - x, j - y, k - z, v);
}
}
@@ -148,8 +147,8 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
default int getBitsPer(int needed) {
int target = 1;
for (int i = 1; i < 8; i++) {
if (Math.pow(2, i) > needed) {
for(int i = 1; i < 8; i++) {
if(Math.pow(2, i) > needed) {
target = i;
break;
}
@@ -161,7 +160,7 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
default void write(DataOutputStream dos) throws IOException {
dos.writeUTF(getType().getCanonicalName());
if ((this instanceof PaletteOrHunk f && f.isPalette())) {
if((this instanceof PaletteOrHunk f && f.isPalette())) {
f.palette().writeDos(dos);
return;
}
@@ -173,7 +172,7 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
palette.writePalette(dos);
dos.writeBoolean(isMapped());
if (isMapped()) {
if(isMapped()) {
Varint.writeUnsignedVarInt(getEntryCount(), dos);
iterateSyncIO((x, y, z, b) -> {
Varint.writeUnsignedVarInt(Cache.to1D(x, y, z, w, h), dos);
@@ -185,7 +184,7 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
}
default void read(DataInputStream din) throws IOException {
if ((this instanceof PaletteOrHunk f && f.isPalette())) {
if((this instanceof PaletteOrHunk f && f.isPalette())) {
f.setPalette(new DataContainer<>(din, this));
return;
}
@@ -193,11 +192,11 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
int w = getWidth();
int h = getHeight();
MatterPalette<T> palette = new MatterPalette<T>(this, din);
if (din.readBoolean()) {
if(din.readBoolean()) {
int nodes = Varint.readUnsignedVarInt(din);
int[] pos;
while (nodes-- > 0) {
while(nodes-- > 0) {
pos = Cache.to3D(Varint.readUnsignedVarInt(din), w, h);
setRaw(pos[0], pos[1], pos[2], palette.readNode(din));
}

View File

@@ -25,15 +25,15 @@ import org.bukkit.block.data.BlockData;
public class WorldMatter {
public static void placeMatter(Matter matter, Location at) {
if (matter.hasSlice(BlockData.class)) {
if(matter.hasSlice(BlockData.class)) {
matter.slice(BlockData.class).writeInto(at);
}
if (matter.hasSlice(MatterEntityGroup.class)) {
if(matter.hasSlice(MatterEntityGroup.class)) {
matter.slice(MatterEntityGroup.class).writeInto(at);
}
if (matter.hasSlice(MatterTile.class)) {
if(matter.hasSlice(MatterTile.class)) {
matter.slice(MatterTile.class).writeInto(at);
}
}

View File

@@ -18,7 +18,6 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.B;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.Bukkit;

View File

@@ -56,7 +56,7 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
public EntityMatter(int width, int height, int depth) {
super(width, height, depth, MatterEntityGroup.class);
registerWriter(World.class, ((w, d, x, y, z) -> {
for (MatterEntity i : d.getEntities()) {
for(MatterEntity i : d.getEntities()) {
Location realPosition = new Location(w, x + i.getXOff(), y + i.getYOff(), z + i.getZOff());
INMS.get().deserializeEntity(i.getEntityData(), realPosition);
}
@@ -65,13 +65,13 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
IrisPosition pos = new IrisPosition(x, y, z);
KList<Entity> entities = entityCache.get(pos);
MatterEntityGroup g = new MatterEntityGroup();
if (entities != null) {
for (Entity i : entities) {
if(entities != null) {
for(Entity i : entities) {
g.getEntities().add(new MatterEntity(
Math.abs(i.getLocation().getX()) - Math.abs(i.getLocation().getBlockX()),
Math.abs(i.getLocation().getY()) - Math.abs(i.getLocation().getBlockY()),
Math.abs(i.getLocation().getZ()) - Math.abs(i.getLocation().getBlockZ()),
INMS.get().serializeEntity(i)
Math.abs(i.getLocation().getX()) - Math.abs(i.getLocation().getBlockX()),
Math.abs(i.getLocation().getY()) - Math.abs(i.getLocation().getBlockY()),
Math.abs(i.getLocation().getZ()) - Math.abs(i.getLocation().getBlockZ()),
INMS.get().serializeEntity(i)
));
}
@@ -88,36 +88,41 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
* block position with a list of entities within that block, and directly feed
* the reader with the entities we capture.
*
* @param w the world
* @param x the x offset
* @param y the y offset
* @param z the z offset
* @param <W> the type
* @param w
* the world
* @param x
* the x offset
* @param y
* the y offset
* @param z
* the z offset
* @param <W>
* the type
* @return true if we read
*/
@Override
public synchronized <W> boolean readFrom(W w, int x, int y, int z) {
if (!(w instanceof World)) {
if(!(w instanceof World)) {
return super.readFrom(w, x, y, z);
}
MatterReader<W, MatterEntityGroup> reader = (MatterReader<W, MatterEntityGroup>) readFrom(World.class);
if (reader == null) {
if(reader == null) {
return false;
}
entityCache = new KMap<>();
for (Entity i : ((World) w).getNearbyEntities(new BoundingBox(x, y, z, x + getWidth(), y + getHeight(), z + getHeight()))) {
for(Entity i : ((World) w).getNearbyEntities(new BoundingBox(x, y, z, x + getWidth(), y + getHeight(), z + getHeight()))) {
entityCache.computeIfAbsent(new IrisPosition(i.getLocation()),
k -> new KList<>()).add(i);
k -> new KList<>()).add(i);
}
for (IrisPosition i : entityCache.keySet()) {
for(IrisPosition i : entityCache.keySet()) {
MatterEntityGroup g = reader.readMatter(w, i.getX(), i.getY(), i.getZ());
if (g != null) {
if(g != null) {
set(i.getX() - x, i.getY() - y, i.getZ() - z, g);
}
}
@@ -130,7 +135,7 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
@Override
public void writeNode(MatterEntityGroup b, DataOutputStream dos) throws IOException {
Varint.writeUnsignedVarInt(b.getEntities().size(), dos);
for (MatterEntity i : b.getEntities()) {
for(MatterEntity i : b.getEntities()) {
dos.writeByte((int) (i.getXOff() * 255) + Byte.MIN_VALUE);
dos.writeByte((int) (i.getYOff() * 255) + Byte.MIN_VALUE);
dos.writeByte((int) (i.getZOff() * 255) + Byte.MIN_VALUE);
@@ -143,12 +148,12 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
MatterEntityGroup g = new MatterEntityGroup();
int c = Varint.readUnsignedVarInt(din);
while (c-- > 0) {
while(c-- > 0) {
g.getEntities().add(new MatterEntity(
((int) din.readByte() - Byte.MIN_VALUE) / 255F,
((int) din.readByte() - Byte.MIN_VALUE) / 255F,
((int) din.readByte() - Byte.MIN_VALUE) / 255F,
(CompoundTag) NBTUtil.read(din, false).getTag()));
((int) din.readByte() - Byte.MIN_VALUE) / 255F,
((int) din.readByte() - Byte.MIN_VALUE) / 255F,
((int) din.readByte() - Byte.MIN_VALUE) / 255F,
(CompoundTag) NBTUtil.read(din, false).getTag()));
}
return g;

View File

@@ -49,10 +49,10 @@ public class TileMatter extends RawMatter<MatterTile> {
registerWriter(World.class, ((w, d, x, y, z) -> INMS.get().deserializeTile(d.getTileData(), new Location(w, x, y, z))));
registerReader(World.class, (w, x, y, z) -> {
Location l = new Location(w, x, y, z);
if (INMS.get().hasTile(l)) {
if(INMS.get().hasTile(l)) {
CompoundTag tag = INMS.get().serializeTile(l);
if (tag != null) {
if(tag != null) {
return new MatterTile(tag);
}
}