2024-08-23 14:12:59 -04:00
|
|
|
package noppes.npcs.controllers.data;
|
|
|
|
|
|
2025-03-04 16:34:18 -05:00
|
|
|
import cpw.mods.fml.common.registry.GameRegistry;
|
|
|
|
|
import net.minecraft.item.Item;
|
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;
|
2025-03-04 16:34:18 -05:00
|
|
|
import noppes.npcs.constants.EnumTextureType;
|
2024-08-23 14:12:59 -04:00
|
|
|
import noppes.npcs.controllers.MagicController;
|
2025-02-27 00:36:59 -05:00
|
|
|
|
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;
|
|
|
|
|
|
2025-03-04 16:34:18 -05:00
|
|
|
public ItemStack item = null;
|
|
|
|
|
|
|
|
|
|
public EnumTextureType type = EnumTextureType.BASE;
|
2025-02-03 16:59:06 -05:00
|
|
|
public String iconTexture = "";
|
2025-02-27 00:36:59 -05:00
|
|
|
public Map<Integer, Float> interactions = new HashMap<>();
|
2025-02-03 16:59:06 -05:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public Magic() {
|
|
|
|
|
}
|
2025-02-03 16:59:06 -05:00
|
|
|
|
|
|
|
|
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-03-04 16:34:18 -05:00
|
|
|
|
|
|
|
|
type = EnumTextureType.values()[compound.getInteger("Type")];
|
2025-02-03 16:59:06 -05:00
|
|
|
iconTexture = compound.getString("IconTexture");
|
2025-03-12 20:12:01 -04:00
|
|
|
if (type == EnumTextureType.ITEM && !iconTexture.isEmpty()) {
|
2025-03-04 16:34:18 -05:00
|
|
|
String[] parts = iconTexture.split(":");
|
|
|
|
|
if (parts.length == 2) {
|
|
|
|
|
String modID = parts[0];
|
|
|
|
|
String itemName = parts[1];
|
|
|
|
|
Item item = GameRegistry.findItem(modID, itemName);
|
|
|
|
|
this.item = (item != null) ? new ItemStack(item) : null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-27 00:36:59 -05:00
|
|
|
|
|
|
|
|
interactions.clear();
|
2025-03-12 20:12:01 -04:00
|
|
|
if (compound.hasKey("Interactions")) {
|
2025-02-27 00:36:59 -05:00
|
|
|
NBTTagList interactionsList = compound.getTagList("Interactions", 10);
|
2025-03-12 20:12:01 -04:00
|
|
|
for (int i = 0; i < interactionsList.tagCount(); i++) {
|
2025-02-27 00:36:59 -05:00
|
|
|
NBTTagCompound interactionTag = interactionsList.getCompoundTagAt(i);
|
|
|
|
|
int magicId = interactionTag.getInteger("MagicID");
|
|
|
|
|
float percentage = interactionTag.getFloat("Percentage");
|
|
|
|
|
interactions.put(magicId, percentage);
|
|
|
|
|
}
|
|
|
|
|
}
|
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-03-04 16:34:18 -05:00
|
|
|
compound.setString("IconTexture", iconTexture);
|
|
|
|
|
compound.setInteger("Type", type.ordinal());
|
2025-02-27 00:36:59 -05:00
|
|
|
NBTTagList interactionsList = new NBTTagList();
|
2025-03-12 20:12:01 -04:00
|
|
|
for (Map.Entry<Integer, Float> entry : interactions.entrySet()) {
|
2025-02-27 00:36:59 -05:00
|
|
|
NBTTagCompound interactionTag = new NBTTagCompound();
|
|
|
|
|
interactionTag.setInteger("MagicID", entry.getKey());
|
|
|
|
|
interactionTag.setFloat("Percentage", entry.getValue());
|
|
|
|
|
interactionsList.appendTag(interactionTag);
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("Interactions", interactionsList);
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (type == EnumTextureType.ITEM && !iconTexture.isEmpty()) {
|
2025-03-04 16:34:18 -05:00
|
|
|
String[] parts = iconTexture.split(":");
|
|
|
|
|
if (parts.length == 2) {
|
|
|
|
|
String modID = parts[0];
|
|
|
|
|
String itemName = parts[1];
|
|
|
|
|
Item item = GameRegistry.findItem(modID, itemName);
|
|
|
|
|
this.item = (item != null) ? new ItemStack(item) : null;
|
|
|
|
|
}
|
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-03-12 22:24:58 -04:00
|
|
|
@Override
|
2025-02-27 00:30:39 -05:00
|
|
|
public String getDisplayName() {
|
|
|
|
|
return displayName;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 22:24:58 -04:00
|
|
|
@Override
|
2025-02-27 00:30:39 -05:00
|
|
|
public void setDisplayName(String displayName) {
|
|
|
|
|
this.displayName = displayName;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 22:24:58 -04:00
|
|
|
@Override
|
2025-02-03 16:59:06 -05:00
|
|
|
public void save() {
|
|
|
|
|
MagicController.getInstance().saveMagic(this);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-04 16:34:18 -05:00
|
|
|
public void setItem(ItemStack item) {
|
|
|
|
|
GameRegistry.UniqueIdentifier identifier = GameRegistry.findUniqueIdentifierFor(item.getItem());
|
2025-03-12 20:12:01 -04:00
|
|
|
if (identifier != null) {
|
2025-03-04 16:34:18 -05:00
|
|
|
this.item = item;
|
|
|
|
|
this.type = EnumTextureType.ITEM;
|
|
|
|
|
this.iconTexture = identifier.modId + ":" + identifier.name;
|
|
|
|
|
}
|
2025-02-03 16:59:06 -05:00
|
|
|
}
|
2024-08-23 14:12:59 -04:00
|
|
|
|
2025-03-04 16:34:18 -05:00
|
|
|
public ItemStack getItem() {
|
|
|
|
|
return this.item;
|
2025-02-03 16:59:06 -05:00
|
|
|
}
|
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
|
|
|
}
|
2025-03-12 22:24:58 -04:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean hasInteraction(int magicID) {
|
|
|
|
|
return interactions.containsKey(magicID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setInteraction(int magicID, float value) {
|
|
|
|
|
interactions.put(magicID, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getInteraction(int magicID, float value) {
|
|
|
|
|
if(hasInteraction(magicID))
|
|
|
|
|
return interactions.get(magicID);
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
2024-08-23 14:12:59 -04:00
|
|
|
}
|