From ffaf21d3d824f3ced064c9e7ab09c4d628f072aa Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 4 Mar 2025 16:34:18 -0500 Subject: [PATCH] Magic Editor Sub GUI --- .../noppes/npcs/client/gui/GuiMagicMap.java | 4 +- .../client/gui/advanced/GuiNPCTagSetup.java | 3 +- .../client/gui/global/GuiNpcManageMagic.java | 12 +- .../client/gui/item/SubGuiLinkedItem.java | 3 +- .../npcs/client/gui/magic/SubGuiMagic.java | 272 ++++++++++++++++++ .../client/gui/magic/SubGuiMagicEdit.java | 60 ---- .../npcs/constants/EnumTextureType.java | 25 ++ .../npcs/controllers/MagicController.java | 16 +- .../noppes/npcs/controllers/data/Magic.java | 74 +++-- .../assets/customnpcs/lang/en_US.lang | 6 + 10 files changed, 357 insertions(+), 118 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/magic/SubGuiMagic.java delete mode 100644 src/main/java/noppes/npcs/client/gui/magic/SubGuiMagicEdit.java create mode 100644 src/main/java/noppes/npcs/constants/EnumTextureType.java diff --git a/src/main/java/noppes/npcs/client/gui/GuiMagicMap.java b/src/main/java/noppes/npcs/client/gui/GuiMagicMap.java index d7bee5357..9758e9800 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiMagicMap.java +++ b/src/main/java/noppes/npcs/client/gui/GuiMagicMap.java @@ -79,8 +79,8 @@ public class GuiMagicMap extends GuiDiagram { RenderHelper.enableGUIStandardItemLighting(); - if (magic.iconItem != null) { - renderItem.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), magic.iconItem, iconX, iconY); + if (magic.item != null) { + renderItem.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), magic.item, iconX, iconY); } else if (magic.iconTexture != null && !magic.iconTexture.isEmpty()) { mc.getTextureManager().bindTexture(new ResourceLocation(magic.iconTexture)); this.drawTexturedModalRect(iconX, iconY, 0, 0, size, size); diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java index ea54cf0db..859081c19 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java @@ -113,8 +113,7 @@ public class GuiNPCTagSetup extends GuiNPCInterface2 implements IScrollData,ICus } @Override - public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { - } + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {} public void save() { NBTTagCompound tagCompound = new NBTTagCompound(); diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageMagic.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageMagic.java index bda39aff3..4931854b9 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageMagic.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageMagic.java @@ -8,7 +8,7 @@ import java.util.Vector; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.magic.*; import noppes.npcs.client.gui.magic.SubGuiMagicCycleEdit; -import noppes.npcs.client.gui.magic.SubGuiMagicEdit; +import noppes.npcs.client.gui.magic.SubGuiMagic; import noppes.npcs.client.gui.magic.SubGuiMagicInteractionsEdit; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumScrollData; @@ -23,16 +23,16 @@ import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIc public class GuiNpcManageMagic extends GuiNPCInterface2 implements ISubGuiListener, ICustomScrollListener, IScrollData, IGuiData { // Left scroll (for cycles) and right scroll (for magics). - private GuiCustomScroll leftScroll; // Only used in cycle view. - private GuiCustomScroll rightScroll; // Displays the magics list. + public GuiCustomScroll leftScroll; // Only used in cycle view. + public GuiCustomScroll rightScroll; // Displays the magics list. // When true, we are in global magic view (single list with all magics). // When false, we are in cycle view (two lists: left for cycles and right for associated magics). private boolean viewByCycle = true; // Data maps for cycles and magics. (Keys are display names) - private HashMap cycleData = new HashMap<>(); - private HashMap magicData = new HashMap<>(); + public HashMap cycleData = new HashMap<>(); + public HashMap magicData = new HashMap<>(); // currentMagicList is the subset shown in the right scroll. // In global view it contains all magic names; in cycle view it contains only those associated with the selected cycle. @@ -409,7 +409,7 @@ public class GuiNpcManageMagic extends GuiNPCInterface2 implements ISubGuiListen break; case 2: // Edit Magic. if (selectedMagic != null) { - setSubGui(new SubGuiMagicEdit(selectedMagic)); + setSubGui(new SubGuiMagic(this, selectedMagic)); } break; case 3: // Edit Interactions. diff --git a/src/main/java/noppes/npcs/client/gui/item/SubGuiLinkedItem.java b/src/main/java/noppes/npcs/client/gui/item/SubGuiLinkedItem.java index 92d4df551..5b8d02189 100644 --- a/src/main/java/noppes/npcs/client/gui/item/SubGuiLinkedItem.java +++ b/src/main/java/noppes/npcs/client/gui/item/SubGuiLinkedItem.java @@ -20,7 +20,6 @@ import org.lwjgl.opengl.GL11; public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListener, GuiYesNoCallback, ISubGuiListener { - private final GuiNPCManageLinked parent; public LinkedItem linkedItem; private final String originalName; @@ -283,7 +282,7 @@ public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListe return; } else if (id == -3) { PacketClient.sendClient(new LinkedItemSavePacket(linkedItem.writeToNBT(false), originalName)); - GuiScriptLinkedItem scriptGUI = new GuiScriptLinkedItem(this.parent, linkedItem); + GuiScriptLinkedItem scriptGUI = new GuiScriptLinkedItem((GuiNPCManageLinked) this.parent, linkedItem); scriptGUI.setWorldAndResolution(mc, width, height); scriptGUI.initGui(); mc.currentScreen = scriptGUI; diff --git a/src/main/java/noppes/npcs/client/gui/magic/SubGuiMagic.java b/src/main/java/noppes/npcs/client/gui/magic/SubGuiMagic.java new file mode 100644 index 000000000..34cfc9c06 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/magic/SubGuiMagic.java @@ -0,0 +1,272 @@ +package noppes.npcs.client.gui.magic; + +import kamkeel.npcs.network.PacketClient; +import kamkeel.npcs.network.packets.request.magic.MagicSavePacket; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; +import noppes.npcs.client.gui.SubGuiColorSelector; +import noppes.npcs.client.gui.global.GuiNpcManageMagic; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumTextureType; +import noppes.npcs.controllers.data.Magic; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class SubGuiMagic extends SubGuiInterface implements ITextfieldListener, ISubGuiListener, ICustomScrollListener { + + public GuiNpcManageMagic parent; + private GuiCustomScroll allMagic; + private GuiCustomScroll interactionsScroll; + private Magic magic; + private String search = ""; + + private GuiNpcTextField interactionField; + + private String selectedInteraction; + private HashMap interactionNames = new HashMap<>(); + private HashMap interactionValues = new HashMap<>(); + + public SubGuiMagic(GuiNpcManageMagic parent, Magic magic) { + this.magic = magic; + this.parent = parent; + setBackground("menubg.png"); + xSize = 360; + ySize = 216; + + closeOnEsc = true; + + processInteractions(); + } + + @Override + public void initGui() { + super.initGui(); + + int y = guiTop + 6; + + addLabel(new GuiNpcLabel(1,"gui.name", guiLeft + 4, y + 5)); + addTextField(new GuiNpcTextField(1, this, this.fontRendererObj, guiLeft + 80, y, 200, 20, magic.name)); + + addLabel(new GuiNpcLabel(100,"ID", guiLeft + 200 + 105, guiTop + 4)); + addLabel(new GuiNpcLabel(100, magic.id + "", + 200 + 105, guiTop + 14)); + + y += 25; + + // Edit Magic Display Name + addLabel(new GuiNpcLabel(2, "gui.displayName", guiLeft + 4, y + 5)); + addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 80, y, 200, 20, magic.displayName)); + + String color = Integer.toHexString(magic.color); + while(color.length() < 6) + color = 0 + color; + addButton(new GuiNpcButton(12, guiLeft + 80 + 5 + 200, y, 65, 20, color)); + getButton(12).setTextColor(magic.color); + + y += 25; + + addLabel(new GuiNpcLabel(3, "display.texture", guiLeft + 4, y + 5)); + addTextField(new GuiNpcTextField(3, this, fontRendererObj, guiLeft + 80, y, 200, 20, magic.iconTexture)); + addButton(new GuiNpcButton(13, guiLeft + 80 + 5 + 200, y, 65, 20, EnumTextureType.names(), magic.type.ordinal())); + + + // Interactions + if(allMagic == null){ + allMagic = new GuiCustomScroll(this,0); + allMagic.setSize(150, 107); + } + allMagic.guiLeft = guiLeft + 5; + allMagic.guiTop = guiTop + 80; + this.addScroll(allMagic); + addTextField(new GuiNpcTextField(34, this, fontRendererObj, guiLeft + 5, guiTop + 30 + 160, 150, 20, search)); + allMagic.setList(getSearchList()); + + if(interactionsScroll == null){ + interactionsScroll = new GuiCustomScroll(this,1); + interactionsScroll.setSize(150, 107); + } + interactionsScroll.guiLeft = guiLeft + 200; + interactionsScroll.guiTop = guiTop + 80; + interactionsScroll.setList(new ArrayList<>(interactionNames.keySet())); + this.addScroll(interactionsScroll); + + addLabel(new GuiNpcLabel(50, "magic.interaction", guiLeft + 170, guiTop + 30 + 160 + 5)); + interactionField = new GuiNpcTextField(90, this, fontRendererObj, guiLeft + 245, guiTop + 30 + 160, 45, 20, ""); + interactionField.setFloatsOnly(); + addTextField(interactionField); + if(selectedInteraction != null){ + interactionField.setText(interactionValues.get(selectedInteraction) + ""); + } else { + interactionField.enabled = false; + } + + addButton(new GuiNpcButton(60, guiLeft + 160, guiTop + 90, 30, 20, ">")); + addButton(new GuiNpcButton(61, guiLeft + 160, guiTop + 112, 30, 20, "<")); + + addButton(new GuiNpcButton(62, guiLeft + 160, guiTop + 140, 30, 20, ">>")); + addButton(new GuiNpcButton(63, guiLeft + 160, guiTop + 162, 30, 20, "<<")); + + // Done Button + addButton(new GuiNpcButton(99, guiLeft + 303, guiTop + 30 + 160, 50, 20, "gui.done")); + } + + @Override + public void actionPerformed(GuiButton button) { + if(button.id == 99){ + close(); + } + if(button.id == 13){ + magic.type = EnumTextureType.values()[((GuiNpcButton)button).getValue()]; + } + if (button.id == 12) { + setSubGui(new SubGuiColorSelector(magic.color)); + } + if (button.id == 60 && allMagic.hasSelected() && !interactionNames.containsKey(allMagic.getSelected()) && this.parent.magicData.containsKey(allMagic.getSelected())) { + interactionNames.put(allMagic.getSelected(), this.parent.magicData.get(allMagic.getSelected())); + interactionValues.put(allMagic.getSelected(), 0.0f); + interactionsScroll.list.add(allMagic.getSelected()); + } + if (button.id == 61 && interactionsScroll.hasSelected()) { + // Remove + interactionNames.remove(interactionsScroll.getSelected()); + interactionValues.remove(interactionsScroll.getSelected()); + + interactionsScroll.list.remove(interactionsScroll.selected); + interactionsScroll.selected = -1; + interactionField.enabled = false; + interactionField.setText(""); + } + if (button.id == 62) { + // Add All + for(String name : this.parent.magicData.keySet()){ + if(!interactionNames.containsKey(name)){ + interactionNames.put(name, this.parent.magicData.get(name)); + interactionValues.put(name, 0.0f); + } + } + interactionsScroll.setList(new ArrayList<>(interactionNames.keySet())); + } + if (button.id == 63) { + // Remove All + interactionNames.clear(); + interactionValues.clear(); + + interactionsScroll.setList(new ArrayList<>()); + interactionsScroll.selected = -1; + interactionField.enabled = false; + interactionField.setText(""); + } + } + + @Override + public void unFocused(GuiNpcTextField guiNpcTextField) { + if(guiNpcTextField.id == 1) { + if(magic.id < 0) + guiNpcTextField.setText(""); + else{ + String name = guiNpcTextField.getText(); + if(name.isEmpty() || ((GuiNpcManageMagic)this.parent).magicData.containsKey(name)){ + guiNpcTextField.setText(magic.name); + } + else if(magic.id >= 0){ + String old = magic.name; + ((GuiNpcManageMagic)this.parent).magicData.remove(old); + magic.name = name; + ((GuiNpcManageMagic)this.parent).magicData.put(magic.name, magic.id); + ((GuiNpcManageMagic)this.parent).rightScroll.replace(old, magic.name); + } + } + } + if(guiNpcTextField.id == 2){ + magic.displayName = guiNpcTextField.getText(); + } + if(guiNpcTextField.id == 3){ + magic.iconTexture = guiNpcTextField.getText(); + } + } + + public void mouseClicked(int i, int j, int k) + { + super.mouseClicked(i, j, k); + if(k == 0 && allMagic != null) + allMagic.mouseClicked(i, j, k); + } + + public void keyTyped(char c, int i) + { + super.keyTyped(c, i); + if(getTextField(34) != null && getTextField(34).isFocused()){ + if(search.equals(getTextField(34).getText())) + return; + search = getTextField(34).getText().toLowerCase(); + allMagic.setList(getSearchList()); + allMagic.resetScroll(); + } + } + + private List getSearchList(){ + List original = new ArrayList<>(this.parent.magicData.keySet()); + if(search.isEmpty()){ + return original; + } + List filtered = new ArrayList<>(); + for(String name : original){ + if(name.toLowerCase().contains(search)){ + filtered.add(name); + } + } + return filtered; + } + + public void processInteractions(){ + interactionNames.clear(); + interactionValues.clear(); + for(int id : magic.interactions.keySet()){ + for(String name : this.parent.magicData.keySet()){ + if(this.parent.magicData.get(name) == id){ + interactionNames.put(name, id); + interactionValues.put(name, magic.interactions.get(id)); + } + } + } + } + + public void setInteractions(){ + magic.interactions.clear(); + for(String name : interactionNames.keySet()){ + magic.interactions.put(interactionNames.get(name), interactionValues.get(name)); + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + if(subgui instanceof SubGuiColorSelector){ + magic.color = ((SubGuiColorSelector) subgui).color; + initGui(); + } + } + + public void close(){ + setInteractions(); + NBTTagCompound compound = new NBTTagCompound(); + magic.writeNBT(compound); + PacketClient.sendClient(new MagicSavePacket(compound)); + + + super.close(); + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if(guiCustomScroll.id == 1){ + selectedInteraction = interactionsScroll.getSelected(); + interactionField.enabled = true; + interactionField.setText(interactionValues.get(selectedInteraction) + ""); + } + } + + @Override + public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {} +} diff --git a/src/main/java/noppes/npcs/client/gui/magic/SubGuiMagicEdit.java b/src/main/java/noppes/npcs/client/gui/magic/SubGuiMagicEdit.java deleted file mode 100644 index 42a1bec9e..000000000 --- a/src/main/java/noppes/npcs/client/gui/magic/SubGuiMagicEdit.java +++ /dev/null @@ -1,60 +0,0 @@ -package noppes.npcs.client.gui.magic; - -import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.packets.request.magic.MagicSavePacket; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.client.gui.util.*; -import noppes.npcs.controllers.data.Magic; - -public class SubGuiMagicEdit extends SubGuiInterface implements ITextfieldListener { - - private Magic magic; - - public SubGuiMagicEdit(Magic magic) { - this.magic = magic; - setBackground("menubg.png"); - xSize = 360; - ySize = 240; - } - - @Override - public void initGui() { - super.initGui(); - // Display the Magic's ID - addLabel(new GuiNpcLabel(0, "ID: " + magic.id, guiLeft + 4, guiTop + 4)); - - // Edit Magic Name - addLabel(new GuiNpcLabel(1, "Name:", guiLeft + 4, guiTop + 28)); - addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 60, guiTop + 24, 200, 20, magic.name)); - - // Edit Magic Display Name - addLabel(new GuiNpcLabel(2, "Display Name:", guiLeft + 4, guiTop + 52)); - addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 90, guiTop + 48, 200, 20, magic.displayName)); - - // Button to edit interactions - addButton(new GuiNpcButton(10, guiLeft + 4, guiTop + 80, 120, 20, "Edit Interactions")); - - // Done button to save changes - addButton(new GuiNpcButton(99, guiLeft + 4, guiTop + 110, 60, 20, "Done")); - } - - @Override - public void actionPerformed(GuiButton button) { - if (button.id == 10) { - setSubGui(new SubGuiMagicInteractionsEdit(magic)); - } - if (button.id == 99) { - // Update magic fields and send save packet - magic.name = getTextField(1).getText(); - magic.displayName = getTextField(2).getText(); - NBTTagCompound compound = new NBTTagCompound(); - magic.writeNBT(compound); - PacketClient.sendClient(new MagicSavePacket(compound)); - close(); - } - } - - @Override - public void unFocused(GuiNpcTextField textField) {} -} diff --git a/src/main/java/noppes/npcs/constants/EnumTextureType.java b/src/main/java/noppes/npcs/constants/EnumTextureType.java new file mode 100644 index 000000000..db500e2be --- /dev/null +++ b/src/main/java/noppes/npcs/constants/EnumTextureType.java @@ -0,0 +1,25 @@ +package noppes.npcs.constants; + +import java.util.ArrayList; + +public enum EnumTextureType { + BASE("texture.base"), + ITEM("texture.item"); + + private String lang; + EnumTextureType(String langName){ + this.lang = langName; + } + + public String getLang(){ + return lang; + } + + public static String[] names(){ + ArrayList list = new ArrayList(); + for(EnumTextureType e : values()) + list.add(e.lang); + + return list.toArray(new String[list.size()]); + } +} diff --git a/src/main/java/noppes/npcs/controllers/MagicController.java b/src/main/java/noppes/npcs/controllers/MagicController.java index 3b78207e4..5f2060a4b 100644 --- a/src/main/java/noppes/npcs/controllers/MagicController.java +++ b/src/main/java/noppes/npcs/controllers/MagicController.java @@ -74,28 +74,28 @@ public class MagicController { if (magics.isEmpty()) { // Create default magics Magic earth = new Magic(0, "Earth", 0x00DD00); - earth.setIconItem(new ItemStack(CustomItems.earthElement)); + earth.setItem(new ItemStack(CustomItems.earthElement)); Magic water = new Magic(1, "Water", 0xF2DD00); - water.setIconItem(new ItemStack(CustomItems.waterElement)); + water.setItem(new ItemStack(CustomItems.waterElement)); Magic fire = new Magic(2, "Fire", 0xDD0000); - fire.setIconItem(new ItemStack(CustomItems.spellFire)); + fire.setItem(new ItemStack(CustomItems.spellFire)); Magic air = new Magic(3, "Air", 0xDD0000); - air.setIconItem(new ItemStack(CustomItems.airElement)); + air.setItem(new ItemStack(CustomItems.airElement)); Magic dark = new Magic(4, "Dark", 0xDD0000); - dark.setIconItem(new ItemStack(CustomItems.spellDark)); + dark.setItem(new ItemStack(CustomItems.spellDark)); Magic holy = new Magic(5, "Holy", 0xDD0000); - holy.setIconItem(new ItemStack(CustomItems.spellHoly)); + holy.setItem(new ItemStack(CustomItems.spellHoly)); Magic nature = new Magic(6, "Nature", 0xDD0000); - nature.setIconItem(new ItemStack(CustomItems.spellNature)); + nature.setItem(new ItemStack(CustomItems.spellNature)); Magic arcane = new Magic(7, "Arcane", 0xDD0000); - arcane.setIconItem(new ItemStack(CustomItems.spellArcane)); + arcane.setItem(new ItemStack(CustomItems.spellArcane)); // Insiders earth.interactions.put(air.id, 0.60f); diff --git a/src/main/java/noppes/npcs/controllers/data/Magic.java b/src/main/java/noppes/npcs/controllers/data/Magic.java index 4423a741a..6e1dc98a2 100644 --- a/src/main/java/noppes/npcs/controllers/data/Magic.java +++ b/src/main/java/noppes/npcs/controllers/data/Magic.java @@ -1,14 +1,15 @@ package noppes.npcs.controllers.data; +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.api.handler.data.IMagic; +import noppes.npcs.constants.EnumTextureType; import noppes.npcs.controllers.MagicController; -import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; public class Magic implements IMagic { @@ -17,10 +18,11 @@ public class Magic implements IMagic { public int color = Integer.parseInt("FF00", 16); public int id = -1; - public ItemStack iconItem = null; + public ItemStack item = null; + + public EnumTextureType type = EnumTextureType.BASE; public String iconTexture = ""; public Map interactions = new HashMap<>(); - public HashSet cycles = new HashSet<>(); public Magic() {} @@ -41,12 +43,18 @@ public class Magic implements IMagic { displayName = compound.getString("DisplayName"); color = compound.getInteger("Color"); id = compound.getInteger("Slot"); - // Read icon item. - if(compound.hasKey("IconItem")){ - NBTTagCompound itemTag = compound.getCompoundTag("IconItem"); - iconItem = ItemStack.loadItemStackFromNBT(itemTag); - } + + type = EnumTextureType.values()[compound.getInteger("Type")]; iconTexture = compound.getString("IconTexture"); + if(type == EnumTextureType.ITEM && !iconTexture.isEmpty()){ + 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; + } + } interactions.clear(); if(compound.hasKey("Interactions")) { @@ -58,15 +66,6 @@ public class Magic implements IMagic { 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")); - } - } } public void writeNBT(NBTTagCompound compound) { @@ -74,16 +73,8 @@ public class Magic implements IMagic { compound.setString("Name", name); compound.setString("DisplayName", displayName); compound.setInteger("Color", color); - // Write icon item. - if(iconItem != null) { - NBTTagCompound itemTag = new NBTTagCompound(); - iconItem.writeToNBT(itemTag); - compound.setTag("IconItem", itemTag); - } - if(iconTexture != null && !iconTexture.isEmpty()){ - compound.setString("IconTexture", iconTexture); - } - + compound.setString("IconTexture", iconTexture); + compound.setInteger("Type", type.ordinal()); NBTTagList interactionsList = new NBTTagList(); for (Map.Entry entry : interactions.entrySet()){ NBTTagCompound interactionTag = new NBTTagCompound(); @@ -93,13 +84,15 @@ public class Magic implements IMagic { } compound.setTag("Interactions", interactionsList); - NBTTagList cyclesList = new NBTTagList(); - for (Integer cycle : cycles) { - NBTTagCompound cycleTag = new NBTTagCompound(); - cycleTag.setInteger("Cycle", cycle); - cyclesList.appendTag(cycleTag); + if(type == EnumTextureType.ITEM && !iconTexture.isEmpty()){ + 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; + } } - compound.setTag("Cycles", cyclesList); } public int getId() { @@ -135,12 +128,17 @@ public class Magic implements IMagic { MagicController.getInstance().saveMagic(this); } - public void setIconItem(ItemStack item) { - this.iconItem = item; + public void setItem(ItemStack item) { + GameRegistry.UniqueIdentifier identifier = GameRegistry.findUniqueIdentifierFor(item.getItem()); + if(identifier != null){ + this.item = item; + this.type = EnumTextureType.ITEM; + this.iconTexture = identifier.modId + ":" + identifier.name; + } } - public ItemStack getIconItem() { - return this.iconItem; + public ItemStack getItem() { + return this.item; } public void setIconTexture(String texture) { diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 9b8d16b3a..7b26fe40c 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -62,6 +62,7 @@ gui.view=View gui.remove=Remove gui.save=Save gui.name=Name +gui.displayName=Display Name gui.color=Color gui.none=None gui.time=Time @@ -1308,6 +1309,9 @@ hitbox.hitbox=Hitbox hitbox.width=Width Scale hitbox.height=Height Scale +texture.item=Item +texture.base=Base + general.menuName=Menu Name effect.runsEveryX=Runs every X tick @@ -1334,6 +1338,8 @@ profile.completion=Completion profile.cooldown=Cooldown profile.individual=Individual +magic.interaction=Interaction + rpgcore:tooltip=Hold %key% to view attributes rpgcore:attribute.damage=Damage rpgcore:attribute.defense=Defense