mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-01 23:47:21 +00:00
fix legacy tile data loading from mantle
This commit is contained in:
parent
dafca8e9db
commit
bb7bbb6379
@ -202,9 +202,9 @@ public class IrisBlockData extends IrisRegistrant {
|
||||
public TileData tryGetTile(IrisData data) {
|
||||
//TODO Do like a registry thing with the tile data registry. Also update the parsing of data to include **block** entities.
|
||||
var type = getBlockData(data).getMaterial();
|
||||
if (!INMS.get().hasTile(type))
|
||||
if (!INMS.get().hasTile(type) || tileData == null || tileData.isEmpty())
|
||||
return null;
|
||||
return new TileData().setMaterial(type).setProperties(this.tileData);
|
||||
return new TileData(type, this.tileData);
|
||||
}
|
||||
|
||||
private String keyify(String dat) {
|
||||
|
@ -2,6 +2,8 @@ package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.apache.commons.io.function.IOFunction;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.block.*;
|
||||
@ -14,6 +16,8 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class LegacyTileData extends TileData {
|
||||
private static final Map<Integer, IOFunction<DataInputStream, Handler>> legacy = Map.of(
|
||||
0, SignHandler::new,
|
||||
@ -41,11 +45,18 @@ public class LegacyTileData extends TileData {
|
||||
handler.toBinary(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileData clone() {
|
||||
return this;
|
||||
}
|
||||
|
||||
private interface Handler {
|
||||
void toBinary(DataOutputStream out) throws IOException;
|
||||
void toBukkit(Block block);
|
||||
}
|
||||
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
private static class SignHandler implements Handler {
|
||||
private final String line1;
|
||||
private final String line2;
|
||||
@ -81,7 +92,8 @@ public class LegacyTileData extends TileData {
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
private static class SpawnerHandler implements Handler {
|
||||
private final EntityType type;
|
||||
|
||||
@ -101,7 +113,8 @@ public class LegacyTileData extends TileData {
|
||||
spawner.update();
|
||||
}
|
||||
}
|
||||
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
private static class BannerHandler implements Handler {
|
||||
private final KList<Pattern> patterns;
|
||||
private final DyeColor baseColor;
|
||||
|
@ -23,27 +23,29 @@ import com.google.gson.GsonBuilder;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.*;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
@SuppressWarnings("ALL")
|
||||
@Accessors(chain = true)
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class TileData implements Cloneable {
|
||||
private static final Gson gson = new GsonBuilder().disableHtmlEscaping().setLenient().create();
|
||||
|
||||
private Material material = null;
|
||||
private KMap<String, Object> properties = new KMap<>();
|
||||
@NonNull
|
||||
private Material material;
|
||||
@NonNull
|
||||
private KMap<String, Object> properties;
|
||||
|
||||
public static boolean setTileState(Block block, TileData data) {
|
||||
if (block.getState() instanceof TileState && data.isApplicable(block.getBlockData()))
|
||||
@ -62,14 +64,9 @@ public class TileData implements Cloneable {
|
||||
throw new IOException("Mark not supported");
|
||||
in.mark(Integer.MAX_VALUE);
|
||||
try {
|
||||
TileData d = new TileData();
|
||||
var material = in.readUTF();
|
||||
d.material = Material.matchMaterial(material);
|
||||
if (d.material == null) throw new IOException("Unknown material: " + material);
|
||||
var properties = in.readUTF();
|
||||
d.properties = gson.fromJson(properties, KMap.class);
|
||||
if (d.properties == null) throw new IOException("Invalid properties: " + properties);
|
||||
return d;
|
||||
return new TileData(
|
||||
Material.matchMaterial(in.readUTF()),
|
||||
gson.fromJson(in.readUTF(), KMap.class));
|
||||
} catch (Throwable e) {
|
||||
in.reset();
|
||||
return new LegacyTileData(in);
|
||||
|
Loading…
x
Reference in New Issue
Block a user