mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 01:27:27 +00:00
Tags can now be added through a new sub gui in the NPC advanced tab.
This commit is contained in:
1 parent
9a6cf94c73
commit
aba24fc93c
7 files changed
+182
-20
No files matched your search
@@ -2,6 +2,7 @@ package noppes.npcs;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import noppes.npcs.constants.EnumJobType;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.controllers.GlobalDataController;
|
||||
@@ -13,6 +14,8 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.roles.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DataAdvanced {
|
||||
|
||||
@@ -32,6 +35,7 @@ public class DataAdvanced {
|
||||
|
||||
private EntityNPCInterface npc;
|
||||
public FactionOptions factions = new FactionOptions();
|
||||
public HashSet<UUID> tagUUIDs = new HashSet<>();
|
||||
|
||||
public EnumRoleType role = EnumRoleType.None;
|
||||
public EnumJobType job = EnumJobType.None;
|
||||
@@ -78,6 +82,12 @@ public class DataAdvanced {
|
||||
compound.setBoolean("RefuseSoulStone", refuseSoulStone);
|
||||
compound.setString("SoulStonePlayerName", soulStonePlayerName);
|
||||
compound.setInteger("MinFactionPointsToSoulStone", minFactionPointsToSoulStone);
|
||||
|
||||
NBTTagList nbtTagList = new NBTTagList();
|
||||
for (UUID uuid : tagUUIDs) {
|
||||
nbtTagList.appendTag(new NBTTagString(uuid.toString()));
|
||||
}
|
||||
compound.setTag("TagUUIDs", nbtTagList);
|
||||
|
||||
return compound;
|
||||
}
|
||||
@@ -113,6 +123,11 @@ public class DataAdvanced {
|
||||
refuseSoulStone = compound.getBoolean("RefuseSoulStone");
|
||||
soulStonePlayerName = compound.getString("SoulStonePlayerName");
|
||||
minFactionPointsToSoulStone = compound.getInteger("MinFactionPointsToSoulStone");
|
||||
|
||||
NBTTagList nbtTagList = compound.getTagList("TagUUIDs",8);
|
||||
for (int i = 0; i < nbtTagList.tagCount(); i++) {
|
||||
tagUUIDs.add(UUID.fromString(nbtTagList.getStringTagAt(i)));
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<Integer, DialogOption> getDialogs(NBTTagList tagList) {
|
||||
|
||||
@@ -95,6 +95,19 @@ public class PacketHandlerServer{
|
||||
map.put(provider.getDimensionName(), id);
|
||||
}
|
||||
NoppesUtilServer.sendScrollData(player, map);
|
||||
} else if(type == EnumPacketServer.TagsGet){
|
||||
NoppesUtilServer.sendTagDataAll(player);
|
||||
} else if (type == EnumPacketServer.NpcTagsGet) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
for (UUID uuid : npc.advanced.tagUUIDs) {
|
||||
Tag tag = TagController.getInstance().getTagFromUUID(uuid);
|
||||
if (tag != null) {
|
||||
tagList.appendTag(new NBTTagString(tag.name));
|
||||
}
|
||||
}
|
||||
compound.setTag("TagNames",tagList);
|
||||
Server.sendData(player, EnumPacketClient.GUI_DATA, compound);
|
||||
}
|
||||
|
||||
if(type.needsNpc && npc == null){
|
||||
@@ -404,9 +417,6 @@ public class PacketHandlerServer{
|
||||
else if(type == EnumPacketServer.FactionsGet){
|
||||
NoppesUtilServer.sendFactionDataAll(player);
|
||||
}
|
||||
else if(type == EnumPacketServer.TagsGet){
|
||||
NoppesUtilServer.sendTagDataAll(player);
|
||||
}
|
||||
else if(type == EnumPacketServer.DialogGet){
|
||||
Dialog dialog = DialogController.instance.dialogs.get(buffer.readInt());
|
||||
if(dialog != null){
|
||||
@@ -751,7 +761,13 @@ public class PacketHandlerServer{
|
||||
Server.sendData(player, EnumPacketClient.GUI_DATA, compound);
|
||||
}
|
||||
else if(type == EnumPacketServer.TagSet){
|
||||
// npc.setFaction(buffer.readInt());
|
||||
npc.advanced.tagUUIDs.clear();
|
||||
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);
|
||||
}
|
||||
}
|
||||
else if(type == EnumPacketServer.TagSave){
|
||||
Tag tag = new Tag();
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.gui.SubGuiNpcFactionOptions;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class GuiNPCTagSetup extends GuiNPCInterface2 implements IScrollData,ICustomScrollListener,IGuiData
|
||||
{
|
||||
private GuiCustomScroll scrollTags;
|
||||
private GuiCustomScroll npcTags;
|
||||
private HashMap<String,Integer> data = new HashMap<>();
|
||||
private final ArrayList<String> tagNames = new ArrayList<>();
|
||||
|
||||
public GuiNPCTagSetup(EntityNPCInterface npc)
|
||||
{
|
||||
super(npc);
|
||||
Client.sendData(EnumPacketServer.TagsGet);
|
||||
Client.sendData(EnumPacketServer.NpcTagsGet);
|
||||
}
|
||||
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
|
||||
if(scrollTags == null){
|
||||
scrollTags = new GuiCustomScroll(this,0);
|
||||
scrollTags.setSize(120, 180);
|
||||
}
|
||||
scrollTags.guiLeft = guiLeft + 50;
|
||||
scrollTags.guiTop = guiTop + 24;
|
||||
this.addScroll(scrollTags);
|
||||
|
||||
if(npcTags == null){
|
||||
npcTags = new GuiCustomScroll(this,1);
|
||||
npcTags.setSize(120, 180);
|
||||
}
|
||||
npcTags.guiLeft = guiLeft + width - 180;
|
||||
npcTags.guiTop = guiTop + 24;
|
||||
npcTags.setList(tagNames);
|
||||
this.addScroll(npcTags);
|
||||
|
||||
addButton(new GuiNpcButton(10, guiLeft + 180, guiTop + 90, 55, 20, ">"));
|
||||
addButton(new GuiNpcButton(11, guiLeft + 180, guiTop + 112, 55, 20, "<"));
|
||||
|
||||
addButton(new GuiNpcButton(12, guiLeft + 180, guiTop + 140, 55, 20, ">>"));
|
||||
addButton(new GuiNpcButton(13, guiLeft + 180, 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<String> list, HashMap<String, Integer> 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);
|
||||
}
|
||||
}
|
||||
@@ -27,21 +27,24 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
|
||||
@Override
|
||||
public void initGui(){
|
||||
super.initGui();
|
||||
this.addButton(new GuiNpcButton(3, guiLeft + 85 + 160, guiTop + 20, 52, 20, "selectServer.edit"));
|
||||
this.addButton(new GuiNpcButton(8, guiLeft + 85, guiTop + 20,155,20, new String[]{"role.none","role.trader","role.follower","role.bank","role.transporter", "role.mailman", NoppesStringUtils.translate("role.companion", "(WIP)")},npc.advanced.role.ordinal()));
|
||||
int y = guiTop + 10;
|
||||
int gap = 21;
|
||||
this.addButton(new GuiNpcButton(3, guiLeft + 85 + 160, y, 52, 20, "selectServer.edit"));
|
||||
this.addButton(new GuiNpcButton(8, guiLeft + 85, y,155,20, new String[]{"role.none","role.trader","role.follower","role.bank","role.transporter", "role.mailman", NoppesStringUtils.translate("role.companion", "(WIP)")},npc.advanced.role.ordinal()));
|
||||
getButton(3).setEnabled(npc.advanced.role != EnumRoleType.None && npc.advanced.role != EnumRoleType.Postman);
|
||||
|
||||
this.addButton(new GuiNpcButton(4, guiLeft + 85 + 160, guiTop + 43, 52, 20, "selectServer.edit"));
|
||||
this.addButton(new GuiNpcButton(5, guiLeft + 85, guiTop + 43,155,20, new String[]{"job.none","job.bard","job.healer","job.guard","job.itemgiver","role.follower", "job.spawner", "job.conversation", "job.chunkloader"},npc.advanced.job.ordinal()));
|
||||
this.addButton(new GuiNpcButton(4, guiLeft + 85 + 160, y += gap, 52, 20, "selectServer.edit"));
|
||||
this.addButton(new GuiNpcButton(5, guiLeft + 85, y,155,20, new String[]{"job.none","job.bard","job.healer","job.guard","job.itemgiver","role.follower", "job.spawner", "job.conversation", "job.chunkloader"},npc.advanced.job.ordinal()));
|
||||
|
||||
getButton(4).setEnabled(npc.advanced.job != EnumJobType.None && npc.advanced.job != EnumJobType.ChunkLoader);
|
||||
|
||||
this.addButton(new GuiNpcButton(7, guiLeft + 85, guiTop + 66, 214, 20, "advanced.lines"));
|
||||
this.addButton(new GuiNpcButton(9, guiLeft + 85, guiTop + 89, 214, 20, "menu.factions"));
|
||||
this.addButton(new GuiNpcButton(10, guiLeft + 85, guiTop + 112, 214, 20, "dialog.dialogs"));
|
||||
this.addButton(new GuiNpcButton(11, guiLeft + 85, guiTop + 135, 214, 20, "advanced.sounds"));
|
||||
this.addButton(new GuiNpcButton(12, guiLeft + 85, guiTop + 158, 214, 20, "advanced.night"));
|
||||
this.addButton(new GuiNpcButton(13, guiLeft + 85, guiTop + 181, 214, 20, "global.linked"));
|
||||
this.addButton(new GuiNpcButton(7, guiLeft + 85, y += gap, 214, 20, "advanced.lines"));
|
||||
this.addButton(new GuiNpcButton(9, guiLeft + 85, y += gap, 214, 20, "menu.factions"));
|
||||
this.addButton(new GuiNpcButton(10, guiLeft + 85, y += gap, 214, 20, "dialog.dialogs"));
|
||||
this.addButton(new GuiNpcButton(11, guiLeft + 85, y += gap, 214, 20, "advanced.sounds"));
|
||||
this.addButton(new GuiNpcButton(12, guiLeft + 85, y += gap, 214, 20, "advanced.night"));
|
||||
this.addButton(new GuiNpcButton(13, guiLeft + 85, y += gap, 214, 20, "global.linked"));
|
||||
this.addButton(new GuiNpcButton(14, guiLeft + 85, y += gap, 214, 20, "menu.tags"));
|
||||
|
||||
}
|
||||
|
||||
@@ -92,6 +95,10 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData
|
||||
save();
|
||||
NoppesUtil.openGUI(player, new GuiNPCAdvancedLinkedNpc(npc));
|
||||
}
|
||||
if(button.id == 14){
|
||||
save();
|
||||
NoppesUtil.openGUI(player, new GuiNPCTagSetup(npc));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -66,7 +66,7 @@ public enum EnumPacketServer {
|
||||
FactionRemove(CustomNpcsPermissions.GLOBAL_FACTION),
|
||||
FactionSave(CustomNpcsPermissions.GLOBAL_FACTION), FactionsGet, FactionGet,
|
||||
TagRemove(CustomNpcsPermissions.GLOBAL_TAG),
|
||||
TagSave(CustomNpcsPermissions.GLOBAL_TAG), TagsGet, TagGet,
|
||||
TagSave(CustomNpcsPermissions.GLOBAL_TAG), TagsGet, TagGet, NpcTagsGet,
|
||||
QuestCategorySave(CustomNpcsPermissions.GLOBAL_QUEST), QuestCategoriesGet,
|
||||
QuestRemove(CustomNpcsPermissions.GLOBAL_QUEST),
|
||||
QuestCategoryRemove(CustomNpcsPermissions.GLOBAL_QUEST),
|
||||
|
||||
@@ -10,10 +10,7 @@ import noppes.npcs.api.handler.data.ITag;
|
||||
import noppes.npcs.controllers.data.Tag;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class TagController implements ITagHandler {
|
||||
@@ -206,6 +203,7 @@ public class TagController implements ITagHandler {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Tag getTagFromName(String tagname){
|
||||
for (Map.Entry<Integer,Tag> entryTag: TagController.getInstance().tags.entrySet()){
|
||||
if (entryTag.getValue().name.equalsIgnoreCase(tagname)){
|
||||
@@ -224,4 +222,13 @@ public class TagController implements ITagHandler {
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
public Tag getTagFromUUID(UUID uuid){
|
||||
for (Map.Entry<Integer,Tag> entryTag: TagController.getInstance().tags.entrySet()){
|
||||
if (entryTag.getValue().uuid.equals(uuid)) {
|
||||
return entryTag.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user