Skip to content

Commit 055cd4f

Browse files
committed
setup mixins using GTNH IMixins system
1 parent 00cdc25 commit 055cd4f

File tree

9 files changed

+181
-4
lines changed

9 files changed

+181
-4
lines changed

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,26 @@ apiPackage =
7474
accessTransformersFile =
7575

7676
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
77-
usesMixins = false
77+
usesMixins = true
7878

7979
# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
8080
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
8181
# Mixin classes will have access to "main" classes, but not the other way around.
8282
separateMixinSourceSet =
8383

8484
# Adds some debug arguments like verbose output and class export.
85-
usesMixinDebug = false
85+
usesMixinDebug = true
8686

8787
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
8888
mixinPlugin =
8989

9090
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
91-
mixinsPackage =
91+
mixinsPackage = mixins
9292

9393
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
9494
# This parameter is for legacy compatibility only
9595
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
96-
coreModClass =
96+
coreModClass = mixins.EarlyMixinsLoader
9797

9898
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
9999
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.myname.mymodid.mixins;
2+
3+
import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader;
4+
import com.gtnewhorizon.gtnhmixins.builders.IMixins;
5+
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
6+
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.Set;
10+
11+
@IFMLLoadingPlugin.MCVersion("1.7.10")
12+
public class EarlyMixinsLoader implements IFMLLoadingPlugin, IEarlyMixinLoader {
13+
14+
@Override
15+
public String[] getASMTransformerClass() {
16+
return null;
17+
}
18+
19+
@Override
20+
public String getModContainerClass() {
21+
return null;
22+
}
23+
24+
@Override
25+
public String getSetupClass() {
26+
return null;
27+
}
28+
29+
@Override
30+
public void injectData(Map<String, Object> data) {}
31+
32+
@Override
33+
public String getAccessTransformerClass() {
34+
return null;
35+
}
36+
37+
@Override
38+
public String getMixinConfig() {
39+
// rename the associated .json file by replacing the "mymodid" with your own mod ID
40+
// in the .json file edit the "package" and "refmap" properties to match your mod
41+
// also edit the "refmap" property in the "mixins.mymodid.json" file
42+
return "mixins.mymodid.early.json";
43+
}
44+
45+
@Override
46+
public List<String> getMixins(Set<String> loadedCoreMods) {
47+
return IMixins.getEarlyMixins(Mixins.class, loadedCoreMods);
48+
}
49+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.myname.mymodid.mixins;
2+
3+
import com.gtnewhorizon.gtnhmixins.ILateMixinLoader;
4+
import com.gtnewhorizon.gtnhmixins.LateMixin;
5+
import com.gtnewhorizon.gtnhmixins.builders.IMixins;
6+
7+
import javax.annotation.Nonnull;
8+
import java.util.List;
9+
import java.util.Set;
10+
11+
// The annotation is required, it indicates to
12+
// the mixins framework to instantiate this class
13+
// and look for LateMixins to load.
14+
@LateMixin
15+
public class LateMixinsLoader implements ILateMixinLoader {
16+
17+
@Override
18+
public String getMixinConfig() {
19+
// rename the associated .json file by replacing the "mymodid" with your own mod ID
20+
// in the .json file edit the "package" and "refmap" properties to match your mod
21+
// also edit the "refmap" property in the "mixins.mymodid.json" file
22+
return "mixins.mymodid.late.json";
23+
}
24+
25+
@Nonnull
26+
@Override
27+
public List<String> getMixins(Set<String> loadedMods) {
28+
return IMixins.getLateMixins(Mixins.class, loadedMods);
29+
}
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.myname.mymodid.mixins;
2+
3+
import com.gtnewhorizon.gtnhmixins.builders.IMixins;
4+
import com.gtnewhorizon.gtnhmixins.builders.MixinBuilder;
5+
6+
import javax.annotation.Nonnull;
7+
8+
public enum Mixins implements IMixins {
9+
10+
// Read the java doc of IMixins and MixinBuilder for further information
11+
12+
// You should declare all of your mixins early and late in this same enum
13+
14+
EXAMPLE(new MixinBuilder()
15+
.setPhase(Phase.EARLY)
16+
.addClientMixins("MixinMinecraft_Example"));
17+
18+
private final MixinBuilder builder;
19+
20+
Mixins(MixinBuilder builder) {
21+
this.builder = builder;
22+
}
23+
24+
@Nonnull
25+
@Override
26+
public MixinBuilder getBuilder() {
27+
return builder;
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.myname.mymodid.mixins;
2+
3+
import com.gtnewhorizon.gtnhmixins.builders.ITargetMod;
4+
import com.gtnewhorizon.gtnhmixins.builders.TargetModBuilder;
5+
6+
import javax.annotation.Nonnull;
7+
8+
public enum TargetMods implements ITargetMod {
9+
10+
// Read the java doc of ITargetMod and TargetModBuilder for further information
11+
12+
// Add to this enum information about the mods you need to identify during runtime
13+
14+
COFHCORE("cofh.asm.LoadingPlugin", "CoFHCore"),
15+
OPTIFINE("optifine.OptiFineForgeTweaker", "Optifine");
16+
17+
private final TargetModBuilder builder;
18+
19+
TargetMods(String coreModClass, String modId) {
20+
this.builder = new TargetModBuilder().setCoreModClass(coreModClass).setModId(modId);
21+
}
22+
23+
@Nonnull
24+
@Override
25+
public TargetModBuilder getBuilder() {
26+
return builder;
27+
}
28+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.myname.mymodid.mixins.early;
2+
3+
import net.minecraft.client.Minecraft;
4+
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
9+
10+
@Mixin(Minecraft.class) // the class targeted by this mixin
11+
public class MixinMinecraft_Example { // This is an example you should delete this class
12+
13+
@Inject(method = "startGame", at = @At("TAIL"))
14+
private void example$sayHello(CallbackInfo ci) {
15+
// this line of code will be injected at the end of the method "startGame" in the Minecraft class
16+
System.out.println("Example mod says Hello from within Minecraft.startGame()!");
17+
}
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"required": true,
3+
"minVersion": "0.8.5-GTNH",
4+
"package": "com.myname.mymodid.mixins.early",
5+
"refmap": "mixins.mymodid.refmap.json",
6+
"target": "@env(DEFAULT)",
7+
"compatibilityLevel": "JAVA_8"
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"required": true,
3+
"minVersion": "0.8.5-GTNH",
4+
"refmap": "mixins.mymodid.refmap.json",
5+
"target": "@env(DEFAULT)",
6+
"compatibilityLevel": "JAVA_8"
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"required": true,
3+
"minVersion": "0.8.5-GTNH",
4+
"package": "com.myname.mymodid.mixins.late",
5+
"refmap": "mixins.mymodid.refmap.json",
6+
"target": "@env(DEFAULT)",
7+
"compatibilityLevel": "JAVA_8"
8+
}

0 commit comments

Comments
 (0)