mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 10:49:07 +00:00
Allow Tag Modifying through Cloner without Closing + Fix Removing All Tags Bug
This commit is contained in:
1 parent
810d2ca12c
commit
6a59dc91a0
5 files changed
+80
-45
No files matched your search
@@ -1299,6 +1299,10 @@ public class PacketHandlerServer{
|
||||
String name = Server.readString(buffer);
|
||||
int tab = buffer.readInt();
|
||||
NBTTagCompound tagExtra = Server.readNBT(buffer);
|
||||
NBTTagCompound tagCompound = Server.readNBT(buffer);
|
||||
|
||||
NBTTagList tagList = tagCompound.getTagList("TagUUIDs", 8);
|
||||
data.cloned.setTag("TagUUIDs", tagList);
|
||||
ServerCloneController.Instance.addClone(data.cloned, name, tab, tagExtra);
|
||||
}
|
||||
else if(type == EnumPacketServer.CloneRemove){
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.controllers.ServerCloneController;
|
||||
import noppes.npcs.controllers.ServerTagMapController;
|
||||
import noppes.npcs.controllers.data.TagMap;
|
||||
|
||||
import java.io.File;
|
||||
@@ -30,14 +31,17 @@ public class ClientCloneController extends ServerCloneController{
|
||||
tagUUIDs.add(UUID.fromString(nbtTagList.getStringTagAt(i)));
|
||||
}
|
||||
}
|
||||
if(tagUUIDs.size() > 0){
|
||||
TagMap tagMap = ClientTagMapController.Instance.getTagMap(tab);
|
||||
tagMap.putClone(name, tagUUIDs);
|
||||
ClientTagMapController.Instance.saveTagMap(tagMap);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
TagMap tagMap = ClientTagMapController.Instance.getTagMap(tab);
|
||||
if(!tagUUIDs.isEmpty()){
|
||||
tagMap.putClone(name, tagUUIDs);
|
||||
}
|
||||
else {
|
||||
tagMap.removeClone(name);
|
||||
}
|
||||
ClientTagMapController.Instance.saveTagMap(tagMap);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromTagMap(String name, int tab){
|
||||
|
||||
@@ -13,6 +13,7 @@ import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.controllers.ClientCloneController;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.controllers.TagController;
|
||||
import noppes.npcs.controllers.data.Tag;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
@@ -23,24 +24,28 @@ import java.util.UUID;
|
||||
|
||||
public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ISubGuiListener {
|
||||
|
||||
private Entity toClone;
|
||||
private NBTTagCompound compound;
|
||||
private Entity toClone;
|
||||
private NBTTagCompound compound;
|
||||
private static boolean serverSide = false;
|
||||
private static int tab = 1;
|
||||
public boolean isNPC = false;
|
||||
|
||||
// Selected Tags to Add
|
||||
public static NBTTagList tagsCompound;
|
||||
public static HashSet<String> addTags;
|
||||
public static ArrayList<String> allTags = new ArrayList<>();
|
||||
public static HashMap<String, UUID> tagMap = new HashMap<>();
|
||||
public static HashSet<UUID> addTagUUIDs;
|
||||
public static HashMap<String, UUID> tagMap = new HashMap<>();
|
||||
|
||||
public GuiNpcMobSpawnerAdd(NBTTagCompound compound){
|
||||
this.toClone = EntityList.createEntityFromNBT(compound, Minecraft.getMinecraft().theWorld);
|
||||
this.compound = compound;
|
||||
if(toClone instanceof EntityNPCInterface){
|
||||
isNPC = true;
|
||||
}
|
||||
tagsCompound = new NBTTagList();
|
||||
|
||||
if(toClone instanceof EntityNPCInterface){
|
||||
isNPC = true;
|
||||
tagsCompound = this.compound.getTagList("TagUUIDs",8);
|
||||
}
|
||||
setBackground("menubg.png");
|
||||
xSize = 256;
|
||||
ySize = 216;
|
||||
@@ -49,6 +54,9 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall
|
||||
if(addTags == null){
|
||||
addTags = new HashSet<>();
|
||||
}
|
||||
if(addTagUUIDs == null){
|
||||
addTagUUIDs = new HashSet<>();
|
||||
}
|
||||
if(isNPC){
|
||||
Client.sendData(EnumPacketServer.CloneAllTagsShort);
|
||||
}
|
||||
@@ -112,7 +120,7 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall
|
||||
}
|
||||
if (id == 5) {
|
||||
if(isNPC){
|
||||
this.setSubGui(new SubGuiClonerNPCTags((EntityNPCInterface) toClone));
|
||||
this.setSubGui(new SubGuiClonerNPCTags((EntityNPCInterface) toClone, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,14 +131,21 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall
|
||||
if(confirm){
|
||||
String name = getTextField(0).getText();
|
||||
NBTTagCompound extraTags = new NBTTagCompound();
|
||||
if(isNPC && addTags.size() > 0){
|
||||
if(isNPC){
|
||||
extraTags = setTempTags();
|
||||
}
|
||||
if(!serverSide){
|
||||
if(isNPC){
|
||||
compound.setTag("TagUUIDs", tagsCompound);
|
||||
}
|
||||
ClientCloneController.Instance.addClone(compound, name, tab, extraTags);
|
||||
}
|
||||
else{
|
||||
Client.sendData(EnumPacketServer.CloneSave, name, tab, extraTags);
|
||||
else {
|
||||
NBTTagCompound compounder = new NBTTagCompound();
|
||||
if(isNPC){
|
||||
compounder.setTag("TagUUIDs", tagsCompound);
|
||||
}
|
||||
Client.sendData(EnumPacketServer.CloneSave, name, tab, extraTags, compounder);
|
||||
}
|
||||
|
||||
close();
|
||||
@@ -141,9 +156,7 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall
|
||||
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
|
||||
}
|
||||
public void save() {}
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
@@ -157,6 +170,7 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall
|
||||
NBTTagList validTags = compound.getTagList("ShortTags", 10);
|
||||
tagMap.clear();
|
||||
allTags.clear();
|
||||
addTagUUIDs.clear();
|
||||
if(validTags != null){
|
||||
for(int j = 0; j < validTags.tagCount(); j++)
|
||||
{
|
||||
@@ -164,6 +178,7 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall
|
||||
Tag tag = new Tag();
|
||||
tag.readShortNBT(tagStructure);
|
||||
tagMap.put(tag.name, tag.uuid);
|
||||
addTagUUIDs.add(tag.uuid);
|
||||
}
|
||||
allTags.addAll(tagMap.keySet());
|
||||
allTags.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
@@ -174,27 +189,20 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if(subgui instanceof SubGuiClonerNPCTags){
|
||||
close();
|
||||
return;
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
|
||||
public NBTTagCompound setTempTags(){
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
nbtTagCompound.setTag("TempTagUUIDs", nbtTagList);
|
||||
|
||||
return nbtTagCompound;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
@@ -8,6 +9,8 @@ import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.controllers.TagController;
|
||||
import noppes.npcs.controllers.data.Tag;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -22,16 +25,19 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc
|
||||
private final ArrayList<String> tagNames = new ArrayList<>();
|
||||
private String search = "";
|
||||
private final EntityNPCInterface npc;
|
||||
private GuiNpcMobSpawnerAdd mobSpawnerAdd;
|
||||
|
||||
public SubGuiClonerNPCTags(EntityNPCInterface npc)
|
||||
public SubGuiClonerNPCTags(EntityNPCInterface npc, GuiNpcMobSpawnerAdd guiNpcMobSpawnerAdd)
|
||||
{
|
||||
this.parent = guiNpcMobSpawnerAdd;
|
||||
this.mobSpawnerAdd = guiNpcMobSpawnerAdd;
|
||||
Client.sendData(EnumPacketServer.TagsGet);
|
||||
Client.sendData(EnumPacketServer.NpcTagsGet);
|
||||
setBackground("menubg.png");
|
||||
xSize = 305;
|
||||
ySize = 220;
|
||||
this.npc = npc;
|
||||
closeOnEsc = false;
|
||||
closeOnEsc = true;
|
||||
}
|
||||
|
||||
public void initGui()
|
||||
@@ -86,12 +92,17 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc
|
||||
tagNames.clear();
|
||||
}
|
||||
if (guibutton.id == 66) {
|
||||
save();
|
||||
close();
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(){
|
||||
super.close();
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data)
|
||||
{
|
||||
@@ -126,9 +137,14 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc
|
||||
public void save() {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
NBTTagList UUIDTagList = new NBTTagList();
|
||||
for (String string : this.tagNames) {
|
||||
tagList.appendTag(new NBTTagString(string));
|
||||
if(GuiNpcMobSpawnerAdd.tagMap.containsKey(string))
|
||||
UUIDTagList.appendTag(new NBTTagString(GuiNpcMobSpawnerAdd.tagMap.get(string).toString()));
|
||||
}
|
||||
|
||||
GuiNpcMobSpawnerAdd.tagsCompound = UUIDTagList;
|
||||
tagCompound.setTag("TagNames",tagList);
|
||||
Client.sendData(EnumPacketServer.TagSet, tagCompound);
|
||||
}
|
||||
|
||||
@@ -223,13 +223,16 @@ public class ServerCloneController implements ICloneHandler {
|
||||
tagUUIDs.add(UUID.fromString(nbtTagList.getStringTagAt(i)));
|
||||
}
|
||||
}
|
||||
if(tagUUIDs.size() > 0){
|
||||
TagMap tagMap = ServerTagMapController.Instance.getTagMap(tab);
|
||||
|
||||
TagMap tagMap = ServerTagMapController.Instance.getTagMap(tab);
|
||||
if(!tagUUIDs.isEmpty()){
|
||||
tagMap.putClone(name, tagUUIDs);
|
||||
ServerTagMapController.Instance.saveTagMap(tagMap);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
else {
|
||||
tagMap.removeClone(name);
|
||||
}
|
||||
ServerTagMapController.Instance.saveTagMap(tagMap);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeFromTagMap(String name, int tab){
|
||||
|
||||
Reference in new issue
Block a user