Implemented tag filters

This commit is contained in:
Luis C.M committed 2023-03-21 03:16:52 -05:00
1 parent aba24fc93c
commit 0f619d710a
8 files changed
+259 -31

No files matched your search

@@ -6,6 +6,7 @@ import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
import cpw.mods.fml.relauncher.Side;
import foxz.utils.Market;
import io.netty.buffer.ByteBuf;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.passive.EntityVillager;
@@ -761,7 +762,7 @@ public class PacketHandlerServer{
Server.sendData(player, EnumPacketClient.GUI_DATA, compound);
}
else if(type == EnumPacketServer.TagSet){
npc.advanced.tagUUIDs.clear();
npc.advanced.tagUUIDs.removeIf(uuid -> TagController.getInstance().getTagFromUUID(uuid) != null);
NBTTagCompound compound = Server.readNBT(buffer);
NBTTagList list = compound.getTagList("TagNames",8);
for (int i = 0; i < list.tagCount(); i++) {
@@ -1074,6 +1075,33 @@ public class PacketHandlerServer{
Server.sendData(player, EnumPacketClient.GUI_DATA, compound);
}
else if (type == EnumPacketServer.CloneTagList) {
int tab = buffer.readInt();
List<String> cloneNames = ServerCloneController.Instance.getClones(tab);
NBTTagList cloneTags = new NBTTagList();
for (String name : cloneNames) {
NBTTagCompound compound = ServerCloneController.Instance.getCloneData(null, name, tab);
if (compound.hasKey("TagUUIDs")) {
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setString("Name",name);
NBTTagList uuidList = compound.getTagList("TagUUIDs",8);
NBTTagList tags = new NBTTagList();
for (int i = 0; i < uuidList.tagCount(); i++) {
String uuidString = uuidList.getStringTagAt(i);
NBTTagCompound tagNBT = new NBTTagCompound();
TagController.getInstance().getTagFromUUID(UUID.fromString(uuidString)).writeNBT(tagNBT);
tags.appendTag(tagNBT);
}
tagCompound.setTag("Tags",tags);
cloneTags.appendTag(tagCompound);
}
}
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("CloneTags", cloneTags);
Server.sendData(player, EnumPacketClient.GUI_DATA, compound);
}
else
warn(player,"tried todo something with the wrong tool, probably a hacker");
}
@@ -12,15 +12,19 @@ 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.data.Tag;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{
public class GuiNpcMobSpawner extends GuiNPCInterface implements IScrollData,IGuiData,ISubGuiListener {
public static HashSet<String> allTags = new HashSet<>();
public static HashSet<String> filter = new HashSet<>();
public static boolean showNoTags = true;
public HashMap<String,HashSet<Tag>> tags = new HashMap<>();
private GuiCustomScroll scroll;
private final GuiCustomScrollCloner scroll = new GuiCustomScrollCloner(this,0);
private int posX,posY,posZ;
private List<String> list;
@@ -41,6 +45,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{
this.closeOnEsc = true;
setBackground("menubg.png");
Client.sendData(EnumPacketServer.TagsGet);
}
public void initGui()
{
@@ -48,12 +53,8 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{
guiTop += 10;
guiLeft += 30;
if(scroll == null){
scroll = new GuiCustomScroll(this,0);
scroll.setSize(293, 188);
}
else
scroll.clear();
scroll.clear();
scroll.setSize(293, 188);
scroll.guiLeft = guiLeft + 4;
scroll.guiTop = guiTop + 26;
addScroll(scroll);
@@ -68,8 +69,10 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{
addTopButton(button = new GuiMenuTopButton(4, button, "spawner.entities"));
button.active = showingClones == 1;
addButton(new GuiNpcButton(1, guiLeft + 298, guiTop + 6, 52, 20, "item.monsterPlacer.name"));
addButton(new GuiNpcButton(7, guiLeft + 298, guiTop + 78, 52, 20, "gui.filters"));
addButton(new GuiNpcButton(2, guiLeft + 298, guiTop + 100, 52, 20, "spawner.mobspawner"));
if(showingClones == 0 || showingClones == 2){
@@ -120,6 +123,7 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{
scroll.setList(getSearchList());
}
private void showClones() {
Client.sendData(EnumPacketServer.CloneTagList, activeTab);
if(showingClones == 2){
Client.sendData(EnumPacketServer.CloneList, activeTab);
return;
@@ -227,12 +231,26 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{
initGui();
}
}
if (id == 7) {
setSubGui(new SubGuiNpcFilterTags());
}
if(id > 20){
activeTab = id - 20;
initGui();
}
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data)
{
allTags.addAll(list);
filter.addAll(allTags);
}
@Override
public void setSelected(String selected) {
}
@Override
public void save() {
// TODO Auto-generated method stub
@@ -240,13 +258,39 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData{
}
@Override
public void setGuiData(NBTTagCompound compound) {
NBTTagList nbtlist = compound.getTagList("List", 8);
List<String> list = new ArrayList<String>();
for(int i = 0; i < nbtlist.tagCount(); i++){
list.add(nbtlist.getStringTagAt(i));
if (compound.hasKey("CloneTags")) {
this.tags.clear();
NBTTagList cloneTags = compound.getTagList("CloneTags", 10);
for (int i = 0; i < cloneTags.tagCount(); i++) {
NBTTagCompound tagCompound = cloneTags.getCompoundTagAt(i);
String name = tagCompound.getString("Name");
HashSet<Tag> tagNames = new HashSet<>();
NBTTagList tagList = tagCompound.getTagList("Tags", 10);
for (int j = 0; j < tagList.tagCount(); j++) {
Tag tag = new Tag();
tag.readNBT(tagList.getCompoundTagAt(j));
tagNames.add(tag);
}
this.tags.put(name, tagNames);
}
} else {
NBTTagList nbtlist = compound.getTagList("List", 8);
List<String> list = new ArrayList<String>();
for(int i = 0; i < nbtlist.tagCount(); i++){
list.add(nbtlist.getStringTagAt(i));
}
this.list = list;
scroll.setList(getSearchList());
}
this.list = list;
scroll.setList(getSearchList());
}
@Override
public void subGuiClosed(SubGuiInterface subgui) {
SubGuiNpcFilterTags filterGui = (SubGuiNpcFilterTags) subgui;
filter = filterGui.filterScroll.getSelectedList();
showNoTags = filterGui.showNoTags;
initGui();
}
}
@@ -0,0 +1,67 @@
package noppes.npcs.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.SubGuiInterface;
import java.util.*;
public class SubGuiNpcFilterTags extends SubGuiInterface
{
ArrayList<String> allTags = new ArrayList<>();
HashSet<String> filter;
public GuiCustomScroll filterScroll;
public boolean showNoTags;
public SubGuiNpcFilterTags(){
setBackground("menubg.png");
xSize = 305;
ySize = 200;
closeOnEsc = true;
this.allTags.addAll(GuiNpcMobSpawner.allTags);
this.filter = GuiNpcMobSpawner.filter;
this.showNoTags = GuiNpcMobSpawner.showNoTags;
}
public void initGui(){
super.initGui();
if(filterScroll == null){
filterScroll = new GuiCustomScroll(this,0);
filterScroll.setSize(140, 180);
}
filterScroll.guiLeft = guiLeft + 4;
filterScroll.guiTop = guiTop + 14;
filterScroll.setList(this.allTags);
filterScroll.multipleSelection = true;
filterScroll.setSelectedList(this.filter);
this.addScroll(filterScroll);
addButton(new GuiNpcButton(10, guiLeft + 150, guiTop + 20, 120, 20, "gui.selectAll"));
addButton(new GuiNpcButton(11, guiLeft + 150, guiTop + 43, 120, 20, "gui.deselectAll"));
addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("tags.taglessEntries") + ":", guiLeft + 150, guiTop + 72));
addButton(new GuiNpcButton(12, guiLeft + 240, guiTop + 65, new String[]{"display.show", "display.hide"}, showNoTags ? 0 : 1));
getButton(12).width = 60;
getButton(12).height = 20;
addButton(new GuiNpcButton(66, guiLeft + 240, guiTop + 175, 60, 20, "gui.done"));
}
protected void actionPerformed(GuiButton guibutton){
if (guibutton.id == 10) {
HashSet<String> hashSet = new HashSet<>(this.allTags);
filterScroll.setSelectedList(hashSet);
}
if (guibutton.id == 11) {
filterScroll.setSelectedList(new HashSet<>());
}
if (guibutton.id == 12) {
showNoTags = !showNoTags;
}
if (guibutton.id == 66) {
close();
}
}
}
@@ -42,7 +42,7 @@ public class GuiNPCTagSetup extends GuiNPCInterface2 implements IScrollData,ICus
npcTags = new GuiCustomScroll(this,1);
npcTags.setSize(120, 180);
}
npcTags.guiLeft = guiLeft + width - 180;
npcTags.guiLeft = guiLeft + 250;
npcTags.guiTop = guiTop + 24;
npcTags.setList(tagNames);
this.addScroll(npcTags);
@@ -6,29 +6,27 @@ import net.minecraft.util.StatCollector;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.*;
public class GuiCustomScroll extends GuiScreen
{
public static final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/misc.png");
private List<String> list;
protected List<String> list;
public final HashMap<String,Integer> colors = new HashMap<>();
public int id;
public int guiLeft = 0;
public int guiTop = 0;
public int xSize, ySize;
public int selected;
private HashSet<String> selectedList;
private int hover;
protected HashSet<String> selectedList;
protected int hover;
private int listHeight;
private int scrollY;
private int maxScrollY;
private int scrollHeight;
protected int scrollY;
protected int maxScrollY;
protected int scrollHeight;
private boolean isScrolling;
private boolean multipleSelection = false;
public boolean multipleSelection = false;
private ICustomScrollListener listener;
private boolean isSorted = true;
public boolean visible = true;
@@ -0,0 +1,85 @@
package noppes.npcs.client.gui.util;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.gui.GuiNpcMobSpawner;
import noppes.npcs.controllers.data.Tag;
import java.util.HashSet;
public class GuiCustomScrollCloner extends GuiCustomScroll {
private final GuiNpcMobSpawner parent;
public GuiCustomScrollCloner(GuiNpcMobSpawner parent, int id) {
super(parent, id);
this.parent = parent;
}
protected void drawItems()
{
int l = 0;
for(int i = 0; i < list.size(); i++)
{
if (this.parent.tags.containsKey(list.get(i))) {
HashSet<Tag> tags = this.parent.tags.get(list.get(i));
boolean inFilter = false;
for (Tag tag : tags) {
if (GuiNpcMobSpawner.filter.contains(tag.name)) {
inFilter = true;
break;
}
}
if (!inFilter) {
continue;
}
} else if (!GuiNpcMobSpawner.showNoTags) {
continue;
}
int j = 4;
int k = (14 * l + 4) - scrollY;
l++;
if(k >= 4 && k + 12 < ySize)
{
int xOffset = scrollHeight < ySize - 8?0:10;
String displayString = StatCollector.translateToLocal(list.get(i));
String text = "";
float maxWidth = (xSize + xOffset - 8) * 0.8f;
if(fontRendererObj.getStringWidth(displayString) > maxWidth){
for(int h = 0; h < displayString.length(); h++){
char c = displayString.charAt(h);
text += c;
if(fontRendererObj.getStringWidth(text) > maxWidth)
break;
}
if(displayString.length() > text.length())
text += "...";
}
else
text = displayString;
if((multipleSelection && selectedList.contains(text)) || (!multipleSelection && selected == i)) {
drawVerticalLine(j-2, k-4, k + 10, 0xffffffff);
drawVerticalLine(j + xSize - 18 + xOffset, k - 4, k + 10, 0xffffffff);
drawHorizontalLine(j - 2, j + xSize - 18 + xOffset, k - 3 , 0xffffffff);
drawHorizontalLine(j - 2, j + xSize - 18 + xOffset, k + 10 , 0xffffffff);
fontRendererObj.drawString(text, j , k, this.colors.getOrDefault(text, 0xffffff));
} else if(i == hover) {
fontRendererObj.drawString(text, j, k, 0x00ff00);
} else {
fontRendererObj.drawString(text, j, k, this.colors.getOrDefault(text, 0xffffff));
}
int tagStartX = j + fontRendererObj.getStringWidth(displayString) + 5;
if (this.parent.tags.containsKey(list.get(i))) {
for (Tag tag : this.parent.tags.get(list.get(i))) {
if (!tag.getIsHidden()) {
fontRendererObj.drawString("[" + tag.name + "]", tagStartX, k, tag.color);
tagStartX += fontRendererObj.getStringWidth("[" + tag.name + "]") + 2;
}
}
}
}
}
}
}
@@ -33,7 +33,7 @@ public enum EnumPacketServer {
RoleCompanionUpdate(CustomNpcsPermissions.NPC_ADVANCED, true),
LinkedSet(CustomNpcsPermissions.NPC_ADVANCED, true),
ClonePreSave(CustomNpcsPermissions.NPC_CLONE), CloneSave(CustomNpcsPermissions.NPC_CLONE), CloneRemove(CustomNpcsPermissions.NPC_CLONE), CloneList,
ClonePreSave(CustomNpcsPermissions.NPC_CLONE), CloneSave(CustomNpcsPermissions.NPC_CLONE), CloneRemove(CustomNpcsPermissions.NPC_CLONE), CloneList, CloneTagList,
ScriptGlobalGuiDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false),
ScriptGlobalGuiDataGet(false),