From 9af7c67798332a8265fc3a558bf7098625b470a0 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Tue, 19 Mar 2024 22:13:29 -0500 Subject: [PATCH] Fixed slots being replaced when custom GUIs are read from NBT. --- .../noppes/npcs/scripted/gui/ScriptGui.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java index 8f5abb208..f24dbfe5f 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java @@ -256,14 +256,21 @@ public class ScriptGui implements ICustomGui { } } - List slots = new ArrayList(); + List slots = new ArrayList<>(); list = tag.getTagList("slots", 10); for(int i = 0; i < list.tagCount(); i++){ - NBTBase b = list.getCompoundTagAt(i); - ScriptGuiItemSlot component = (ScriptGuiItemSlot)ScriptGuiComponent.createFromNBT((NBTTagCompound)b); - components.put(component.getID(), component); - slots.add(component); + NBTTagCompound slotNbt = list.getCompoundTagAt(i); + + int id = slotNbt.getInteger("id"); + if (!components.containsKey(id)) { + components.put(id, ScriptGuiComponent.createFromNBT(slotNbt)); + } else { + components.get(id).fromNBT(slotNbt); + } + + ScriptGuiItemSlot slot = (ScriptGuiItemSlot) components.get(id); + slots.add(slot); } this.slots = slots;