Skip to content

Commit c4df59d

Browse files
committed
setup mixins using GTNH early/late mixins system
1 parent 00cdc25 commit c4df59d

File tree

7 files changed

+157
-4
lines changed

7 files changed

+157
-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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.myname.mymodid.mixins;
2+
3+
import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader;
4+
import cpw.mods.fml.relauncher.FMLLaunchHandler;
5+
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
import java.util.Map;
10+
import java.util.Set;
11+
12+
@IFMLLoadingPlugin.MCVersion("1.7.10")
13+
public class EarlyMixinsLoader implements IFMLLoadingPlugin, IEarlyMixinLoader {
14+
15+
@Override
16+
public String[] getASMTransformerClass() {
17+
return null;
18+
}
19+
20+
@Override
21+
public String getModContainerClass() {
22+
return null;
23+
}
24+
25+
@Override
26+
public String getSetupClass() {
27+
return null;
28+
}
29+
30+
@Override
31+
public void injectData(Map<String, Object> data) {}
32+
33+
@Override
34+
public String getAccessTransformerClass() {
35+
return null;
36+
}
37+
38+
@Override
39+
public String getMixinConfig() {
40+
// rename the associated .json file by replacing the "mymodid" with your own mod ID
41+
// in the .json file edit the "package" and "refmap" properties to match your mod
42+
// also edit the "refmap" property in the "mixins.mymodid.json" file
43+
return "mixins.mymodid.early.json";
44+
}
45+
46+
@Override
47+
public List<String> getMixins(Set<String> loadedCoreMods) {
48+
// Register your mixins here by adding them to the list.
49+
// The early mixins are mixins that target minecraft/forge classes
50+
// The early mixins should be placed in the "mixins/early" package
51+
// If your mixins targets a class from another mod, register it in the LateMixinLoader
52+
List<String> mixins = new ArrayList<>();
53+
54+
// The parameter loadedCoreMods contains the name of coremods that are currently loaded
55+
// you can check this Set to decide to load certain mixins or not.
56+
//if (!loadedCoreMods.contains("optifine.OptiFineForgeTweaker")) {
57+
// // this mixins won't be loaded if Optifine is present
58+
// mixins.add("MixinClass");
59+
//}
60+
61+
if (FMLLaunchHandler.side().isClient()) {
62+
// register here your mixins that should only be loaded on the client
63+
mixins.add("MixinMinecraft_Example");// this is an example you should delete it and the associated mixin class as well
64+
} else {
65+
// register here your mixins that should only be loaded on the dedicated server
66+
// mixins.add("MixinClass");
67+
}
68+
69+
// register here your mixins that should be loaded on both sides
70+
// mixins.add("MixinClass");
71+
72+
// If you need more complex registration logic consider switching to the IMixins registration
73+
// system see com.gtnewhorizon.gtnhmixins.builders.IMixins
74+
return mixins;
75+
}
76+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.myname.mymodid.mixins;
2+
3+
import com.gtnewhorizon.gtnhmixins.ILateMixinLoader;
4+
import com.gtnewhorizon.gtnhmixins.LateMixin;
5+
6+
import javax.annotation.Nonnull;
7+
import java.util.ArrayList;
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+
// Register your mixins here by adding them to the list.
29+
// The late mixins are mixins that target classes from other mods
30+
// The late mixins should be placed in the "mixins/late" package
31+
List<String> mixins = new ArrayList<>();
32+
// The loadedMods contains the mod ID of the mods that are currently loaded
33+
// you can check this Set to decide to load certain mixins or not.
34+
return mixins;
35+
}
36+
}
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)