2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs.client.gui;
|
|
|
|
|
|
2025-02-02 22:31:39 -05:00
|
|
|
import kamkeel.npcs.network.PacketClient;
|
|
|
|
|
import kamkeel.npcs.network.packets.request.clone.CloneAllTagsShortPacket;
|
|
|
|
|
import kamkeel.npcs.network.packets.request.clone.ClonePreSavePacket;
|
|
|
|
|
import kamkeel.npcs.network.packets.request.clone.CloneSavePacket;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
|
import net.minecraft.client.gui.GuiYesNo;
|
|
|
|
|
import net.minecraft.client.gui.GuiYesNoCallback;
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.EntityList;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2023-04-08 18:03:05 -04:00
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2023-05-08 23:47:45 -04:00
|
|
|
import net.minecraft.nbt.NBTTagString;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.client.controllers.ClientCloneController;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.client.gui.util.GuiButtonBiDirectional;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiNpcButton;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
|
|
|
|
import noppes.npcs.client.gui.util.IGuiData;
|
|
|
|
|
import noppes.npcs.client.gui.util.ISubGuiListener;
|
|
|
|
|
import noppes.npcs.client.gui.util.SubGuiInterface;
|
2023-05-08 23:47:45 -04:00
|
|
|
import noppes.npcs.controllers.data.Tag;
|
2023-04-12 14:22:22 -05:00
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2024-02-15 17:54:28 -05:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.UUID;
|
2023-04-08 18:03:05 -04:00
|
|
|
|
2023-05-08 23:47:45 -04:00
|
|
|
public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ISubGuiListener {
|
2024-02-15 17:54:28 -05:00
|
|
|
|
2024-12-21 14:23:22 -05:00
|
|
|
private Entity toClone;
|
|
|
|
|
private NBTTagCompound compound;
|
2025-03-13 17:14:45 -04:00
|
|
|
private static boolean serverSide = false;
|
|
|
|
|
private static int tab = 1;
|
|
|
|
|
public boolean isNPC = false;
|
2023-05-08 23:47:45 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
// Selected Tags to Add
|
2024-12-21 14:23:22 -05:00
|
|
|
public static NBTTagList tagsCompound;
|
2025-03-13 17:14:45 -04:00
|
|
|
public static HashSet<String> addTags;
|
|
|
|
|
public static ArrayList<String> allTags = new ArrayList<>();
|
2024-12-21 14:23:22 -05:00
|
|
|
public static HashSet<UUID> addTagUUIDs;
|
|
|
|
|
public static HashMap<String, UUID> tagMap = new HashMap<>();
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public GuiNpcMobSpawnerAdd(NBTTagCompound compound) {
|
|
|
|
|
this.toClone = EntityList.createEntityFromNBT(compound, Minecraft.getMinecraft().theWorld);
|
|
|
|
|
this.compound = compound;
|
2024-12-21 14:23:22 -05:00
|
|
|
tagsCompound = new NBTTagList();
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (toClone instanceof EntityNPCInterface) {
|
|
|
|
|
isNPC = true;
|
|
|
|
|
tagsCompound = this.compound.getTagList("TagUUIDs", 8);
|
|
|
|
|
}
|
|
|
|
|
setBackground("menubg.png");
|
|
|
|
|
xSize = 256;
|
|
|
|
|
ySize = 216;
|
|
|
|
|
closeOnEsc = true;
|
|
|
|
|
|
|
|
|
|
if (addTags == null) {
|
|
|
|
|
addTags = new HashSet<>();
|
|
|
|
|
}
|
|
|
|
|
if (addTagUUIDs == null) {
|
2024-12-21 14:23:22 -05:00
|
|
|
addTagUUIDs = new HashSet<>();
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
if (isNPC) {
|
2025-02-02 22:31:39 -05:00
|
|
|
PacketClient.sendClient(new CloneAllTagsShortPacket());
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initGui() {
|
|
|
|
|
super.initGui();
|
|
|
|
|
String name = toClone.getCommandSenderName();
|
|
|
|
|
addLabel(new GuiNpcLabel(0, "Save as", guiLeft + 4, guiTop + 6));
|
|
|
|
|
addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 4, guiTop + 18, 200, 20, name));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addLabel(new GuiNpcLabel(1, "Tab", guiLeft + 10, guiTop + 50));
|
|
|
|
|
addButton(new GuiButtonBiDirectional(2, guiLeft + 40, guiTop + 45, 60, 20, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"}, tab - 1));
|
|
|
|
|
|
|
|
|
|
addButton(new GuiNpcButton(3, guiLeft + 4, guiTop + 95, new String[]{"Client side", "Server side"}, serverSide ? 1 : 0));
|
|
|
|
|
addLabel(new GuiNpcLabel(1, "Tab", guiLeft + 10, guiTop + 50));
|
|
|
|
|
|
|
|
|
|
addButton(new GuiNpcButton(0, guiLeft + 4, guiTop + 70, 80, 20, "gui.save"));
|
|
|
|
|
addButton(new GuiNpcButton(1, guiLeft + 86, guiTop + 70, 80, 20, "gui.cancel"));
|
|
|
|
|
|
|
|
|
|
if (isNPC) {
|
|
|
|
|
addButton(new GuiNpcButton(4, guiLeft + 4, guiTop + 120, 99, 20, "cloner.wandTags"));
|
|
|
|
|
addButton(new GuiNpcButton(5, guiLeft + 106, guiTop + 120, 99, 20, "cloner.npcTags"));
|
|
|
|
|
if (addTags.size() > 0) {
|
|
|
|
|
addLabel(new GuiNpcLabel(6, "cloner.wandtagsapplied", guiLeft + 10, guiTop + 160));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void buttonEvent(GuiButton guibutton) {
|
|
|
|
|
int id = guibutton.id;
|
|
|
|
|
if (id == 0) {
|
|
|
|
|
String name = getTextField(0).getText();
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
int tab = ((GuiNpcButton) guibutton).getValue() + 1;
|
|
|
|
|
if (!serverSide) {
|
|
|
|
|
if (ClientCloneController.Instance.getCloneData(null, name, tab) != null)
|
|
|
|
|
displayGuiScreen(new GuiYesNo(this, "Warning", "You are about to overwrite a clone", 1));
|
|
|
|
|
else
|
|
|
|
|
confirmClicked(true, 0);
|
|
|
|
|
} else
|
2025-02-02 22:31:39 -05:00
|
|
|
PacketClient.sendClient(new ClonePreSavePacket(name, tab));
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
if (id == 1) {
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
if (id == 2) {
|
|
|
|
|
tab = ((GuiNpcButton) guibutton).getValue() + 1;
|
|
|
|
|
}
|
|
|
|
|
if (id == 3) {
|
|
|
|
|
serverSide = ((GuiNpcButton) guibutton).getValue() == 1;
|
|
|
|
|
}
|
|
|
|
|
if (id == 4) {
|
|
|
|
|
if (isNPC) {
|
|
|
|
|
this.setSubGui(new SubGuiClonerQuickTags(this));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (id == 5) {
|
|
|
|
|
if (isNPC) {
|
|
|
|
|
this.setSubGui(new SubGuiClonerNPCTags((EntityNPCInterface) toClone, this));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void confirmClicked(boolean confirm, int id) {
|
|
|
|
|
if (confirm) {
|
|
|
|
|
String name = getTextField(0).getText();
|
|
|
|
|
NBTTagCompound extraTags = new NBTTagCompound();
|
|
|
|
|
if (isNPC) {
|
|
|
|
|
extraTags = setTempTags();
|
|
|
|
|
}
|
|
|
|
|
if (!serverSide) {
|
|
|
|
|
if (isNPC) {
|
2024-12-21 14:23:22 -05:00
|
|
|
compound.setTag("TagUUIDs", tagsCompound);
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
ClientCloneController.Instance.addClone(compound, name, tab, extraTags);
|
|
|
|
|
} else {
|
2024-12-21 14:23:22 -05:00
|
|
|
NBTTagCompound compounder = new NBTTagCompound();
|
2025-03-13 17:14:45 -04:00
|
|
|
if (isNPC) {
|
2024-12-21 14:23:22 -05:00
|
|
|
compounder.setTag("TagUUIDs", tagsCompound);
|
|
|
|
|
}
|
2025-02-02 22:31:39 -05:00
|
|
|
PacketClient.sendClient(new CloneSavePacket(name, tab, extraTags, compounder));
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
2023-05-08 23:47:45 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
close();
|
|
|
|
|
} else
|
|
|
|
|
displayGuiScreen(this);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2023-04-08 18:03:05 -04:00
|
|
|
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
@Override
|
|
|
|
|
public void save() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setGuiData(NBTTagCompound compound) {
|
|
|
|
|
if (compound.hasKey("NameExists")) {
|
|
|
|
|
if (compound.getBoolean("NameExists"))
|
|
|
|
|
displayGuiScreen(new GuiYesNo(this, "Warning", "You are about to overwrite a clone", 1));
|
|
|
|
|
else
|
|
|
|
|
confirmClicked(true, 0);
|
|
|
|
|
} else if (compound.hasKey("ShortTags")) {
|
|
|
|
|
NBTTagList validTags = compound.getTagList("ShortTags", 10);
|
|
|
|
|
tagMap.clear();
|
|
|
|
|
allTags.clear();
|
2024-12-21 14:23:22 -05:00
|
|
|
addTagUUIDs.clear();
|
2025-03-13 17:14:45 -04:00
|
|
|
if (validTags != null) {
|
|
|
|
|
for (int j = 0; j < validTags.tagCount(); j++) {
|
|
|
|
|
NBTTagCompound tagStructure = validTags.getCompoundTagAt(j);
|
|
|
|
|
Tag tag = new Tag();
|
|
|
|
|
tag.readShortNBT(tagStructure);
|
|
|
|
|
tagMap.put(tag.name, tag.uuid);
|
2024-12-21 14:23:22 -05:00
|
|
|
addTagUUIDs.add(tag.uuid);
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
allTags.addAll(tagMap.keySet());
|
|
|
|
|
allTags.sort(String.CASE_INSENSITIVE_ORDER);
|
|
|
|
|
}
|
|
|
|
|
initGui();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void subGuiClosed(SubGuiInterface subgui) {
|
|
|
|
|
initGui();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound setTempTags() {
|
2024-12-21 14:23:22 -05:00
|
|
|
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
|
|
|
|
NBTTagList nbtTagList = new NBTTagList();
|
|
|
|
|
for (String name : addTags) {
|
|
|
|
|
if (tagMap.containsKey(name)) {
|
|
|
|
|
nbtTagList.appendTag(new NBTTagString(tagMap.get(name).toString()));
|
|
|
|
|
} else {
|
|
|
|
|
addTags.remove(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
nbtTagCompound.setTag("TempTagUUIDs", nbtTagList);
|
|
|
|
|
return nbtTagCompound;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|