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-03 16:59:06 -05:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
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-24 02:57:43 -05:00
|
|
|
public Map<Integer, Float> weaknesses = new HashMap<>();
|
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-24 02:57:43 -05:00
|
|
|
// No longer reading index/priority here.
|
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");
|
|
|
|
|
weaknesses.clear();
|
|
|
|
|
if(compound.hasKey("Weaknesses")) {
|
2025-02-24 02:57:43 -05:00
|
|
|
NBTTagList weaknessList = compound.getTagList("Weaknesses", 10);
|
2025-02-03 16:59:06 -05:00
|
|
|
for(int i = 0; i < weaknessList.tagCount(); i++){
|
|
|
|
|
NBTTagCompound weaknessTag = weaknessList.getCompoundTagAt(i);
|
|
|
|
|
int weakMagicId = weaknessTag.getInteger("MagicID");
|
|
|
|
|
float percentage = weaknessTag.getFloat("Percentage");
|
|
|
|
|
weaknesses.put(weakMagicId, percentage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-24 02:57:43 -05:00
|
|
|
// No longer writing index/priority here.
|
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);
|
|
|
|
|
}
|
|
|
|
|
NBTTagList weaknessList = new NBTTagList();
|
|
|
|
|
for(Map.Entry<Integer, Float> entry : weaknesses.entrySet()){
|
|
|
|
|
NBTTagCompound weaknessTag = new NBTTagCompound();
|
|
|
|
|
weaknessTag.setInteger("MagicID", entry.getKey());
|
|
|
|
|
weaknessTag.setFloat("Percentage", entry.getValue());
|
|
|
|
|
weaknessList.appendTag(weaknessTag);
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("Weaknesses", weaknessList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-03 16:59:06 -05:00
|
|
|
public void setWeaknesses(Map<Integer, Float> weaknesses) {
|
|
|
|
|
this.weaknesses = weaknesses;
|
|
|
|
|
}
|
2024-08-23 14:12:59 -04:00
|
|
|
|
2025-02-03 16:59:06 -05:00
|
|
|
public Map<Integer, Float> getWeaknesses() {
|
|
|
|
|
return this.weaknesses;
|
|
|
|
|
}
|
2024-08-23 14:12:59 -04:00
|
|
|
}
|