From 36cd81e6e4cc69afac1239bca275abbb4320cb47 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 2 May 2023 19:07:47 -0400 Subject: [PATCH] Fix NPC Tag Modifier not saving and isNPC Crash --- .../npcs/client/gui/GuiNpcMobSpawnerAdd.java | 34 +++++++++++-------- .../npcs/client/gui/SubGuiClonerNPCTags.java | 14 +++++++- ...ckTags.java => SubGuiClonerQuickTags.java} | 4 +-- 3 files changed, 35 insertions(+), 17 deletions(-) rename src/main/java/noppes/npcs/client/gui/{SubGuiNpcQuickTags.java => SubGuiClonerQuickTags.java} (93%) diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java index a3c7060d7..905029191 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java @@ -9,14 +9,11 @@ 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; import java.util.HashSet; import java.util.UUID; @@ -35,10 +32,11 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall public GuiNpcMobSpawnerAdd(NBTTagCompound compound){ this.toClone = EntityList.createEntityFromNBT(compound, Minecraft.getMinecraft().theWorld); this.compound = compound; + updateIsNPC(); // Get Tag UUIDs - this.getTagUUIDs(); if(isNPC){ + this.getTagUUIDs(); Client.sendData(EnumPacketServer.TagsGet); } @@ -72,14 +70,10 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall } public void getTagUUIDs(){ - // Is an NPC - if(compound.hasKey("ModRev")){ - this.isNPC = true; - if(compound.hasKey("TagUUIDs")){ - NBTTagList nbtTagList = compound.getTagList("TagUUIDs",8); - for (int i = 0; i < nbtTagList.tagCount(); i++) { - npcTags.add(UUID.fromString(nbtTagList.getStringTagAt(i))); - } + if(compound.hasKey("TagUUIDs")){ + NBTTagList nbtTagList = compound.getTagList("TagUUIDs",8); + for (int i = 0; i < nbtTagList.tagCount(); i++) { + npcTags.add(UUID.fromString(nbtTagList.getStringTagAt(i))); } } } @@ -153,10 +147,22 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall } } + public void updateIsNPC(){ + if(compound.hasKey("id")){ + String id = compound.getString("id"); + if(id.equals("customnpcs.CustomNpc")){ + this.isNPC = true; + return; + } + } + this.isNPC = false; + } + + @Override public void subGuiClosed(SubGuiInterface subgui) { - if (subgui instanceof SubGuiNpcQuickTags) { - SubGuiNpcQuickTags filterGui = (SubGuiNpcQuickTags) subgui; + if (subgui instanceof SubGuiClonerQuickTags) { + SubGuiClonerQuickTags filterGui = (SubGuiClonerQuickTags) 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 index 72006bd71..3a8741fc4 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java @@ -29,7 +29,7 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc setBackground("menubg.png"); xSize = 305; ySize = 220; - closeOnEsc = true; + closeOnEsc = false; } public void initGui() @@ -60,6 +60,8 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc addButton(new GuiNpcButton(12, guiLeft + 120, guiTop + 140, 55, 20, ">>")); addButton(new GuiNpcButton(13, guiLeft + 120, guiTop + 162, 55, 20, "<<")); + + addButton(new GuiNpcButton(66, guiLeft + 120, guiTop + 50, 55, 20, "gui.save")); } @Override @@ -77,6 +79,9 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc if (guibutton.id == 13) { tagNames.clear(); } + if (guibutton.id == 66) { + close(); + } initGui(); } @@ -122,4 +127,11 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc tagCompound.setTag("TagNames",tagList); Client.sendData(EnumPacketServer.TagSet, tagCompound); } + + @Override + public void close() { + save(); + super.close(); + } + } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuickTags.java b/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java similarity index 93% rename from src/main/java/noppes/npcs/client/gui/SubGuiNpcQuickTags.java rename to src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java index 029b15835..e5a4cf1a6 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuickTags.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java @@ -10,14 +10,14 @@ import noppes.npcs.client.gui.util.SubGuiInterface; import java.util.ArrayList; import java.util.HashSet; -public class SubGuiNpcQuickTags extends SubGuiInterface +public class SubGuiClonerQuickTags extends SubGuiInterface { public GuiNpcMobSpawnerAdd parent; ArrayList allTags = new ArrayList<>(); HashSet filter; public GuiCustomScroll filterScroll; - public SubGuiNpcQuickTags(GuiNpcMobSpawnerAdd par){ + public SubGuiClonerQuickTags(GuiNpcMobSpawnerAdd par){ this.parent = par; setBackground("menubg.png"); xSize = 305;