Skip to content

Commit 4874dfa

Browse files
authored
Placeholder class for certain mods (#21)
1 parent bf07ca7 commit 4874dfa

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package zone.rong.mixinbooter;
2+
3+
import net.minecraft.launchwrapper.Launch;
4+
import net.minecraftforge.fml.common.Loader;
5+
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
6+
7+
import java.util.Collection;
8+
9+
/**
10+
* This class contains loading context for callers
11+
*
12+
*
13+
* @since 10.0
14+
* @deprecated We forked Mixin.
15+
* <br>New approach:
16+
* Check <a href=https://github.com/CleanroomMC/Fugue/tree/master>Fugue</a>.<br>
17+
* Summary:<br>
18+
* If you are coremod, just call {@link org.spongepowered.asm.mixin.Mixins#addConfigurations(String...)} in loadingPluging or Tweaker, and handle shouldApply in IMixinConfigPlugin<br>
19+
* If you aren't coremod:<br>
20+
* Group mixins by phase, add target env in config, use @env(MOD) for mod mixins.<br>
21+
* Add {"MixinConfigs": "modid.mod.mixin.json,modid.default.mixin.json"} to your jar manifest.<br>
22+
* Handle shouldApply in IMixinConfigPlugin. You can call {@link net.minecraftforge.fml.common.Loader#isModLoaded(String)} for {@link org.spongepowered.asm.mixin.MixinEnvironment.Phase#MOD} mixin.<br>
23+
* Recommend to group target mod name by package name. You can also get config instance from {@link org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin#injectConfig(org.spongepowered.asm.mixin.transformer.Config)}.
24+
*/
25+
// TODO: Actually implement the logic
26+
@Deprecated
27+
public final class Context {
28+
29+
public enum ModLoader {
30+
FORGE,
31+
CLEANROOM;
32+
}
33+
34+
private final String mixinConfig;
35+
private final Collection<String> presentMods;
36+
37+
public Context(String mixinConfigIn, Collection<String> presentModsIn) {
38+
this.mixinConfig = mixinConfigIn;
39+
this.presentMods = presentModsIn;
40+
}
41+
42+
public Context(String mixinConfigIn) {
43+
this(mixinConfigIn, null);
44+
}
45+
46+
/**
47+
* @return the current mod loader
48+
*/
49+
public ModLoader modLoader() {
50+
return ModLoader.CLEANROOM;
51+
}
52+
53+
/**
54+
* @return if the current environment is in-dev
55+
*/
56+
public boolean inDev() {
57+
return FMLLaunchHandler.isDeobfuscatedEnvironment();
58+
}
59+
60+
/**
61+
* @return name of the mixin config that is currently being processed
62+
*/
63+
public String mixinConfig() {
64+
return mixinConfig;
65+
}
66+
67+
/**
68+
* <p>For early contexts, the list of mods are gathered from culling the classloader
69+
* for any jars that has the mcmod.info file. The mod IDs are obtained from the mcmod.info file.
70+
* This means mostly, if not only coremods are queryable here,
71+
* make sure to test a normal mod's existence in your mixin plugin or in the mixin itself.</p>
72+
*
73+
* <p>For late contexts, it comes from {@link net.minecraftforge.fml.common.Loader#getActiveModList}
74+
* akin to {@link net.minecraftforge.fml.common.Loader#isModLoaded(String)}</p>
75+
* @param modId to check against the list of present mods in the context
76+
* @return whether the mod is present
77+
*/
78+
public boolean isModPresent(String modId) {
79+
return presentMods == null ? Loader.isModLoaded(modId) : presentMods.contains(modId);
80+
}
81+
82+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package zone.rong.mixinbooter;
2+
3+
import java.util.Set;
4+
5+
/**
6+
* Hijackers are used to stop certain mixin configurations from ever being applied.
7+
* Usage is similar to {@link IEarlyMixinLoader}, implement it in your coremod class.
8+
* Requested by: @Desoroxxx
9+
*
10+
* @since 9.0
11+
* @deprecated We forked Mixin.
12+
* <br>New approach:
13+
* Check <a href=https://github.com/CleanroomMC/Fugue/tree/master>Fugue</a>.<br>
14+
* Summary:<br>
15+
* If you are coremod, just call {@link org.spongepowered.asm.mixin.Mixins#addConfigurations(String...)} in loadingPlugin or Tweaker, and handle shouldApply in IMixinConfigPlugin<br>
16+
* If you aren't coremod:<br>
17+
* Group mixins by phase, add target env in config, use @env(MOD) for mod mixins.<br>
18+
* Add {"MixinConfigs": "modid.mod.mixin.json,modid.default.mixin.json"} to your jar manifest.<br>
19+
* Handle shouldApply in IMixinConfigPlugin. You can call {@link net.minecraftforge.fml.common.Loader#isModLoaded(String)} for {@link org.spongepowered.asm.mixin.MixinEnvironment.Phase#MOD} mixin.<br>
20+
* Recommend to group target mod name by package name. You can also get config instance from {@link org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin#injectConfig(org.spongepowered.asm.mixin.transformer.Config)}.
21+
*
22+
* If you what to block a mixin config, {@code GlobalProperties.get(GlobalProperties.Keys.CLEANROOM_DISABLE_MIXIN_CONFIGS)#add(String)}
23+
*/
24+
25+
// TODO: Actually implement the logic
26+
@Deprecated
27+
public interface IMixinConfigHijacker {
28+
29+
/**
30+
* Return a set of mixin config names to not be loaded by the mixin environment.
31+
*
32+
* @since 9.0
33+
*/
34+
Set<String> getHijackedMixinConfigs();
35+
36+
/**
37+
* Return a set of mixin config names to not be loaded by the mixin environment.
38+
*
39+
* @since 10.3
40+
* @param context current context of the loading process. Mixin config will be null as it is not applicable.
41+
*/
42+
default Set<String> getHijackedMixinConfigs(Context context) {
43+
return getHijackedMixinConfigs();
44+
}
45+
46+
}

0 commit comments

Comments
 (0)