From 1d94e5f1e7ec61d27993f0a65653358bea9f1f1b Mon Sep 17 00:00:00 2001 From: KAMKEEL Date: Thu, 12 Jan 2023 03:32:49 -0500 Subject: [PATCH] Animation Booleans and Read/Write NBT Fixes --- .../java/noppes/npcs/AnimationDataShared.java | 94 +++++++++++-------- .../java/noppes/npcs/AnimationPartConfig.java | 51 +++++----- 2 files changed, 84 insertions(+), 61 deletions(-) diff --git a/src/main/java/noppes/npcs/AnimationDataShared.java b/src/main/java/noppes/npcs/AnimationDataShared.java index 08e793247..dd6809ba9 100644 --- a/src/main/java/noppes/npcs/AnimationDataShared.java +++ b/src/main/java/noppes/npcs/AnimationDataShared.java @@ -18,9 +18,10 @@ public class AnimationDataShared { public boolean allowAnimation = false; // Full Model Animation + public boolean enableFullModel = true; + public float rotationX, rotationY, rotationZ; public boolean rotationEnabledX, rotationEnabledY, rotationEnabledZ; - public boolean fullAnimate = false; public float animRate = 1.0F; public boolean fullAngles; @@ -58,54 +59,73 @@ public class AnimationDataShared { } public NBTTagCompound writeToNBT(NBTTagCompound compound) { - compound.setTag("PuppetHead", head.writeNBT()); - compound.setTag("PuppetLArm", larm.writeNBT()); - compound.setTag("PuppetRArm", rarm.writeNBT()); - compound.setTag("PuppetBody", body.writeNBT()); - compound.setTag("PuppetLLeg", lleg.writeNBT()); - compound.setTag("PuppetRLeg", rleg.writeNBT()); compound.setBoolean("PuppetEnabled", allowAnimation); - compound.setFloat("PuppetRotationX",rotationX); - compound.setFloat("PuppetRotationY",rotationY); - compound.setFloat("PuppetRotationZ",rotationZ); - compound.setBoolean("PuppetRotationEnabledX",rotationEnabledX); - compound.setBoolean("PuppetRotationEnabledY",rotationEnabledY); - compound.setBoolean("PuppetRotationEnabledZ",rotationEnabledZ); + // ALWAYS SAVE allowAnimation + if(allowAnimation){ + // GROUP INTO ANIMATION TAG + + compound.setTag("PuppetHead", head.writeNBT()); + compound.setTag("PuppetLArm", larm.writeNBT()); + compound.setTag("PuppetRArm", rarm.writeNBT()); + compound.setTag("PuppetBody", body.writeNBT()); + compound.setTag("PuppetLLeg", lleg.writeNBT()); + compound.setTag("PuppetRLeg", rleg.writeNBT()); + + // GROUP THIS INTO "PuppetFullModel" + compound.setBoolean("PuppetFullModelEnabled", enableFullModel); + if(enableFullModel){ + compound.setFloat("PuppetRotationX",rotationX); + compound.setFloat("PuppetRotationY",rotationY); + compound.setFloat("PuppetRotationZ",rotationZ); + compound.setBoolean("PuppetRotationEnabledX",rotationEnabledX); + compound.setBoolean("PuppetRotationEnabledY",rotationEnabledY); + compound.setBoolean("PuppetRotationEnabledZ",rotationEnabledZ); + + compound.setBoolean("PuppetFullAngles", fullAngles); + compound.setBoolean("PuppetInterpolate", interpolate); + compound.setBoolean("PuppetAnimate", fullAnimate); + compound.setFloat("PuppetAnimSpeed", animRate); + } + } - compound.setBoolean("PuppetFullAngles", fullAngles); - compound.setBoolean("PuppetInterpolate", interpolate); - compound.setBoolean("PuppetAnimate", fullAnimate); - compound.setFloat("PuppetAnimSpeed", animRate); return compound; } public void readFromNBT(NBTTagCompound compound) { - head.readNBT(compound.getCompoundTag("PuppetHead")); - larm.readNBT(compound.getCompoundTag("PuppetLArm")); - rarm.readNBT(compound.getCompoundTag("PuppetRArm")); - body.readNBT(compound.getCompoundTag("PuppetBody")); - lleg.readNBT(compound.getCompoundTag("PuppetLLeg")); - rleg.readNBT(compound.getCompoundTag("PuppetRLeg")); - allowAnimation = compound.getBoolean("PuppetEnabled"); + if(allowAnimation) { + head.readNBT(compound.getCompoundTag("PuppetHead")); + larm.readNBT(compound.getCompoundTag("PuppetLArm")); + rarm.readNBT(compound.getCompoundTag("PuppetRArm")); + body.readNBT(compound.getCompoundTag("PuppetBody")); + lleg.readNBT(compound.getCompoundTag("PuppetLLeg")); + rleg.readNBT(compound.getCompoundTag("PuppetRLeg")); - rotationX = compound.getFloat("PuppetRotationX"); - rotationY = compound.getFloat("PuppetRotationY"); - rotationZ = compound.getFloat("PuppetRotationZ"); - rotationEnabledX = compound.getBoolean("PuppetRotationEnabledX"); - rotationEnabledY = compound.getBoolean("PuppetRotationEnabledY"); - rotationEnabledZ = compound.getBoolean("PuppetRotationEnabledZ"); + enableFullModel = compound.getBoolean("PuppetFullModelEnabled"); + if (enableFullModel) { + rotationX = compound.getFloat("PuppetRotationX"); + rotationY = compound.getFloat("PuppetRotationY"); + rotationZ = compound.getFloat("PuppetRotationZ"); + rotationEnabledX = compound.getBoolean("PuppetRotationEnabledX"); + rotationEnabledY = compound.getBoolean("PuppetRotationEnabledY"); + rotationEnabledZ = compound.getBoolean("PuppetRotationEnabledZ"); - fullAngles = compound.getBoolean("PuppetFullAngles"); - if (!compound.hasKey("PuppetInterpolate")) { - interpolate = true; - } else { - interpolate = compound.getBoolean("PuppetInterpolate"); + fullAngles = compound.getBoolean("PuppetFullAngles"); + if (!compound.hasKey("PuppetInterpolate")) { + interpolate = true; + } else { + interpolate = compound.getBoolean("PuppetInterpolate"); + } + fullAnimate = compound.getBoolean("PuppetAnimate"); + animRate = compound.getFloat("PuppetAnimSpeed"); + } + } + else { + // IF HAS ANIMATION TAG + // REMOVE IT! } - fullAnimate = compound.getBoolean("PuppetAnimate"); - animRate = compound.getFloat("PuppetAnimSpeed"); } public void setEnabled(boolean enabled) { diff --git a/src/main/java/noppes/npcs/AnimationPartConfig.java b/src/main/java/noppes/npcs/AnimationPartConfig.java index 8f13e639d..60dfd879b 100644 --- a/src/main/java/noppes/npcs/AnimationPartConfig.java +++ b/src/main/java/noppes/npcs/AnimationPartConfig.java @@ -22,40 +22,43 @@ public class AnimationPartConfig { public NBTTagCompound writeNBT() { NBTTagCompound compound = new NBTTagCompound(); compound.setBoolean("EnablePart", enablePart); - compound.setFloat("RotationX", rotationX); - compound.setFloat("RotationY", rotationY); - compound.setFloat("RotationZ", rotationZ); - compound.setFloat("PivotX", pivotX); - compound.setFloat("PivotY", pivotY); - compound.setFloat("PivotZ", pivotZ); + if(enablePart){ + compound.setFloat("RotationX", rotationX); + compound.setFloat("RotationY", rotationY); + compound.setFloat("RotationZ", rotationZ); + compound.setFloat("PivotX", pivotX); + compound.setFloat("PivotY", pivotY); + compound.setFloat("PivotZ", pivotZ); - compound.setBoolean("PuppetFullAngles", fullAngles); + compound.setBoolean("PuppetFullAngles", fullAngles); - compound.setBoolean("PuppetInterpolate", interpolate); - compound.setBoolean("PuppetAnimate", animate); - compound.setFloat("PuppetAnimSpeed", animRate); + compound.setBoolean("PuppetInterpolate", interpolate); + compound.setBoolean("PuppetAnimate", animate); + compound.setFloat("PuppetAnimSpeed", animRate); + } return compound; } public void readNBT(NBTTagCompound compound) { enablePart = compound.getBoolean("EnablePart"); + if(enablePart){ + rotationX = compound.getFloat("RotationX"); + rotationY = compound.getFloat("RotationY"); + rotationZ = compound.getFloat("RotationZ"); + pivotX = compound.getFloat("PivotX"); + pivotY = compound.getFloat("PivotY"); + pivotZ = compound.getFloat("PivotZ"); - rotationX = compound.getFloat("RotationX"); - rotationY = compound.getFloat("RotationY"); - rotationZ = compound.getFloat("RotationZ"); - pivotX = compound.getFloat("PivotX"); - pivotY = compound.getFloat("PivotY"); - pivotZ = compound.getFloat("PivotZ"); + fullAngles = compound.getBoolean("PuppetFullAngles"); - fullAngles = compound.getBoolean("PuppetFullAngles"); - - if (!compound.hasKey("PuppetInterpolate")) { - interpolate = true; - } else { - interpolate = compound.getBoolean("PuppetInterpolate"); + if (!compound.hasKey("PuppetInterpolate")) { + interpolate = true; + } else { + interpolate = compound.getBoolean("PuppetInterpolate"); + } + animate = compound.getBoolean("PuppetAnimate"); + animRate = compound.getFloat("PuppetAnimSpeed"); } - animate = compound.getBoolean("PuppetAnimate"); - animRate = compound.getFloat("PuppetAnimSpeed"); } public void setEnabled(boolean enabled) {