mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 04:57:27 +00:00
Magic Editor Sub GUI
This commit is contained in:
1 parent
0aef78fd43
commit
ffaf21d3d8
10 files changed
+357
-118
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<String, Integer> cycleData = new HashMap<>();
|
||||
private HashMap<String, Integer> magicData = new HashMap<>();
|
||||
public HashMap<String, Integer> cycleData = new HashMap<>();
|
||||
public HashMap<String, Integer> 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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<String, Integer> interactionNames = new HashMap<>();
|
||||
private HashMap<String, Float> 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<String> getSearchList(){
|
||||
List<String> original = new ArrayList<>(this.parent.magicData.keySet());
|
||||
if(search.isEmpty()){
|
||||
return original;
|
||||
}
|
||||
List<String> 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) {}
|
||||
}
|
||||
@@ -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) {}
|
||||
}
|
||||
@@ -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<String> list = new ArrayList<String>();
|
||||
for(EnumTextureType e : values())
|
||||
list.add(e.lang);
|
||||
|
||||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Integer, Float> interactions = new HashMap<>();
|
||||
public HashSet<Integer> 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<Integer, Float> 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) {
|
||||
|
||||
Reference in new issue
Block a user