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/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 82dc476ba..e88713118 100644 --- a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java @@ -2,11 +2,11 @@ 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; 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; @@ -74,22 +74,21 @@ 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}; + 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; - } 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]; @@ -103,6 +102,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; @@ -171,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 15b0f66ed..8494a63ad 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; @@ -86,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}; @@ -93,15 +93,12 @@ 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 = false; - public float originalPivotX = 0f; - public float originalPivotY = 0f; - public float originalPivotZ = 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;