Read/Write NBT for Animation/Frame/FramePart

This commit is contained in:
KAMKEEL committed 2023-01-12 20:34:07 -05:00
1 parent 3e6e28d857
commit 569c7790fc
4 files changed
+120 -21

No files matched your search

@@ -1,18 +1,11 @@
package noppes.npcs.constants;
public enum EnumAnimationPart {
HEAD ("HEAD"),
BODY ("BODY"),
RIGHT_ARM ("RARM"),
LEFT_ARM ("LARM"),
RIGHT_LEG ("RLEG"),
LEFT_LEG ("LLEG"),
FULL_MODEL ("MODEL");
public final String partName;
EnumAnimationPart(String name){
this.partName = name;
}
HEAD,
BODY,
RIGHT_ARM,
LEFT_ARM,
RIGHT_LEG,
LEFT_LEG,
FULL_MODEL;
}
@@ -1,6 +1,11 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.ModelPartData;
import java.util.ArrayList;
import java.util.HashMap;
public class Animation {
@@ -45,6 +50,37 @@ public class Animation {
return smooth;
}
// MAKE WRITE NBT
// MAKE READ NBT
public void readFromNBT(NBTTagCompound compound){
name = compound.getString("Name");
id = compound.getInteger("ID");
speed = compound.getFloat("Speed");
smooth = compound.getBoolean("Smooth");
ArrayList<Frame> frames = new ArrayList<Frame>();
NBTTagList list = compound.getTagList("Frames", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
Frame frame = new Frame();
frame.readFromNBT(item);
frames.add(frame);
}
this.frames = frames;
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setString("Name", name);
compound.setInteger("ID", id);
compound.setFloat("Speed", speed);
compound.setBoolean("Smooth", smooth);
NBTTagList list = new NBTTagList();
for(Frame frame : frames){
NBTTagCompound item = frame.writeToNBT();
list.appendTag(item);
}
compound.setTag("Frames", list);
return compound;
}
}
@@ -1,5 +1,7 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.constants.EnumAnimationPart;
import java.util.ArrayList;
@@ -68,6 +70,44 @@ public class Frame {
this.smooth = smooth;
}
// MAKE WRITE NBT
// MAKE READ NBT
public void readFromNBT(NBTTagCompound compound){
duration = compound.getInteger("Duration");
// Customized = TRUE if Speed or Smooth Exist
if(compound.hasKey("Speed")){
customized = true;
speed = compound.getFloat("Speed");
}
if(compound.hasKey("Smooth")){
customized = true;
smooth = compound.getBoolean("Smooth");
}
ArrayList<FramePart> frameParts = new ArrayList<FramePart>();
NBTTagList list = compound.getTagList("FrameParts", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
FramePart framePart = new FramePart();
framePart.readFromNBT(item);
frameParts.add(framePart);
}
this.frameParts = frameParts;
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("Duration", duration);
if(customized){
compound.setFloat("Speed", speed);
compound.setBoolean("Smooth", smooth);
}
NBTTagList list = new NBTTagList();
for(FramePart framePart : frameParts){
NBTTagCompound item = framePart.writeToNBT();
list.appendTag(item);
}
compound.setTag("FrameParts", list);
return compound;
}
}
@@ -2,10 +2,13 @@ package noppes.npcs.controllers.data;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.Vec3;
import noppes.npcs.constants.EnumAnimationPart;
import javax.vecmath.Vector3f;
import java.util.ArrayList;
import java.util.Vector;
@@ -19,7 +22,7 @@ public class FramePart {
public float speed = 1.0F;
public boolean smooth = false;
public FramePart(){}
public FramePart(EnumAnimationPart part){
@@ -89,6 +92,33 @@ public class FramePart {
this.smooth = smooth;
}
// MAKE WRITE NBT
// MAKE READ NBT
public void readFromNBT(NBTTagCompound compound){
part = EnumAnimationPart.valueOf(compound.getString("Part"));
rotation = compound.getIntArray("Rotation");
pivot = compound.getIntArray("Pivot");
// Customized = TRUE if Speed or Smooth Exist
if(compound.hasKey("Speed")){
customized = true;
speed = compound.getFloat("Speed");
}
if(compound.hasKey("Smooth")){
customized = true;
smooth = compound.getBoolean("Smooth");
}
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setString("Part", part.toString());
compound.setIntArray("Rotation", rotation);
compound.setIntArray("Pivot", pivot);
if(customized){
compound.setFloat("Speed", speed);
compound.setBoolean("Smooth", smooth);
}
return compound;
}
}