2024-08-23 14:12:59 -04:00
|
|
|
package noppes.npcs.controllers.data;
|
|
|
|
|
|
2025-02-03 16:59:06 -05:00
|
|
|
import net.minecraft.item.ItemStack;
|
2024-08-23 14:12:59 -04:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2025-02-03 16:59:06 -05:00
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2024-08-23 14:12:59 -04:00
|
|
|
import noppes.npcs.api.handler.data.IMagic;
|
|
|
|
|
import noppes.npcs.controllers.MagicController;
|
2025-02-27 00:36:59 -05:00
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2025-02-03 16:59:06 -05:00
|
|
|
import java.util.HashMap;
|
2025-02-27 00:36:59 -05:00
|
|
|
import java.util.HashSet;
|
2025-02-03 16:59:06 -05:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
2024-08-23 14:12:59 -04:00
|
|
|
public class Magic implements IMagic {
|
2025-02-03 16:59:06 -05:00
|
|
|
public String name = "";
|
2025-02-27 00:30:39 -05:00
|
|
|
public String displayName = "";
|
2025-02-03 16:59:06 -05:00
|
|
|
public int color = Integer.parseInt("FF00", 16);
|
|
|
|
|
public int id = -1;
|
|
|
|
|
|
|
|
|
|
public ItemStack iconItem = null;
|
|
|
|
|
public String iconTexture = "";
|
2025-02-27 00:36:59 -05:00
|
|
|
public Map<Integer, Float> interactions = new HashMap<>();
|
|
|
|
|
public HashSet<Integer> cycles = new HashSet<>();
|
2025-02-03 16:59:06 -05:00
|
|
|
|
|
|
|
|
public Magic() {}
|
|
|
|
|
|
|
|
|
|
public Magic(int id, String name, int color) {
|
|
|
|
|
this.name = name;
|
2025-02-27 00:30:39 -05:00
|
|
|
this.displayName = name;
|
2025-02-03 16:59:06 -05:00
|
|
|
this.color = color;
|
|
|
|
|
this.id = id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String formatName(String name) {
|
|
|
|
|
name = name.toLowerCase().trim();
|
|
|
|
|
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readNBT(NBTTagCompound compound) {
|
2024-08-23 14:12:59 -04:00
|
|
|
name = compound.getString("Name");
|
2025-02-27 00:30:39 -05:00
|
|
|
displayName = compound.getString("DisplayName");
|
2024-08-23 14:12:59 -04:00
|
|
|
color = compound.getInteger("Color");
|
|
|
|
|
id = compound.getInteger("Slot");
|
2025-02-27 00:36:59 -05:00
|
|
|
// Read icon item.
|
2025-02-03 16:59:06 -05:00
|
|
|
if(compound.hasKey("IconItem")){
|
|
|
|
|
NBTTagCompound itemTag = compound.getCompoundTag("IconItem");
|
|
|
|
|
iconItem = ItemStack.loadItemStackFromNBT(itemTag);
|
|
|
|
|
}
|
|
|
|
|
iconTexture = compound.getString("IconTexture");
|
2025-02-27 00:36:59 -05:00
|
|
|
|
|
|
|
|
interactions.clear();
|
|
|
|
|
if(compound.hasKey("Interactions")) {
|
|
|
|
|
NBTTagList interactionsList = compound.getTagList("Interactions", 10);
|
|
|
|
|
for (int i = 0; i < interactionsList.tagCount(); i++){
|
|
|
|
|
NBTTagCompound interactionTag = interactionsList.getCompoundTagAt(i);
|
|
|
|
|
int magicId = interactionTag.getInteger("MagicID");
|
|
|
|
|
float percentage = interactionTag.getFloat("Percentage");
|
|
|
|
|
interactions.put(magicId, percentage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cycles.clear();
|
|
|
|
|
if(compound.hasKey("Cycles")) {
|
|
|
|
|
NBTTagList cyclesList = compound.getTagList("Cycles", 10);
|
|
|
|
|
for (int i = 0; i < cyclesList.tagCount(); i++){
|
|
|
|
|
NBTTagCompound cycleTag = cyclesList.getCompoundTagAt(i);
|
|
|
|
|
cycles.add(cycleTag.getInteger("Cycle"));
|
2025-02-03 16:59:06 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void writeNBT(NBTTagCompound compound) {
|
|
|
|
|
compound.setInteger("Slot", id);
|
|
|
|
|
compound.setString("Name", name);
|
2025-02-27 00:30:39 -05:00
|
|
|
compound.setString("DisplayName", displayName);
|
2025-02-03 16:59:06 -05:00
|
|
|
compound.setInteger("Color", color);
|
2025-02-27 00:36:59 -05:00
|
|
|
// Write icon item.
|
2025-02-03 16:59:06 -05:00
|
|
|
if(iconItem != null) {
|
|
|
|
|
NBTTagCompound itemTag = new NBTTagCompound();
|
|
|
|
|
iconItem.writeToNBT(itemTag);
|
|
|
|
|
compound.setTag("IconItem", itemTag);
|
|
|
|
|
}
|
|
|
|
|
if(iconTexture != null && !iconTexture.isEmpty()){
|
|
|
|
|
compound.setString("IconTexture", iconTexture);
|
|
|
|
|
}
|
2025-02-27 00:36:59 -05:00
|
|
|
|
|
|
|
|
NBTTagList interactionsList = new NBTTagList();
|
|
|
|
|
for (Map.Entry<Integer, Float> entry : interactions.entrySet()){
|
|
|
|
|
NBTTagCompound interactionTag = new NBTTagCompound();
|
|
|
|
|
interactionTag.setInteger("MagicID", entry.getKey());
|
|
|
|
|
interactionTag.setFloat("Percentage", entry.getValue());
|
|
|
|
|
interactionsList.appendTag(interactionTag);
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("Interactions", interactionsList);
|
|
|
|
|
|
|
|
|
|
NBTTagList cyclesList = new NBTTagList();
|
|
|
|
|
for (Integer cycle : cycles) {
|
|
|
|
|
NBTTagCompound cycleTag = new NBTTagCompound();
|
|
|
|
|
cycleTag.setInteger("Cycle", cycle);
|
|
|
|
|
cyclesList.appendTag(cycleTag);
|
2025-02-03 16:59:06 -05:00
|
|
|
}
|
2025-02-27 00:36:59 -05:00
|
|
|
compound.setTag("Cycles", cyclesList);
|
2025-02-03 16:59:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getId() {
|
|
|
|
|
return this.id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
|
return this.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setName(String name) {
|
|
|
|
|
this.name = name;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-24 02:57:43 -05:00
|
|
|
public void setColor(int c) {
|
|
|
|
|
this.color = c;
|
2025-02-03 16:59:06 -05:00
|
|
|
}
|
|
|
|
|
|
2025-02-24 02:57:43 -05:00
|
|
|
@Override
|
2025-02-03 16:59:06 -05:00
|
|
|
public int getColor() {
|
|
|
|
|
return this.color;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-27 00:30:39 -05:00
|
|
|
public String getDisplayName() {
|
|
|
|
|
return displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDisplayName(String displayName) {
|
|
|
|
|
this.displayName = displayName;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 16:59:06 -05:00
|
|
|
public void save() {
|
|
|
|
|
MagicController.getInstance().saveMagic(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setIconItem(ItemStack item) {
|
|
|
|
|
this.iconItem = item;
|
|
|
|
|
}
|
2024-08-23 14:12:59 -04:00
|
|
|
|
2025-02-03 16:59:06 -05:00
|
|
|
public ItemStack getIconItem() {
|
|
|
|
|
return this.iconItem;
|
|
|
|
|
}
|
2024-08-23 14:12:59 -04:00
|
|
|
|
2025-02-03 16:59:06 -05:00
|
|
|
public void setIconTexture(String texture) {
|
|
|
|
|
this.iconTexture = texture;
|
|
|
|
|
}
|
2024-08-23 14:12:59 -04:00
|
|
|
|
2025-02-03 16:59:06 -05:00
|
|
|
public String getIconTexture() {
|
|
|
|
|
return this.iconTexture;
|
|
|
|
|
}
|
2024-08-23 14:12:59 -04:00
|
|
|
|
2025-02-27 00:36:59 -05:00
|
|
|
public void setInteractions(Map<Integer, Float> interactions) {
|
|
|
|
|
this.interactions = interactions;
|
2025-02-03 16:59:06 -05:00
|
|
|
}
|
2024-08-23 14:12:59 -04:00
|
|
|
|
2025-02-27 00:36:59 -05:00
|
|
|
public Map<Integer, Float> getInteractions() {
|
|
|
|
|
return this.interactions;
|
2025-02-03 16:59:06 -05:00
|
|
|
}
|
2024-08-23 14:12:59 -04:00
|
|
|
}
|