From bef4fdd9497763e20e511fecdd5f6952e3e49ad3 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Sun, 13 Jul 2025 22:31:17 +0200 Subject: [PATCH] Delete overkill mixin registration system (#44) --- dependencies.gradle | 4 +- gradle.properties | 2 +- settings.gradle | 2 +- .../structurelib/core/StructureLibCore.java | 30 ++- .../structurelib/mixins/Mixins.java | 188 ------------------ 5 files changed, 17 insertions(+), 209 deletions(-) delete mode 100644 src/main/java/com/gtnewhorizon/structurelib/mixins/Mixins.java diff --git a/dependencies.gradle b/dependencies.gradle index c0518bc2..9ed65e07 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,8 +1,8 @@ // Add your dependencies here dependencies { - api("com.github.GTNewHorizons:GTNHLib:0.6.31:dev") - implementation("com.github.GTNewHorizons:NotEnoughItems:2.7.56-GTNH:dev") + api("com.github.GTNewHorizons:GTNHLib:0.6.37:dev") + implementation("com.github.GTNewHorizons:NotEnoughItems:2.7.62-GTNH:dev") testImplementation(platform('org.junit:junit-bom:5.9.2')) testImplementation('org.junit.jupiter:junit-jupiter') diff --git a/gradle.properties b/gradle.properties index 27cfee52..1baf9d19 100644 --- a/gradle.properties +++ b/gradle.properties @@ -151,7 +151,7 @@ modrinthProjectId = # type can be one of [project, version], # and the name is the Modrinth project or version slug/id of the other mod. # Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech -# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true +# Note: UniMixins is automatically set as a required dependency if usesMixins = true. modrinthRelations = # Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens. diff --git a/settings.gradle b/settings.gradle index ff436f2c..04935549 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,7 @@ pluginManagement { } plugins { - id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.38' + id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.40' } diff --git a/src/main/java/com/gtnewhorizon/structurelib/core/StructureLibCore.java b/src/main/java/com/gtnewhorizon/structurelib/core/StructureLibCore.java index 17533eb5..e8eb6d4b 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/core/StructureLibCore.java +++ b/src/main/java/com/gtnewhorizon/structurelib/core/StructureLibCore.java @@ -1,34 +1,20 @@ package com.gtnewhorizon.structurelib.core; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader; -import com.gtnewhorizon.structurelib.mixins.Mixins; import cpw.mods.fml.relauncher.IFMLLoadingPlugin; +@IFMLLoadingPlugin.MCVersion("1.7.10") public class StructureLibCore implements IFMLLoadingPlugin, IEarlyMixinLoader { - public static final Logger log = LogManager.getLogger("StructureLibCore"); - - @Override - public String getMixinConfig() { - return "mixins.structurelib.early.json"; - } - - @Override - public List getMixins(Set loadedCoreMods) { - return Mixins.getEarlyMixins(loadedCoreMods); - } - @Override public String[] getASMTransformerClass() { - return new String[0]; + return null; } @Override @@ -50,4 +36,14 @@ public class StructureLibCore implements IFMLLoadingPlugin, IEarlyMixinLoader { public String getAccessTransformerClass() { return null; } + + @Override + public String getMixinConfig() { + return "mixins.structurelib.early.json"; + } + + @Override + public List getMixins(Set loadedCoreMods) { + return Arrays.asList("blockChangeNotifier.MixinForgeHooks", "blockChangeNotifier.MixinWorld"); + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/mixins/Mixins.java b/src/main/java/com/gtnewhorizon/structurelib/mixins/Mixins.java deleted file mode 100644 index e27b1610..00000000 --- a/src/main/java/com/gtnewhorizon/structurelib/mixins/Mixins.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.gtnewhorizon.structurelib.mixins; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.function.Supplier; - -import com.gtnewhorizon.structurelib.core.StructureLibCore; - -import cpw.mods.fml.relauncher.FMLLaunchHandler; - -public enum Mixins { - - BLOCK_CHANGE_NOTIFIER(new Builder("Block Change Notifier").setPhase(Phase.EARLY) - .addMixinClasses("blockChangeNotifier.MixinForgeHooks", "blockChangeNotifier.MixinWorld") - .addTargetedMod(TargetedMod.VANILLA).setSide(Side.BOTH).setApplyIf(() -> true)); - - private final List mixinClasses; - private final List targetedMods; - private final List excludedMods; - private final Supplier applyIf; - private final Phase phase; - private final Side side; - - Mixins(Builder builder) { - this.mixinClasses = builder.mixinClasses; - this.targetedMods = builder.targetedMods; - this.excludedMods = builder.excludedMods; - this.applyIf = builder.applyIf; - this.phase = builder.phase; - this.side = builder.side; - if (this.mixinClasses.isEmpty()) { - throw new RuntimeException("No mixin class specified for Mixin : " + this.name()); - } - if (this.targetedMods.isEmpty()) { - throw new RuntimeException("No targeted mods specified for Mixin : " + this.name()); - } - if (this.applyIf == null) { - throw new RuntimeException("No ApplyIf function specified for Mixin : " + this.name()); - } - if (this.phase == null) { - throw new RuntimeException("No Phase specified for Mixin : " + this.name()); - } - if (this.side == null) { - throw new RuntimeException("No Side function specified for Mixin : " + this.name()); - } - } - - public static List getEarlyMixins(Set loadedCoreMods) { - final List mixins = new ArrayList<>(); - final List notLoading = new ArrayList<>(); - for (Mixins mixin : Mixins.values()) { - if (mixin.phase == Phase.EARLY) { - if (mixin.shouldLoad(loadedCoreMods, Collections.emptySet())) { - mixins.addAll(mixin.mixinClasses); - } else { - notLoading.addAll(mixin.mixinClasses); - } - } - } - StructureLibCore.log.info("Not loading the following EARLY mixins: {}", notLoading.toString()); - return mixins; - } - - public static List getLateMixins(Set loadedMods) { - // NOTE: Any targetmod here needs a modid, not a coremod id - final List mixins = new ArrayList<>(); - final List notLoading = new ArrayList<>(); - for (Mixins mixin : Mixins.values()) { - if (mixin.phase == Phase.LATE) { - if (mixin.shouldLoad(Collections.emptySet(), loadedMods)) { - mixins.addAll(mixin.mixinClasses); - } else { - notLoading.addAll(mixin.mixinClasses); - } - } - } - StructureLibCore.log.info("Not loading the following LATE mixins: {}", notLoading.toString()); - return mixins; - } - - private boolean shouldLoadSide() { - return side == Side.BOTH || (side == Side.SERVER && FMLLaunchHandler.side().isServer()) - || (side == Side.CLIENT && FMLLaunchHandler.side().isClient()); - } - - private boolean allModsLoaded(List targetedMods, Set loadedCoreMods, Set loadedMods) { - if (targetedMods.isEmpty()) return false; - - for (TargetedMod target : targetedMods) { - if (target == TargetedMod.VANILLA) continue; - - // Check coremod first - if (!loadedCoreMods.isEmpty() && target.coreModClass != null - && !loadedCoreMods.contains(target.coreModClass)) - return false; - else if (!loadedMods.isEmpty() && target.modId != null && !loadedMods.contains(target.modId)) return false; - } - - return true; - } - - private boolean noModsLoaded(List targetedMods, Set loadedCoreMods, Set loadedMods) { - if (targetedMods.isEmpty()) return true; - - for (TargetedMod target : targetedMods) { - if (target == TargetedMod.VANILLA) continue; - - // Check coremod first - if (!loadedCoreMods.isEmpty() && target.coreModClass != null - && loadedCoreMods.contains(target.coreModClass)) - return false; - else if (!loadedMods.isEmpty() && target.modId != null && loadedMods.contains(target.modId)) return false; - } - - return true; - } - - private boolean shouldLoad(Set loadedCoreMods, Set loadedMods) { - return (shouldLoadSide() && applyIf.get() - && allModsLoaded(targetedMods, loadedCoreMods, loadedMods) - && noModsLoaded(excludedMods, loadedCoreMods, loadedMods)); - } - - private static class Builder { - - private final String name; - private final List mixinClasses = new ArrayList<>(); - private final List targetedMods = new ArrayList<>(); - private final List excludedMods = new ArrayList<>(); - private Supplier applyIf = null; - private Phase phase = null; - private Side side = null; - - public Builder(String name) { - this.name = name; - } - - public Builder addMixinClasses(String... mixinClasses) { - this.mixinClasses.addAll(Arrays.asList(mixinClasses)); - return this; - } - - public Builder setPhase(Phase phase) { - if (this.phase != null) { - throw new RuntimeException("Trying to define Phase twice for " + this.name); - } - this.phase = phase; - return this; - } - - public Builder setSide(Side side) { - if (this.side != null) { - throw new RuntimeException("Trying to define Side twice for " + this.name); - } - this.side = side; - return this; - } - - public Builder setApplyIf(Supplier applyIf) { - this.applyIf = applyIf; - return this; - } - - public Builder addTargetedMod(TargetedMod mod) { - this.targetedMods.add(mod); - return this; - } - - public Builder addExcludedMod(TargetedMod mod) { - this.excludedMods.add(mod); - return this; - } - } - - private enum Side { - BOTH, - CLIENT, - SERVER - } - - private enum Phase { - EARLY, - LATE, - } -}