mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-26 10:39:07 +00:00
Working on block entity support.
This commit is contained in:
@@ -126,8 +126,8 @@ public class NMSBinding18_2 implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeTile(CompoundTag c, Location newPosition) {
|
||||
((CraftWorld) newPosition.getWorld()).getHandle().getChunkAt(new BlockPos(newPosition.getBlockX(), 0, newPosition.getBlockZ())).setBlockEntityNbt(convert(c));
|
||||
public void deserializeTile(CompoundTag c, Location pos) {
|
||||
((CraftWorld) pos.getWorld()).getHandle().getChunkAt(new BlockPos(pos.getBlockX(), 0, pos.getBlockZ())).setBlockEntityNbt(convert(c));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,10 +38,7 @@ import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.mantle.MantleChunk;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.matter.Matter;
|
||||
import com.volmit.iris.util.matter.MatterCavern;
|
||||
import com.volmit.iris.util.matter.MatterFluidBody;
|
||||
import com.volmit.iris.util.matter.MatterMarker;
|
||||
import com.volmit.iris.util.matter.*;
|
||||
import com.volmit.iris.util.matter.slices.UpdateMatter;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
@@ -109,17 +106,14 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
|
||||
@Override
|
||||
default void setTile(int x, int y, int z, TileData<? extends TileState> d) {
|
||||
// TODO SET TILE
|
||||
getMantle().set(x, y, z, new TileWrapper(d));
|
||||
}
|
||||
|
||||
@Override
|
||||
default BlockData get(int x, int y, int z) {
|
||||
BlockData block = getMantle().get(x, y, z, BlockData.class);
|
||||
|
||||
if(block == null) {
|
||||
if(block == null)
|
||||
return AIR;
|
||||
}
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -199,6 +200,19 @@ public class IrisBlockData extends IrisRegistrant {
|
||||
});
|
||||
}
|
||||
|
||||
public TileData<?> tryGetTile() {
|
||||
//TODO Do like a registry thing with the tile data registry. Also update the parsing of data to include **block** entities.
|
||||
if(data.containsKey("entitySpawn")) {
|
||||
TileSpawner spawner = new TileSpawner();
|
||||
String name = (String)data.get("entitySpawn");
|
||||
if(name.contains(":"))
|
||||
name = name.split(":")[1];
|
||||
spawner.setEntityType(EntityType.fromName(name));
|
||||
return spawner;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String keyify(String dat) {
|
||||
if(dat.contains(":")) {
|
||||
return dat;
|
||||
|
||||
@@ -34,6 +34,8 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Snippet("palette")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@@ -66,6 +68,14 @@ public class IrisMaterialPalette {
|
||||
return getLayerGenerator(rng, rdata).fit(getBlockData(rdata), x / zoom, y / zoom, z / zoom);
|
||||
}
|
||||
|
||||
public Optional<TileData<?>> getTile(RNG rng, double x, double y, double z, IrisData rdata) {
|
||||
if(getBlockData(rdata).isEmpty())
|
||||
return Optional.empty();
|
||||
|
||||
TileData<?> tile = getBlockData(rdata).size() == 1 ? palette.get(0).tryGetTile() : palette.getRandom(rng).tryGetTile();
|
||||
return tile != null ? Optional.of(tile) : Optional.empty();
|
||||
}
|
||||
|
||||
public CNG getLayerGenerator(RNG rng, IrisData rdata) {
|
||||
return layerGenerator.aquire(() ->
|
||||
{
|
||||
|
||||
@@ -34,8 +34,6 @@ import com.volmit.iris.util.math.AxisAlignedBB;
|
||||
import com.volmit.iris.util.math.BlockPosition;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.matter.IrisMatter;
|
||||
import com.volmit.iris.util.matter.Matter;
|
||||
import com.volmit.iris.util.matter.MatterMarker;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
@@ -65,11 +63,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -739,10 +733,16 @@ public class IrisObject extends IrisRegistrant {
|
||||
if(j.isExact() ? k.matches(data) : k.getMaterial().equals(data.getMaterial())) {
|
||||
BlockData newData = j.getReplace(rng, i.getX() + x, i.getY() + y, i.getZ() + z, rdata).clone();
|
||||
|
||||
if(newData.getMaterial() == data.getMaterial()) {
|
||||
if(newData.getMaterial() == data.getMaterial())
|
||||
data = data.merge(newData);
|
||||
} else {
|
||||
else
|
||||
data = newData;
|
||||
|
||||
if(newData.getMaterial() == Material.SPAWNER) {
|
||||
Optional<TileData<?>> t = j.getReplace().getTile(rng, x, y, z, rdata);
|
||||
if(t.isPresent()) {
|
||||
tile = t.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class TileBanner implements TileData<Banner> {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void toNBT(CompoundTag tag) {
|
||||
public CompoundTag toNBT(CompoundTag tag) {
|
||||
@SuppressWarnings("unchecked") ListTag<CompoundTag> listTag = (ListTag<CompoundTag>) ListTag.createUnchecked(CompoundTag.class);
|
||||
for(Pattern p : patterns) {
|
||||
CompoundTag pattern = new CompoundTag();
|
||||
@@ -107,6 +107,7 @@ public class TileBanner implements TileData<Banner> {
|
||||
listTag.add(pattern);
|
||||
}
|
||||
tag.put("Patterns", listTag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
public boolean isBanner(Material material) {
|
||||
|
||||
@@ -29,11 +29,12 @@ import org.bukkit.block.data.BlockData;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
public interface TileData<T extends TileState> extends Cloneable {
|
||||
|
||||
KList<TileData<? extends TileState>> registry = setup();
|
||||
static final KList<TileData<? extends TileState>> registry = setup();
|
||||
|
||||
static KList<TileData<? extends TileState>> setup() {
|
||||
KList<TileData<? extends TileState>> registry = new KList<>();
|
||||
@@ -45,11 +46,15 @@ public interface TileData<T extends TileState> extends Cloneable {
|
||||
return registry;
|
||||
}
|
||||
|
||||
static TileData<? extends TileState> read(DataInputStream s) throws Throwable {
|
||||
int id = s.readShort();
|
||||
@SuppressWarnings("unchecked") TileData<? extends TileState> d = registry.get(id).getClass().getConstructor().newInstance();
|
||||
d.fromBinary(s);
|
||||
return d;
|
||||
static TileData<? extends TileState> read(DataInputStream s) throws IOException {
|
||||
try {
|
||||
int id = s.readShort();
|
||||
@SuppressWarnings("unchecked") TileData<? extends TileState> d = registry.get(id).getClass().getConstructor().newInstance();
|
||||
d.fromBinary(s);
|
||||
return d;
|
||||
} catch(InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
|
||||
throw new IOException("Failed to create TileData instance due to missing type registrar!");
|
||||
}
|
||||
}
|
||||
|
||||
static void setTileState(Block block, TileData<? extends TileState> data) {
|
||||
@@ -111,11 +116,11 @@ public interface TileData<T extends TileState> extends Cloneable {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileData<T> clone();
|
||||
CompoundTag toNBT(CompoundTag parent);
|
||||
|
||||
void toBinary(DataOutputStream out) throws IOException;
|
||||
|
||||
void toNBT(CompoundTag tag);
|
||||
|
||||
void fromBinary(DataInputStream in) throws IOException;
|
||||
|
||||
TileData<T> clone();
|
||||
}
|
||||
|
||||
@@ -98,11 +98,12 @@ public class TileSign implements TileData<Sign> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(CompoundTag tag) {
|
||||
public CompoundTag toNBT(CompoundTag tag) {
|
||||
tag.putString("Text1", line1);
|
||||
tag.putString("Text2", line2);
|
||||
tag.putString("Text3", line3);
|
||||
tag.putString("Text4", line4);
|
||||
tag.putString("Color", dyeColor.name().toLowerCase());
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,12 +32,13 @@ import java.io.IOException;
|
||||
|
||||
@Data
|
||||
public class TileSpawner implements TileData<CreatureSpawner> {
|
||||
public static final int id = 1;
|
||||
private EntityType entityType;
|
||||
|
||||
public static final int id = 1;
|
||||
|
||||
private EntityType entityType;
|
||||
@Override
|
||||
public String getTileId() {
|
||||
return "minecraft:spawner";
|
||||
return "minecraft:mob_spawner";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,7 +76,7 @@ public class TileSpawner implements TileData<CreatureSpawner> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(CompoundTag tag) {
|
||||
public CompoundTag toNBT(CompoundTag parent) {
|
||||
@SuppressWarnings("unchecked") ListTag<CompoundTag> potentials = (ListTag<CompoundTag>) ListTag.createUnchecked(CompoundTag.class);
|
||||
CompoundTag t = new CompoundTag();
|
||||
CompoundTag ent = new CompoundTag();
|
||||
@@ -83,6 +84,7 @@ public class TileSpawner implements TileData<CreatureSpawner> {
|
||||
t.put("Entity", ent);
|
||||
t.putInt("Weight", 1);
|
||||
potentials.add(t);
|
||||
tag.put("SpawnPotentials", potentials);
|
||||
parent.put("SpawnPotentials", potentials);
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,10 @@
|
||||
|
||||
package com.volmit.iris.util.matter;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import com.volmit.iris.engine.object.TileData;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class MatterTile {
|
||||
private final CompoundTag tileData;
|
||||
public class TileWrapper {
|
||||
private final TileData<?> data;
|
||||
}
|
||||
@@ -33,8 +33,8 @@ public class WorldMatter {
|
||||
matter.slice(MatterEntityGroup.class).writeInto(at);
|
||||
}
|
||||
|
||||
if(matter.hasSlice(MatterTile.class)) {
|
||||
matter.slice(MatterTile.class).writeInto(at);
|
||||
if(matter.hasSlice(TileWrapper.class)) {
|
||||
matter.slice(TileWrapper.class).writeInto(at);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class WorldMatter {
|
||||
s.getHeader().setAuthor(author);
|
||||
s.slice(BlockData.class).readFrom(c.getLowerNE());
|
||||
s.slice(MatterEntityGroup.class).readFrom(c.getLowerNE());
|
||||
s.slice(MatterTile.class).readFrom(c.getLowerNE());
|
||||
s.slice(TileWrapper.class).readFrom(c.getLowerNE());
|
||||
s.trimSlices();
|
||||
|
||||
return s;
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.engine.object.TileData;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.MatterTile;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import com.volmit.iris.util.nbt.io.NBTUtil;
|
||||
import com.volmit.iris.util.matter.TileWrapper;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -31,43 +32,49 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Sliced
|
||||
public class TileMatter extends RawMatter<MatterTile> {
|
||||
public static final MatterTile EMPTY = new MatterTile(new CompoundTag());
|
||||
public class TileMatter extends RawMatter<TileWrapper> {
|
||||
|
||||
public TileMatter() {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<MatterTile> getGlobalPalette() {
|
||||
public Palette<TileWrapper> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public TileMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, MatterTile.class);
|
||||
registerWriter(World.class, ((w, d, x, y, z) -> INMS.get().deserializeTile(d.getTileData(), new Location(w, x, y, z))));
|
||||
super(width, height, depth, TileWrapper.class);
|
||||
registerWriter(World.class, (w, d, x, y, z) -> {
|
||||
CompoundTag tag = commonNbt(x, y, z, d.getData().getTileId());
|
||||
INMS.get().deserializeTile(d.getData().toNBT(d.getData().toNBT(tag)), new Location(w, x, y, z));
|
||||
Iris.warn("S: " + tag);
|
||||
});
|
||||
registerReader(World.class, (w, x, y, z) -> {
|
||||
Location l = new Location(w, x, y, z);
|
||||
if(INMS.get().hasTile(l)) {
|
||||
CompoundTag tag = INMS.get().serializeTile(l);
|
||||
|
||||
if(tag != null) {
|
||||
return new MatterTile(tag);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
TileData d = TileData.getTileState(w.getBlockAt(new Location(w, x, y, z)));
|
||||
if(d == null)
|
||||
return null;
|
||||
return new TileWrapper(d);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNode(MatterTile b, DataOutputStream dos) throws IOException {
|
||||
NBTUtil.write(b.getTileData(), dos, false);
|
||||
public void writeNode(TileWrapper b, DataOutputStream dos) throws IOException {
|
||||
b.getData().toBinary(dos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MatterTile readNode(DataInputStream din) throws IOException {
|
||||
return new MatterTile((CompoundTag) NBTUtil.read(din, false).getTag());
|
||||
public TileWrapper readNode(DataInputStream din) throws IOException {
|
||||
return new TileWrapper(TileData.read(din));
|
||||
}
|
||||
|
||||
private CompoundTag commonNbt(int x, int y, int z, String mobId) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt("x", x);
|
||||
tag.putInt("y", y);
|
||||
tag.putInt("z", z);
|
||||
tag.putBoolean("keepPacked", false);
|
||||
tag.putString("id", mobId);
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user