2025-02-24 02:57:43 -05:00
|
|
|
package noppes.npcs.controllers.data;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2025-03-12 22:24:58 -04:00
|
|
|
import noppes.npcs.api.handler.data.IMagicCycle;
|
2025-03-03 23:03:12 -05:00
|
|
|
import noppes.npcs.constants.EnumDiagramLayout;
|
|
|
|
|
|
2025-02-24 02:57:43 -05:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Holds category information for magic.
|
|
|
|
|
* Each category can have many magic associations.
|
|
|
|
|
*/
|
2025-03-12 22:24:58 -04:00
|
|
|
public class MagicCycle implements IMagicCycle {
|
2025-02-24 02:57:43 -05:00
|
|
|
public int id = -1;
|
2025-03-03 23:03:12 -05:00
|
|
|
public String name = "";
|
|
|
|
|
public String displayName = "";
|
|
|
|
|
public EnumDiagramLayout layout = EnumDiagramLayout.CIRCULAR;
|
2025-02-24 02:57:43 -05:00
|
|
|
public HashMap<Integer, MagicAssociation> associations = new HashMap<>();
|
2025-03-12 20:12:01 -04:00
|
|
|
|
2025-05-20 13:53:26 -04:00
|
|
|
public MagicCycle() {
|
|
|
|
|
}
|
2025-02-24 02:57:43 -05:00
|
|
|
|
|
|
|
|
public void readNBT(NBTTagCompound compound) {
|
2025-03-04 03:28:11 -05:00
|
|
|
id = compound.getInteger("ID");
|
2025-03-03 23:03:12 -05:00
|
|
|
name = compound.getString("Name");
|
|
|
|
|
displayName = compound.getString("DisplayName");
|
|
|
|
|
layout = EnumDiagramLayout.values()[compound.getInteger("Layout")];
|
2025-02-24 02:57:43 -05:00
|
|
|
associations.clear();
|
|
|
|
|
NBTTagList list = compound.getTagList("Associations", 10); // compound tags
|
|
|
|
|
for (int i = 0; i < list.tagCount(); i++) {
|
|
|
|
|
NBTTagCompound assocTag = list.getCompoundTagAt(i);
|
|
|
|
|
MagicAssociation assoc = new MagicAssociation();
|
|
|
|
|
assoc.magicId = assocTag.getInteger("MagicID");
|
|
|
|
|
assoc.index = assocTag.getInteger("Index");
|
|
|
|
|
assoc.priority = assocTag.getInteger("Priority");
|
|
|
|
|
associations.put(assoc.magicId, assoc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void writeNBT(NBTTagCompound compound) {
|
2025-03-04 03:28:11 -05:00
|
|
|
compound.setInteger("ID", id);
|
|
|
|
|
compound.setString("Name", name);
|
2025-03-03 23:03:12 -05:00
|
|
|
compound.setString("DisplayName", displayName);
|
|
|
|
|
compound.setInteger("Layout", layout.ordinal());
|
2025-02-24 02:57:43 -05:00
|
|
|
NBTTagList list = new NBTTagList();
|
|
|
|
|
for (MagicAssociation assoc : associations.values()) {
|
|
|
|
|
NBTTagCompound assocTag = new NBTTagCompound();
|
|
|
|
|
assocTag.setInteger("MagicID", assoc.magicId);
|
|
|
|
|
assocTag.setInteger("Index", assoc.index);
|
|
|
|
|
assocTag.setInteger("Priority", assoc.priority);
|
|
|
|
|
list.appendTag(assocTag);
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("Associations", list);
|
|
|
|
|
}
|
2025-03-03 23:03:12 -05:00
|
|
|
|
2025-03-12 22:24:58 -04:00
|
|
|
@Override
|
2025-03-03 23:03:12 -05:00
|
|
|
public int getId() {
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 22:24:58 -04:00
|
|
|
@Override
|
2025-03-03 23:03:12 -05:00
|
|
|
public String getName() {
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 22:24:58 -04:00
|
|
|
@Override
|
2025-03-03 23:03:12 -05:00
|
|
|
public void setName(String name) {
|
|
|
|
|
this.name = name;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 22:24:58 -04:00
|
|
|
@Override
|
2025-03-03 23:03:12 -05:00
|
|
|
public String getDisplayName() {
|
|
|
|
|
return displayName;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 22:24:58 -04:00
|
|
|
@Override
|
2025-03-03 23:03:12 -05:00
|
|
|
public void setDisplayName(String displayName) {
|
|
|
|
|
this.displayName = displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EnumDiagramLayout getLayout() {
|
|
|
|
|
return layout;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 22:24:58 -04:00
|
|
|
@Override
|
|
|
|
|
public int getLayoutType() {
|
|
|
|
|
return layout.ordinal();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-03 23:03:12 -05:00
|
|
|
public void setLayout(EnumDiagramLayout layout) {
|
|
|
|
|
this.layout = layout;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 22:24:58 -04:00
|
|
|
@Override
|
|
|
|
|
public void setLayoutType(int layout) {
|
2025-05-20 13:53:26 -04:00
|
|
|
if (layout < 0 || layout > EnumDiagramLayout.values().length - 1)
|
2025-03-12 22:24:58 -04:00
|
|
|
return;
|
|
|
|
|
this.layout = EnumDiagramLayout.values()[layout];
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-03 23:03:12 -05:00
|
|
|
public HashMap<Integer, MagicAssociation> getAssociations() {
|
|
|
|
|
return associations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAssociations(HashMap<Integer, MagicAssociation> associations) {
|
|
|
|
|
this.associations = associations;
|
|
|
|
|
}
|
2025-02-24 02:57:43 -05:00
|
|
|
}
|