Skip to content

Commit

Permalink
Merge pull request #1066 from VolmitDev/better-version-compat
Browse files Browse the repository at this point in the history
Better version compat
  • Loading branch information
NextdoorPsycho authored Jan 25, 2024
2 parents e68b1a5 + 82640de commit 7d4c9d6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ plugins {
id "de.undercouch.download" version "5.0.1"
}

version '3.0.0-1.19.2-1.20.2'
version '3.0.0-1.19.2-1.20.4'
def specialSourceVersion = '1.11.0' //[NMS]

// ADD YOURSELF AS A NEW LINE IF YOU WANT YOUR OWN BUILD TASK GENERATED
Expand All @@ -44,7 +44,7 @@ registerCustomOutputTaskUnix('PsychoLT', '/Volumes/PRO-G40/Minecraft/MinecraftDe
// ==============================================================

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_R1", "1.20.1-R0.1-SNAPSHOT",
"v1_19_R3", "1.19.4-R0.1-SNAPSHOT",
Expand Down Expand Up @@ -344,4 +344,4 @@ def registerCustomOutputTaskUnix(name, path) {
}
}

tasks.build.dependsOn(shadowJar)
tasks.build.dependsOn(shadowJar)
22 changes: 16 additions & 6 deletions core/src/main/java/com/volmit/iris/engine/object/IrisCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private static KList<IrisCompatabilityBlockFilter> getDefaultBlockCompatabilityF
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"));
Expand All @@ -254,6 +254,7 @@ private static KList<IrisCompatabilityBlockFilter> getDefaultBlockCompatabilityF
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;
}
Expand All @@ -262,7 +263,7 @@ public BlockData getBlock(String n) {
String buf = n;
int err = 16;

BlockData tx = B.getOrNull(buf);
BlockData tx = B.getOrNull(buf, false);

if (tx != null) {
return tx;
Expand All @@ -271,11 +272,19 @@ public BlockData getBlock(String n) {
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) {
Expand All @@ -287,7 +296,8 @@ public BlockData getBlock(String n) {
}
}

return B.get("STONE");
Iris.error("Can't find block data for " + n);
return B.getNoCompat("STONE");
}
}

Expand Down Expand Up @@ -330,7 +340,7 @@ public Material getItem(String n) {
}

buf = n;
BlockData tx = B.getOrNull(buf);
BlockData tx = B.getOrNull(buf, false);

if (tx != null) {
return tx.getMaterial();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public BlockData getFind() {
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;
});
Expand Down
41 changes: 28 additions & 13 deletions core/src/main/java/com/volmit/iris/util/data/B.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -407,7 +408,7 @@ public static boolean isSolid(BlockData mat) {
return mat.getMaterial().isSolid();
}

public static BlockData getOrNull(String bdxf) {
public static BlockData getOrNull(String bdxf, boolean warn) {
try {
String bd = bdxf.trim();

Expand All @@ -423,9 +424,9 @@ public static BlockData getOrNull(String bdxf) {
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 + "'");
}
Expand All @@ -444,8 +445,8 @@ public static BlockData getOrNull(String bdxf) {
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;
Expand All @@ -454,20 +455,34 @@ public static BlockData get(String bdxf) {
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;

Expand All @@ -481,15 +496,15 @@ private static BlockData parseBlockData(String ix) {

if (bx == null) {
try {
bx = createBlockData(ix.toLowerCase());
bx = createBlockData(ix.toLowerCase(), warn);
} catch (Throwable e) {
e.printStackTrace();
}
}

if (bx == null) {
try {
bx = createBlockData("minecraft:" + ix.toLowerCase());
bx = createBlockData("minecraft:" + ix.toLowerCase(), warn);
} catch (Throwable e) {

}
Expand Down Expand Up @@ -549,7 +564,7 @@ private static BlockData parseBlockData(String ix) {
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) {
Expand All @@ -563,7 +578,7 @@ private static BlockData parseBlockData(String ix) {
Iris.debug("Converting " + ix + " to " + newBlock);

try {
return createBlockData(newBlock);
return createBlockData(newBlock, warn);
} catch (Throwable e1) {
Iris.reportError(e1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static BlockData getBlockData(CompoundTag tag) {
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();
Expand Down

0 comments on commit 7d4c9d6

Please sign in to comment.