reimplement IrisCompat

This commit is contained in:
CrazyDev22
2023-12-31 19:13:57 +01:00
parent c11b5342e3
commit 9b89ae7846
5 changed files with 48 additions and 23 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ registerCustomOutputTaskUnix('PsychoLT', '/Volumes/PRO-G40/Minecraft/MinecraftDe
// ============================================================== // ==============================================================
def NMS_BINDINGS = Map.of( def NMS_BINDINGS = Map.of(
// "v1_20_R3", "1.20.4-R0.1-SNAPSHOT", "v1_20_R3", "1.20.4-R0.1-SNAPSHOT",
"v1_20_R2", "1.20.2-R0.1-SNAPSHOT", "v1_20_R2", "1.20.2-R0.1-SNAPSHOT",
"v1_20_R1", "1.20.1-R0.1-SNAPSHOT", "v1_20_R1", "1.20.1-R0.1-SNAPSHOT",
"v1_19_R3", "1.19.4-R0.1-SNAPSHOT", "v1_19_R3", "1.19.4-R0.1-SNAPSHOT",
@@ -234,7 +234,7 @@ public class IrisCompat {
filters.add(new IrisCompatabilityBlockFilter("ACACIA_WALL_SIGN", "LEGACY_WALL_SIGN")); filters.add(new IrisCompatabilityBlockFilter("ACACIA_WALL_SIGN", "LEGACY_WALL_SIGN"));
filters.add(new IrisCompatabilityBlockFilter("ACACIA_SIGN", "LEGACY_SIGN_POST")); filters.add(new IrisCompatabilityBlockFilter("ACACIA_SIGN", "LEGACY_SIGN_POST"));
filters.add(new IrisCompatabilityBlockFilter("SCAFFOLDING", "BIRCH_FENCE")); filters.add(new IrisCompatabilityBlockFilter("SCAFFOLDING", "BIRCH_FENCE"));
filters.add(new IrisCompatabilityBlockFilter("LOOM", "LOOM")); //filters.add(new IrisCompatabilityBlockFilter("LOOM", "LOOM"));
filters.add(new IrisCompatabilityBlockFilter("LECTERN", "BOOKSHELF")); filters.add(new IrisCompatabilityBlockFilter("LECTERN", "BOOKSHELF"));
filters.add(new IrisCompatabilityBlockFilter("LANTERN", "REDSTONE_LAMP")); filters.add(new IrisCompatabilityBlockFilter("LANTERN", "REDSTONE_LAMP"));
filters.add(new IrisCompatabilityBlockFilter("JIGSAW", "AIR")); filters.add(new IrisCompatabilityBlockFilter("JIGSAW", "AIR"));
@@ -254,6 +254,7 @@ public class IrisCompat {
filters.add(new IrisCompatabilityBlockFilter("BAMBOO", "BIRCH_FENCE")); filters.add(new IrisCompatabilityBlockFilter("BAMBOO", "BIRCH_FENCE"));
filters.add(new IrisCompatabilityBlockFilter("BAMBOO_SAPLING", "BIRCH_SAPLING")); filters.add(new IrisCompatabilityBlockFilter("BAMBOO_SAPLING", "BIRCH_SAPLING"));
filters.add(new IrisCompatabilityBlockFilter("POTTED_BAMBOO", "POTTED_BIRCH_SAPLING")); filters.add(new IrisCompatabilityBlockFilter("POTTED_BAMBOO", "POTTED_BIRCH_SAPLING"));
filters.add(new IrisCompatabilityBlockFilter("GRASS", "SHORT_GRASS"));
return filters; return filters;
} }
@@ -262,7 +263,7 @@ public class IrisCompat {
String buf = n; String buf = n;
int err = 16; int err = 16;
BlockData tx = B.getOrNull(buf); BlockData tx = B.getOrNull(buf, false);
if (tx != null) { if (tx != null) {
return tx; return tx;
@@ -271,11 +272,19 @@ public class IrisCompat {
searching: searching:
while (true) { while (true) {
if (err-- <= 0) { if (err-- <= 0) {
return B.get("STONE"); Iris.error("Can't find block data for " + n);
return B.getNoCompat("STONE");
}
String m = buf;
if (m.contains("[")) {
m = m.split("\\Q[\\E")[0];
}
if (m.contains(":")) {
m = m.split("\\Q:\\E", 2)[1];
} }
for (IrisCompatabilityBlockFilter i : blockFilters) { for (IrisCompatabilityBlockFilter i : blockFilters) {
if (i.getWhen().equalsIgnoreCase(buf)) { if (i.getWhen().equalsIgnoreCase(i.isExact() ? buf : m)) {
BlockData b = i.getReplace(); BlockData b = i.getReplace();
if (b != null) { if (b != null) {
@@ -287,7 +296,8 @@ public class IrisCompat {
} }
} }
return B.get("STONE"); Iris.error("Can't find block data for " + n);
return B.getNoCompat("STONE");
} }
} }
@@ -330,7 +340,7 @@ public class IrisCompat {
} }
buf = n; buf = n;
BlockData tx = B.getOrNull(buf); BlockData tx = B.getOrNull(buf, false);
if (tx != null) { if (tx != null) {
return tx.getMaterial(); return tx.getMaterial();
@@ -57,13 +57,13 @@ public class IrisCompatabilityBlockFilter {
public BlockData getReplace() { public BlockData getReplace() {
return replaceData.aquire(() -> return replaceData.aquire(() ->
{ {
BlockData b = B.getOrNull(supplement); BlockData b = B.getOrNull(supplement, false);
if (b == null) { if (b == null) {
return null; return null;
} }
Iris.warn("Compat: Using " + supplement + " in place of " + when + " since this server doesnt support '" + supplement + "'"); Iris.warn("Compat: Using '%s' in place of '%s' since this server doesnt support '%s'", supplement, when, when);
return b; return b;
}); });
@@ -22,6 +22,7 @@ import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.link.Identifier; import com.volmit.iris.core.link.Identifier;
import com.volmit.iris.core.service.ExternalDataSVC; import com.volmit.iris.core.service.ExternalDataSVC;
import com.volmit.iris.engine.object.IrisCompat;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.scheduling.ChronoLatch; import com.volmit.iris.util.scheduling.ChronoLatch;
@@ -406,7 +407,7 @@ public class B {
return mat.getMaterial().isSolid(); return mat.getMaterial().isSolid();
} }
public static BlockData getOrNull(String bdxf) { public static BlockData getOrNull(String bdxf, boolean warn) {
try { try {
String bd = bdxf.trim(); String bd = bdxf.trim();
@@ -422,9 +423,9 @@ public class B {
return DIRT_PATH.createBlockData(); return DIRT_PATH.createBlockData();
} }
BlockData bdx = parseBlockData(bd); BlockData bdx = parseBlockData(bd, warn);
if (bdx == null) { if (bdx == null && warn) {
if (clw.flip()) { if (clw.flip()) {
Iris.warn("Unknown Block Data '" + bd + "'"); Iris.warn("Unknown Block Data '" + bd + "'");
} }
@@ -443,8 +444,8 @@ public class B {
return null; return null;
} }
public static BlockData get(String bdxf) { public static BlockData getNoCompat(String bdxf) {
BlockData bd = getOrNull(bdxf); BlockData bd = getOrNull(bdxf, true);
if (bd != null) { if (bd != null) {
return bd; return bd;
@@ -453,20 +454,34 @@ public class B {
return AIR; return AIR;
} }
private static synchronized BlockData createBlockData(String s) { public static BlockData get(String bdxf) {
if (bdxf.contains(":")) {
if (bdxf.startsWith("minecraft:")) {
return Iris.compat.getBlock(bdxf);
} else {
return getNoCompat(bdxf);
}
} else {
return Iris.compat.getBlock(bdxf);
}
}
private static synchronized BlockData createBlockData(String s, boolean warn) {
try { try {
return Bukkit.createBlockData(s); return Bukkit.createBlockData(s);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
if (s.contains("[")) { if (s.contains("[")) {
return createBlockData(s.split("\\Q[\\E")[0]); return createBlockData(s.split("\\Q[\\E")[0], warn);
} }
} }
Iris.error("Can't find block data for " + s); if (warn) {
Iris.error("Can't find block data for " + s);
}
return null; return null;
} }
private static BlockData parseBlockData(String ix) { private static BlockData parseBlockData(String ix, boolean warn) {
try { try {
BlockData bx = null; BlockData bx = null;
@@ -480,7 +495,7 @@ public class B {
if (bx == null) { if (bx == null) {
try { try {
bx = createBlockData(ix.toLowerCase()); bx = createBlockData(ix.toLowerCase(), warn);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -488,7 +503,7 @@ public class B {
if (bx == null) { if (bx == null) {
try { try {
bx = createBlockData("minecraft:" + ix.toLowerCase()); bx = createBlockData("minecraft:" + ix.toLowerCase(), warn);
} catch (Throwable e) { } catch (Throwable e) {
} }
@@ -548,7 +563,7 @@ public class B {
for (String key : stateMap.keySet()) { //Iterate through every state and check if its valid for (String key : stateMap.keySet()) { //Iterate through every state and check if its valid
try { try {
String newState = block + "[" + key + "=" + stateMap.get(key) + "]"; String newState = block + "[" + key + "=" + stateMap.get(key) + "]";
createBlockData(newState); createBlockData(newState, warn);
newStates.put(key, stateMap.get(key)); newStates.put(key, stateMap.get(key));
} catch (IllegalArgumentException ignored) { } catch (IllegalArgumentException ignored) {
@@ -562,7 +577,7 @@ public class B {
Iris.debug("Converting " + ix + " to " + newBlock); Iris.debug("Converting " + ix + " to " + newBlock);
try { try {
return createBlockData(newBlock); return createBlockData(newBlock, warn);
} catch (Throwable e1) { } catch (Throwable e1) {
Iris.reportError(e1); Iris.reportError(e1);
} }
@@ -107,7 +107,7 @@ public class NBTWorld {
p.deleteCharAt(p.length() - 1).append(']'); p.deleteCharAt(p.length() - 1).append(']');
} }
BlockData b = B.getOrNull(p.toString()); BlockData b = B.getOrNull(p.toString(), true);
if (b == null) { if (b == null) {
return B.getAir(); return B.getAir();