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

Commit

Permalink
Use IMixinConfigPlugin#postApply to substitute JEID config for mine
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
sam-kirby committed Jul 10, 2019
1 parent 2fa1abc commit 47be42a
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'org.spongepowered.mixin'

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class JEIDsILoadingPlugin implements IFMLLoadingPlugin {

public JEIDsILoadingPlugin() {
MixinBootstrap.init();
Mixins.addConfiguration("mixins.jeid.server.init.json"); // We NEED JEID's loader plugin on the server too
Mixins.addConfiguration("mixins.jeid.server.init.json"); // We NEED JEID's Loader plugin on the server too
Mixins.addConfiguration("mixins.jeidsi.init.json");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.dimdev.jeid.INewChunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
Expand All @@ -15,8 +17,6 @@
import zmaster587.advancedRocketry.network.PacketBiomeIDChange;
import zmaster587.libVulpes.util.HashedBlockPosition;

import static uk.bobbytables.jeidsi.JEIDsI.LOGGER;

@Mixin(PacketBiomeIDChange.class)
public class MixinPacketBiomeIDChange {
@Shadow
Expand Down Expand Up @@ -73,6 +73,7 @@ public void readClient(ByteBuf in) {
/**
* @author sk2048
*/
@SideOnly(Side.CLIENT)
@Overwrite(remap = false)
public void executeClient(EntityPlayer thePlayer) {
if (thePlayer.world.provider.getDimension() == worldId) {
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/uk/bobbytables/jeidsi/core/init/InitPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package uk.bobbytables.jeidsi.core.init;

import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.LdcInsnNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import static uk.bobbytables.jeidsi.core.JEIDsILoadingPlugin.LOGGER;

public class InitPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return true;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
for (MethodNode methodNode : targetClass.methods) {
Iterator<AbstractInsnNode> insnNodeIterator = methodNode.instructions.iterator();
while (insnNodeIterator.hasNext()) {
AbstractInsnNode abstractInsnNode = insnNodeIterator.next();

if (abstractInsnNode.getOpcode() != Opcodes.LDC) continue;

LdcInsnNode ldcInsnNode = (LdcInsnNode) abstractInsnNode;
if (ldcInsnNode.cst.equals("mixins.jeid.modsupport.json")) {
LOGGER.info("JEID modsupport init method found: {}", methodNode.name);
LOGGER.info("Substituting our config at instruction {}", methodNode.instructions.indexOf(ldcInsnNode));
ldcInsnNode.cst = "mixins.jeidsi.jeidmodsupport.json";
return;
}
}
}
LOGGER.error("JEIDsI has not got a veto over JEID's mod support, report to JEIDsI");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Inject into loadMods BEFORE JEID does, adding our configs to the mixin environment it uses
*/
@Mixin(value = Loader.class, priority = 500)
public class MixinLoaderEarly {
public class MixinLoader {
@Inject(
method = "loadMods",
at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/LoadController;transition(Lnet/minecraftforge/fml/common/LoaderState;Z)V", ordinal = 1),
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/resources/mixins.jeidsi.init.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"package": "uk.bobbytables.jeidsi.core.init",
"plugin": "uk.bobbytables.jeidsi.core.init.InitPlugin",
"required": true,
"refmap": "mixins.jeidsi.refmap.json",
"target": "@env(INIT)",
"minVersion": "0.6",
"compatibilityLevel": "JAVA_8",
"mixins": [
"mixins.MixinLoaderEarly",
"mixins.MixinLoaderLate"
"mixins.MixinLoader"
],
"injectors": {
"maxShiftBy": 10
Expand Down

0 comments on commit 47be42a

Please sign in to comment.