mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-12 08:27:33 +00:00
Allow mixins to depend on multiple mods
This commit is contained in:
1 parent
6cd68ed3df
commit
198ba19ebb
2 files changed
+31
-20
No files matched your search
@@ -1,5 +1,8 @@
|
||||
package com.myname.mymodid.mixinplugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.myname.mymodid.mixinplugin.TargetedMod.*;
|
||||
|
||||
public enum Mixin {
|
||||
@@ -11,17 +14,18 @@ public enum Mixin {
|
||||
//
|
||||
|
||||
// Replace with your own mixins:
|
||||
ItemEditableBookMixin("minecraft.ItemEditableBookMixin", VANILLA, false),
|
||||
GT_Block_Ores_AbstractMixin("gregtech.GT_Block_Ores_AbstractMixin", GREGTECH, false);
|
||||
ItemEditableBookMixin("minecraft.ItemEditableBookMixin", false, VANILLA),
|
||||
// You may also require multiple mods to be loaded if your mixin requires both
|
||||
GT_Block_Ores_AbstractMixin("gregtech.GT_Block_Ores_AbstractMixin", false, GREGTECH, VANILLA);
|
||||
|
||||
public final String mixinClass;
|
||||
public final TargetedMod targetedMod;
|
||||
public final List<TargetedMod> targetedMods;
|
||||
// Injecting into @SideOnly(Side.Client) classes will crash the server. Flag them as clientSideOnly!
|
||||
public final boolean clientSideOnly;
|
||||
|
||||
Mixin(String mixinClass, TargetedMod targetedMod, boolean clientSideOnly) {
|
||||
Mixin(String mixinClass, boolean clientSideOnly, TargetedMod... targetedMods) {
|
||||
this.mixinClass = mixinClass;
|
||||
this.targetedMod = targetedMod;
|
||||
this.targetedMods = Arrays.asList(targetedMods);
|
||||
this.clientSideOnly = clientSideOnly;
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,16 @@ import ru.timeconqueror.spongemixins.MinecraftURLClassPath;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.myname.mymodid.mixinplugin.TargetedMod.VANILLA;
|
||||
|
||||
public class MixinPlugin implements IMixinConfigPlugin {
|
||||
|
||||
private static Logger LOG = LogManager.getLogger(Tags.MODID + " mixins");
|
||||
private static final Logger LOG = LogManager.getLogger(Tags.MODID + " mixins");
|
||||
|
||||
@Override
|
||||
public void onLoad(String mixinPackage) {
|
||||
@@ -46,25 +50,28 @@ public class MixinPlugin implements IMixinConfigPlugin {
|
||||
final boolean loadClientSideOnlyClasses = FMLLaunchHandler.side().isClient();
|
||||
final boolean isDevelopmentEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
|
||||
|
||||
List<String> mixins = new ArrayList<>();
|
||||
for (TargetedMod targetedMod : TargetedMod.values()) {
|
||||
if (targetedMod == TargetedMod.VANILLA
|
||||
|| (targetedMod.loadInDevelopment && isDevelopmentEnvironment)
|
||||
|| loadJar(targetedMod.jarNameBeginsWith)) {
|
||||
LOG.info("Found " + targetedMod.modName + "! Integrating now...");
|
||||
for (Mixin mixin : Mixin.values()) {
|
||||
if (mixin.targetedMod == targetedMod
|
||||
&& (mixin.clientSideOnly == false || loadClientSideOnlyClasses)) {
|
||||
mixins.add(mixin.mixinClass);
|
||||
LOG.debug("Loading mixin: " + mixin.mixinClass);
|
||||
}
|
||||
}
|
||||
List<TargetedMod> loadedMods = Arrays.stream(TargetedMod.values())
|
||||
.filter(mod -> mod == VANILLA
|
||||
|| (mod.loadInDevelopment && isDevelopmentEnvironment)
|
||||
|| loadJar(mod.jarNameBeginsWith))
|
||||
.collect(Collectors.toList());
|
||||
for (TargetedMod mod : TargetedMod.values()) {
|
||||
if(loadedMods.contains(mod)) {
|
||||
LOG.info("Found " + mod.modName + "! Integrating now...");
|
||||
}
|
||||
else {
|
||||
LOG.info("Could not find " + targetedMod.modName + "! Skipping integration....");
|
||||
LOG.info("Could not find " + mod.modName + "! Skipping integration....");
|
||||
}
|
||||
}
|
||||
|
||||
List<String> mixins = new ArrayList<>();
|
||||
for (Mixin mixin : Mixin.values()) {
|
||||
if (loadedMods.containsAll(mixin.targetedMods)
|
||||
&& (mixin.clientSideOnly == false || loadClientSideOnlyClasses)) {
|
||||
mixins.add(mixin.mixinClass);
|
||||
LOG.debug("Loading mixin: " + mixin.mixinClass);
|
||||
}
|
||||
}
|
||||
return mixins;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user