forked from BLOCKFANTASY/LOOHP-Limbo
Catch unknown block errors
This commit is contained in:
parent
26ce9c4a9d
commit
c29b219d9c
|
|
@ -133,7 +133,7 @@ public class PacketRegistry {
|
||||||
JSONObject jsonIds = (JSONObject) jsonMappings.get(boundKey);
|
JSONObject jsonIds = (JSONObject) jsonMappings.get(boundKey);
|
||||||
for (Object objPacketKey : jsonIds.keySet()) {
|
for (Object objPacketKey : jsonIds.keySet()) {
|
||||||
String packetKey = (String) objPacketKey;
|
String packetKey = (String) objPacketKey;
|
||||||
idMapping.put(Key.key(packetKey), (int) (long) ((JSONObject) jsonIds.get(packetKey)).get("protocol_id"));
|
idMapping.put(Key.key(packetKey), ((Number) ((JSONObject) jsonIds.get(packetKey)).get("protocol_id")).intValue());
|
||||||
}
|
}
|
||||||
mappings.put(packetBound, idMapping);
|
mappings.put(packetBound, idMapping);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
package com.loohp.limbo.world;
|
package com.loohp.limbo.world;
|
||||||
|
|
||||||
import com.loohp.limbo.Limbo;
|
import com.loohp.limbo.Limbo;
|
||||||
|
import net.querz.nbt.io.SNBTUtil;
|
||||||
import net.querz.nbt.tag.CompoundTag;
|
import net.querz.nbt.tag.CompoundTag;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
@ -56,16 +57,15 @@ public class GeneratedBlockDataMappings {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static int getGlobalPaletteIDFromState(CompoundTag tag) {
|
public static int getGlobalPaletteIDFromState(CompoundTag tag) {
|
||||||
|
try {
|
||||||
String blockname = tag.getString("Name");
|
String blockname = tag.getString("Name");
|
||||||
|
|
||||||
JSONObject data = (JSONObject) globalPalette.get(blockname);
|
JSONObject data = (JSONObject) globalPalette.get(blockname);
|
||||||
Object obj = data.get("properties");
|
Object obj = data.get("properties");
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return (int) (long) ((JSONObject) ((JSONArray) data.get("states")).get(0)).get("id");
|
return ((Number) ((JSONObject) ((JSONArray) data.get("states")).get(0)).get("id")).intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
//JSONObject properties = (JSONObject) obj;
|
|
||||||
|
|
||||||
if (tag.containsKey("Properties")) {
|
if (tag.containsKey("Properties")) {
|
||||||
CompoundTag blockProp = tag.get("Properties", CompoundTag.class);
|
CompoundTag blockProp = tag.get("Properties", CompoundTag.class);
|
||||||
Map<String, String> blockstate = new HashMap<>();
|
Map<String, String> blockstate = new HashMap<>();
|
||||||
|
|
@ -76,16 +76,27 @@ public class GeneratedBlockDataMappings {
|
||||||
for (Object entry : (JSONArray) data.get("states")) {
|
for (Object entry : (JSONArray) data.get("states")) {
|
||||||
JSONObject jsonobj = (JSONObject) entry;
|
JSONObject jsonobj = (JSONObject) entry;
|
||||||
if (((JSONObject) jsonobj.get("properties")).keySet().stream().allMatch(key -> Objects.equals(blockstate.get(key), ((JSONObject) jsonobj.get("properties")).get(key)))) {
|
if (((JSONObject) jsonobj.get("properties")).keySet().stream().allMatch(key -> Objects.equals(blockstate.get(key), ((JSONObject) jsonobj.get("properties")).get(key)))) {
|
||||||
return (int) (long) jsonobj.get("id");
|
return ((Number) jsonobj.get("id")).intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Object entry : (JSONArray) data.get("states")) {
|
for (Object entry : (JSONArray) data.get("states")) {
|
||||||
if (((JSONObject) entry).containsKey("default") && ((boolean) ((JSONObject) entry).get("default"))) {
|
if (((JSONObject) entry).containsKey("default") && ((boolean) ((JSONObject) entry).get("default"))) {
|
||||||
return (int) (long) ((JSONObject) entry).get("id");
|
return ((Number) ((JSONObject) entry).get("id")).intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new IllegalStateException();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
String snbt;
|
||||||
|
try {
|
||||||
|
snbt = SNBTUtil.toSNBT(tag);
|
||||||
|
} catch (IOException e1) {
|
||||||
|
snbt = tag.valueToString();
|
||||||
|
}
|
||||||
|
new IllegalStateException("Unable to get global palette id for " + snbt + " (Is this scheme created in the same Minecraft version as Limbo?)", e).printStackTrace();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue