Skip to content
This repository was archived by the owner on Aug 30, 2019. It is now read-only.

Commit 47be42a

Browse files
committed
Use IMixinConfigPlugin#postApply to substitute JEID config for mine
* As there is no way within the mixin framework to alter the target method at runtime, this is the best way I have found to apply this.
1 parent 2fa1abc commit 47be42a

File tree

7 files changed

+73
-21
lines changed

7 files changed

+73
-21
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ apply plugin: 'org.spongepowered.mixin'
1414

1515
def buildnumber = System.getenv('TRAVIS_BUILD_NUMBER')
1616
def suffix = buildnumber != null ? ".$buildnumber" : "-SNAPSHOT"
17-
version = "1.3.0$suffix"
17+
version = "1.3.1$suffix"
1818
group = "uk.bobbytables.jeidsi" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
1919
archivesBaseName = "jeidsi"
2020

src/main/java/uk/bobbytables/jeidsi/core/JEIDsILoadingPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class JEIDsILoadingPlugin implements IFMLLoadingPlugin {
1717

1818
public JEIDsILoadingPlugin() {
1919
MixinBootstrap.init();
20-
Mixins.addConfiguration("mixins.jeid.server.init.json"); // We NEED JEID's loader plugin on the server too
20+
Mixins.addConfiguration("mixins.jeid.server.init.json"); // We NEED JEID's Loader plugin on the server too
2121
Mixins.addConfiguration("mixins.jeidsi.init.json");
2222
}
2323

src/main/java/uk/bobbytables/jeidsi/core/compat/advancedrocketry/mixins/MixinPacketBiomeIDChange.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import net.minecraft.client.Minecraft;
55
import net.minecraft.entity.player.EntityPlayer;
66
import net.minecraft.world.chunk.Chunk;
7+
import net.minecraftforge.fml.relauncher.Side;
8+
import net.minecraftforge.fml.relauncher.SideOnly;
79
import org.dimdev.jeid.INewChunk;
810
import org.spongepowered.asm.mixin.Mixin;
911
import org.spongepowered.asm.mixin.Overwrite;
@@ -15,8 +17,6 @@
1517
import zmaster587.advancedRocketry.network.PacketBiomeIDChange;
1618
import zmaster587.libVulpes.util.HashedBlockPosition;
1719

18-
import static uk.bobbytables.jeidsi.JEIDsI.LOGGER;
19-
2020
@Mixin(PacketBiomeIDChange.class)
2121
public class MixinPacketBiomeIDChange {
2222
@Shadow
@@ -73,6 +73,7 @@ public void readClient(ByteBuf in) {
7373
/**
7474
* @author sk2048
7575
*/
76+
@SideOnly(Side.CLIENT)
7677
@Overwrite(remap = false)
7778
public void executeClient(EntityPlayer thePlayer) {
7879
if (thePlayer.world.provider.getDimension() == worldId) {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package uk.bobbytables.jeidsi.core.init;
2+
3+
import org.spongepowered.asm.lib.Opcodes;
4+
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
5+
import org.spongepowered.asm.lib.tree.ClassNode;
6+
import org.spongepowered.asm.lib.tree.LdcInsnNode;
7+
import org.spongepowered.asm.lib.tree.MethodNode;
8+
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
9+
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
10+
11+
import java.util.Iterator;
12+
import java.util.List;
13+
import java.util.Set;
14+
15+
import static uk.bobbytables.jeidsi.core.JEIDsILoadingPlugin.LOGGER;
16+
17+
public class InitPlugin implements IMixinConfigPlugin {
18+
@Override
19+
public void onLoad(String mixinPackage) {
20+
}
21+
22+
@Override
23+
public String getRefMapperConfig() {
24+
return null;
25+
}
26+
27+
@Override
28+
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
29+
return true;
30+
}
31+
32+
@Override
33+
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
34+
}
35+
36+
@Override
37+
public List<String> getMixins() {
38+
return null;
39+
}
40+
41+
@Override
42+
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
43+
}
44+
45+
@Override
46+
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
47+
for (MethodNode methodNode : targetClass.methods) {
48+
Iterator<AbstractInsnNode> insnNodeIterator = methodNode.instructions.iterator();
49+
while (insnNodeIterator.hasNext()) {
50+
AbstractInsnNode abstractInsnNode = insnNodeIterator.next();
51+
52+
if (abstractInsnNode.getOpcode() != Opcodes.LDC) continue;
53+
54+
LdcInsnNode ldcInsnNode = (LdcInsnNode) abstractInsnNode;
55+
if (ldcInsnNode.cst.equals("mixins.jeid.modsupport.json")) {
56+
LOGGER.info("JEID modsupport init method found: {}", methodNode.name);
57+
LOGGER.info("Substituting our config at instruction {}", methodNode.instructions.indexOf(ldcInsnNode));
58+
ldcInsnNode.cst = "mixins.jeidsi.jeidmodsupport.json";
59+
return;
60+
}
61+
}
62+
}
63+
LOGGER.error("JEIDsI has not got a veto over JEID's mod support, report to JEIDsI");
64+
}
65+
}

src/main/java/uk/bobbytables/jeidsi/core/init/mixins/MixinLoaderEarly.java renamed to src/main/java/uk/bobbytables/jeidsi/core/init/mixins/MixinLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Inject into loadMods BEFORE JEID does, adding our configs to the mixin environment it uses
1313
*/
1414
@Mixin(value = Loader.class, priority = 500)
15-
public class MixinLoaderEarly {
15+
public class MixinLoader {
1616
@Inject(
1717
method = "loadMods",
1818
at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/LoadController;transition(Lnet/minecraftforge/fml/common/LoaderState;Z)V", ordinal = 1),

src/main/java/uk/bobbytables/jeidsi/core/init/mixins/MixinLoaderLate.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/resources/mixins.jeidsi.init.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"package": "uk.bobbytables.jeidsi.core.init",
3+
"plugin": "uk.bobbytables.jeidsi.core.init.InitPlugin",
34
"required": true,
45
"refmap": "mixins.jeidsi.refmap.json",
56
"target": "@env(INIT)",
67
"minVersion": "0.6",
78
"compatibilityLevel": "JAVA_8",
89
"mixins": [
9-
"mixins.MixinLoaderEarly",
10-
"mixins.MixinLoaderLate"
10+
"mixins.MixinLoader"
1111
],
1212
"injectors": {
1313
"maxShiftBy": 10

0 commit comments

Comments
 (0)