[Forge] Mixins Not Working


#1

Hi, I’m attempting to implement Mixins into my ForgeGradle mod. I’ve setup ForgeGradle as per, and for implementing Mixin I have followed this guide (https://docs.spongepowered.org/5.1.0/en/plugin/internals/mixins.html). The files from the package org.spongepowered can all be used and I have setup a MixinEntityPlayerSP, and a MixinLoader that initializes the MixinBootstrap:

MixinBootstrap.init();
    Mixins.addConfiguration("mixins.myplugin.json");

Here is the MixinEntityPlayerSP in question:

@Mixin(EntityPlayerSP.class)
public abstract class MixinEntityPlayerSP 
{
	@Inject(method = "onLivingUpdate", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/entity/EntityPlayerSP;sprintToggleTimer:I", ordinal = 1, shift = At.Shift.AFTER), cancellable = true)
public void IonLivingUpdate(CallbackInfo callback) {
		System.out.println("test123");
}
}

When I add the bootstrap to the FMLInitializationEvent, it produces this output in console:

SpongePowered MIXIN Subsystem Version=0.5.17 Source=file:/C:/Users/Jamie/.gradle/caches/modules-2/files-2.1/org.spongepowered/mixin/0.5.17-SNAPSHOT/b0bd746034c6530282b5145c432ac03b23776ff2/mixin-0.5.17-SNAPSHOT.jar Env=CLIENT
[03:32:40] [Client thread/INFO]: Compatibility level set to JAVA_8
[03:32:40] [Client thread/WARN]: MixinBootstrap.doInit() called during a tweak constructor. Expect CoModificationException in 5.. 4..

However, when I place the bootstrap in my MixinLoader, there is nothing - no logs in the console, nothing at all. Even though everything is in place the Mixins don’t work at all.

Apologies if this all sounds slightly vague, I’m fairly new to Minecraft modding and I’m not very familiar with some of the processes involved. Nonetheless, if anybody has any idea how to fix this problem, then any advice would be greatly appreciated.


#2

A few things:

  • Mixins need to be initialized by a Coremod, not by an event listener as it’s too late at that point in the initialization process
  • Your Mixin version is severely out of date (we’re on version 0.7.4 already running for 1.12.2)
  • Your injection should probably target a method call instead of a field getter as fields are almost always multiple times in a method.

#3

Thanks for your reply. I’ve managed to fix the problem and the Mixins are working well. However, I’ve encountered another problem involving a private method inside the Minecraft source code.

this.mc.entityRenderer.orientCamera(Wrapper.MC_MIXIN.getTimer().renderPartialTicks);

Basically I’m trying to access the method orientCamera, however it is a private method. How would I access this method?

EDIT: Nevermind, I’ve fixed the problem, just used reflection to grab the method and invoke it.


#4

If you’re mixing into Minecraft, you can shadow the private method. The wiki goes over a lot about using Mixins, I’d absolutely recommend reading through it all.