Skip inactive player pose work

This commit is contained in:
KAMKEEL committed 2026-09-18 04:48:54 -04:00
1 parent dbbca1c4ec
commit 3ecf0a8970
6 files changed
+78 -24

No files matched your search

@@ -64,6 +64,7 @@ public class ClientEventHandler {
public static boolean renderingEntityInGUI;
public static EntityNPCInterface renderingNpc;
public static EntityPlayer renderingPlayer;
public static boolean renderingPlayerAnimation;
public static HashMap<EnumAnimationPart, String[]> partNames = new HashMap<>();
public static HashMap<Class<?>, Field[]> declaredFieldCache = new HashMap<>();
@@ -164,6 +165,7 @@ public class ClientEventHandler {
public void onRenderEntity(RenderLivingEvent.Pre event) {
if (event.entity instanceof EntityNPCInterface) {
ClientEventHandler.renderingPlayer = null;
ClientEventHandler.renderingPlayerAnimation = false;
ClientEventHandler.renderingNpc = (EntityNPCInterface) event.entity;
}
ClientEventHandler.renderer = event.renderer;
@@ -230,6 +232,7 @@ public class ClientEventHandler {
public void onRenderPlayer(RenderPlayerEvent.Pre event) {
ClientEventHandler.renderingNpc = null;
ClientEventHandler.renderingPlayer = event.entityPlayer;
ClientEventHandler.renderingPlayerAnimation = PlayerModelAnimation.shouldApply(event.entityPlayer);
if (!loggedPlayerRenderer) {
loggedPlayerRenderer = true;
String model = event.renderer.mainModel == null ? "null"
@@ -253,6 +256,7 @@ public class ClientEventHandler {
restoreEquippedItemPose();
EntityPlayer player = event.entityPlayer;
ClientEventHandler.renderingPlayer = null;
ClientEventHandler.renderingPlayerAnimation = false;
if (hasOverlays(player)) {
if (renderPlayerJBRA != null && renderPlayerJBRA.isInstance(event.renderer))
@@ -283,6 +287,10 @@ public class ClientEventHandler {
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void applyEquippedItemPose(RenderPlayerEvent.Specials.Pre event) {
restoreEquippedItemPose();
if (!ClientEventHandler.renderingPlayerAnimation) {
return;
}
ModelBiped model = event.renderer.modelBipedMain;
if (model == null) {
return;
@@ -1,11 +1,15 @@
package noppes.npcs.client.model;
import kamkeel.npcs.addon.DBCAddon;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import noppes.npcs.AnimationMixinFunctions;
import java.util.HashSet;
import java.util.Set;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.controllers.data.AnimationData;
public final class PlayerModelAnimation {
private PlayerModelAnimation() {
@@ -15,6 +19,22 @@ public final class PlayerModelAnimation {
return new Pose(parts(model));
}
/**
* Avoids snapshotting and reapplying six model parts for every visible
* player when there is no animation capable of changing their pose.
* DBC is kept on the compatibility path because its optional addon owns
* its animation-active check inside applyRenderModel.
*/
public static boolean shouldApply(Entity entity) {
if (entity == null) {
return false;
}
AnimationData data = ClientCacheHandler.playerAnimations.get(entity.getUniqueID());
return data != null && data.animation != null && data.isActive()
|| DBCAddon.IsAvailable();
}
private static final Set<String> REPORTED = new HashSet<String>();
public static void apply(ModelBiped model) {
@@ -1,6 +1,7 @@
package noppes.npcs.mixin.late;
import net.minecraft.client.model.ModelBiped;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.client.model.PlayerModelAnimation;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
@@ -30,9 +31,15 @@ public abstract class MixinGalacticraftPlayerModel {
private void cnpc$beginRender(Entity entity, float limbSwing, float limbSwingAmount,
float age, float yaw, float pitch, float scale,
CallbackInfo callbackInfo) {
cnpc$rendering = ClientEventHandler.renderingPlayer == entity
&& ClientEventHandler.renderingPlayerAnimation;
if (!cnpc$rendering) {
cnpc$pose = null;
return;
}
ModelBiped model = (ModelBiped) (Object) this;
cnpc$pose = PlayerModelAnimation.capture(model);
cnpc$rendering = true;
}
@Inject(
@@ -1,6 +1,7 @@
package noppes.npcs.mixin.late;
import net.minecraft.client.model.ModelBiped;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.client.model.PlayerModelAnimation;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
@@ -21,6 +22,7 @@ public abstract class MixinMPMModel {
@Unique private static boolean cnpc$loggedModelEntry;
@Unique private static boolean cnpc$loggedModelHook;
@Unique private PlayerModelAnimation.Pose cnpc$pose;
@Unique private boolean cnpc$rendering;
@Inject(
method = {
@@ -34,11 +36,16 @@ public abstract class MixinMPMModel {
private void cnpc$logModelEntry(Entity entity, float limbSwing, float limbSwingAmount,
float age, float yaw, float pitch, float scale,
CallbackInfo callbackInfo) {
cnpc$pose = PlayerModelAnimation.capture((ModelBiped) (Object) this);
if (!cnpc$loggedModelEntry) {
cnpc$loggedModelEntry = true;
System.out.println("[CustomNPC+] MPM ModelMPM render method is running");
}
cnpc$rendering = ClientEventHandler.renderingPlayer == entity
&& ClientEventHandler.renderingPlayerAnimation;
cnpc$pose = cnpc$rendering
? PlayerModelAnimation.capture((ModelBiped) (Object) this)
: null;
}
@Inject(
@@ -58,6 +65,10 @@ public abstract class MixinMPMModel {
private void cnpc$applyPlayerAnimation(Entity entity, float limbSwing, float limbSwingAmount,
float age, float yaw, float pitch, float scale,
CallbackInfo callbackInfo) {
if (!cnpc$rendering) {
return;
}
ModelBiped model = (ModelBiped) (Object) this;
if (!cnpc$loggedModelHook) {
cnpc$loggedModelHook = true;
@@ -84,5 +95,6 @@ public abstract class MixinMPMModel {
cnpc$pose.restore();
cnpc$pose = null;
}
cnpc$rendering = false;
}
}
@@ -2,9 +2,7 @@ package noppes.npcs.mixin.late;
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;
@@ -45,6 +43,11 @@ public abstract class MixinMPMModelScaleRenderer {
System.out.println("[CustomNPC+] MPM ModelScaleRenderer render hook is running; model="
+ renderer.baseModel.getClass().getName());
}
cnpc$changed = false;
if (!ClientEventHandler.renderingPlayerAnimation) {
return;
}
cnpc$pointX = renderer.rotationPointX;
cnpc$pointY = renderer.rotationPointY;
cnpc$pointZ = renderer.rotationPointZ;
@@ -58,25 +61,21 @@ 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());
}
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) {
@@ -1,6 +1,7 @@
package noppes.npcs.mixin.late;
import net.minecraft.client.model.ModelBiped;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.client.model.PlayerModelAnimation;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
@@ -31,12 +32,19 @@ public abstract class MixinPlayerAPIModel {
private void cnpc$beginRender(Entity entity, float limbSwing, float limbSwingAmount,
float age, float yaw, float pitch, float scale,
CallbackInfo callbackInfo) {
cnpc$rendering = ClientEventHandler.renderingPlayer == entity
&& ClientEventHandler.renderingPlayerAnimation;
if (!cnpc$rendering) {
cnpc$pose = null;
return;
}
ModelBiped model = cnpc$model();
if (model == null) {
cnpc$rendering = false;
return;
}
cnpc$pose = PlayerModelAnimation.capture(model);
cnpc$rendering = true;
}
@Inject(