diff --git a/src/main/java/io/github/null2264/cobblegen/mixin/core/CobbleGenMixinPlugin.java b/src/main/java/io/github/null2264/cobblegen/mixin/core/CobbleGenMixinPlugin.java index e7391b7..3369586 100644 --- a/src/main/java/io/github/null2264/cobblegen/mixin/core/CobbleGenMixinPlugin.java +++ b/src/main/java/io/github/null2264/cobblegen/mixin/core/CobbleGenMixinPlugin.java @@ -1,12 +1,15 @@ package io.github.null2264.cobblegen.mixin.core; import io.github.null2264.cobblegen.compat.LoaderCompat; +import io.github.null2264.cobblegen.util.CGLog; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import java.util.ArrayList; import java.util.List; import java.util.Set; +import java.util.regex.PatternSyntaxException; public class CobbleGenMixinPlugin implements IMixinConfigPlugin { @@ -21,23 +24,54 @@ public String getRefMapperConfig() { } /** - * Checks if loaded Create mod is patch F or newer - * @return 0 for Patch F, 1 for not Patch E, -1 for always Patch E + * Check Create mod version. Returns integer, in case Create introduced yet another breaking change + * + * @return -1 for Unsupported, 0 for Patch E or older, 1 for Patch F or newer */ - private int isPatchEOrOlder() { + private int getPatchVersion() { //#if FABRIC<=0 - //$$ return -1; // Always use Patch E mixin for Forge-alike + //$$ return 0; // Always use Patch E mixin for Forge-alike //#else //#if MC>1.16.5 try { String version = net.fabricmc.loader.api.FabricLoader.getInstance().getModContainer("create") .orElseThrow().getMetadata().getVersion().getFriendlyString(); - if (version.contains("0.5.1-e") || version.contains("0.5.1.e")) return 0; - } catch (java.util.NoSuchElementException exc) { - return 1; + ArrayList split = new ArrayList<>(); + String patch = "a"; + // version = 0.5.1-a-build.69 + for (String s : version.split("\\.")) { + try { + // 0.5. + split.add(Integer.valueOf(s)); + } catch (NumberFormatException exc) { + // 1a or 1-a-build -> 1 + split.add(Integer.valueOf(s.substring(0, 1))); + // -a-build -> '', a, build | a-build -> a, build + String[] patchSplit = s.substring(1).split("-"); + if (patchSplit[0].equalsIgnoreCase("")) { + patch = patchSplit[1]; + } else { + // For older version that use 0.5.0a format instead of 0.5.0-a + patch = patchSplit[0]; + } + break; + } + } + if (split.get(0) == 0) { + if (split.get(1) == 5 && split.get(2) == 0 || split.get(1) < 5) return 0; + if (split.get(1) > 5 || split.get(2) > 1) return 1; // Assume they don't introduce breaking changes on version bump + + int compare = patch.compareToIgnoreCase("e"); + if (compare <= 0) return 0; + return 1; + } + // They're definitely going to introduce breaking changes on major version bump + return -1; + } catch (java.util.NoSuchElementException | PatternSyntaxException | NumberFormatException exc) { + CGLog.error(exc); + return -1; } - return 1; //#else //$$ return 0; // We don't support create integration for MC1.16.5 //#endif @@ -49,8 +83,10 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { if (mixinClassName.contains("CreateFluidReactionsMixin")) { if (!LoaderCompat.isModLoaded("create")) return false; - if (mixinClassName.endsWith("PatchF")) return isPatchEOrOlder() >= 1; - if (mixinClassName.endsWith("PatchE")) return isPatchEOrOlder() <= 0; + int patchVersion = getPatchVersion(); + if (patchVersion == -1) return false; + if (mixinClassName.endsWith("PatchF")) return patchVersion >= 1; + if (mixinClassName.endsWith("PatchE")) return patchVersion <= 0; } return true; }