diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 9900676ac..b52f9a4c6 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -763,13 +763,7 @@ public class PacketHandlerServer{ Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } else if(type == EnumPacketServer.TagSet){ - npc.advanced.tagUUIDs.removeIf(uuid -> TagController.getInstance().getTagFromUUID(uuid) != null); - NBTTagCompound compound = Server.readNBT(buffer); - NBTTagList list = compound.getTagList("TagNames",8); - for (int i = 0; i < list.tagCount(); i++) { - String tagName = list.getStringTagAt(i); - npc.advanced.tagUUIDs.add(((Tag)TagController.getInstance().getTagFromName(tagName)).uuid); - } + this.setTags(npc,buffer); } else if(type == EnumPacketServer.TagSave){ Tag tag = new Tag(); @@ -1095,8 +1089,23 @@ public class PacketHandlerServer{ compound.setTag("AllTags", validTagList); Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } - else - warn(player,"WE 2 tried todo something with the wrong tool, probably a hacker"); + else if (type == EnumPacketServer.TagSet) { + EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player); + this.setTags(npc,buffer); + } + else if (type != EnumPacketServer.NpcTagsGet && type != EnumPacketServer.TagsGet) { + warn(player, "WE 2 tried todo something with the wrong tool, probably a hacker"); + } + } + + private void setTags(EntityNPCInterface npc, ByteBuf buffer) throws IOException { + npc.advanced.tagUUIDs.removeIf(uuid -> TagController.getInstance().getTagFromUUID(uuid) != null); + NBTTagCompound compound = Server.readNBT(buffer); + NBTTagList list = compound.getTagList("TagNames",8); + for (int i = 0; i < list.tagCount(); i++) { + String tagName = list.getStringTagAt(i); + npc.advanced.tagUUIDs.add(((Tag)TagController.getInstance().getTagFromName(tagName)).uuid); + } } private void warn(EntityPlayer player, String warning){ diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index 0add96661..97d0f405a 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -95,6 +95,9 @@ public class ServerEventsHandler { if(!Server.sendData((EntityPlayerMP)event.entityPlayer, EnumPacketClient.CLONE, compound)) event.entityPlayer.addChatMessage(new ChatComponentText("Entity too big to clone")); data.cloned = compound; + if (event.target instanceof EntityNPCInterface) { + NoppesUtilServer.setEditingNpc(event.entityPlayer, (EntityNPCInterface) event.target); + } event.setCanceled(true); } else if(item.getItem() == CustomItems.scripter && !isRemote && npcInteracted){ diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java index b46da836d..a3c7060d7 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java @@ -9,9 +9,12 @@ import net.minecraft.entity.EntityList; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.client.Client; +import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.controllers.ClientCloneController; +import noppes.npcs.client.gui.advanced.GuiNPCTagSetup; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.entity.EntityNPCInterface; import javax.annotation.Nullable; import java.util.ArrayList; @@ -106,6 +109,9 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall if(id == 3){ serverSide = ((GuiNpcButton)guibutton).getValue() == 1; } + if (id == 5) { + this.setSubGui(new SubGuiClonerNPCTags((EntityNPCInterface) toClone)); + } } @@ -149,8 +155,10 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall @Override public void subGuiClosed(SubGuiInterface subgui) { - SubGuiNpcQuickTags filterGui = (SubGuiNpcQuickTags) subgui; - // filter = filterGui.filterScroll.getSelectedList(); + if (subgui instanceof SubGuiNpcQuickTags) { + SubGuiNpcQuickTags filterGui = (SubGuiNpcQuickTags) subgui; + // filter = filterGui.filterScroll.getSelectedList(); + } initGui(); } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java b/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java new file mode 100644 index 000000000..72006bd71 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java @@ -0,0 +1,125 @@ +package noppes.npcs.client.gui; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.util.StatCollector; +import noppes.npcs.client.Client; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.entity.EntityNPCInterface; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Vector; + +public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,IScrollData,ICustomScrollListener { + private final EntityNPCInterface npc; + private GuiCustomScroll scrollTags; + private GuiCustomScroll npcTags; + private HashMap data = new HashMap<>(); + private final ArrayList tagNames = new ArrayList<>(); + + public SubGuiClonerNPCTags(EntityNPCInterface npc) + { + this.npc = npc; + Client.sendData(EnumPacketServer.TagsGet); + Client.sendData(EnumPacketServer.NpcTagsGet); + setBackground("menubg.png"); + xSize = 305; + ySize = 220; + closeOnEsc = true; + } + + public void initGui() + { + super.initGui(); + + addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("tags.allTags"), guiLeft + 5, guiTop + 11)); + if(scrollTags == null){ + scrollTags = new GuiCustomScroll(this,0); + scrollTags.setSize(100, 180); + } + scrollTags.guiLeft = guiLeft + 5; + scrollTags.guiTop = guiTop + 24; + this.addScroll(scrollTags); + + addLabel(new GuiNpcLabel(2, StatCollector.translateToLocal("tags.selectedTags"), guiLeft + 190, guiTop + 11)); + if(npcTags == null){ + npcTags = new GuiCustomScroll(this,1); + npcTags.setSize(100, 180); + } + npcTags.guiLeft = guiLeft + 190; + npcTags.guiTop = guiTop + 24; + npcTags.setList(tagNames); + this.addScroll(npcTags); + + addButton(new GuiNpcButton(10, guiLeft + 120, guiTop + 90, 55, 20, ">")); + addButton(new GuiNpcButton(11, guiLeft + 120, guiTop + 112, 55, 20, "<")); + + addButton(new GuiNpcButton(12, guiLeft + 120, guiTop + 140, 55, 20, ">>")); + addButton(new GuiNpcButton(13, guiLeft + 120, guiTop + 162, 55, 20, "<<")); + } + + @Override + public void buttonEvent(GuiButton guibutton) { + if (guibutton.id == 10 && scrollTags.hasSelected() && !tagNames.contains(scrollTags.getSelected())) { + tagNames.add(scrollTags.getSelected()); + } + if (guibutton.id == 12) { + tagNames.clear(); + tagNames.addAll(data.keySet()); + } + if (guibutton.id == 11 && npcTags.hasSelected()) { + tagNames.remove(npcTags.getSelected()); + } + if (guibutton.id == 13) { + tagNames.clear(); + } + initGui(); + } + + @Override + public void setData(Vector list, HashMap data) + { + this.data = data; + scrollTags.setList(list); + initGui(); + } + + @Override + public void setGuiData(NBTTagCompound compound) { + NBTTagList tagList = compound.getTagList("TagNames",8); + tagNames.clear(); + for (int i = 0; i < tagList.tagCount(); i++) { + tagNames.add(tagList.getStringTagAt(i)); + } + } + + public void mouseClicked(int i, int j, int k) + { + super.mouseClicked(i, j, k); + if(k == 0 && scrollTags != null) + scrollTags.mouseClicked(i, j, k); + } + + @Override + public void setSelected(String selected) { + scrollTags.setSelected(selected); + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + } + + public void save() { + NBTTagCompound tagCompound = new NBTTagCompound(); + NBTTagList tagList = new NBTTagList(); + for (String string : this.tagNames) { + tagList.appendTag(new NBTTagString(string)); + } + tagCompound.setTag("TagNames",tagList); + Client.sendData(EnumPacketServer.TagSet, tagCompound); + } +}