This commit is contained in:
cyberpwn 2021-09-23 21:23:38 -04:00
parent 5078becbb3
commit bf2da499d6
30 changed files with 152 additions and 406 deletions

View File

@ -29,7 +29,6 @@ import com.volmit.iris.engine.object.annotations.Snippet;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.MatterFluidBody;
import com.volmit.iris.util.matter.slices.FluidBodyMatter;
import com.volmit.iris.util.noise.CNG;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -66,46 +65,6 @@ public class IrisLake implements IRare {
}
public void generate(MantleWriter writer, RNG rng, Engine engine, int x, int y, int z) {
KList<IrisPosition> pos = getWorm().generate(rng, engine.getData(), writer, null, x, y, z, (at) -> {
});
CNG dg = depthStyle.getGenerator().createNoCache(rng, engine.getData());
CNG bw = widthStyle.getGenerator().createNoCache(rng, engine.getData());
IrisPosition avg;
double ax = 0;
double ay = 0;
double az = 0;
double[] surfaces = new double[pos.size()];
int i = 0;
for (IrisPosition p : pos) {
surfaces[i] = engine.getComplex().getHeightStream().get(x, z);
ax += p.getX();
ay += surfaces[i];
az += p.getZ();
i++;
}
avg = new IrisPosition(ax / pos.size(), ay / pos.size(), az / pos.size());
MatterFluidBody body = FluidBodyMatter.get(customBiome, false);
i = 0;
for (IrisPosition p : pos) {
double surface = surfaces[i];
double depth = dg.fitDouble(depthStyle.getMin(), depthStyle.getMax(), p.getX(), p.getZ()) + (surface - avg.getY());
double width = bw.fitDouble(widthStyle.getMin(), widthStyle.getMax(), p.getX(), p.getZ());
if (depth > 1) {
writer.setElipsoidFunction(p.getX(), avg.getY(), p.getZ(), width, depth, width, true, (xx, yy, zz) -> {
if (yy > avg.getY()) {
return null;
}
return body;
});
}
i++;
}
}
}

View File

@ -29,7 +29,6 @@ import com.volmit.iris.engine.object.annotations.Snippet;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.MatterFluidBody;
import com.volmit.iris.util.matter.slices.FluidBodyMatter;
import com.volmit.iris.util.noise.CNG;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -69,46 +68,6 @@ public class IrisRiver implements IRare {
}
public void generate(MantleWriter writer, RNG rng, Engine engine, int x, int y, int z) {
KList<IrisPosition> pos = getWorm().generate(rng, engine.getData(), writer, null, x, y, z, (at) -> {
});
CNG dg = depthStyle.getGenerator().createNoCache(rng, engine.getData());
CNG bw = widthStyle.getGenerator().createNoCache(rng, engine.getData());
IrisPosition avg;
double ax = 0;
double ay = 0;
double az = 0;
double[] surfaces = new double[pos.size()];
int i = 0;
for (IrisPosition p : pos) {
surfaces[i] = engine.getComplex().getHeightStream().get(x, z);
ax += p.getX();
ay += surfaces[i];
az += p.getZ();
i++;
}
avg = new IrisPosition(ax / pos.size(), ay / pos.size(), az / pos.size());
MatterFluidBody body = FluidBodyMatter.get(customBiome, false);
i = 0;
for (IrisPosition p : pos) {
double surface = surfaces[i];
double depth = dg.fitDouble(depthStyle.getMin(), depthStyle.getMax(), p.getX(), p.getZ()) + (surface - avg.getY());
double width = bw.fitDouble(widthStyle.getMin(), widthStyle.getMax(), p.getX(), p.getZ());
if (depth > 1) {
writer.setElipsoidFunction(p.getX(), avg.getY(), p.getZ(), width, depth, width, true, (xx, yy, zz) -> {
if (yy > avg.getY()) {
return null;
}
return body;
});
}
i++;
}
}
}

View File

@ -18,6 +18,7 @@
package com.volmit.iris.util.hunk.bits;
import com.volmit.iris.Iris;
import com.volmit.iris.util.data.Varint;
import org.apache.commons.lang3.Validate;
@ -66,7 +67,7 @@ public class DataBits {
public DataBits(int bits, int length, DataInputStream din) throws IOException
{
this(bits, length, longs(din, (length + ((char) (64 / bits)) - 1) / ((char) (64 / bits))));
this(bits, length, longs(din));
}
public DataBits(int bits, int length, AtomicLongArray data) {
@ -80,10 +81,11 @@ public class DataBits {
this.divideAdd = MAGIC[var3 + 1];
this.divideShift = MAGIC[var3 + 2];
int var4 = (length + valuesPerLong - 1) / valuesPerLong;
if (data != null) {
if (data.length() != var4)
{
throw new RuntimeException("NO!");
throw new RuntimeException("NO! Trying to load " + data.length() + " into actual size of " + var4 + " because length: " + length + " (bits: " + bits + ")");
}
this.data = data;
} else {
@ -91,10 +93,20 @@ public class DataBits {
}
}
private static AtomicLongArray longs(DataInputStream din, int len) throws IOException{
AtomicLongArray a = new AtomicLongArray(len);
public String toString()
{
return "DBits: " + size + "/" + bits + "[" + data.length() + "]";
}
for(int i = 0; i < len; i++)
private static int dataLength(int bits, int length)
{
return (length + ((char) (64 / bits)) - 1) / ((char) (64 / bits));
}
private static AtomicLongArray longs(DataInputStream din) throws IOException{
AtomicLongArray a = new AtomicLongArray(din.readInt());
for(int i = 0; i < a.length(); i++)
{
a.set(i, din.readLong());
}
@ -108,7 +120,12 @@ public class DataBits {
{
DataBits newData = new DataBits(newBits, size);
AtomicInteger c = new AtomicInteger(0);
getAll((i) -> newData.set(c.incrementAndGet(), i));
for(int i = 0; i < size; i++)
{
newData.set(i, get(i));
}
return newData;
}
@ -181,7 +198,7 @@ public class DataBits {
}
public void write(DataOutputStream dos) throws IOException {
dos.writeByte(bits);
dos.writeInt(data.length());
for(int i = 0; i < data.length(); i++)
{

View File

@ -18,13 +18,13 @@
package com.volmit.iris.util.hunk.bits;
import com.volmit.iris.Iris;
import com.volmit.iris.util.data.Varint;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@ -40,13 +40,27 @@ public class DataContainer<T> {
private final int length;
private final Writable<T> writer;
public DataContainer(Writable<T> writer, int length)
public DataContainer(Writable<T> writer, int length, T empty)
{
this.writer = writer;
this.length = length;
this.palette = new AtomicReference<>(newPalette(INITIAL_BITS));
this.data = new AtomicReference<>(new DataBits(INITIAL_BITS, length));
this.bits = new AtomicInteger(INITIAL_BITS);
this.data = new AtomicReference<>(new DataBits(INITIAL_BITS, length));
this.palette = new AtomicReference<>(newPalette(INITIAL_BITS));
this.ensurePaletted(empty);
}
public DataContainer(DataInputStream din, Writable<T> writer) throws IOException {
this.writer = writer;
this.length = din.readInt();
this.palette = new AtomicReference<>(newPalette(din));
this.data = new AtomicReference<>(new DataBits(palette.get().bits(), length, din));
this.bits = new AtomicInteger(palette.get().bits());
}
public String toString(){
return "DataContainer <" + length + " x " + bits + " bits> -> Palette<"+palette.get().getClass().getSimpleName().replaceAll("\\QPalette\\E", "")+">: " + palette.get().size() +
" " + data.get().toString() + " PalBit: " + palette.get().bits();
}
public byte[] write() throws IOException
@ -56,33 +70,25 @@ public class DataContainer<T> {
return boas.toByteArray();
}
public static <T> DataContainer<T> read(InputStream in, Writable<T> writer) throws IOException {
DataInputStream din = new DataInputStream(in);
return readDin(din, writer);
}
public static <T> DataContainer<T> readDin(DataInputStream in, Writable<T> writer) throws IOException {
DataInputStream din = new DataInputStream(in);
DataContainer<T> container = new DataContainer<>(writer, Varint.readUnsignedVarInt(din));
int paletteSize = Varint.readUnsignedVarInt(din);
container.palette.set(container.newPalette(BIT[paletteSize]).from(paletteSize, writer, din));
container.data.set(new DataBits(container.palette.get().bits(), container.length, din));
return container;
}
public void write(OutputStream out) throws IOException
{
DataOutputStream dos = new DataOutputStream(out);
writeDos(dos);
writeDos(new DataOutputStream(out));
}
public void writeDos(DataOutputStream out) throws IOException
public void writeDos(DataOutputStream dos) throws IOException
{
DataOutputStream dos = new DataOutputStream(out);
Varint.writeUnsignedVarInt(length);
Varint.writeUnsignedVarInt(palette.get().size());
dos.writeInt(length);
dos.writeInt(palette.get().size());
palette.get().iterateIO((data, __) -> writer.writeNodeData(dos, data));
data.get().write(dos);
dos.flush();
}
private Palette<T> newPalette(DataInputStream din) throws IOException {
int paletteSize = din.readInt();
Palette<T> d = newPalette(bits(paletteSize));
d.from(paletteSize, writer, din);
return d;
}
private Palette<T> newPalette(int bits)
@ -95,12 +101,29 @@ public class DataContainer<T> {
return new HashPalette<>();
}
private void checkBits()
{
if(palette.get().size() >= BIT[bits.get()])
{
setBits(bits.get() + 1);
}
}
public void ensurePaletted(T t)
{
if(palette.get().id(t) == -1)
{
checkBits();
}
}
public void set(int position, T t)
{
int id = palette.get().id(t);
if(id == -1)
{
checkBits();
id = palette.get().add(t);
}
@ -109,7 +132,7 @@ public class DataContainer<T> {
public T get(int position)
{
int id = data.get().get(position);
int id = data.get().get(position)+1;
if(id <= 0)
{
@ -143,4 +166,22 @@ public class DataContainer<T> {
return m;
}
protected static int bits(int size)
{
if(DataContainer.BIT[INITIAL_BITS] >= size)
{
return INITIAL_BITS;
}
for(int i = 0; i < DataContainer.BIT.length; i++)
{
if(DataContainer.BIT[i] >= size)
{
return i;
}
}
return DataContainer.BIT.length - 1;
}
}

View File

@ -18,20 +18,22 @@
package com.volmit.iris.util.hunk.bits;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.function.Consumer2;
import java.util.LinkedHashMap;
import java.util.concurrent.atomic.AtomicInteger;
public class HashPalette<T> implements Palette<T> {
private final KMap<T, Integer> palette;
private final LinkedHashMap<T, Integer> palette;
private final KMap<Integer, T> lookup;
private final AtomicInteger size;
public HashPalette()
{
this.size = new AtomicInteger(0);
this.palette = new KMap<>();
this.palette = new LinkedHashMap<>();
this.lookup = new KMap<>();
}
@ -49,7 +51,12 @@ public class HashPalette<T> implements Palette<T> {
public int add(T t) {
int index = size.getAndIncrement();
palette.put(t, index);
if(t != null)
{
lookup.put(index, t);
}
return index;
}

View File

@ -70,7 +70,12 @@ public class LinearPalette<T> implements Palette<T> {
public int id(T t) {
for(int i = 0; i < size(); i++)
{
if(t.equals(palette.get().get(i)))
if(t == null && palette.get().get(i) == null)
{
return i;
}
if(t != null && t.equals(palette.get().get(i)))
{
return i;
}

View File

@ -18,6 +18,7 @@
package com.volmit.iris.util.hunk.bits;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.function.Consumer2;
import com.volmit.iris.util.function.Consumer2IO;
@ -35,25 +36,7 @@ public interface Palette<T> {
default int bits()
{
return bits(DataContainer.INITIAL_BITS);
}
default int bits(int minBits)
{
if(size() <= DataContainer.BIT[minBits])
{
return minBits;
}
for(int i = 0; i < DataContainer.BIT.length; i++)
{
if(DataContainer.BIT[i] >= size())
{
return i;
}
}
return DataContainer.BIT.length - 1;
return DataContainer.bits(size());
}
void iterate(Consumer2<T, Integer> c);
@ -83,4 +66,11 @@ public interface Palette<T> {
oldPalette.iterate((k,v) -> add(k));
return this;
}
default KList<T> list()
{
KList<T> t = new KList<>();
iterate((tx, __) -> t.add(tx));
return t;
}
}

View File

@ -37,12 +37,11 @@ import java.util.Map;
public class PaletteHunk<T> extends StorageHunk<T> implements Hunk<T> {
private DataContainer<T> data;
public PaletteHunk(int w, int h, int d, Writable<T> writer) {
public PaletteHunk(int w, int h, int d, Writable<T> writer, T e) {
super(w,h,d);
data = new DataContainer<>(writer, w * h * d);
data = new DataContainer<>(writer, w * h * d, e);
}
public void setPalette(DataContainer<T> c) {
data = c;
}

View File

@ -31,9 +31,9 @@ import java.util.function.Supplier;
public abstract class PaletteOrHunk<T> extends StorageHunk<T> implements Hunk<T>, Writable<T> {
private final Hunk<T> hunk;
public PaletteOrHunk(int width, int height, int depth, boolean allow, Supplier<Hunk<T>> factory) {
public PaletteOrHunk(int width, int height, int depth, boolean allow, Supplier<Hunk<T>> factory, T e) {
super(width, height, depth);
hunk = (allow) ? new PaletteHunk<>(width, height, depth, this) : factory.get();
hunk = (allow) ? new PaletteHunk<>(width, height, depth, this, e) : factory.get();
}
public DataContainer<T> palette()

View File

@ -191,7 +191,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()))
{
f.setPalette(DataContainer.readDin(din, this));
f.setPalette(new DataContainer<>(din, this));
return;
}

View File

@ -19,67 +19,20 @@
package com.volmit.iris.util.matter;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.object.NoiseStyle;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.data.palette.PalettedContainer;
import com.volmit.iris.util.hunk.bits.DataContainer;
import com.volmit.iris.util.hunk.bits.Writable;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.noise.CNG;
import org.checkerframework.checker.units.qual.K;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class MatterTest {
public static void test()
{
try
{
CNG cng = NoiseStyle.STATIC.create(new RNG(1337));
Writable<Integer> ffs = new Writable<Integer>() {
@Override
public Integer readNodeData(DataInputStream din) throws IOException {
return din.readInt();
}
@Override
public void writeNodeData(DataOutputStream dos, Integer integer) throws IOException {
dos.writeInt(integer);
}
};
DataContainer<Integer> p = new DataContainer<>(ffs, 32);
for(int i = 0; i < 32; i++)
{
p.set(i,cng.fit(1, 7, i, i * 2));
}
byte[] dat = p.write();
Iris.info("RAW DATA: " + IO.bytesToHex(dat));
DataContainer<Integer> f = DataContainer.read(new ByteArrayInputStream(dat), ffs);
byte[] d2 = f.write();
if(Arrays.equals(dat, d2))
{
Iris.info("Correct! All data matches!");
}
else
{
Iris.warn("No match");
Iris.error("RAW DATA: " + IO.bytesToHex(d2));
}
}
catch(Throwable e)
{
e.printStackTrace();
}
}
}

View File

@ -1,40 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.engine.object.IrisBiome;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.entity.Player;
@Sliced
public class BiomeMatter extends RegistryMatter<IrisBiome> {
public BiomeMatter() {
this(1, 1, 1);
}
@Override
public Palette<IrisBiome> getGlobalPalette() {
return null;
}
public BiomeMatter(int width, int height, int depth) {
super(width, height, depth, IrisBiome.class);
}
}

View File

@ -21,6 +21,7 @@ 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.Material;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
@ -31,6 +32,8 @@ import java.io.IOException;
@Sliced
public class BlockMatter extends RawMatter<BlockData> {
public static final BlockData AIR = Material.AIR.createBlockData();
public BlockMatter() {
this(1, 1, 1);
}
@ -41,7 +44,7 @@ public class BlockMatter extends RawMatter<BlockData> {
}
public BlockMatter(int width, int height, int depth) {
super(width, height, depth, BlockData.class);
super(width, height, depth, BlockData.class, AIR);
registerWriter(World.class, ((w, d, x, y, z) -> w.getBlockAt(x, y, z).setBlockData(d)));
registerReader(World.class, (w, x, y, z) -> {
BlockData d = w.getBlockAt(x, y, z).getBlockData();

View File

@ -38,7 +38,7 @@ public class BooleanMatter extends RawMatter<Boolean> {
}
public BooleanMatter(int width, int height, int depth) {
super(width, height, depth, Boolean.class);
super(width, height, depth, Boolean.class, false);
}
@Override

View File

@ -29,6 +29,8 @@ import java.io.IOException;
@Sliced
public class CavernMatter extends RawMatter<MatterCavern> {
public static final MatterCavern EMPTY = new MatterCavern(false, "", (byte) 0);
public CavernMatter() {
this(1, 1, 1);
}
@ -39,7 +41,7 @@ public class CavernMatter extends RawMatter<MatterCavern> {
}
public CavernMatter(int width, int height, int depth) {
super(width, height, depth, MatterCavern.class);
super(width, height, depth, MatterCavern.class, EMPTY);
}
public static MatterCavern get(String customBiome, int liquid) {

View File

@ -23,11 +23,13 @@ import com.volmit.iris.util.nbt.tag.CompoundTag;
@Sliced
public class CompoundMatter extends NBTMatter<CompoundTag> {
public static final CompoundTag EMPTY = new CompoundTag();
public CompoundMatter() {
this(1, 1, 1);
}
public CompoundMatter(int width, int height, int depth) {
super(width, height, depth, CompoundTag.class);
super(width, height, depth, CompoundTag.class, EMPTY);
}
}

View File

@ -42,6 +42,7 @@ import java.io.IOException;
@Sliced
public class EntityMatter extends RawMatter<MatterEntityGroup> {
public static final MatterEntityGroup EMPTY = new MatterEntityGroup();
private transient KMap<IrisPosition, KList<Entity>> entityCache = new KMap<>();
public EntityMatter() {
@ -54,7 +55,7 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
}
public EntityMatter(int width, int height, int depth) {
super(width, height, depth, MatterEntityGroup.class);
super(width, height, depth, MatterEntityGroup.class, EMPTY);
registerWriter(World.class, ((w, d, x, y, z) -> {
for (MatterEntity i : d.getEntities()) {
Location realPosition = new Location(w, x + i.getXOff(), y + i.getYOff(), z + i.getZOff());

View File

@ -1,64 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.MatterFluidBody;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.entity.Player;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class FluidBodyMatter extends RawMatter<MatterFluidBody> {
public FluidBodyMatter() {
this(1, 1, 1);
}
@Override
public Palette<MatterFluidBody> getGlobalPalette() {
return null;
}
public FluidBodyMatter(int width, int height, int depth) {
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());
dos.writeBoolean(b.isLava());
dos.writeUTF(b.getCustomBiome());
}
@Override
public MatterFluidBody readNode(DataInputStream din) throws IOException {
boolean b = din.readBoolean();
boolean l = din.readBoolean();
String v = din.readUTF();
return new MatterFluidBody(b, v, l);
}
}

View File

@ -39,7 +39,7 @@ public class IntMatter extends RawMatter<Integer> {
}
public IntMatter(int width, int height, int depth) {
super(width, height, depth, Integer.class);
super(width, height, depth, Integer.class, 0);
}
@Override

View File

@ -39,7 +39,7 @@ public class LongMatter extends RawMatter<Long> {
}
public LongMatter(int width, int height, int depth) {
super(width, height, depth, Long.class);
super(width, height, depth, Long.class, 0L);
}
@Override

View File

@ -30,6 +30,7 @@ import java.io.IOException;
@Sliced
public class MarkerMatter extends RawMatter<MatterMarker> {
public static final MatterMarker NONE = new MatterMarker("none");
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<>();
@ -44,7 +45,7 @@ public class MarkerMatter extends RawMatter<MatterMarker> {
}
public MarkerMatter(int width, int height, int depth) {
super(width, height, depth, MatterMarker.class);
super(width, height, depth, MatterMarker.class, NONE);
}
@Override

View File

@ -20,6 +20,8 @@ package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.nbt.tag.IntTag;
import com.volmit.iris.util.nbt.tag.Tag;
import org.bukkit.entity.Player;
@ -28,8 +30,8 @@ import java.io.DataOutputStream;
import java.io.IOException;
public class NBTMatter<T extends Tag<?>> extends RawMatter<T> {
public NBTMatter(int width, int height, int depth, Class<T> c) {
super(width, height, depth, c);
public NBTMatter(int width, int height, int depth, Class<T> c, T e) {
super(width, height, depth, c, e);
}
@Override

View File

@ -1,60 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.MatterTile;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.UUID;
@Sliced
public class PlayerMatter extends RawMatter<Player> {
public PlayerMatter() {
this(1, 1, 1);
}
@Override
public Palette<Player> getGlobalPalette() {
return null;
}
public PlayerMatter(int width, int height, int depth) {
super(width, height, depth, Player.class);
}
@Override
public void writeNode(Player b, DataOutputStream dos) throws IOException {
Varint.writeSignedVarLong(b.getUniqueId().getMostSignificantBits(), dos);
Varint.writeSignedVarLong(b.getUniqueId().getLeastSignificantBits(), dos);
}
@Override
public Player readNode(DataInputStream din) throws IOException {
UUID id = new UUID(Varint.readSignedVarLong(din), Varint.readSignedVarLong(din));
return Bukkit.getPlayer(id);
}
}

View File

@ -37,8 +37,8 @@ public abstract class RawMatter<T> extends PaletteOrHunk<T> implements MatterSli
@Getter
private final Class<T> type;
public RawMatter(int width, int height, int depth, Class<T> type) {
super(width, height, depth, false, () -> new MappedHunk<>(width, height, depth));
public RawMatter(int width, int height, int depth, Class<T> type, T e) {
super(width, height, depth, false, () -> new MappedHunk<>(width, height, depth), e);
writers = new KMap<>();
readers = new KMap<>();
this.type = type;

View File

@ -1,33 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.core.loader.IrisRegistrant;
import com.volmit.iris.util.matter.Sliced;
@Sliced
public class RegionMatter extends RegistryMatter<IrisRegistrant> {
public RegionMatter() {
this(1, 1, 1);
}
public RegionMatter(int width, int height, int depth) {
super(width, height, depth, IrisRegistrant.class);
}
}

View File

@ -28,8 +28,8 @@ import java.io.DataOutputStream;
import java.io.IOException;
public class RegistryMatter<T extends IrisRegistrant> extends RawMatter<T> {
public RegistryMatter(int width, int height, int depth, Class<T> c) {
super(width, height, depth, c);
public RegistryMatter(int width, int height, int depth, Class<T> c, T e) {
super(width, height, depth, c, e);
}
@Override

View File

@ -28,6 +28,6 @@ public class SpawnerMatter extends RegistryMatter<IrisSpawner> {
}
public SpawnerMatter(int width, int height, int depth) {
super(width, height, depth, IrisSpawner.class);
super(width, height, depth, IrisSpawner.class, new IrisSpawner());
}
}

View File

@ -32,7 +32,7 @@ public class StringMatter extends RawMatter<String> {
}
public StringMatter(int width, int height, int depth) {
super(width, height, depth, String.class);
super(width, height, depth, String.class, "");
}
@Override

View File

@ -33,6 +33,8 @@ import java.io.IOException;
@Sliced
public class TileMatter extends RawMatter<MatterTile> {
public static final MatterTile EMPTY = new MatterTile(new CompoundTag());
public TileMatter() {
this(1, 1, 1);
}
@ -43,7 +45,7 @@ public class TileMatter extends RawMatter<MatterTile> {
}
public TileMatter(int width, int height, int depth) {
super(width, height, depth, MatterTile.class);
super(width, height, depth, MatterTile.class, EMPTY);
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);

View File

@ -44,7 +44,7 @@ public class UpdateMatter extends RawMatter<MatterUpdate> {
}
public UpdateMatter(int width, int height, int depth) {
super(width, height, depth, MatterUpdate.class);
super(width, height, depth, MatterUpdate.class, OFF);
}
@Override