From 7f407c3c44543c963525d94889e96ce677140491 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Tue, 10 Jan 2023 13:10:22 -0600 Subject: [PATCH 1/5] Fixed puppet model rotations/offsets crossing over NPCs when they shouldn't. --- .../npcs/client/ClientEventHandler.java | 3 +++ .../noppes/npcs/mixin/MixinModelRenderer.java | 22 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index 0439765f4..a09f858a7 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -31,6 +31,9 @@ public class ClientEventHandler { public static EntityPlayer renderingPlayer; public static RendererLivingEntity renderer; + public static float[] undoRotations = new float[]{0,0,0}; + public static float[] undoPivots = new float[]{0,0,0}; + @SubscribeEvent public void onMouse(MouseEvent event) { if (Minecraft.getMinecraft().currentScreen != null) diff --git a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java index 82dc476ba..b8c304155 100644 --- a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java @@ -2,7 +2,6 @@ package noppes.npcs.mixin; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.client.model.ModelBiped; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.EntityLivingBase; import noppes.npcs.client.Client; @@ -75,6 +74,9 @@ public class MixinModelRenderer { } } if (ClientEventHandler.renderingNpc != null && ClientEventHandler.renderingNpc.jobInterface instanceof JobPuppet) { + ClientEventHandler.undoRotations = new float[]{this.rotateAngleX,this.rotateAngleY,this.rotateAngleZ}; + ClientEventHandler.undoPivots = new float[]{this.rotationPointX,this.rotationPointY,this.rotationPointZ}; + this.partName = this.getPartName((ModelRenderer) (Object) this, this.partNames); JobPuppet modelData = (JobPuppet) ClientEventHandler.renderingNpc.jobInterface; this.setModelParts(modelData); @@ -103,6 +105,24 @@ public class MixinModelRenderer { } } + @SideOnly(Side.CLIENT) + @Inject(method = "render", at = @At(value = "TAIL")) + private void originalRotations(float p_78785_1_, CallbackInfo callbackInfo) + { + if (ClientEventHandler.undoRotations != null) { + this.rotateAngleX = ClientEventHandler.undoRotations[0]; + this.rotateAngleY = ClientEventHandler.undoRotations[1]; + this.rotateAngleZ = ClientEventHandler.undoRotations[2]; + ClientEventHandler.undoRotations = null; + } + if (ClientEventHandler.undoPivots != null) { + this.rotationPointX = ClientEventHandler.undoPivots[0]; + this.rotationPointY = ClientEventHandler.undoPivots[1]; + this.rotationPointZ = ClientEventHandler.undoPivots[2]; + ClientEventHandler.undoPivots = null; + } + } + public String getPartName(ModelRenderer renderer, HashMap partNames) { Class RenderClass = renderer.baseModel.getClass(); Object model = renderer.baseModel; From 1aee4c06fc7a24ae1ec2afdedac41873d154d990 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Tue, 10 Jan 2023 13:25:21 -0600 Subject: [PATCH 2/5] Small optimizations for the NPC puppet mixin. --- .../npcs/client/renderer/RenderCustomNpc.java | 2 +- .../noppes/npcs/mixin/MixinModelRenderer.java | 41 ++++++------------- .../java/noppes/npcs/roles/JobPuppet.java | 5 --- 3 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java index 22c619b99..a1261f2c1 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java @@ -22,7 +22,7 @@ import org.lwjgl.opengl.GL11; public class RenderCustomNpc extends RenderNPCHumanMale{ - private RendererLivingEntity renderEntity; + public static RendererLivingEntity renderEntity; private EntityLivingBase entity; private ModelRenderPassHelper renderpass = new ModelRenderPassHelper(); diff --git a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java index b8c304155..b822cab61 100644 --- a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java @@ -6,6 +6,7 @@ import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.EntityLivingBase; import noppes.npcs.client.Client; import noppes.npcs.client.ClientEventHandler; +import noppes.npcs.client.renderer.RenderCustomNpc; import noppes.npcs.controllers.data.PlayerModelData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -73,26 +74,17 @@ public class MixinModelRenderer { } } } - if (ClientEventHandler.renderingNpc != null && ClientEventHandler.renderingNpc.jobInterface instanceof JobPuppet) { - ClientEventHandler.undoRotations = new float[]{this.rotateAngleX,this.rotateAngleY,this.rotateAngleZ}; - ClientEventHandler.undoPivots = new float[]{this.rotationPointX,this.rotationPointY,this.rotationPointZ}; - + if (ClientEventHandler.renderingNpc != null && ClientEventHandler.renderingNpc.jobInterface instanceof JobPuppet && RenderCustomNpc.renderEntity != null) { this.partName = this.getPartName((ModelRenderer) (Object) this, this.partNames); JobPuppet modelData = (JobPuppet) ClientEventHandler.renderingNpc.jobInterface; this.setModelParts(modelData); if (modelData.isActive()) { JobPuppet.PartConfig[] partConfigs = new JobPuppet.PartConfig[]{modelData.head, modelData.body, modelData.larm, modelData.rarm, modelData.lleg, modelData.rleg}; - EntityLivingBase entityModel = ((EntityCustomNpc) ClientEventHandler.renderingNpc).modelData.getEntity(ClientEventHandler.renderingNpc); - if (entityModel == null || entityModel instanceof EntityNPCInterface) { - return; - } + ClientEventHandler.undoRotations = new float[]{this.rotateAngleX,this.rotateAngleY,this.rotateAngleZ}; + ClientEventHandler.undoPivots = new float[]{this.rotationPointX,this.rotationPointY,this.rotationPointZ}; for (JobPuppet.PartConfig partConfig : partConfigs) { if (isPart(partConfig)) { - if (partConfig.npcModel == null || !partConfig.npcModel.getClass().equals(entityModel.getClass())) { - partConfig.setOriginalPivot = false; - partConfig.npcModel = entityModel; - } this.rotateAngleX = partConfig.prevRotations[0]; this.rotateAngleY = partConfig.prevRotations[1]; this.rotateAngleZ = partConfig.prevRotations[2]; @@ -180,30 +172,23 @@ public class MixinModelRenderer { } public void addInterpolatedOffset(JobPuppet.PartConfig modelPart) { - if (!modelPart.setOriginalPivot) { - modelPart.setOriginalPivot = true; - modelPart.originalPivotX = this.rotationPointX; - modelPart.originalPivotY = this.rotationPointY; - modelPart.originalPivotZ = this.rotationPointZ; - } - if (!modelPart.animate) { - this.rotationPointX = modelPart.originalPivotX + modelPart.pivotX; - this.rotationPointY = modelPart.originalPivotY + modelPart.pivotY; - this.rotationPointZ = modelPart.originalPivotZ + modelPart.pivotZ; + this.rotationPointX = ClientEventHandler.undoPivots[0] + modelPart.pivotX; + this.rotationPointY = ClientEventHandler.undoPivots[1] + modelPart.pivotY; + this.rotationPointZ = ClientEventHandler.undoPivots[2] + modelPart.pivotZ; } else if (modelPart.partialPivotTick != ClientEventHandler.partialRenderTick) { modelPart.partialPivotTick = ClientEventHandler.partialRenderTick; if (modelPart.interpolate) { modelPart.destPivotX = (modelPart.pivotX - modelPart.destPivotX) * Math.abs(modelPart.animRate) / 10f + modelPart.destPivotX; - this.rotationPointX = modelPart.originalPivotX + modelPart.destPivotX; + this.rotationPointX = ClientEventHandler.undoPivots[0] + modelPart.destPivotX; modelPart.destPivotY = (modelPart.pivotY - modelPart.destPivotY) * Math.abs(modelPart.animRate) / 10f + modelPart.destPivotY; - this.rotationPointY = modelPart.originalPivotY + modelPart.destPivotY; + this.rotationPointY = ClientEventHandler.undoPivots[1] + modelPart.destPivotY; modelPart.destPivotZ = (modelPart.pivotZ - modelPart.destPivotZ) * Math.abs(modelPart.animRate) / 10f + modelPart.destPivotZ; - this.rotationPointZ = modelPart.originalPivotZ + modelPart.destPivotZ; + this.rotationPointZ = ClientEventHandler.undoPivots[2] + modelPart.destPivotZ; } else { - this.rotationPointX = modelPart.originalPivotX + modelPart.prevPivots[0]; - this.rotationPointY = modelPart.originalPivotY + modelPart.prevPivots[1]; - this.rotationPointZ = modelPart.originalPivotZ + modelPart.prevPivots[2]; + this.rotationPointX = ClientEventHandler.undoPivots[0] + modelPart.prevPivots[0]; + this.rotationPointY = ClientEventHandler.undoPivots[1] + modelPart.prevPivots[1]; + this.rotationPointZ = ClientEventHandler.undoPivots[2] + modelPart.prevPivots[2]; int directionX = Float.compare(modelPart.pivotX, modelPart.prevPivots[0]); modelPart.prevPivots[0] += directionX * modelPart.animRate / 10f; modelPart.prevPivots[0] = directionX == 1 ? diff --git a/src/main/java/noppes/npcs/roles/JobPuppet.java b/src/main/java/noppes/npcs/roles/JobPuppet.java index 15b0f66ed..b52e99c08 100644 --- a/src/main/java/noppes/npcs/roles/JobPuppet.java +++ b/src/main/java/noppes/npcs/roles/JobPuppet.java @@ -73,7 +73,6 @@ public class JobPuppet extends JobInterface{ public static class PartConfig implements IModelPart { public Object parent; - public EntityLivingBase npcModel; public float rotationX = 0f; public float rotationY = 0f; @@ -96,10 +95,6 @@ public class JobPuppet extends JobInterface{ public float destPivotX = 0f; public float destPivotY = 0f; public float destPivotZ = 0f; - public boolean setOriginalPivot = false; - public float originalPivotX = 0f; - public float originalPivotY = 0f; - public float originalPivotZ = 0f; // ^^^ Client-sided use ^^^ public boolean disabled = false; From cbc0b823564359a26649575fc9a6b62d0503e395 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Tue, 10 Jan 2023 15:06:37 -0600 Subject: [PATCH 3/5] Undid previous commit, messed with offsets too much. --- .../noppes/npcs/client/renderer/RenderCustomNpc.java | 2 +- .../java/noppes/npcs/mixin/MixinModelRenderer.java | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java index 22c619b99..0406ceabe 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java @@ -23,7 +23,7 @@ import org.lwjgl.opengl.GL11; public class RenderCustomNpc extends RenderNPCHumanMale{ private RendererLivingEntity renderEntity; - private EntityLivingBase entity; + public static EntityLivingBase entity; private ModelRenderPassHelper renderpass = new ModelRenderPassHelper(); diff --git a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java index b8c304155..327ac9f58 100644 --- a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java @@ -6,6 +6,7 @@ import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.EntityLivingBase; import noppes.npcs.client.Client; import noppes.npcs.client.ClientEventHandler; +import noppes.npcs.client.renderer.RenderCustomNpc; import noppes.npcs.controllers.data.PlayerModelData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -73,7 +74,7 @@ public class MixinModelRenderer { } } } - if (ClientEventHandler.renderingNpc != null && ClientEventHandler.renderingNpc.jobInterface instanceof JobPuppet) { + if (ClientEventHandler.renderingNpc != null && ClientEventHandler.renderingNpc.jobInterface instanceof JobPuppet && RenderCustomNpc.entity != null) { ClientEventHandler.undoRotations = new float[]{this.rotateAngleX,this.rotateAngleY,this.rotateAngleZ}; ClientEventHandler.undoPivots = new float[]{this.rotationPointX,this.rotationPointY,this.rotationPointZ}; @@ -82,16 +83,12 @@ public class MixinModelRenderer { this.setModelParts(modelData); if (modelData.isActive()) { JobPuppet.PartConfig[] partConfigs = new JobPuppet.PartConfig[]{modelData.head, modelData.body, modelData.larm, modelData.rarm, modelData.lleg, modelData.rleg}; - EntityLivingBase entityModel = ((EntityCustomNpc) ClientEventHandler.renderingNpc).modelData.getEntity(ClientEventHandler.renderingNpc); - if (entityModel == null || entityModel instanceof EntityNPCInterface) { - return; - } for (JobPuppet.PartConfig partConfig : partConfigs) { if (isPart(partConfig)) { - if (partConfig.npcModel == null || !partConfig.npcModel.getClass().equals(entityModel.getClass())) { + if (partConfig.npcModel == null || !partConfig.npcModel.getClass().equals(RenderCustomNpc.entity.getClass())) { partConfig.setOriginalPivot = false; - partConfig.npcModel = entityModel; + partConfig.npcModel = RenderCustomNpc.entity; } this.rotateAngleX = partConfig.prevRotations[0]; this.rotateAngleY = partConfig.prevRotations[1]; From a1a382b67fa27ca3692e2793a9d792ad327b6cac Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Tue, 10 Jan 2023 15:09:06 -0600 Subject: [PATCH 4/5] Undid previous commit, messed with offsets too much. --- src/main/java/noppes/npcs/roles/JobPuppet.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/roles/JobPuppet.java b/src/main/java/noppes/npcs/roles/JobPuppet.java index b52e99c08..33bb4b26d 100644 --- a/src/main/java/noppes/npcs/roles/JobPuppet.java +++ b/src/main/java/noppes/npcs/roles/JobPuppet.java @@ -85,6 +85,7 @@ public class JobPuppet extends JobInterface{ public boolean animate = false; public float animRate = 1.0F; public boolean interpolate = true; + public boolean disabled = false; // vvv Client-sided use vvv public float[] prevRotations = new float[]{0,0,0}; @@ -95,8 +96,12 @@ public class JobPuppet extends JobInterface{ public float destPivotX = 0f; public float destPivotY = 0f; public float destPivotZ = 0f; + public boolean setOriginalPivot; + public float originalPivotX; + public float originalPivotY; + public float originalPivotZ; + public EntityLivingBase npcModel; // ^^^ Client-sided use ^^^ - public boolean disabled = false; public PartConfig(Object parent) { this.parent = parent; From 6897512a0126dc40770a7c1dd19491c7a9210718 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Tue, 10 Jan 2023 15:21:58 -0600 Subject: [PATCH 5/5] Removed redundant client-side fields from puppet parts. --- .../noppes/npcs/mixin/MixinModelRenderer.java | 18 +++++++++--------- src/main/java/noppes/npcs/roles/JobPuppet.java | 3 --- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java index 327ac9f58..e88713118 100644 --- a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java @@ -188,19 +188,19 @@ public class MixinModelRenderer { this.rotationPointX = modelPart.originalPivotX + modelPart.pivotX; this.rotationPointY = modelPart.originalPivotY + modelPart.pivotY; this.rotationPointZ = modelPart.originalPivotZ + modelPart.pivotZ; + modelPart.prevPivots[0] = modelPart.pivotX; + modelPart.prevPivots[1] = modelPart.pivotY; + modelPart.prevPivots[2] = modelPart.pivotZ; } else if (modelPart.partialPivotTick != ClientEventHandler.partialRenderTick) { modelPart.partialPivotTick = ClientEventHandler.partialRenderTick; + this.rotationPointX = modelPart.originalPivotX + modelPart.prevPivots[0]; + this.rotationPointY = modelPart.originalPivotY + modelPart.prevPivots[1]; + this.rotationPointZ = modelPart.originalPivotZ + modelPart.prevPivots[2]; if (modelPart.interpolate) { - modelPart.destPivotX = (modelPart.pivotX - modelPart.destPivotX) * Math.abs(modelPart.animRate) / 10f + modelPart.destPivotX; - this.rotationPointX = modelPart.originalPivotX + modelPart.destPivotX; - modelPart.destPivotY = (modelPart.pivotY - modelPart.destPivotY) * Math.abs(modelPart.animRate) / 10f + modelPart.destPivotY; - this.rotationPointY = modelPart.originalPivotY + modelPart.destPivotY; - modelPart.destPivotZ = (modelPart.pivotZ - modelPart.destPivotZ) * Math.abs(modelPart.animRate) / 10f + modelPart.destPivotZ; - this.rotationPointZ = modelPart.originalPivotZ + modelPart.destPivotZ; + modelPart.prevPivots[0] = (modelPart.pivotX - modelPart.prevPivots[0]) * Math.abs(modelPart.animRate) / 10f + modelPart.prevPivots[0]; + modelPart.prevPivots[1] = (modelPart.pivotY - modelPart.prevPivots[1]) * Math.abs(modelPart.animRate) / 10f + modelPart.prevPivots[1]; + modelPart.prevPivots[2] = (modelPart.pivotZ - modelPart.prevPivots[2]) * Math.abs(modelPart.animRate) / 10f + modelPart.prevPivots[2]; } else { - this.rotationPointX = modelPart.originalPivotX + modelPart.prevPivots[0]; - this.rotationPointY = modelPart.originalPivotY + modelPart.prevPivots[1]; - this.rotationPointZ = modelPart.originalPivotZ + modelPart.prevPivots[2]; int directionX = Float.compare(modelPart.pivotX, modelPart.prevPivots[0]); modelPart.prevPivots[0] += directionX * modelPart.animRate / 10f; modelPart.prevPivots[0] = directionX == 1 ? diff --git a/src/main/java/noppes/npcs/roles/JobPuppet.java b/src/main/java/noppes/npcs/roles/JobPuppet.java index 33bb4b26d..8494a63ad 100644 --- a/src/main/java/noppes/npcs/roles/JobPuppet.java +++ b/src/main/java/noppes/npcs/roles/JobPuppet.java @@ -93,9 +93,6 @@ public class JobPuppet extends JobInterface{ public float partialRotationTick = 0f; public float partialPivotTick = 0f; - public float destPivotX = 0f; - public float destPivotY = 0f; - public float destPivotZ = 0f; public boolean setOriginalPivot; public float originalPivotX; public float originalPivotY;