Make MPM animation hooks fail loud and traceable

This commit is contained in:
KAMKEEL committed 2026-09-17 18:38:31 -04:00
1 parent e910691279
commit 2ef2936496
3 files changed
+56 -5

No files matched your search

@@ -14,7 +14,7 @@ import java.util.Set;
public class CustomNPCsMixinPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
System.out.println("[CustomNPC+] Mixin plugin loaded from " + mixinPackage);
}
@Override
@@ -39,6 +39,9 @@ public class CustomNPCsMixinPlugin implements IMixinConfigPlugin {
String configPath = "config" + File.separator + "CustomNpcPlus" + File.separator;
ConfigMixin.init(new File(configPath + "mixin.cfg"));
boolean client = FMLLaunchHandler.side().isClient();
System.out.println("[CustomNPC+] Choosing mixins: side=" + FMLLaunchHandler.side()
+ ", animation=" + ConfigMixin.AnimationMixin
+ ", firstPersonAnimation=" + ConfigMixin.FirstPersonAnimationMixin);
List<String> mixins = new ArrayList<>();
@@ -65,16 +68,22 @@ public class CustomNPCsMixinPlugin implements IMixinConfigPlugin {
mixins.add("MixinEntityTrackerEntry");
}
System.out.println("[CustomNPC+] Selected mixins: " + mixins);
return mixins;
}
@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
if (mixinClassName.endsWith("MixinMPMModelScaleRenderer")) {
System.out.println("[CustomNPC+] Applying MPM animation mixin to " + targetClassName);
}
}
@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
if (mixinClassName.endsWith("MixinMPMModelScaleRenderer")) {
System.out.println("[CustomNPC+] Applied MPM animation mixin to " + targetClassName);
}
}
}
@@ -2,6 +2,9 @@ package noppes.npcs.mixin;
import net.minecraft.client.model.ModelRenderer;
import noppes.npcs.AnimationMixinFunctions;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.controllers.data.AnimationData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
@@ -30,10 +33,18 @@ public abstract class MixinMPMModelScaleRenderer {
@Unique private float cnpc$offsetX;
@Unique private float cnpc$offsetY;
@Unique private float cnpc$offsetZ;
@Unique private static boolean cnpc$loggedRenderHook;
@Unique private static boolean cnpc$loggedAnimation;
@Unique private static boolean cnpc$loggedChangedValues;
@Inject(method = {"render(F)V", "func_78785_a(F)V"}, at = @At("HEAD"), remap = false, require = 0)
@Inject(method = {"render(F)V", "func_78785_a(F)V"}, at = @At("HEAD"), remap = false, require = 1)
private void cnpc$applyAnimation(float scale, CallbackInfo callbackInfo) {
ModelRenderer renderer = (ModelRenderer) (Object) this;
if (!cnpc$loggedRenderHook) {
cnpc$loggedRenderHook = true;
System.out.println("[CustomNPC+] MPM ModelScaleRenderer render hook is running; model="
+ renderer.baseModel.getClass().getName());
}
cnpc$pointX = renderer.rotationPointX;
cnpc$pointY = renderer.rotationPointY;
cnpc$pointZ = renderer.rotationPointZ;
@@ -46,12 +57,36 @@ public abstract class MixinMPMModelScaleRenderer {
try {
cnpc$changed = AnimationMixinFunctions.applyValues(renderer);
if (ClientEventHandler.renderingPlayer != null) {
AnimationData data = ClientCacheHandler.playerAnimations.get(
ClientEventHandler.renderingPlayer.getUniqueID());
if (data != null && data.animation != null && data.isActive()) {
boolean valuesChanged = cnpc$pointX != renderer.rotationPointX
|| cnpc$pointY != renderer.rotationPointY
|| cnpc$pointZ != renderer.rotationPointZ
|| cnpc$angleX != renderer.rotateAngleX
|| cnpc$angleY != renderer.rotateAngleY
|| cnpc$angleZ != renderer.rotateAngleZ;
if (!cnpc$loggedAnimation) {
cnpc$loggedAnimation = true;
System.out.println("[CustomNPC+] MPM render hook sees active animation for "
+ ClientEventHandler.renderingPlayer.getCommandSenderName());
}
if (valuesChanged && !cnpc$loggedChangedValues) {
cnpc$loggedChangedValues = true;
System.out.println("[CustomNPC+] MPM animation changed limb values; limb="
+ renderer.getClass().getName());
}
}
}
} catch (Exception ignored) {
cnpc$changed = false;
System.out.println("[CustomNPC+] MPM animation hook failed: " + ignored);
ignored.printStackTrace(System.out);
}
}
@Inject(method = {"render(F)V", "func_78785_a(F)V"}, at = @At("RETURN"), remap = false, require = 0)
@Inject(method = {"render(F)V", "func_78785_a(F)V"}, at = @At("RETURN"), remap = false, require = 1)
private void cnpc$restoreAnimation(float scale, CallbackInfo callbackInfo) {
if (!cnpc$changed) return;
@@ -4,6 +4,7 @@ import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.AnimationMixinFunctions;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -11,11 +12,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(RendererLivingEntity.class)
public class MixinRendererLivingEntity {
@Unique private static boolean cnpc$loggedLivingRenderHook;
@Inject(method = "doRender(Lnet/minecraft/entity/EntityLivingBase;DDDFF)V", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/entity/RendererLivingEntity;renderModel(Lnet/minecraft/entity/EntityLivingBase;FFFFFF)V",
shift = At.Shift.BEFORE))
public void render_pre(EntityLivingBase p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_, CallbackInfo ci) {
if (!cnpc$loggedLivingRenderHook) {
cnpc$loggedLivingRenderHook = true;
System.out.println("[CustomNPC+] RendererLivingEntity animation hook is running");
}
AnimationMixinFunctions.playerFullModel_head(p_76986_1_, ci);
}
}