9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-30 12:29:20 +00:00

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

View File

@@ -234,7 +234,7 @@ public class IrisCompat {
filters.add(new IrisCompatabilityBlockFilter("ACACIA_WALL_SIGN", "LEGACY_WALL_SIGN"));
filters.add(new IrisCompatabilityBlockFilter("ACACIA_SIGN", "LEGACY_SIGN_POST"));
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("LANTERN", "REDSTONE_LAMP"));
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_SAPLING", "BIRCH_SAPLING"));
filters.add(new IrisCompatabilityBlockFilter("POTTED_BAMBOO", "POTTED_BIRCH_SAPLING"));
filters.add(new IrisCompatabilityBlockFilter("GRASS", "SHORT_GRASS"));
return filters;
}
@@ -262,7 +263,7 @@ public class IrisCompat {
String buf = n;
int err = 16;
BlockData tx = B.getOrNull(buf);
BlockData tx = B.getOrNull(buf, false);
if (tx != null) {
return tx;
@@ -271,11 +272,19 @@ public class IrisCompat {
searching:
while (true) {
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) {
if (i.getWhen().equalsIgnoreCase(buf)) {
if (i.getWhen().equalsIgnoreCase(i.isExact() ? buf : m)) {
BlockData b = i.getReplace();
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;
BlockData tx = B.getOrNull(buf);
BlockData tx = B.getOrNull(buf, false);
if (tx != null) {
return tx.getMaterial();

View File

@@ -57,13 +57,13 @@ public class IrisCompatabilityBlockFilter {
public BlockData getReplace() {
return replaceData.aquire(() ->
{
BlockData b = B.getOrNull(supplement);
BlockData b = B.getOrNull(supplement, false);
if (b == 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;
});

View File

@@ -22,6 +22,7 @@ import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.link.Identifier;
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.KMap;
import com.volmit.iris.util.scheduling.ChronoLatch;
@@ -406,7 +407,7 @@ public class B {
return mat.getMaterial().isSolid();
}
public static BlockData getOrNull(String bdxf) {
public static BlockData getOrNull(String bdxf, boolean warn) {
try {
String bd = bdxf.trim();
@@ -422,9 +423,9 @@ public class B {
return DIRT_PATH.createBlockData();
}
BlockData bdx = parseBlockData(bd);
BlockData bdx = parseBlockData(bd, warn);
if (bdx == null) {
if (bdx == null && warn) {
if (clw.flip()) {
Iris.warn("Unknown Block Data '" + bd + "'");
}
@@ -443,8 +444,8 @@ public class B {
return null;
}
public static BlockData get(String bdxf) {
BlockData bd = getOrNull(bdxf);
public static BlockData getNoCompat(String bdxf) {
BlockData bd = getOrNull(bdxf, true);
if (bd != null) {
return bd;
@@ -453,20 +454,34 @@ public class B {
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 {
return Bukkit.createBlockData(s);
} catch (IllegalArgumentException e) {
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;
}
private static BlockData parseBlockData(String ix) {
private static BlockData parseBlockData(String ix, boolean warn) {
try {
BlockData bx = null;
@@ -480,7 +495,7 @@ public class B {
if (bx == null) {
try {
bx = createBlockData(ix.toLowerCase());
bx = createBlockData(ix.toLowerCase(), warn);
} catch (Throwable e) {
e.printStackTrace();
}
@@ -488,7 +503,7 @@ public class B {
if (bx == null) {
try {
bx = createBlockData("minecraft:" + ix.toLowerCase());
bx = createBlockData("minecraft:" + ix.toLowerCase(), warn);
} catch (Throwable e) {
}
@@ -548,7 +563,7 @@ public class B {
for (String key : stateMap.keySet()) { //Iterate through every state and check if its valid
try {
String newState = block + "[" + key + "=" + stateMap.get(key) + "]";
createBlockData(newState);
createBlockData(newState, warn);
newStates.put(key, stateMap.get(key));
} catch (IllegalArgumentException ignored) {
@@ -562,7 +577,7 @@ public class B {
Iris.debug("Converting " + ix + " to " + newBlock);
try {
return createBlockData(newBlock);
return createBlockData(newBlock, warn);
} catch (Throwable e1) {
Iris.reportError(e1);
}

View File

@@ -107,7 +107,7 @@ public class NBTWorld {
p.deleteCharAt(p.length() - 1).append(']');
}
BlockData b = B.getOrNull(p.toString());
BlockData b = B.getOrNull(p.toString(), true);
if (b == null) {
return B.getAir();