From f0f83d19ba8c5490b3b11f51c52390ad1723c190 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 16 Nov 2023 15:08:25 -0500 Subject: [PATCH 01/25] Fix Memory Leak --- .../client/model/util/Model2DRenderer.java | 48 +++++++-------- .../client/model/util/ModelScaleRenderer.java | 60 +++++++++---------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java b/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java index 72c59888c..0cb4d163e 100644 --- a/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java +++ b/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java @@ -11,14 +11,14 @@ import org.lwjgl.opengl.GL11; public class Model2DRenderer extends ModelRenderer { - private boolean compiled; + private boolean compiledModel; + + private int displayListModel; - private int displayList; - private float x1, x2, y1, y2; private int width, height; private float rotationOffsetX, rotationOffsetY; - + private float scaleX = 1, scaleY = 1, thickness = 1; public Model2DRenderer(ModelBase par1ModelBase, float x, float y, int width, int height, float textureWidth, float textureHeight) { @@ -27,7 +27,7 @@ public class Model2DRenderer extends ModelRenderer { this.height = height; this.textureWidth = textureWidth; this.textureHeight = textureHeight; - + x1 = x / textureWidth; y1 = y / textureHeight; @@ -42,16 +42,16 @@ public class Model2DRenderer extends ModelRenderer { public void render(float par1) { if(!showModel || isHidden) return; - if(!compiled) - compileDisplayList(par1); - + if(!compiledModel) + compileDisplayListModel(par1); + GL11.glPushMatrix(); this.postRender(par1); - - GL11.glCallList(this.displayList); + + GL11.glCallList(this.displayListModel); GL11.glPopMatrix(); } - + public void setRotationOffset(float x, float y){ rotationOffsetX = x; rotationOffsetY = y; @@ -69,23 +69,23 @@ public class Model2DRenderer extends ModelRenderer { public void setThickness(float thickness) { this.thickness = thickness; } - @SideOnly(Side.CLIENT) - private void compileDisplayList(float par1) - { - this.displayList = GLAllocation.generateDisplayLists(1); - GL11.glNewList(this.displayList, GL11.GL_COMPILE); + @SideOnly(Side.CLIENT) + private void compileDisplayListModel(float par1) + { + this.displayListModel = GLAllocation.generateDisplayLists(1); + GL11.glNewList(this.displayListModel, GL11.GL_COMPILE); GL11.glScalef(scaleX * width / height, scaleY, thickness); - GL11.glRotatef(180, 1F, 0F, 0F); - if(mirror){ - GL11.glTranslatef(0, 0, -1f * par1); - GL11.glRotatef(180, 0, 1F, 0F); - } + GL11.glRotatef(180, 1F, 0F, 0F); + if(mirror){ + GL11.glTranslatef(0, 0, -1f * par1); + GL11.glRotatef(180, 0, 1F, 0F); + } GL11.glTranslated( rotationOffsetX * par1, rotationOffsetY * par1, 0); ItemRenderer.renderItemIn2D(Tessellator.instance, x1, y1, x2, y2, width, height, par1); - GL11.glEndList(); - this.compiled = true; - } + GL11.glEndList(); + this.compiledModel = true; + } } diff --git a/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java b/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java index 2e64ab9a5..586109151 100644 --- a/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java +++ b/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java @@ -10,51 +10,51 @@ import org.lwjgl.opengl.GL11; public class ModelScaleRenderer extends ModelRenderer { - public boolean compiled; + public boolean compiledModel; /** The GL display list rendered by the Tessellator for this model */ - public int displayList; - + public int displayListModel; + protected ModelScalePart config; - + public float x, y, z; - public ModelScaleRenderer(ModelBase par1ModelBase) { - super(par1ModelBase); - } + public ModelScaleRenderer(ModelBase par1ModelBase) { + super(par1ModelBase); + } public ModelScaleRenderer(ModelBase par1ModelBase, int par2, int par3) { this(par1ModelBase); this.setTextureOffset(par2, par3); } - + public void setConfig(ModelScalePart config, float x, float y, float z){ - this.config = config; - this.x = x; - this.y = y; - this.z = z; + this.config = config; + this.x = x; + this.y = y; + this.z = z; } - public void setRotation(ModelRenderer model, float x, float y, float z) { - model.rotateAngleX = x; - model.rotateAngleY = y; - model.rotateAngleZ = z; - } + public void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } public void render(float par1) { - if(!showModel || isHidden) - return; - if(!compiled) - compileDisplayList(par1); + if(!showModel || isHidden) + return; + if(!compiledModel) + compileDisplayListModel(par1); GL11.glPushMatrix(); GL11.glTranslatef(x, y, z); - if(config != null) - GL11.glTranslatef(0, 0, 0); + if(config != null) + GL11.glTranslatef(0, 0, 0); this.postRender(par1); - if(config != null) - GL11.glScalef(config.scaleX, config.scaleY, config.scaleZ); - GL11.glCallList(this.displayList); + if(config != null) + GL11.glScalef(config.scaleX, config.scaleY, config.scaleZ); + GL11.glCallList(this.displayListModel); if (this.childModels != null) { for (int i = 0; i < this.childModels.size(); ++i) @@ -65,10 +65,10 @@ public class ModelScaleRenderer extends ModelRenderer { GL11.glPopMatrix(); } - public void compileDisplayList(float par1) + public void compileDisplayListModel(float par1) { - this.displayList = GLAllocation.generateDisplayLists(1); - GL11.glNewList(this.displayList, GL11.GL_COMPILE); + this.displayListModel = GLAllocation.generateDisplayLists(1); + GL11.glNewList(this.displayListModel, GL11.GL_COMPILE); Tessellator tessellator = Tessellator.instance; for (int i = 0; i < this.cubeList.size(); ++i) @@ -77,7 +77,7 @@ public class ModelScaleRenderer extends ModelRenderer { } GL11.glEndList(); - this.compiled = true; + this.compiledModel = true; } } From 510c7283f48fc762cf8dc1253b042f29f9d59611 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 16 Nov 2023 15:17:52 -0500 Subject: [PATCH 02/25] Prevents Client from Opening Scripter if Client Side config is disabled --- src/main/java/noppes/npcs/client/ClientProxy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index dd2ddc950..fbdc87dfd 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -303,7 +303,7 @@ public class ClientProxy extends CommonProxy { else if (gui == EnumGuiType.PlayerTransporter) return new GuiTransportSelection(npc); - else if (gui == EnumGuiType.Script && ConfigScript.ScriptingEnabled) + else if (gui == EnumGuiType.Script) return new GuiScript(npc); else if (gui == EnumGuiType.ScriptItem) From f9486c66a2d836b9d09931ce1d77e078721cd9cb Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 16 Nov 2023 15:19:32 -0500 Subject: [PATCH 03/25] Hard disable --- src/main/java/noppes/npcs/controllers/ScriptController.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index bfdc56f45..bcd1c66d2 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -9,6 +9,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; +import noppes.npcs.config.ConfigScript; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.GlobalNPCDataScript; import noppes.npcs.controllers.data.PlayerDataScript; @@ -55,6 +56,8 @@ public class ScriptController { loaded = false; Instance = this; manager = new ScriptEngineManager(); + if(!ConfigScript.ScriptingEnabled) + return; LogWriter.info("Script Engines Available:"); ScriptEngine engine = manager.getEngineByName("nashorn"); From 03aa9c2e9ae15f4e10bdd47a911f5fd5a95f5542 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 20 Nov 2023 11:56:04 -0500 Subject: [PATCH 04/25] Fix Button Position --- .../gui/global/GuiNpcManageRecipes.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java index c0cc81241..3734bb5fd 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java @@ -46,27 +46,28 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS scroll.guiLeft = guiLeft + 172; scroll.guiTop = guiTop + 8; addScroll(scroll); - addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 172, guiTop + 8 + 3 + 180, 130, 20, search)); - - this.addButton(new GuiNpcButton(0,guiLeft + 306, guiTop + 10, 94, 30, "menu.global")); - this.addButton(new GuiNpcButton(1,guiLeft + 306, guiTop + 32, 94, 20, "tile.npcCarpentyBench.name")); - this.getButton(0).setEnabled(container.width == 4); - this.getButton(1).setEnabled(container.width == 3); - this.addButton(new GuiNpcButton(3,guiLeft + 306, guiTop + 60, 94, 20, "gui.add")); - this.addButton(new GuiNpcButton(4,guiLeft + 306, guiTop + 82, 94, 20, "gui.remove")); + this.addButton(new GuiNpcButton(0,guiLeft + 306, guiTop + 10, 84, 20, "menu.global")); + this.addButton(new GuiNpcButton(1,guiLeft + 306, guiTop + 32, 84, 20, "tile.npcCarpentyBench.name")); + this.getButton(0).setEnabled(container.width == 4); + this.getButton(1).setEnabled(container.width == 3); + + this.addButton(new GuiNpcButton(3,guiLeft + 306, guiTop + 60, 84, 20, "gui.add")); + this.addButton(new GuiNpcButton(4,guiLeft + 306, guiTop + 82, 84, 20, "gui.remove")); this.addLabel(new GuiNpcLabel(0, "gui.ignoreDamage", guiLeft + 86, guiTop + 32)); this.addButton(new GuiNpcButtonYesNo(5,guiLeft + 114, guiTop + 40, 50, 20, container.recipe.ignoreDamage)); this.addLabel(new GuiNpcLabel(1, "gui.ignoreNBT", guiLeft + 86, guiTop + 82)); this.addButton(new GuiNpcButtonYesNo(6,guiLeft + 114, guiTop + 90, 50, 20, container.recipe.ignoreNBT)); - - this.addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 8, guiTop + 8, 160, 20, container.recipe.name)); - this.getTextField(0).enabled = false; - this.getButton(5).setEnabled(false); - this.getButton(6).setEnabled(false); - } + + this.addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 8, guiTop + 8, 160, 20, container.recipe.name)); + this.getTextField(0).enabled = false; + this.getButton(5).setEnabled(false); + this.getButton(6).setEnabled(false); + + this.addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 172, guiTop + 8 + 3 + 180, 130, 20, search)); + } @Override protected void actionPerformed(GuiButton guibutton){ From 9df21358940e1622bb21e0782ce913ae2930bcb5 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 20 Nov 2023 16:48:33 -0500 Subject: [PATCH 05/25] Fix Recipe Duplication Glitch --- .../gui/global/GuiNpcManageRecipes.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java index 3734bb5fd..a44cca5f5 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java @@ -73,10 +73,16 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS protected void actionPerformed(GuiButton guibutton){ GuiNpcButton button = (GuiNpcButton) guibutton; if(button.id == 0){ + getTextField(55).setText(""); + search = ""; + scroll.clear(); save(); NoppesUtil.requestOpenGUI(EnumGuiType.ManageRecipes,3,0,0); } if(button.id == 1){ + getTextField(55).setText(""); + search = ""; + scroll.clear(); save(); NoppesUtil.requestOpenGUI(EnumGuiType.ManageRecipes,4,0,0); } @@ -193,14 +199,16 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS @Override public void unFocused(GuiNpcTextField guiNpcTextField) { - String name = guiNpcTextField.getText(); - if(!name.isEmpty() && !data.containsKey(name)){ - String old = container.recipe.name; - data.remove(container.recipe.name); - container.recipe.name = name; - data.put(container.recipe.name, container.recipe.id); - selected = name; - scroll.replace(old,container.recipe.name); + if(guiNpcTextField.id == 0){ + String name = guiNpcTextField.getText(); + if(!name.isEmpty() && !data.containsKey(name)){ + String old = container.recipe.name; + data.remove(container.recipe.name); + container.recipe.name = name; + data.put(container.recipe.name, container.recipe.id); + selected = name; + scroll.replace(old,container.recipe.name); + } } } } From debd00c1c27b3bb899689adfb11eb796608da899 Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 22 Nov 2023 17:12:30 -0500 Subject: [PATCH 06/25] updateEntity --- src/api | 2 +- src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api b/src/api index ffe67e93f..0a125ec5e 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit ffe67e93f10c98da09f0a05ff25d0c6202fe6b28 +Subproject commit 0a125ec5e21a23d05147683f4141ac91cc1251d4 diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index 42cfc3985..cdaa9c29c 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -915,4 +915,9 @@ public class ScriptEntity implements IEntity { public boolean equals(Object object) { return object instanceof IEntity && ((IEntity)object).getMCEntity().equals(this.entity); } + + public void updateEntity() { + IWorld world = NpcAPI.Instance().getIWorld(entity.worldObj); + entity.dimension = world.getDimensionID(); + } } \ No newline at end of file From 8f28e94dafa82180290df401cc70f0d10222f5e8 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 30 Nov 2023 02:52:01 -0500 Subject: [PATCH 07/25] Revert "Prevent Misuse Packets" This reverts commit 7ef509b71c27e5b5fdbc2b344233abc7c67c28f2. --- .../java/noppes/npcs/PacketHandlerPlayer.java | 63 ++++++++----------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/src/main/java/noppes/npcs/PacketHandlerPlayer.java b/src/main/java/noppes/npcs/PacketHandlerPlayer.java index c1f06dc7a..d4d1dea95 100644 --- a/src/main/java/noppes/npcs/PacketHandlerPlayer.java +++ b/src/main/java/noppes/npcs/PacketHandlerPlayer.java @@ -12,7 +12,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagString; import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.chunk.Chunk; import noppes.npcs.blocks.tiles.TileBigSign; import noppes.npcs.blocks.tiles.TileBook; import noppes.npcs.constants.*; @@ -274,46 +273,36 @@ public class PacketHandlerPlayer{ } else if(type == EnumPlayerPacket.SignSave){ int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt(); - Chunk chunk = new Chunk(player.worldObj,x,z); - if (chunk.isChunkLoaded) { - if (player.worldObj.blockExists(x,y,z)) { - TileEntity tile = player.worldObj.getTileEntity(x, y, z); - if (tile == null || !(tile instanceof TileBigSign)) - return; - TileBigSign sign = (TileBigSign) tile; - if (sign.canEdit) { - sign.setText(Server.readString(buffer)); - sign.canEdit = false; - player.worldObj.markBlockForUpdate(x, y, z); - } - } + TileEntity tile = player.worldObj.getTileEntity(x, y, z); + if(tile == null || !(tile instanceof TileBigSign)) + return; + TileBigSign sign = (TileBigSign) tile; + if(sign.canEdit){ + sign.setText(Server.readString(buffer)); + sign.canEdit = false; + player.worldObj.markBlockForUpdate(x, y, z); } } else if(type == EnumPlayerPacket.SaveBook){ int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt(); - Chunk chunk = new Chunk(player.worldObj,x,z); - if (chunk.isChunkLoaded) { - if (player.worldObj.blockExists(x,y,z)) { - TileEntity tileentity = player.worldObj.getTileEntity(x, y, z); - if (!(tileentity instanceof TileBook)) - return; - TileBook tile = (TileBook) tileentity; - if (tile.book.getItem() == Items.written_book) - return; - boolean sign = buffer.readBoolean(); - ItemStack book = ItemStack.loadItemStackFromNBT(Server.readNBT(buffer)); - if (book == null) - return; - if (book.getItem() == Items.writable_book && !sign && ItemWritableBook.func_150930_a(book.getTagCompound())) { - tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8)); - } - if (book.getItem() == Items.written_book && sign && ItemEditableBook.validBookTagContents(book.getTagCompound())) { - tile.book.setTagInfo("author", new NBTTagString(player.getCommandSenderName())); - tile.book.setTagInfo("title", new NBTTagString(book.getTagCompound().getString("title"))); - tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8)); - tile.book.func_150996_a(Items.written_book); - } - } + TileEntity tileentity = player.worldObj.getTileEntity(x, y, z); + if(!(tileentity instanceof TileBook)) + return; + TileBook tile = (TileBook) tileentity; + if(tile.book.getItem() == Items.written_book) + return; + boolean sign = buffer.readBoolean(); + ItemStack book = ItemStack.loadItemStackFromNBT(Server.readNBT(buffer)); + if(book == null) + return; + if(book.getItem() == Items.writable_book && !sign && ItemWritableBook.func_150930_a(book.getTagCompound())){ + tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8)); + } + if(book.getItem() == Items.written_book && sign && ItemEditableBook.validBookTagContents(book.getTagCompound())){ + tile.book.setTagInfo("author", new NBTTagString(player.getCommandSenderName())); + tile.book.setTagInfo("title", new NBTTagString(book.getTagCompound().getString("title"))); + tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8)); + tile.book.func_150996_a(Items.written_book); } } } From 156a976cddd208780229acf32c174fd70627065b Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 30 Nov 2023 15:29:35 -0600 Subject: [PATCH 08/25] Implemented get/setDialog functions for ICustomNpc. --- .../java/noppes/npcs/NoppesUtilServer.java | 9 ++++--- .../npcs/scripted/entity/ScriptNpc.java | 26 ++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 70751237b..f790873ed 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -672,17 +672,20 @@ public class NoppesUtilServer { } public static DialogOption setNpcDialog(int slot, int dialogId, EntityPlayer player) throws IOException { - EntityNPCInterface npc = getEditingNpc(player); + return setNpcDialog(slot, dialogId, getEditingNpc(player)); + } + + public static DialogOption setNpcDialog(int slot, int dialogId, EntityNPCInterface npc) { if(npc == null) return null; if(!npc.dialogs.containsKey(slot)) npc.dialogs.put(slot, new DialogOption()); - + DialogOption option = npc.dialogs.get(slot); option.dialogId = dialogId; if(option.hasDialog()) option.title = option.getDialog().title; - + return option; } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index a90216a0a..50814865e 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -10,6 +10,7 @@ import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.entity.data.IModelData; import noppes.npcs.api.handler.IOverlayHandler; import noppes.npcs.api.handler.data.IAnimationData; +import noppes.npcs.api.handler.data.IDialog; import noppes.npcs.api.handler.data.IFaction; import noppes.npcs.api.item.IItemStack; import noppes.npcs.api.jobs.IJob; @@ -17,6 +18,7 @@ import noppes.npcs.api.roles.IRole; import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.*; import noppes.npcs.controllers.FactionController; +import noppes.npcs.controllers.data.DialogOption; import noppes.npcs.controllers.data.Line; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -326,7 +328,29 @@ public class ScriptNpc extends ScriptLiving imp return; npc.say((EntityPlayer) player.getMCEntity(), new Line(message)); } - + + public IDialog getDialog(int slot) { + return NpcAPI.Instance().getDialogs().get(this.getDialogId(slot)); + } + + public int getDialogId(int slot) { + if (npc.dialogs.containsKey(slot)) { + DialogOption option = npc.dialogs.get(slot); + if (option.hasDialog()) { + return option.dialogId; + } + } + return -1; + } + + public void setDialog(int slot, IDialog dialog) { + this.setDialog(slot, dialog.getId()); + } + + public void setDialog(int slot, int dialogId) { + NoppesUtilServer.setNpcDialog(slot,dialogId, this.npc); + } + /** * Kill the npc, doesnt't despawn it */ From eed9dbb92eae3d13d8c766b23565a91f6223ac5f Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sun, 3 Dec 2023 20:48:37 -0600 Subject: [PATCH 09/25] Added line support for ICustomNpc --- src/main/java/noppes/npcs/DataAdvanced.java | 10 ++--- .../noppes/npcs/controllers/data/Line.java | 44 +++++++++++++++++-- .../noppes/npcs/controllers/data/Lines.java | 30 ++++++++++++- .../npcs/entity/EntityNPCInterface.java | 19 ++++---- .../npcs/scripted/entity/ScriptNpc.java | 21 +++++++++ 5 files changed, 104 insertions(+), 20 deletions(-) diff --git a/src/main/java/noppes/npcs/DataAdvanced.java b/src/main/java/noppes/npcs/DataAdvanced.java index 2db06c527..406889b8d 100644 --- a/src/main/java/noppes/npcs/DataAdvanced.java +++ b/src/main/java/noppes/npcs/DataAdvanced.java @@ -161,23 +161,23 @@ public class DataAdvanced { } public Line getInteractLine() { - return interactLines.getLine(!orderedLines); + return (Line) interactLines.getLine(!orderedLines); } public Line getAttackLine() { - return attackLines.getLine(!orderedLines); + return (Line) attackLines.getLine(!orderedLines); } public Line getKilledLine() { - return killedLines.getLine(!orderedLines); + return (Line) killedLines.getLine(!orderedLines); } public Line getKillLine() { - return killLines.getLine(!orderedLines); + return (Line) killLines.getLine(!orderedLines); } public Line getWorldLine() { - return worldLines.getLine(!orderedLines); + return (Line) worldLines.getLine(!orderedLines); } public void setRole(int i) { diff --git a/src/main/java/noppes/npcs/controllers/data/Line.java b/src/main/java/noppes/npcs/controllers/data/Line.java index e9f5904fb..7385516fc 100644 --- a/src/main/java/noppes/npcs/controllers/data/Line.java +++ b/src/main/java/noppes/npcs/controllers/data/Line.java @@ -2,9 +2,11 @@ package noppes.npcs.controllers.data; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import noppes.npcs.api.entity.IEntityLivingBase; +import noppes.npcs.api.handler.data.ILine; -public class Line { +public class Line implements ILine { public Line(){ @@ -17,21 +19,55 @@ public class Line { public String sound = ""; public boolean hideText = false; - public Line copy() { + public ILine copy() { Line line = new Line(text); line.sound = sound; line.hideText = hideText; return line; } - public Line formatTarget(EntityLivingBase entity) { + public ILine formatTarget(EntityLivingBase entity) { if(entity == null) return this; - Line line = copy(); + Line line = (Line) copy(); if(entity instanceof EntityPlayer) line.text = line.text.replace("@target", ((EntityPlayer) entity).getDisplayName()); else line.text = line.text.replace("@target", entity.getCommandSenderName()); return line; } + + public ILine formatTarget(IEntityLivingBase entityLivingBase) { + return this.formatTarget(entityLivingBase.getMCEntity()); + } + + @Override + public String getText() { + return this.text; + } + + @Override + public void setText(String text) { + this.text = text; + } + + @Override + public String getSound() { + return this.sound; + } + + @Override + public void setSound(String sound) { + this.sound = sound; + } + + @Override + public void hideText(boolean hide) { + this.hideText = hide; + } + + @Override + public boolean hideText() { + return this.hideText; + } } diff --git a/src/main/java/noppes/npcs/controllers/data/Lines.java b/src/main/java/noppes/npcs/controllers/data/Lines.java index b649b2cb4..c8ffeb6e0 100644 --- a/src/main/java/noppes/npcs/controllers/data/Lines.java +++ b/src/main/java/noppes/npcs/controllers/data/Lines.java @@ -2,13 +2,15 @@ package noppes.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.api.handler.data.ILine; +import noppes.npcs.api.handler.data.ILines; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Random; -public class Lines { +public class Lines implements ILines { private static final Random random = new Random(); private int lastLine = -1; @@ -49,7 +51,11 @@ public class Lines { lines = map; } - public Line getLine(boolean isRandom) { + public ILine createLine(String text) { + return new Line(text); + } + + public ILine getLine(boolean isRandom) { if(lines.isEmpty()) return null; if(isRandom){ @@ -66,7 +72,27 @@ public class Lines { } } + public ILine getLine(int lineIndex) { + return lines.get(lineIndex); + } + + public void setLine(int lineIndex, ILine line) { + lines.put(lineIndex, (Line) line); + } + + public void removeLine(int lineIndex) { + lines.remove(lineIndex); + } + + public void clear() { + lines.clear(); + } + public boolean isEmpty() { return lines.isEmpty(); } + + public Integer[] getKeys() { + return lines.keySet().toArray(new Integer[0]); + } } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 19475dfb2..f37f333c6 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -46,6 +46,7 @@ import noppes.npcs.ai.target.EntityAIClosestTarget; import noppes.npcs.ai.target.EntityAIOwnerHurtByTarget; import noppes.npcs.ai.target.EntityAIOwnerHurtTarget; import noppes.npcs.api.entity.ICustomNpc; +import noppes.npcs.api.handler.data.ILine; import noppes.npcs.api.item.IItemStack; import noppes.npcs.client.EntityUtil; import noppes.npcs.config.ConfigMain; @@ -914,28 +915,28 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti return chateventPlayer; } - public void saySurrounding(Line line) { - if (line == null || line.text == null || getFakePlayer() == null) + public void saySurrounding(ILine line) { + if (line == null || line.getText() == null || getFakePlayer() == null) return; - ServerChatEvent event = new ServerChatEvent(getFakePlayer(), line.text, new ChatComponentTranslation(line.text.replace("%", "%%"))); + ServerChatEvent event = new ServerChatEvent(getFakePlayer(), line.getText(), new ChatComponentTranslation(line.getText().replace("%", "%%"))); if (MinecraftForge.EVENT_BUS.post(event) || event.component == null){ return; } - line.text = event.component.getUnformattedText().replace("%%", "%"); + line.setText(event.component.getUnformattedText().replace("%%", "%")); List inRange = worldObj.getEntitiesWithinAABB( EntityPlayer.class, this.boundingBox.expand(20D, 20D, 20D)); for (EntityPlayer player : inRange) say(player, line); } - public void say(EntityPlayer player, Line line) { - if (line == null || !this.canSee(player) || line.text == null) + public void say(EntityPlayer player, ILine line) { + if (line == null || !this.canSee(player) || line.getText() == null) return; - if(!line.sound.isEmpty()){ - Server.sendData((EntityPlayerMP)player, EnumPacketClient.PLAY_SOUND, line.sound, (float)posX, (float)posY, (float)posZ); + if(!line.getSound().isEmpty()){ + Server.sendData((EntityPlayerMP)player, EnumPacketClient.PLAY_SOUND, line.getSound(), (float)posX, (float)posY, (float)posZ); } - Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHATBUBBLE, this.getEntityId(), line.text, !line.hideText); + Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHATBUBBLE, this.getEntityId(), line.getText(), !line.hideText()); } public boolean getAlwaysRenderNameTagForRender(){ return true; diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 50814865e..8fde773b6 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -12,6 +12,7 @@ import noppes.npcs.api.handler.IOverlayHandler; import noppes.npcs.api.handler.data.IAnimationData; import noppes.npcs.api.handler.data.IDialog; import noppes.npcs.api.handler.data.IFaction; +import noppes.npcs.api.handler.data.ILines; import noppes.npcs.api.item.IItemStack; import noppes.npcs.api.jobs.IJob; import noppes.npcs.api.roles.IRole; @@ -351,6 +352,26 @@ public class ScriptNpc extends ScriptLiving imp NoppesUtilServer.setNpcDialog(slot,dialogId, this.npc); } + public ILines getInteractLines() { + return this.npc.advanced.interactLines; + } + + public ILines getWorldLines() { + return this.npc.advanced.worldLines; + } + + public ILines getAttackLines() { + return this.npc.advanced.attackLines; + } + + public ILines getKilledLines() { + return this.npc.advanced.killedLines; + } + + public ILines getKillLines() { + return this.npc.advanced.killLines; + } + /** * Kill the npc, doesnt't despawn it */ From 7820ad171bc841d458ac001e34c0f7edd3401779 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sun, 3 Dec 2023 20:48:44 -0600 Subject: [PATCH 10/25] Added line support for ICustomNpc --- src/api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api b/src/api index 0a125ec5e..8c064246f 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 0a125ec5e21a23d05147683f4141ac91cc1251d4 +Subproject commit 8c064246f81db155b323ff6289bac1d6c2ad7fd5 From a67604e22dda21053ab6655f3e052b6f629b2d3b Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:32:09 -0600 Subject: [PATCH 11/25] Implemented animation caching --- .../java/noppes/npcs/PacketHandlerServer.java | 3 + .../npcs/client/ClientCacheHandler.java | 4 ++ .../npcs/client/PacketHandlerClient.java | 32 +++++++--- .../npcs/constants/EnumPacketServer.java | 2 +- .../npcs/controllers/AnimationController.java | 9 +-- .../controllers/PlayerDataController.java | 11 ++++ .../npcs/controllers/data/AnimationData.java | 62 ++++++++++++++++--- 7 files changed, 99 insertions(+), 24 deletions(-) diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 64b8b9c36..acb482d90 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -108,6 +108,9 @@ public class PacketHandlerServer{ } compound.setTag("TagNames",tagList); Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + } else if (type == EnumPacketServer.CacheAnimation) { + PlayerDataController.Instance.getPlayerData(player).animationData.cacheAnimation(buffer.readInt()); + return; } if(type.needsNpc && npc == null){ diff --git a/src/main/java/noppes/npcs/client/ClientCacheHandler.java b/src/main/java/noppes/npcs/client/ClientCacheHandler.java index 05e5b9aca..182065e83 100644 --- a/src/main/java/noppes/npcs/client/ClientCacheHandler.java +++ b/src/main/java/noppes/npcs/client/ClientCacheHandler.java @@ -1,6 +1,7 @@ package noppes.npcs.client; import net.minecraft.util.ResourceLocation; +import noppes.npcs.controllers.data.Animation; import noppes.npcs.controllers.data.AnimationData; import noppes.npcs.client.gui.OverlayQuestTracking; import noppes.npcs.client.gui.customoverlay.OverlayCustom; @@ -14,6 +15,8 @@ import java.util.UUID; public class ClientCacheHandler { private static final CacheHashMap> imageDataCache = new CacheHashMap<>((long) ConfigClient.CacheLife * 60 * 1000); + public static final HashMap animationCache = new HashMap<>(); + public static OverlayQuestTracking questTrackingOverlay = null; public static HashMap customOverlays = new HashMap<>(); public static HashMap> skinOverlays = new HashMap<>(); @@ -39,6 +42,7 @@ public class ClientCacheHandler { public static void clearCache() { ClientCacheHandler.imageDataCache.clear(); + ClientCacheHandler.animationCache.clear(); ClientCacheHandler.questTrackingOverlay = null; ClientCacheHandler.customOverlays.clear(); ClientCacheHandler.skinOverlays.clear(); diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 657b6d455..ae96b4fa6 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -30,6 +30,7 @@ import noppes.npcs.client.gui.util.*; import noppes.npcs.config.ConfigClient; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.constants.EnumPacketClient; +import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.RecipeController; import noppes.npcs.controllers.data.Animation; import noppes.npcs.controllers.data.AnimationData; @@ -299,24 +300,37 @@ public class PacketHandlerClient extends PacketHandlerServer{ } else if(type == EnumPacketClient.UPDATE_ANIMATIONS) { NBTTagCompound compound = Server.readNBT(buffer); + AnimationData animationData = null; if (compound.hasKey("EntityId")) { Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(compound.getInteger("EntityId")); if (entity instanceof EntityNPCInterface) { - AnimationData data = ((EntityNPCInterface) entity).display.animationData; - data.readFromNBT(compound); - data.animation = new Animation(); - data.animation.readFromNBT(compound.getCompoundTag("Animation")); + animationData = ((EntityNPCInterface) entity).display.animationData; } } else { EntityPlayer sendingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(Server.readString(buffer)); if (sendingPlayer != null) { - AnimationData data = new AnimationData(sendingPlayer); - data.readFromNBT(compound); - data.animation = new Animation(); - data.animation.readFromNBT(compound.getCompoundTag("Animation")); - ClientCacheHandler.playerAnimations.put(sendingPlayer.getUniqueID(), data); + ClientCacheHandler.playerAnimations.put(sendingPlayer.getUniqueID(), new AnimationData(sendingPlayer)); + animationData = ClientCacheHandler.playerAnimations.get(sendingPlayer.getUniqueID()); } } + + if (animationData != null) { + animationData.readFromNBT(compound); + int animationId; + if (compound.hasKey("AnimationID")) { + animationId = compound.getInteger("AnimationID"); + } else { + Animation animation = new Animation(); + animation.readFromNBT(compound.getCompoundTag("Animation")); + ClientCacheHandler.animationCache.put(animation.getID(), animation); + animationId = animation.getID(); + } + + Animation animation = new Animation(); + animation.readFromNBT(ClientCacheHandler.animationCache.get(animationId).writeToNBT()); + animationData.animation = animation; + Client.sendData(EnumPacketServer.CacheAnimation, animationId); + } } else if(type == EnumPacketClient.DISABLE_MOUSE_INPUT) { long length = buffer.readLong(); diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index f3569c1d2..89836ae0d 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -91,7 +91,7 @@ public enum EnumPacketServer { RemoteTpToNpc,QuestGet, QuestCategoryGet, SaveTileEntity, NaturalSpawnGetAll, MailOpenSetup, - DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen, + DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen, CacheAnimation, CustomGuiButton,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused, diff --git a/src/main/java/noppes/npcs/controllers/AnimationController.java b/src/main/java/noppes/npcs/controllers/AnimationController.java index 685c94ec6..3b28eb35e 100644 --- a/src/main/java/noppes/npcs/controllers/AnimationController.java +++ b/src/main/java/noppes/npcs/controllers/AnimationController.java @@ -3,15 +3,12 @@ package noppes.npcs.controllers; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; import noppes.npcs.api.handler.IAnimationHandler; import noppes.npcs.api.handler.data.IAnimation; -import noppes.npcs.api.handler.data.IFaction; import noppes.npcs.controllers.data.Animation; -import noppes.npcs.controllers.data.Faction; -import noppes.npcs.controllers.data.TagMap; +import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.util.NBTJsonUtil; import java.io.*; @@ -120,6 +117,10 @@ public class AnimationController implements IAnimationHandler { animations.remove(animation.getID()); animations.put(animation.getID(), (Animation) animation); + for (PlayerData playerData : PlayerDataController.Instance.getAllPlayerData()) { + playerData.animationData.uncacheAnimation(animation.getID()); + } + saveAnimationMap(); // Save Animation File diff --git a/src/main/java/noppes/npcs/controllers/PlayerDataController.java b/src/main/java/noppes/npcs/controllers/PlayerDataController.java index b43a33e91..fcdd7e2e7 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerDataController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerDataController.java @@ -281,6 +281,17 @@ public class PlayerDataController { return data; } + public ArrayList getAllPlayerData() { + ArrayList playerDataList = new ArrayList<>(); + List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList; + for (Object o : list) { + if (o instanceof EntityPlayer) { + playerDataList.add(this.getPlayerData((EntityPlayer)o)); + } + } + return playerDataList; + } + public PlayerData getPlayerData(EntityPlayer player){ PlayerData data = getPlayerDataCache(player.getUniqueID().toString()); if(data != null){ diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index ec0f32753..b4110fd1b 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -1,17 +1,22 @@ package noppes.npcs.controllers.data; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.AxisAlignedBB; import noppes.npcs.DataDisplay; import noppes.npcs.Server; import noppes.npcs.api.handler.data.IAnimationData; import noppes.npcs.api.handler.data.IAnimation; import noppes.npcs.constants.EnumPacketClient; -import noppes.npcs.controllers.data.Animation; -import noppes.npcs.controllers.data.PlayerData; +import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.entity.EntityNPCInterface; +import java.util.HashSet; +import java.util.List; + public class AnimationData implements IAnimationData { //Server-side: DataDisplay, PlayerData //Client-side: DataDisplay, EntityPlayer @@ -20,19 +25,29 @@ public class AnimationData implements IAnimationData { public Animation animation; public boolean allowAnimation = false; + private final HashSet cachedAnimationIDs = new HashSet<>(); + public AnimationData(Object parent){ this.parent = parent; } public void updateClient() { - NBTTagCompound compound = new NBTTagCompound(); - compound = this.writeToNBT(compound); - compound.setTag("Animation",this.animation == null ? new NBTTagCompound() : this.animation.writeToNBT()); - if (parent instanceof PlayerData) { - Server.sendToAll(EnumPacketClient.UPDATE_ANIMATIONS, compound, ((PlayerData) parent).player.getCommandSenderName()); - } else if (parent instanceof DataDisplay) { - compound.setInteger("EntityId",((DataDisplay) parent).npc.getEntityId()); - Server.sendAssociatedData(((DataDisplay) parent).npc, EnumPacketClient.UPDATE_ANIMATIONS, compound); + EntityLivingBase sendingEntity = parent instanceof PlayerData ? ((PlayerData) parent).player : parent instanceof DataDisplay ? ((DataDisplay) parent).npc : null; + float range = parent instanceof PlayerData ? 160 : 60; + if (sendingEntity != null) { + + List entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox( + sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range, + sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range)); + + NBTTagCompound animationNBT = null; + for (EntityPlayer player : entities) { + AnimationData animationData = PlayerDataController.Instance.getPlayerData(player).animationData; + if (animationNBT == null && this.animation != null && !animationData.isCached(this.animation.getID())) { + animationNBT = this.animation.writeToNBT(); + } + animationData.viewAnimation(this.animation, sendingEntity, this, animationNBT); + } } } @@ -62,6 +77,33 @@ public class AnimationData implements IAnimationData { } } + public boolean isCached(int id) { + return this.cachedAnimationIDs.contains(id); + } + + public void cacheAnimation(int id) { + this.cachedAnimationIDs.add(id); + } + + public void uncacheAnimation(int id) { + this.cachedAnimationIDs.remove(id); + } + + public void viewAnimation(Animation animation, EntityLivingBase entity, AnimationData animationData, NBTTagCompound animationNBT) { + NBTTagCompound data = animationData.writeToNBT(new NBTTagCompound()); + if (animation != null) { + if (this.cachedAnimationIDs.contains(animation.getID())) { + data.setInteger("AnimationID", animation.getID()); + } else { + data.setTag("Animation", animationNBT); + } + } + if (!(entity instanceof EntityPlayer)) { + data.setInteger("EntityId", entity.getEntityId()); + } + Server.sendData((EntityPlayerMP) ((PlayerData) parent).player, EnumPacketClient.UPDATE_ANIMATIONS, data, entity.getCommandSenderName()); + } + public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setBoolean("AllowAnimation", allowAnimation); return compound; From bc089a4e141bc719544f29cd4c0331c82e817b81 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Fri, 22 Dec 2023 17:25:40 -0600 Subject: [PATCH 12/25] If the animation data is disabled for players, their last frame of animation will gradually interpolate back to the player's vanilla animations. --- .../npcs/client/PacketHandlerClient.java | 15 +++++--- .../npcs/controllers/data/Animation.java | 9 ++++- .../npcs/controllers/data/AnimationData.java | 26 ++++++++++++-- .../noppes/npcs/mixin/MixinModelRenderer.java | 36 ++++++++++++++----- 4 files changed, 69 insertions(+), 17 deletions(-) diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index ae96b4fa6..61a4ba4c3 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -309,7 +309,9 @@ public class PacketHandlerClient extends PacketHandlerServer{ } else { EntityPlayer sendingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(Server.readString(buffer)); if (sendingPlayer != null) { - ClientCacheHandler.playerAnimations.put(sendingPlayer.getUniqueID(), new AnimationData(sendingPlayer)); + if (!ClientCacheHandler.playerAnimations.containsKey(sendingPlayer.getUniqueID())) { + ClientCacheHandler.playerAnimations.put(sendingPlayer.getUniqueID(), new AnimationData(sendingPlayer)); + } animationData = ClientCacheHandler.playerAnimations.get(sendingPlayer.getUniqueID()); } } @@ -326,10 +328,13 @@ public class PacketHandlerClient extends PacketHandlerServer{ animationId = animation.getID(); } - Animation animation = new Animation(); - animation.readFromNBT(ClientCacheHandler.animationCache.get(animationId).writeToNBT()); - animationData.animation = animation; - Client.sendData(EnumPacketServer.CacheAnimation, animationId); + if (animationData.allowAnimation) { + Animation animation = new Animation(); + animation.readFromNBT(ClientCacheHandler.animationCache.get(animationId).writeToNBT()); + animationData.animation = animation; + animation.parent = animationData; + Client.sendData(EnumPacketServer.CacheAnimation, animationId); + } } } else if(type == EnumPacketClient.DISABLE_MOUSE_INPUT) { diff --git a/src/main/java/noppes/npcs/controllers/data/Animation.java b/src/main/java/noppes/npcs/controllers/data/Animation.java index 0950ee42d..be4e6262c 100644 --- a/src/main/java/noppes/npcs/controllers/data/Animation.java +++ b/src/main/java/noppes/npcs/controllers/data/Animation.java @@ -2,6 +2,7 @@ package noppes.npcs.controllers.data; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.api.handler.data.IAnimation; @@ -13,7 +14,7 @@ import java.util.ArrayList; public class Animation implements IAnimation { - + public AnimationData parent; //Client-sided only public int id = -1; // Only for internal usage public ArrayList frames = new ArrayList<>(); @@ -229,6 +230,10 @@ public class Animation implements IAnimation { if (paused) return; + if (this.parent != null && this.currentFrame < this.frames.size()) { + this.parent.finishedFrame = this.currentFrame; + } + this.currentFrameTime++; if (this.currentFrameTime == this.currentFrame().getDuration()) { Frame prevFrame = (Frame) this.currentFrame(); @@ -247,6 +252,8 @@ public class Animation implements IAnimation { nextFrame.frameParts.get(part).prevPivots = prevFrame.frameParts.get(part).prevPivots; } } + } else if (this.parent != null && this.currentFrame > this.loop) { + this.parent.finishedTime = this.parent.animationEntity.getAge(); } } } diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index b4110fd1b..72d08ff16 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -14,6 +14,7 @@ import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.entity.EntityNPCInterface; +import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -27,11 +28,25 @@ public class AnimationData implements IAnimationData { private final HashSet cachedAnimationIDs = new HashSet<>(); + //Client-side values + public EntityLivingBase animationEntity; + public int finishedTime = -1; + public int finishedFrame = -1; + public AnimationData(Object parent){ this.parent = parent; + if (parent instanceof DataDisplay) { + this.animationEntity = ((DataDisplay) parent).npc; + } else if (parent instanceof EntityPlayer) { + this.animationEntity = (EntityLivingBase) parent; + } } public void updateClient() { + this.updateClient(new EntityPlayer[0]); + } + + public void updateClient(EntityPlayer... excludedPlayers) { EntityLivingBase sendingEntity = parent instanceof PlayerData ? ((PlayerData) parent).player : parent instanceof DataDisplay ? ((DataDisplay) parent).npc : null; float range = parent instanceof PlayerData ? 160 : 60; if (sendingEntity != null) { @@ -40,6 +55,8 @@ public class AnimationData implements IAnimationData { sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range, sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range)); + entities.removeIf(player -> Arrays.stream(excludedPlayers).anyMatch(exp -> player == exp)); + NBTTagCompound animationNBT = null; for (EntityPlayer player : entities) { AnimationData animationData = PlayerDataController.Instance.getPlayerData(player).animationData; @@ -110,11 +127,16 @@ public class AnimationData implements IAnimationData { } public void readFromNBT(NBTTagCompound compound) { - this.allowAnimation = compound.getBoolean("AllowAnimation"); + this.setEnabled(compound.getBoolean("AllowAnimation")); } public void setEnabled(boolean enabled) { - this.allowAnimation = enabled; + if (this.allowAnimation != enabled) { + this.allowAnimation = enabled; + if (this.parent instanceof EntityPlayer) { + this.finishedTime = enabled ? -1 : ((EntityPlayer) this.parent).getAge(); + } + } } public boolean enabled() { diff --git a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java index 41accf7fa..ff9e21cf1 100644 --- a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java @@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.model.ModelRenderer; +import noppes.npcs.controllers.data.Animation; import noppes.npcs.controllers.data.AnimationData; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.ClientEventHandler; @@ -123,7 +124,9 @@ public abstract class MixinModelRenderer { } catch (Exception ignored){} - if (partType != null && animData != null) { + if (partType != null && animData != null && animData.animation != null) { + boolean animDataActive = animData.isActive(); + if (!ClientEventHandler.originalValues.containsKey((ModelRenderer) (Object) this)) { FramePart part = new FramePart(); part.pivot = new float[]{prevPointX, prevPointY, prevPointZ}; @@ -131,23 +134,38 @@ public abstract class MixinModelRenderer { ClientEventHandler.originalValues.put((ModelRenderer) (Object) this, part); } FramePart originalPart = ClientEventHandler.originalValues.get((ModelRenderer) (Object) this); - if (animData.isActive()) { - Frame frame = (Frame) animData.animation.currentFrame(); - if (frame.frameParts.containsKey(partType)) { - FramePart part = frame.frameParts.get(partType); - if (partType == mainPartType) { + Frame frame = (Frame) animData.animation.currentFrame(); + if (!animDataActive && animData.finishedFrame >= 0 && animData.finishedFrame < animData.animation.frames.size()) { + frame = animData.animation.frames.get(animData.finishedFrame); + } + + if (frame != null && frame.frameParts.containsKey(partType)) { + FramePart part = frame.frameParts.get(partType); + if (partType == mainPartType) { + if (animDataActive) { part.interpolateAngles(); part.interpolateOffset(); + } else { + float speed = 0.4F; + part.prevPivots[0] = part.prevPivots[0] * (1.0F - speed); + part.prevPivots[1] = part.prevPivots[1] * (1.0F - speed); + part.prevPivots[2] = part.prevPivots[2] * (1.0F - speed); + part.prevRotations[0] = part.prevRotations[0] * (1.0F - speed) + (this.rotateAngleX * speed); + part.prevRotations[1] = part.prevRotations[1] * (1.0F - speed) + (this.rotateAngleY * speed); + part.prevRotations[2] = part.prevRotations[2] * (1.0F - speed) + (this.rotateAngleZ * speed); + } + + if (animDataActive || (ClientEventHandler.renderingPlayer.getAge() - animData.finishedTime < 20)) { this.rotationPointX = originalPart.pivot[0] + part.prevPivots[0]; this.rotationPointY = originalPart.pivot[1] + part.prevPivots[1]; this.rotationPointZ = originalPart.pivot[2] + part.prevPivots[2]; this.rotateAngleX = part.prevRotations[0]; this.rotateAngleY = part.prevRotations[1]; this.rotateAngleZ = part.prevRotations[2]; - } else { - currentPart = part; - this.rotateAngleZ += part.prevRotations[2]; } + } else { + currentPart = part; + this.rotateAngleZ += part.prevRotations[2]; } } } From 782f21f1feefd9031561777bd24476363bc2eef1 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sat, 23 Dec 2023 18:33:16 -0600 Subject: [PATCH 13/25] Changed animations to flow into each other more smoothly. --- .../npcs/client/PacketHandlerClient.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 61a4ba4c3..d7a0c6365 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -28,18 +28,18 @@ import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.player.GuiBook; import noppes.npcs.client.gui.util.*; import noppes.npcs.config.ConfigClient; +import noppes.npcs.constants.EnumAnimationPart; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.RecipeController; -import noppes.npcs.controllers.data.Animation; -import noppes.npcs.controllers.data.AnimationData; -import noppes.npcs.controllers.data.RecipeCarpentry; +import noppes.npcs.controllers.data.*; import noppes.npcs.entity.EntityDialogNpc; import noppes.npcs.entity.EntityNPCInterface; import java.io.IOException; import java.util.HashMap; +import java.util.Map; public class PacketHandlerClient extends PacketHandlerServer{ @@ -331,6 +331,22 @@ public class PacketHandlerClient extends PacketHandlerServer{ if (animationData.allowAnimation) { Animation animation = new Animation(); animation.readFromNBT(ClientCacheHandler.animationCache.get(animationId).writeToNBT()); + if (animationData.animation != null && animation.frames.size() > 0) { + Frame frame = (Frame) animationData.animation.currentFrame(); + if (frame != null) { + Frame firstFrame = animation.frames.get(0); + for (Map.Entry entry : frame.frameParts.entrySet()) { + if (firstFrame.frameParts.containsKey(entry.getKey())) { + FramePart prevFramePart = entry.getValue(); + FramePart newFramePart = firstFrame.frameParts.get(entry.getKey()); + for (int i = 0; i < 3; i++) { + newFramePart.prevPivots[i] = prevFramePart.prevPivots[i]; + newFramePart.prevRotations[i] = prevFramePart.prevRotations[i]; + } + } + } + } + } animationData.animation = animation; animation.parent = animationData; Client.sendData(EnumPacketServer.CacheAnimation, animationId); From 24d12e25a9be44e5246da800b8af194cf9c6ce3b Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 31 Dec 2023 16:10:38 -0500 Subject: [PATCH 14/25] Fix IProjectile Events Thank you @somehussar --- build.gradle | 2 +- src/api | 2 +- src/main/java/noppes/npcs/EventHooks.java | 16 +++++++++ .../noppes/npcs/entity/EntityProjectile.java | 4 ++- .../scripted/entity/ScriptProjectile.java | 4 +++ .../npcs/scripted/event/ProjectileEvent.java | 35 +++++++++++++++++-- 6 files changed, 57 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 16d8b0e56..a1879f7de 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ configurations { apply plugin: 'forge' -version = "1.9-beta3" +version = "1.9-beta3.2" group= "com.kamkeel.customnpc-plus" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "CustomNPC-Plus" diff --git a/src/api b/src/api index 8c064246f..fd31facd1 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 8c064246f81db155b323ff6289bac1d6c2ad7fd5 +Subproject commit fd31facd1260abe590cffe48fe3fd41c18f03f02 diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 0f590bb3a..ea784ccd4 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -262,6 +262,14 @@ public class EventHooks { script.run(EnumScriptType.PROJECTILE_TICK, event); } } + + EntityLivingBase thrower = projectile.getThrower(); + if(thrower != null){ + if(thrower instanceof EntityNPCInterface){ + ((EntityNPCInterface) thrower).script.callScript(EnumScriptType.PROJECTILE_TICK, event); + } + } + NpcAPI.EVENT_BUS.post(event); } @@ -272,6 +280,14 @@ public class EventHooks { script.run(EnumScriptType.PROJECTILE_IMPACT, event); } } + + EntityLivingBase thrower = projectile.getThrower(); + if(thrower != null){ + if(thrower instanceof EntityNPCInterface){ + ((EntityNPCInterface) thrower).script.callScript(EnumScriptType.PROJECTILE_IMPACT, event); + } + } + NpcAPI.EVENT_BUS.post(event); } diff --git a/src/main/java/noppes/npcs/entity/EntityProjectile.java b/src/main/java/noppes/npcs/entity/EntityProjectile.java index bd50a1aaa..f97c908bd 100644 --- a/src/main/java/noppes/npcs/entity/EntityProjectile.java +++ b/src/main/java/noppes/npcs/entity/EntityProjectile.java @@ -29,6 +29,7 @@ import noppes.npcs.DataStats; import noppes.npcs.EventHooks; import noppes.npcs.api.IPos; import noppes.npcs.api.IWorld; +import noppes.npcs.api.entity.IEntity; import noppes.npcs.api.entity.IProjectile; import noppes.npcs.constants.EnumParticleType; import noppes.npcs.constants.EnumPotionType; @@ -449,7 +450,8 @@ public class EntityProjectile extends EntityThrowable { if (!this.worldObj.isRemote) { ProjectileEvent.ImpactEvent event; if (movingobjectposition.entityHit != null) { - event = new ProjectileEvent.ImpactEvent((IProjectile) NpcAPI.Instance().getIEntity(this), 0, movingobjectposition.entityHit); + IEntity target = NpcAPI.Instance().getIEntity(movingobjectposition.entityHit); + event = new ProjectileEvent.ImpactEvent((IProjectile) NpcAPI.Instance().getIEntity(this), 0, target); } else { IPos pos = NpcAPI.Instance().getIPos(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ); IWorld world = NpcAPI.Instance().getIWorld(this.worldObj); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java b/src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java index e22bdb8f4..b6b32db12 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptProjectile.java @@ -79,6 +79,10 @@ public class ScriptProjectile extends ScriptEntity Date: Mon, 8 Jan 2024 00:15:19 -0600 Subject: [PATCH 15/25] Small fix to animations: still running when using render ticks when the game is paused --- src/main/java/noppes/npcs/client/ClientEventHandler.java | 2 +- src/main/java/noppes/npcs/mixin/MixinModelRenderer.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index 0307b5236..06e24ee67 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -108,7 +108,7 @@ public class ClientEventHandler { ClientEventHandler.playerModel = null; } - if (data != null && data.isActive()) { + if (data != null && data.isActive() && !Minecraft.getMinecraft().isGamePaused()) { Animation animation = data.animation; if (data.isActive() && animation.currentFrame().useRenderTicks()) { animation.increaseTime(); diff --git a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java index ff9e21cf1..9df021671 100644 --- a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java @@ -155,7 +155,7 @@ public abstract class MixinModelRenderer { part.prevRotations[2] = part.prevRotations[2] * (1.0F - speed) + (this.rotateAngleZ * speed); } - if (animDataActive || (ClientEventHandler.renderingPlayer.getAge() - animData.finishedTime < 20)) { + if (animDataActive || (partType != EnumAnimationPart.HEAD && ClientEventHandler.renderingPlayer.getAge() - animData.finishedTime < 20)) { this.rotationPointX = originalPart.pivot[0] + part.prevPivots[0]; this.rotationPointY = originalPart.pivot[1] + part.prevPivots[1]; this.rotationPointZ = originalPart.pivot[2] + part.prevPivots[2]; From ba30c6e09494a9501e5192dbaa4a9e506ad15d08 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Mon, 8 Jan 2024 00:16:44 -0600 Subject: [PATCH 16/25] Added right-hand side buttons and item images to side buttons. Added rhs side buttons to the quest gui. used to go into the party menu --- .../npcs/client/gui/player/GuiParty.java | 78 +++++++++++++++++++ .../npcs/client/gui/player/GuiQuestLog.java | 19 +++++ .../client/gui/util/GuiMenuSideButton.java | 46 +++++++++-- .../npcs/constants/EnumPacketServer.java | 2 + 4 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/player/GuiParty.java diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/GuiParty.java new file mode 100644 index 000000000..582bfd294 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/player/GuiParty.java @@ -0,0 +1,78 @@ +package noppes.npcs.client.gui.player; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.util.*; +import org.lwjgl.opengl.GL11; +import tconstruct.client.tabs.InventoryTabQuests; +import tconstruct.client.tabs.TabRegistry; + +public class GuiParty extends GuiNPCInterface implements IGuiData { + private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); + private final EntityPlayer player; + + public GuiParty(EntityPlayer player) { + super(); + this.player = player; + xSize = 280; + ySize = 180; + drawDefaultBackground = false; + } + + public void initGui(){ + super.initGui(); + + TabRegistry.addTabsToList(buttonList); + TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabQuests.class); + } + + @Override + protected void actionPerformed(GuiButton guibutton){ + initGui(); + } + + @Override + public void drawScreen(int i, int j, float f){ + drawDefaultBackground(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + mc.renderEngine.bindTexture(resource); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, 252, 195); + drawTexturedModalRect(guiLeft + 252, guiTop, 188, 0, 67, 195); + super.drawScreen(i, j, f); + } + + @Override + public void keyTyped(char c, int i) + { + if (i == 1 || i == mc.gameSettings.keyBindInventory.getKeyCode()) // inventory key + { + mc.displayGuiScreen(null); + mc.setIngameFocus(); + } + } + + @Override + public boolean doesGuiPauseGame() + { + return false; + } + + @Override + public void setGuiData(NBTTagCompound compound) { + initGui(); + } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + this.save(); + } + + @Override + public void save() { + + } + +} diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java b/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java index f95aec81e..61dec025f 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java @@ -2,10 +2,14 @@ package noppes.npcs.client.gui.player; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; +import noppes.npcs.CustomItems; import noppes.npcs.NBTTags; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.QuestLogData; @@ -19,6 +23,7 @@ import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.util.ValueUtil; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; import tconstruct.client.tabs.InventoryTabQuests; import tconstruct.client.tabs.TabRegistry; @@ -36,6 +41,9 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I private boolean noQuests = false; private boolean questDetails = true; + private GuiMenuSideButton questsButton; + private GuiMenuSideButton partyButton; + private HashMap questAlertsOnOpen; private String trackedQuestKeyOnOpen; @@ -79,6 +87,17 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I } sideButtons.get(categories.indexOf(data.selectedCategory)).active = true; + this.questsButton = new GuiMenuSideButton(100,guiLeft + xSize + 37, this.guiTop + 3, 22, 22, ""); + this.questsButton.rightSided = true; + this.questsButton.active = true; + this.questsButton.renderStack = new ItemStack(CustomItems.letter); + addButton(this.questsButton); + + this.partyButton = new GuiMenuSideButton(101,guiLeft + xSize + 37, this.guiTop + 3 + 21, 22, 22, ""); + this.partyButton.rightSided = true; + this.partyButton.renderStack = new ItemStack(CustomItems.bag); + addButton(this.partyButton); + if(scroll == null) scroll = new GuiCustomScroll(this,0); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiMenuSideButton.java b/src/main/java/noppes/npcs/client/gui/util/GuiMenuSideButton.java index 506e30075..99fdb45c8 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiMenuSideButton.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiMenuSideButton.java @@ -2,20 +2,27 @@ package noppes.npcs.client.gui.util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; public class GuiMenuSideButton extends GuiNpcButton{ public static final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/menusidebutton.png"); + public static final ResourceLocation resource2 = new ResourceLocation("customnpcs","textures/gui/menusidebutton2.png"); public boolean active; + public boolean rightSided; + public ItemStack renderStack; - public GuiMenuSideButton(int i, int j, int k, String s){ - this(i, j, k, 200, 20, s); + public GuiMenuSideButton(int id, int x, int y, String s){ + this(id, x, y, 200, 20, s); } - public GuiMenuSideButton(int i, int j, int k, int l, int i1, String s){ - super(i, j, k, l, i1, s); + public GuiMenuSideButton(int id, int x, int y, int width, int height, String s){ + super(id, x, y, width, height, s); active = false; } @@ -23,7 +30,7 @@ public class GuiMenuSideButton extends GuiNpcButton{ public int getHoverState(boolean flag){ if (active) return 0; - return 1; + return super.getHoverState(flag); } @Override @@ -32,13 +39,38 @@ public class GuiMenuSideButton extends GuiNpcButton{ return; } FontRenderer fontrenderer = minecraft.fontRenderer; - minecraft.renderEngine.bindTexture(resource); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int width = this.width + (active?2:0); field_146123_n = i >= xPosition && j >= yPosition && i < xPosition + width && j < yPosition + height; int k = getHoverState(field_146123_n); - drawTexturedModalRect(xPosition, yPosition, 0, k * 22, width, height); + + if (this.rightSided) { + minecraft.renderEngine.bindTexture(resource2); + drawTexturedModalRect(xPosition, yPosition, 197 - width, k * 22, width, height); + } else { + minecraft.renderEngine.bindTexture(resource); + drawTexturedModalRect(xPosition, yPosition, 0, k * 22, width, height); + } mouseDragged(minecraft, i, j); + + if (this.renderStack != null) { + RenderHelper.enableGUIStandardItemLighting(); + this.zLevel = 100.0F; + RenderItem itemRenderer = RenderItem.getInstance(); + itemRenderer.zLevel = 100.0F; + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + itemRenderer.renderItemAndEffectIntoGUI(minecraft.fontRenderer, + minecraft.renderEngine, this.renderStack, xPosition + 2, yPosition + height/2 - 8); + itemRenderer.renderItemOverlayIntoGUI(minecraft.fontRenderer, + minecraft.renderEngine, this.renderStack, xPosition + 2, yPosition + height/2 - 8); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_BLEND); + itemRenderer.zLevel = 0.0F; + this.zLevel = 0.0F; + RenderHelper.disableStandardItemLighting(); + } String text = ""; float maxWidth = width * 0.75f; diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 89836ae0d..091faf929 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -95,6 +95,8 @@ public enum EnumPacketServer { CustomGuiButton,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused, + CreateParty, + ServerUpdateSkinOverlays; public CustomNpcsPermissions.Permission permission = null; From cb6a2be523bcaa18c4722a51c74ae3a9260d111c Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Mon, 8 Jan 2024 00:31:54 -0600 Subject: [PATCH 17/25] Added an empty gui for the party button to go into, fixed vanilla top button not aligning correctly all the time when clicked. --- .../npcs/client/gui/player/GuiParty.java | 27 ++++++++++++++++++- .../npcs/client/gui/player/GuiQuestLog.java | 26 +++++++++--------- .../client/tabs/InventoryTabVanilla.java | 13 ++++++++- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/GuiParty.java index 582bfd294..e2e0bef39 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiParty.java @@ -1,15 +1,18 @@ package noppes.npcs.client.gui.player; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; +import noppes.npcs.CustomItems; import noppes.npcs.client.gui.util.*; import org.lwjgl.opengl.GL11; import tconstruct.client.tabs.InventoryTabQuests; import tconstruct.client.tabs.TabRegistry; -public class GuiParty extends GuiNPCInterface implements IGuiData { +public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICustomScrollListener, IGuiData { private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); private final EntityPlayer player; @@ -23,14 +26,32 @@ public class GuiParty extends GuiNPCInterface implements IGuiData { public void initGui(){ super.initGui(); + guiTop +=10; TabRegistry.addTabsToList(buttonList); TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabQuests.class); + + GuiMenuSideButton questsButton = new GuiMenuSideButton(100, guiLeft + xSize + 37, this.guiTop + 3, 22, 22, ""); + questsButton.rightSided = true; + questsButton.renderStack = new ItemStack(CustomItems.letter); + addButton(questsButton); + + GuiMenuSideButton partyButton = new GuiMenuSideButton(101, guiLeft + xSize + 37, this.guiTop + 3 + 21, 22, 22, ""); + partyButton.rightSided = true; + partyButton.active = true; + partyButton.renderStack = new ItemStack(CustomItems.bag); + addButton(partyButton); } @Override protected void actionPerformed(GuiButton guibutton){ initGui(); + + + if (guibutton.id == 100) { + Minecraft mc = Minecraft.getMinecraft(); + mc.displayGuiScreen(new GuiQuestLog(mc.thePlayer)); + } } @Override @@ -75,4 +96,8 @@ public class GuiParty extends GuiNPCInterface implements IGuiData { } + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + + } } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java b/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java index 61dec025f..f9d0ef528 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java @@ -41,9 +41,6 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I private boolean noQuests = false; private boolean questDetails = true; - private GuiMenuSideButton questsButton; - private GuiMenuSideButton partyButton; - private HashMap questAlertsOnOpen; private String trackedQuestKeyOnOpen; @@ -87,16 +84,16 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I } sideButtons.get(categories.indexOf(data.selectedCategory)).active = true; - this.questsButton = new GuiMenuSideButton(100,guiLeft + xSize + 37, this.guiTop + 3, 22, 22, ""); - this.questsButton.rightSided = true; - this.questsButton.active = true; - this.questsButton.renderStack = new ItemStack(CustomItems.letter); - addButton(this.questsButton); + GuiMenuSideButton questsButton = new GuiMenuSideButton(100, guiLeft + xSize + 37, this.guiTop + 3, 22, 22, ""); + questsButton.rightSided = true; + questsButton.active = true; + questsButton.renderStack = new ItemStack(CustomItems.letter); + addButton(questsButton); - this.partyButton = new GuiMenuSideButton(101,guiLeft + xSize + 37, this.guiTop + 3 + 21, 22, 22, ""); - this.partyButton.rightSided = true; - this.partyButton.renderStack = new ItemStack(CustomItems.bag); - addButton(this.partyButton); + GuiMenuSideButton partyButton = new GuiMenuSideButton(101, guiLeft + xSize + 37, this.guiTop + 3 + 21, 22, 22, ""); + partyButton.rightSided = true; + partyButton.renderStack = new ItemStack(CustomItems.bag); + addButton(partyButton); if(scroll == null) scroll = new GuiCustomScroll(this,0); @@ -143,6 +140,11 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I data.toggleQuestAlerts(); } initGui(); + + if (guibutton.id == 101) { + Minecraft mc = Minecraft.getMinecraft(); + mc.displayGuiScreen(new GuiParty(mc.thePlayer)); + } } @Override public void drawScreen(int i, int j, float f){ diff --git a/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java b/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java index a0c8c965f..d5c52e8c5 100644 --- a/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java +++ b/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java @@ -10,7 +10,18 @@ public class InventoryTabVanilla extends AbstractTab { @Override public void onTabClicked() { - TabRegistry.openInventoryGui(); + Thread t = new Thread(){ + @Override + public void run(){ + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + TabRegistry.openInventoryGui(); + } + }; + t.start(); } @Override From 020e39907de101c7252c95573220051ce73e9400 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Mon, 8 Jan 2024 00:33:30 -0600 Subject: [PATCH 18/25] Added side menu button texture --- .../customnpcs/textures/gui/menusidebutton2.png | Bin 0 -> 716 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/assets/customnpcs/textures/gui/menusidebutton2.png diff --git a/src/main/resources/assets/customnpcs/textures/gui/menusidebutton2.png b/src/main/resources/assets/customnpcs/textures/gui/menusidebutton2.png new file mode 100644 index 0000000000000000000000000000000000000000..8ca57f24df345f7bf948ffa698f4f8ebfda61523 GIT binary patch literal 716 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZxy-8q?;Kn_c~qpu?a z!^VE@KZ&eBK4*bPWHAE+-(e7DJf6QIg@J)7(bL5-q$2L^osAPO2Z%TXb{fg-;$F`z zR<%JnDX8CAiAgC)+<{q-Y1)C;n|ikVUj1O6@#Bl$qA&hEe{%k^iS0Cb1K-!*Cm7j_ zCAV#C>m`|@TC5jFSr>N2d< zJ;26rxJY7MKhT%;|9>85bGY^S_;bUr+Zd!7D)sB*k6lq_5Kto;nbrUNb-GpIN$&RB zFOP5ce?4QDP)=bP0l+XkKM_R=& literal 0 HcmV?d00001 From 0ecc94bdb06b7992cc78281b25f64f9765d42bf8 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 8 Jan 2024 18:19:29 -0600 Subject: [PATCH 19/25] More changes to the party menu, rhs tabs always appear, and a small loading text appears before packets are sent. --- .../npcs/client/gui/player/GuiParty.java | 20 ++++++++++++++++- .../npcs/client/gui/player/GuiQuestLog.java | 22 +++++++++---------- .../assets/customnpcs/lang/en_US.lang | 1 + 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/GuiParty.java index e2e0bef39..b6de11855 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiParty.java @@ -6,7 +6,9 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; import noppes.npcs.CustomItems; +import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.*; import org.lwjgl.opengl.GL11; import tconstruct.client.tabs.InventoryTabQuests; @@ -16,12 +18,17 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); private final EntityPlayer player; + private boolean receivedData; + private long renderTicks; + public GuiParty(EntityPlayer player) { super(); this.player = player; xSize = 280; ySize = 180; drawDefaultBackground = false; + + //TODO: Send initial data packet } public void initGui(){ @@ -47,7 +54,6 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus protected void actionPerformed(GuiButton guibutton){ initGui(); - if (guibutton.id == 100) { Minecraft mc = Minecraft.getMinecraft(); mc.displayGuiScreen(new GuiQuestLog(mc.thePlayer)); @@ -56,12 +62,23 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus @Override public void drawScreen(int i, int j, float f){ + renderTicks++; + drawDefaultBackground(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(resource); drawTexturedModalRect(guiLeft, guiTop, 0, 0, 252, 195); drawTexturedModalRect(guiLeft + 252, guiTop, 188, 0, 67, 195); super.drawScreen(i, j, f); + + if(!receivedData){ + String periods = ""; + for (int k = 0; k < (renderTicks/10)%4; k++) { + periods += "."; + } + fontRendererObj.drawString(StatCollector.translateToLocal("gui.loading") + periods,guiLeft + xSize/2,guiTop + 80, CustomNpcResourceListener.DefaultTextColor); + return; + } } @Override @@ -82,6 +99,7 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus @Override public void setGuiData(NBTTagCompound compound) { + this.receivedData = true; initGui(); } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java b/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java index f9d0ef528..ee18b7e5c 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java @@ -67,6 +67,17 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I noQuests = false; + GuiMenuSideButton questsButton = new GuiMenuSideButton(100, guiLeft + xSize + 37, this.guiTop + 3, 22, 22, ""); + questsButton.rightSided = true; + questsButton.active = true; + questsButton.renderStack = new ItemStack(CustomItems.letter); + addButton(questsButton); + + GuiMenuSideButton partyButton = new GuiMenuSideButton(101, guiLeft + xSize + 37, this.guiTop + 3 + 21, 22, 22, ""); + partyButton.rightSided = true; + partyButton.renderStack = new ItemStack(CustomItems.bag); + addButton(partyButton); + if(data.categories.isEmpty()){ noQuests = true; return; @@ -84,17 +95,6 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I } sideButtons.get(categories.indexOf(data.selectedCategory)).active = true; - GuiMenuSideButton questsButton = new GuiMenuSideButton(100, guiLeft + xSize + 37, this.guiTop + 3, 22, 22, ""); - questsButton.rightSided = true; - questsButton.active = true; - questsButton.renderStack = new ItemStack(CustomItems.letter); - addButton(questsButton); - - GuiMenuSideButton partyButton = new GuiMenuSideButton(101, guiLeft + xSize + 37, this.guiTop + 3 + 21, 22, 22, ""); - partyButton.rightSided = true; - partyButton.renderStack = new ItemStack(CustomItems.bag); - addButton(partyButton); - if(scroll == null) scroll = new GuiCustomScroll(this,0); diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 30985a0ae..95c763d61 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -127,6 +127,7 @@ gui.reset=Reset gui.filters=Filters gui.selectAll=Select All gui.deselectAll=Deselect All +gui.loading=Loading scale.shared=Shared filter.contains=Contains From 2ef38dfdf4c8ab5cb72369e94682232958bad651 Mon Sep 17 00:00:00 2001 From: luisc Date: Wed, 10 Jan 2024 22:14:00 -0600 Subject: [PATCH 20/25] More work on the party GUI, which can now properly start a party. Created a party controller. --- .../java/noppes/npcs/PacketHandlerServer.java | 20 +++ .../npcs/client/ClientCacheHandler.java | 4 + .../npcs/client/gui/player/GuiParty.java | 123 +++++++++++++++++- .../npcs/constants/EnumPacketServer.java | 2 +- .../npcs/controllers/PartyController.java | 36 +++++ .../noppes/npcs/controllers/data/Party.java | 101 +++++++++++--- 6 files changed, 263 insertions(+), 23 deletions(-) create mode 100644 src/main/java/noppes/npcs/controllers/PartyController.java diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index acb482d90..403eefa1e 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -111,6 +111,26 @@ public class PacketHandlerServer{ } else if (type == EnumPacketServer.CacheAnimation) { PlayerDataController.Instance.getPlayerData(player).animationData.cacheAnimation(buffer.readInt()); return; + } else if (type == EnumPacketServer.GetPartyData || type == EnumPacketServer.CreateParty) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + if (type == EnumPacketServer.CreateParty) { + Party party = PartyController.Instance().createParty(); + party.addPlayer(player); + party.setLeader(player); + } + + NBTTagCompound compound = new NBTTagCompound(); + if (playerData.partyUUID != null) { + Party party = PartyController.Instance().getParty(playerData.partyUUID); + compound = party.writeToNBT(); + + Quest quest = (Quest) QuestController.Instance.get(party.getCurrentQuestID()); + if (quest != null) { + compound.setString("QuestName", quest.getName()); + compound.setString("QuestCategory", quest.getCategory().getName()); + } + } + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } if(type.needsNpc && npc == null){ diff --git a/src/main/java/noppes/npcs/client/ClientCacheHandler.java b/src/main/java/noppes/npcs/client/ClientCacheHandler.java index 182065e83..faf91da84 100644 --- a/src/main/java/noppes/npcs/client/ClientCacheHandler.java +++ b/src/main/java/noppes/npcs/client/ClientCacheHandler.java @@ -7,6 +7,7 @@ import noppes.npcs.client.gui.OverlayQuestTracking; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.renderer.ImageData; import noppes.npcs.config.ConfigClient; +import noppes.npcs.controllers.data.Party; import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.util.CacheHashMap; @@ -22,6 +23,8 @@ public class ClientCacheHandler { public static HashMap> skinOverlays = new HashMap<>(); public static HashMap playerAnimations = new HashMap<>(); + public static Party party; + public static ImageData getImageData(String directory) { synchronized (imageDataCache) { if (!imageDataCache.containsKey(directory)) { @@ -47,5 +50,6 @@ public class ClientCacheHandler { ClientCacheHandler.customOverlays.clear(); ClientCacheHandler.skinOverlays.clear(); ClientCacheHandler.playerAnimations.clear(); + party = null; } } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/GuiParty.java index b6de11855..b9e9f9cc5 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiParty.java @@ -8,13 +8,19 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import noppes.npcs.CustomItems; +import noppes.npcs.client.Client; +import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.data.Party; import org.lwjgl.opengl.GL11; import tconstruct.client.tabs.InventoryTabQuests; import tconstruct.client.tabs.TabRegistry; -public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICustomScrollListener, IGuiData { +import java.util.UUID; + +public class GuiParty extends GuiNPCInterface implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData { private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); private final EntityPlayer player; @@ -28,10 +34,12 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus ySize = 180; drawDefaultBackground = false; - //TODO: Send initial data packet + Client.sendData(EnumPacketServer.GetPartyData); } public void initGui(){ + Party party = ClientCacheHandler.party; + super.initGui(); guiTop +=10; @@ -48,10 +56,93 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus partyButton.active = true; partyButton.renderStack = new ItemStack(CustomItems.bag); addButton(partyButton); + + if (receivedData) { + if (party == null) { + // + //create party button + // + GuiNpcButton createPartyButton = new GuiNpcButton(200, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 20, "Create Party"); + createPartyButton.width = 100; + this.addButton(createPartyButton); + + this.addLabel(new GuiNpcLabel(201, "You're not in a party!", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 30)); + this.addLabel(new GuiNpcLabel(202, "Either wait for an invite", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 20)); + this.addLabel(new GuiNpcLabel(203, "or create one.", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 10)); + + //party invites list + // + GuiCustomScroll inviteScroll = new GuiCustomScroll(this, 210, false); + inviteScroll.setSize(150, 160); + inviteScroll.guiLeft = guiLeft + 5; + inviteScroll.guiTop = guiTop + 5; + this.addScroll(inviteScroll); + + GuiNpcButton acceptButton = new GuiNpcButton(215, guiLeft + 15, guiTop + ySize - 12, "Accept"); + acceptButton.width = 60; + this.addButton(acceptButton); + + GuiNpcButton ignoreButton = new GuiNpcButton(220, guiLeft + 80, guiTop + ySize - 12, "Ignore"); + ignoreButton.width = 60; + this.addButton(ignoreButton); + } else { + // + //party player list + // + GuiCustomScroll playerScroll = new GuiCustomScroll(this, 300, false); + playerScroll.setSize(150, 160); + playerScroll.guiLeft = guiLeft + 5; + playerScroll.guiTop = guiTop + 5; + this.addScroll(playerScroll); + + //set leader button + // + GuiNpcButton leaderButton = new GuiNpcButton(305, guiLeft + 5, guiTop + ySize - 12, "Make Leader"); + leaderButton.width = 70; + this.addButton(leaderButton); + + //kick player button + // + GuiNpcButton kickButton = new GuiNpcButton(315, guiLeft + 85, guiTop + ySize - 12, "Kick"); + kickButton.width = 70; + this.addButton(kickButton); + + //toggle friendly fire + // + GuiNpcButton friendlyFireButton = new GuiNpcButton(320, guiLeft + xSize/2 + 95, guiTop + ySize/2, new String[] {"On", "Off"}, 0); //party.friendlyFire() ? 0 : 1 + friendlyFireButton.width = 40; + this.addButton(friendlyFireButton); + + GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, "Friendly Fire:", guiLeft + xSize/2 + 20, guiTop + ySize/2 + 5); + this.addLabel(friendlyFireLabel); + + //send invite button (opens subgui) + // + GuiNpcTextField playerTextField = new GuiNpcTextField(325, this, guiLeft + xSize/2 + 20, guiTop + ySize/2 + 40,100, 20, ""); + this.addTextField(playerTextField); + + GuiNpcButton inviteButton = new GuiNpcButton(330, guiLeft + xSize/2 + 125, guiTop + ySize/2 + 40, "Invite"); + inviteButton.width = 50; + this.addButton(inviteButton); + + //disband party + // + GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "Disband Party"); + disbandButton.width = 100; + this.addButton(disbandButton); + } + } } @Override protected void actionPerformed(GuiButton guibutton){ + switch (guibutton.id) { + case 200: + Client.sendData(EnumPacketServer.CreateParty); + receivedData = false; + break; + } + initGui(); if (guibutton.id == 100) { @@ -77,17 +168,19 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus periods += "."; } fontRendererObj.drawString(StatCollector.translateToLocal("gui.loading") + periods,guiLeft + xSize/2,guiTop + 80, CustomNpcResourceListener.DefaultTextColor); - return; } } @Override public void keyTyped(char c, int i) { - if (i == 1 || i == mc.gameSettings.keyBindInventory.getKeyCode()) // inventory key - { - mc.displayGuiScreen(null); - mc.setIngameFocus(); + super.keyTyped(c, i); + if (!GuiNpcTextField.isFieldActive()) { + if (i == 1 || i == mc.gameSettings.keyBindInventory.getKeyCode()) // inventory key + { + mc.displayGuiScreen(null); + mc.setIngameFocus(); + } } } @@ -100,6 +193,17 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus @Override public void setGuiData(NBTTagCompound compound) { this.receivedData = true; + + if (compound.hasKey("PartyUUID")) { + Party party = ClientCacheHandler.party; + UUID uuid = UUID.fromString(compound.getString("PartyUUID")); + if (party == null || !party.getPartyUUID().equals(uuid)) { + ClientCacheHandler.party = new Party(uuid); + party = ClientCacheHandler.party; + } + party.readFromNBT(compound); + } + initGui(); } @@ -118,4 +222,9 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { } + + @Override + public void unFocused(GuiNpcTextField textfield) { + + } } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 091faf929..11c4420e7 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -95,7 +95,7 @@ public enum EnumPacketServer { CustomGuiButton,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused, - CreateParty, + CreateParty, GetPartyData, ServerUpdateSkinOverlays; diff --git a/src/main/java/noppes/npcs/controllers/PartyController.java b/src/main/java/noppes/npcs/controllers/PartyController.java new file mode 100644 index 000000000..42c68989e --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/PartyController.java @@ -0,0 +1,36 @@ +package noppes.npcs.controllers; + +import noppes.npcs.controllers.data.Party; + +import java.util.HashMap; +import java.util.UUID; + +public class PartyController { + private static PartyController Instance; + + private HashMap parties = new HashMap<>(); + + private PartyController() { + } + + public static PartyController Instance() { + if (Instance == null) { + Instance = new PartyController(); + } + return Instance; + } + + public Party createParty() { + Party party = new Party(); + this.parties.put(party.getPartyUUID(), party); + return party; + } + + public Party getParty(UUID partyUUID) { + return this.parties.get(partyUUID); + } + + public void deleteParty(UUID partyUUID) { + this.parties.remove(partyUUID); + } +} diff --git a/src/main/java/noppes/npcs/controllers/data/Party.java b/src/main/java/noppes/npcs/controllers/data/Party.java index a8ab6699a..0c3728ed6 100644 --- a/src/main/java/noppes/npcs/controllers/data/Party.java +++ b/src/main/java/noppes/npcs/controllers/data/Party.java @@ -2,7 +2,13 @@ package noppes.npcs.controllers.data; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import noppes.npcs.NoppesUtilServer; import noppes.npcs.api.handler.IPlayerQuestData; import noppes.npcs.api.handler.data.IQuest; import noppes.npcs.controllers.PlayerDataController; @@ -14,8 +20,7 @@ import java.net.URL; import java.util.*; public class Party { - - private final UUID partyUUID = UUID.randomUUID(); + private final UUID partyUUID; private UUID partyLeader; private final HashMap partyMembers = new HashMap<>(); @@ -23,12 +28,21 @@ public class Party { private int currentQuestID = -1; - public UUID getPartyLeader() { - return partyLeader; + private boolean friendlyFire; + + //Client-sided + private String partyLeaderName; + + public Party() { + this.partyUUID = UUID.randomUUID(); } - public void setPartyLeader(UUID partyLeader) { - this.partyLeader = partyLeader; + public Party(UUID uuid) { + this.partyUUID = uuid; + } + + public UUID getPartyUUID() { + return this.partyUUID; } public int getCurrentQuestID() { @@ -44,6 +58,9 @@ public class Party { return false; } + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + playerData.partyUUID = this.partyUUID; + partyMembers.put(player.getUniqueID(), player.getCommandSenderName()); partyOrder.add(player.getUniqueID()); return true; @@ -71,12 +88,13 @@ public class Party { return false; } - public boolean removePlayer(UUID player) { - if(partyMembers.containsKey(player)){ - partyMembers.remove(player); - partyOrder.remove(player); + public boolean removePlayer(EntityPlayer player) { + UUID uuid = player.getUniqueID(); + if(partyMembers.containsKey(uuid)){ + partyMembers.remove(uuid); + partyOrder.remove(uuid); - if(player.equals(partyLeader)){ + if(uuid.equals(partyLeader)){ if(partyMembers.size() > 0){ partyLeader = partyOrder.get(0); } @@ -88,8 +106,8 @@ public class Party { return false; } - public boolean hasPlayer(UUID player) { - return partyMembers.containsKey(player); + public boolean hasPlayer(EntityPlayer player) { + return partyMembers.containsKey(player.getUniqueID()); } public boolean hasPlayer(String playerName) { @@ -100,8 +118,18 @@ public class Party { return partyMembers.containsKey(uuid); } - public boolean setLeader(UUID uuid){ - if(partyLeader.equals(uuid)){ + public EntityPlayer getPartyLeader() { + return NoppesUtilServer.getPlayer(this.partyLeader); + } + + @SideOnly(Side.CLIENT) + public String getPartyLeaderName() { + return this.partyLeaderName; + } + + public boolean setLeader(EntityPlayer player){ + UUID uuid = player.getUniqueID(); + if(partyLeader != null && partyLeader.equals(uuid)){ return false; } @@ -120,6 +148,10 @@ public class Party { return true; } + public Collection getPlayerNames() { + return this.partyMembers.values(); + } + // To Be Called DURING Invite, Leave, Quest Switch, Leader Switch, etc. public static boolean validateQuest(int questID, Collection players){ IQuest quest = QuestController.Instance.get(questID); @@ -154,6 +186,14 @@ public class Party { } } + public void toggleFriendlyFire() { + this.friendlyFire = !this.friendlyFire; + } + + public boolean friendlyFire() { + return this.friendlyFire; + } + public static UUID getUUID(String name) { UUID uuid = null; try { @@ -168,4 +208,35 @@ public class Party { return uuid; } + public void readFromNBT(NBTTagCompound compound) { + this.partyLeaderName = compound.getString("PartyLeader"); + this.currentQuestID = compound.getInteger("PartyQuestID"); + + NBTTagList list = compound.getTagList("PartyMembers", 10); + for (int i = 0; i < list.tagCount(); i++) { + NBTTagCompound tagCompound = list.getCompoundTagAt(i); + UUID uuid = UUID.fromString(tagCompound.getString("UUID")); + String playerName = tagCompound.getString("PlayerName"); + this.partyOrder.add(uuid); + this.partyMembers.put(uuid, playerName); + } + } + + public NBTTagCompound writeToNBT() { + NBTTagCompound compound = new NBTTagCompound(); + + compound.setString("PartyUUID", this.partyUUID.toString()); + compound.setInteger("PartyQuestID", this.currentQuestID); + compound.setString("PartyLeader", getPartyLeader().getCommandSenderName()); + NBTTagList list = new NBTTagList(); + for (UUID uuid : this.partyOrder) { + NBTTagCompound uuidCompound = new NBTTagCompound(); + uuidCompound.setString("UUID", uuid.toString()); + uuidCompound.setString("PlayerName", this.partyMembers.get(uuid)); + list.appendTag(uuidCompound); + } + compound.setTag("PartyMembers", list); + + return compound; + } } From 42f16d6ce162ba5d66eee4eda34d931455fa6308 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 11 Jan 2024 03:50:10 -0500 Subject: [PATCH 21/25] Remove Faction Inventory Tab for Sub Inventory Tab --- .../java/noppes/npcs/client/ClientProxy.java | 7 +-- .../noppes/npcs/client/ClientTickHandler.java | 4 +- .../player/inventory/GuiCNPCInventory.java | 52 +++++++++++++++++++ .../player/{ => inventory}/GuiFaction.java | 52 +++++++++++-------- .../gui/player/{ => inventory}/GuiParty.java | 43 ++++++--------- .../player/{ => inventory}/GuiQuestLog.java | 41 ++++++--------- ...Quests.java => InventoryTabCustomNpc.java} | 6 +-- .../client/tabs/InventoryTabFactions.java | 37 ------------- 8 files changed, 120 insertions(+), 122 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/player/inventory/GuiCNPCInventory.java rename src/main/java/noppes/npcs/client/gui/player/{ => inventory}/GuiFaction.java (83%) rename src/main/java/noppes/npcs/client/gui/player/{ => inventory}/GuiParty.java (88%) rename src/main/java/noppes/npcs/client/gui/player/{ => inventory}/GuiQuestLog.java (90%) rename src/main/java/tconstruct/client/tabs/{InventoryTabQuests.java => InventoryTabCustomNpc.java} (82%) delete mode 100644 src/main/java/tconstruct/client/tabs/InventoryTabFactions.java diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index fbdc87dfd..deaa74a22 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -53,7 +53,6 @@ import noppes.npcs.client.renderer.blocks.*; import noppes.npcs.client.renderer.customitem.CustomItemRenderer; import noppes.npcs.config.ConfigClient; import noppes.npcs.config.ConfigMain; -import noppes.npcs.config.ConfigScript; import noppes.npcs.config.StringCache; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.containers.*; @@ -63,8 +62,7 @@ import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.data.ModelPartData; import noppes.npcs.items.ItemScripted; import org.lwjgl.input.Keyboard; -import tconstruct.client.tabs.InventoryTabFactions; -import tconstruct.client.tabs.InventoryTabQuests; +import tconstruct.client.tabs.InventoryTabCustomNpc; import tconstruct.client.tabs.InventoryTabVanilla; import tconstruct.client.tabs.TabRegistry; @@ -152,8 +150,7 @@ public class ClientProxy extends CommonProxy { if (TabRegistry.getTabList().size() < 2){ TabRegistry.registerTab(new InventoryTabVanilla()); } - TabRegistry.registerTab(new InventoryTabFactions()); - TabRegistry.registerTab(new InventoryTabQuests()); + TabRegistry.registerTab(new InventoryTabCustomNpc()); } } diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 9a1ec9a75..940cdbf6c 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -3,18 +3,16 @@ package noppes.npcs.client; import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent; -import cpw.mods.fml.common.gameevent.PlayerEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ContainerPlayer; import net.minecraft.world.World; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.controllers.ScriptSoundController; -import noppes.npcs.client.gui.player.GuiQuestLog; +import noppes.npcs.client.gui.player.inventory.GuiQuestLog; import noppes.npcs.client.renderer.RenderNPCInterface; import noppes.npcs.constants.EnumPlayerPacket; import org.lwjgl.input.Keyboard; diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiCNPCInventory.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiCNPCInventory.java new file mode 100644 index 000000000..b39eb51e5 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiCNPCInventory.java @@ -0,0 +1,52 @@ +package noppes.npcs.client.gui.player.inventory; + +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.CustomItems; +import noppes.npcs.client.gui.util.GuiMenuSideButton; +import noppes.npcs.client.gui.util.GuiNPCInterface; +import tconstruct.client.tabs.InventoryTabCustomNpc; +import tconstruct.client.tabs.TabRegistry; + +public class GuiCNPCInventory extends GuiNPCInterface { + private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); + protected static int activeTab = 0; + private Minecraft mc = Minecraft.getMinecraft(); + + public GuiCNPCInventory() { + super(); + xSize = 280; + ySize = 180; + drawDefaultBackground = false; + } + + public void initGui(){ + super.initGui(); + guiTop +=10; + + TabRegistry.addTabsToList(buttonList); + TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); + + GuiMenuSideButton questsButton = new GuiMenuSideButton(100, guiLeft + xSize + 37, this.guiTop + 3, 22, 22, ""); + questsButton.rightSided = true; + questsButton.active = activeTab == 0; + questsButton.renderStack = new ItemStack(CustomItems.letter); + addButton(questsButton); + + GuiMenuSideButton partyButton = new GuiMenuSideButton(101, guiLeft + xSize + 37, this.guiTop + 3 + 21, 22, 22, ""); + partyButton.rightSided = true; + partyButton.active = activeTab == 1; + partyButton.renderStack = new ItemStack(CustomItems.bag); + addButton(partyButton); + + GuiMenuSideButton factionButton = new GuiMenuSideButton(102, guiLeft + xSize + 37, this.guiTop + 3 + 21*2, 22, 22, ""); + factionButton.rightSided = true; + factionButton.active = activeTab == 2; + factionButton.renderStack = new ItemStack(CustomItems.wallBanner); + addButton(factionButton); + } + + @Override + public void save() {} +} diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiFaction.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java similarity index 83% rename from src/main/java/noppes/npcs/client/gui/player/GuiFaction.java rename to src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java index a26e43ec2..9cbc9fa6c 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiFaction.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java @@ -1,5 +1,6 @@ -package noppes.npcs.client.gui.player; +package noppes.npcs.client.gui.player.inventory; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -8,54 +9,46 @@ import net.minecraft.util.StatCollector; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.GuiButtonNextPage; -import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.IGuiData; import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.controllers.data.Faction; import noppes.npcs.controllers.data.PlayerFactionData; import org.lwjgl.opengl.GL11; -import tconstruct.client.tabs.InventoryTabFactions; +import tconstruct.client.tabs.InventoryTabCustomNpc; import tconstruct.client.tabs.TabRegistry; import java.util.ArrayList; -public class GuiFaction extends GuiNPCInterface implements IGuiData{ +public class GuiFaction extends GuiCNPCInventory implements IGuiData{ - private int xSize; - private int ySize; - private int guiLeft; - private int guiTop; + private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); private ArrayList playerFactions = new ArrayList(); + private Minecraft mc = Minecraft.getMinecraft(); private int page = 0; private int pages = 1; private GuiButtonNextPage buttonNextPage; private GuiButtonNextPage buttonPreviousPage; - private ResourceLocation indicator; public GuiFaction() { super(); - xSize = 200; - ySize = 195; + xSize = 280; + ySize = 180; this.drawDefaultBackground = false; title = ""; + activeTab = 2; NoppesUtilPlayer.sendData(EnumPlayerPacket.FactionsGet); - indicator = getResource("standardbg.png"); } @Override public void initGui() { - super.initGui(); - guiLeft = (width - xSize) / 2; - guiTop = (height - ySize) / 2 + 12; - - - TabRegistry.updateTabValues(guiLeft, guiTop + 8, InventoryTabFactions.class); + super.initGui(); TabRegistry.addTabsToList(buttonList); - + TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); + this.buttonList.add(buttonNextPage = new GuiButtonNextPage(1, guiLeft + xSize - 43, guiTop + 180, true)); this.buttonList.add(buttonPreviousPage = new GuiButtonNextPage(2, guiLeft + 20, guiTop + 180, false)); updateButtons(); @@ -66,9 +59,9 @@ public class GuiFaction extends GuiNPCInterface implements IGuiData{ { drawDefaultBackground(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture(indicator); - drawTexturedModalRect(guiLeft, guiTop + 8, 0, 0, xSize, ySize); - drawTexturedModalRect(guiLeft + 4, guiTop + 8, 56, 0, 200, ySize); + mc.renderEngine.bindTexture(resource); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, 252, 195); + drawTexturedModalRect(guiLeft + 252, guiTop, 188, 0, 67, 195); if(playerFactions.isEmpty()){ String noFaction = StatCollector.translateToLocal("faction.nostanding"); @@ -124,6 +117,21 @@ public class GuiFaction extends GuiNPCInterface implements IGuiData{ @Override protected void actionPerformed(GuiButton guibutton){ + if (guibutton.id >= 100) { + if (guibutton.id == 100 && activeTab != 0) { + activeTab = 0; + mc.displayGuiScreen(new GuiQuestLog(mc.thePlayer)); + } + if (guibutton.id == 101 && activeTab != 1) { + activeTab = 1; + mc.displayGuiScreen(new GuiParty(mc.thePlayer)); + } + if (guibutton.id == 102 && activeTab != 2) { + activeTab = 2; + mc.displayGuiScreen(new GuiFaction()); + } + } + if(!(guibutton instanceof GuiButtonNextPage)) return; int id = guibutton.id; diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java similarity index 88% rename from src/main/java/noppes/npcs/client/gui/player/GuiParty.java rename to src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java index b9e9f9cc5..c1e76f79a 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java @@ -1,13 +1,11 @@ -package noppes.npcs.client.gui.player; +package noppes.npcs.client.gui.player.inventory; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import noppes.npcs.CustomItems; import noppes.npcs.client.Client; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.CustomNpcResourceListener; @@ -15,14 +13,15 @@ import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.data.Party; import org.lwjgl.opengl.GL11; -import tconstruct.client.tabs.InventoryTabQuests; +import tconstruct.client.tabs.InventoryTabCustomNpc; import tconstruct.client.tabs.TabRegistry; import java.util.UUID; -public class GuiParty extends GuiNPCInterface implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData { +public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData { private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); private final EntityPlayer player; + private Minecraft mc = Minecraft.getMinecraft(); private boolean receivedData; private long renderTicks; @@ -33,29 +32,15 @@ public class GuiParty extends GuiNPCInterface implements ITextfieldListener, ITo xSize = 280; ySize = 180; drawDefaultBackground = false; - + activeTab = 1; Client.sendData(EnumPacketServer.GetPartyData); } public void initGui(){ - Party party = ClientCacheHandler.party; - super.initGui(); - guiTop +=10; - + Party party = ClientCacheHandler.party; TabRegistry.addTabsToList(buttonList); - TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabQuests.class); - - GuiMenuSideButton questsButton = new GuiMenuSideButton(100, guiLeft + xSize + 37, this.guiTop + 3, 22, 22, ""); - questsButton.rightSided = true; - questsButton.renderStack = new ItemStack(CustomItems.letter); - addButton(questsButton); - - GuiMenuSideButton partyButton = new GuiMenuSideButton(101, guiLeft + xSize + 37, this.guiTop + 3 + 21, 22, 22, ""); - partyButton.rightSided = true; - partyButton.active = true; - partyButton.renderStack = new ItemStack(CustomItems.bag); - addButton(partyButton); + TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); if (receivedData) { if (party == null) { @@ -142,13 +127,19 @@ public class GuiParty extends GuiNPCInterface implements ITextfieldListener, ITo receivedData = false; break; } - initGui(); - - if (guibutton.id == 100) { - Minecraft mc = Minecraft.getMinecraft(); + if (guibutton.id == 100 && activeTab != 0) { + activeTab = 0; mc.displayGuiScreen(new GuiQuestLog(mc.thePlayer)); } + if (guibutton.id == 101 && activeTab != 1) { + activeTab = 1; + mc.displayGuiScreen(new GuiParty(mc.thePlayer)); + } + if (guibutton.id == 102 && activeTab != 2) { + activeTab = 2; + mc.displayGuiScreen(new GuiFaction()); + } } @Override diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java similarity index 90% rename from src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java rename to src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java index ee18b7e5c..02be187b6 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiQuestLog.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java @@ -1,15 +1,11 @@ -package noppes.npcs.client.gui.player; +package noppes.npcs.client.gui.player.inventory; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import noppes.npcs.CustomItems; import noppes.npcs.NBTTags; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.QuestLogData; @@ -21,15 +17,13 @@ import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.util.ValueUtil; -import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; -import tconstruct.client.tabs.InventoryTabQuests; +import tconstruct.client.tabs.InventoryTabCustomNpc; import tconstruct.client.tabs.TabRegistry; import java.util.*; -public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,ICustomScrollListener, IGuiData{ +public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener,ICustomScrollListener, IGuiData{ private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); @@ -56,28 +50,16 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I ySize = 180; NoppesUtilPlayer.sendData(EnumPlayerPacket.QuestLog); drawDefaultBackground = false; + activeTab = 0; } public void initGui(){ super.initGui(); sideButtons.clear(); - guiTop +=10; - TabRegistry.addTabsToList(buttonList); - TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabQuests.class); + TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); noQuests = false; - GuiMenuSideButton questsButton = new GuiMenuSideButton(100, guiLeft + xSize + 37, this.guiTop + 3, 22, 22, ""); - questsButton.rightSided = true; - questsButton.active = true; - questsButton.renderStack = new ItemStack(CustomItems.letter); - addButton(questsButton); - - GuiMenuSideButton partyButton = new GuiMenuSideButton(101, guiLeft + xSize + 37, this.guiTop + 3 + 21, 22, 22, ""); - partyButton.rightSided = true; - partyButton.renderStack = new ItemStack(CustomItems.bag); - addButton(partyButton); - if(data.categories.isEmpty()){ noQuests = true; return; @@ -140,11 +122,18 @@ public class GuiQuestLog extends GuiNPCInterface implements ITopButtonListener,I data.toggleQuestAlerts(); } initGui(); - - if (guibutton.id == 101) { - Minecraft mc = Minecraft.getMinecraft(); + if (guibutton.id == 100 && activeTab != 0) { + activeTab = 0; + mc.displayGuiScreen(new GuiQuestLog(mc.thePlayer)); + } + if (guibutton.id == 101 && activeTab != 1) { + activeTab = 1; mc.displayGuiScreen(new GuiParty(mc.thePlayer)); } + if (guibutton.id == 102 && activeTab != 2) { + activeTab = 2; + mc.displayGuiScreen(new GuiFaction()); + } } @Override public void drawScreen(int i, int j, float f){ diff --git a/src/main/java/tconstruct/client/tabs/InventoryTabQuests.java b/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java similarity index 82% rename from src/main/java/tconstruct/client/tabs/InventoryTabQuests.java rename to src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java index bca535a5c..9a7f128b2 100644 --- a/src/main/java/tconstruct/client/tabs/InventoryTabQuests.java +++ b/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java @@ -4,10 +4,10 @@ import net.minecraft.client.Minecraft; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import noppes.npcs.CustomItems; -import noppes.npcs.client.gui.player.GuiQuestLog; +import noppes.npcs.client.gui.player.inventory.GuiQuestLog; -public class InventoryTabQuests extends AbstractTab { - public InventoryTabQuests() { +public class InventoryTabCustomNpc extends AbstractTab { + public InventoryTabCustomNpc() { super(0, 0, 0, new ItemStack(CustomItems.letter)); if(CustomItems.letter == null) diff --git a/src/main/java/tconstruct/client/tabs/InventoryTabFactions.java b/src/main/java/tconstruct/client/tabs/InventoryTabFactions.java deleted file mode 100644 index 0c8174d78..000000000 --- a/src/main/java/tconstruct/client/tabs/InventoryTabFactions.java +++ /dev/null @@ -1,37 +0,0 @@ -package tconstruct.client.tabs; - -import net.minecraft.client.Minecraft; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import noppes.npcs.CustomItems; -import noppes.npcs.client.gui.player.GuiFaction; - -public class InventoryTabFactions extends AbstractTab { - public InventoryTabFactions() { - super(0, 0, 0, new ItemStack(CustomItems.wallBanner, 1, 1)); - if(CustomItems.wallBanner == null) - renderStack = new ItemStack(Blocks.tnt); - } - - @Override - public void onTabClicked() { - Thread t = new Thread(){ - @Override - public void run(){ - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - Minecraft mc = Minecraft.getMinecraft(); - mc.displayGuiScreen(new GuiFaction()); - } - }; - t.start(); - } - - @Override - public boolean shouldAddToList() { - return true; - } -} \ No newline at end of file From 49c036127b5e69704dd59c8b6c54bdec77428971 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 11 Jan 2024 03:51:02 -0500 Subject: [PATCH 22/25] Rename Key Binding Button --- src/main/java/noppes/npcs/client/ClientProxy.java | 6 +++--- src/main/java/noppes/npcs/client/ClientTickHandler.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index deaa74a22..b5f42a5a4 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -73,7 +73,7 @@ import java.io.IOException; import java.util.Random; public class ClientProxy extends CommonProxy { - public static KeyBinding QuestLog; + public static KeyBinding CNPCButton; public static FontContainer Font; @@ -127,9 +127,9 @@ public class ClientProxy extends CommonProxy { } Minecraft mc = Minecraft.getMinecraft(); - QuestLog = new KeyBinding("Quest Log", Keyboard.KEY_L, "key.categories.gameplay"); + CNPCButton = new KeyBinding("CustomNPC+", Keyboard.KEY_L, "key.categories.gameplay"); - ClientRegistry.registerKeyBinding(QuestLog); + ClientRegistry.registerKeyBinding(CNPCButton); mc.gameSettings.loadOptions(); new PresetController(CustomNpcs.Dir); diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 940cdbf6c..a6b93ccc7 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -82,7 +82,7 @@ public class ClientTickHandler{ @SubscribeEvent public void onKey(InputEvent.KeyInputEvent event){ - if(ClientProxy.QuestLog.isPressed()){ + if(ClientProxy.CNPCButton.isPressed()){ Minecraft mc = Minecraft.getMinecraft(); if(mc.currentScreen == null) NoppesUtil.openGUI(mc.thePlayer, new GuiQuestLog(mc.thePlayer)); From a6603afe148d7f494d7218f7a0c5b3460ff03d41 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 11 Jan 2024 03:51:48 -0500 Subject: [PATCH 23/25] Go Bacck GO BACK!!!! --- src/main/java/noppes/npcs/client/ClientProxy.java | 6 +++--- src/main/java/noppes/npcs/client/ClientTickHandler.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index b5f42a5a4..deaa74a22 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -73,7 +73,7 @@ import java.io.IOException; import java.util.Random; public class ClientProxy extends CommonProxy { - public static KeyBinding CNPCButton; + public static KeyBinding QuestLog; public static FontContainer Font; @@ -127,9 +127,9 @@ public class ClientProxy extends CommonProxy { } Minecraft mc = Minecraft.getMinecraft(); - CNPCButton = new KeyBinding("CustomNPC+", Keyboard.KEY_L, "key.categories.gameplay"); + QuestLog = new KeyBinding("Quest Log", Keyboard.KEY_L, "key.categories.gameplay"); - ClientRegistry.registerKeyBinding(CNPCButton); + ClientRegistry.registerKeyBinding(QuestLog); mc.gameSettings.loadOptions(); new PresetController(CustomNpcs.Dir); diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index a6b93ccc7..940cdbf6c 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -82,7 +82,7 @@ public class ClientTickHandler{ @SubscribeEvent public void onKey(InputEvent.KeyInputEvent event){ - if(ClientProxy.CNPCButton.isPressed()){ + if(ClientProxy.QuestLog.isPressed()){ Minecraft mc = Minecraft.getMinecraft(); if(mc.currentScreen == null) NoppesUtil.openGUI(mc.thePlayer, new GuiQuestLog(mc.thePlayer)); From ae43f0548d3ec8f713fec0a8179311b2321c2713 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 11 Jan 2024 17:05:15 -0500 Subject: [PATCH 24/25] GuiFaction Remodel to host two columns now instead of one --- .../gui/player/inventory/GuiFaction.java | 87 +++++++++++-------- 1 file changed, 52 insertions(+), 35 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java index 9cbc9fa6c..9fe7bf8a3 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java @@ -49,8 +49,8 @@ public class GuiFaction extends GuiCNPCInventory implements IGuiData{ TabRegistry.addTabsToList(buttonList); TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); - this.buttonList.add(buttonNextPage = new GuiButtonNextPage(1, guiLeft + xSize - 43, guiTop + 180, true)); - this.buttonList.add(buttonPreviousPage = new GuiButtonNextPage(2, guiLeft + 20, guiTop + 180, false)); + this.buttonList.add(buttonNextPage = new GuiButtonNextPage(1, (guiLeft + (xSize + 35) / 2) + 25, guiTop + 170, true)); + this.buttonList.add(buttonPreviousPage = new GuiButtonNextPage(2, (guiLeft + (xSize + 35) / 2) - 40, guiTop + 170, false)); updateButtons(); } @@ -75,43 +75,60 @@ public class GuiFaction extends GuiCNPCInventory implements IGuiData{ } private void renderScreen(){ - int size = 5; - if(playerFactions.size() % 5 != 0 && page == pages) - size = playerFactions.size() % 5; - + int size = 10; + if(playerFactions.size() % 10 != 0 && page == pages) + size = playerFactions.size() % 10; + + int hLine = 5; + if(size < 5){ + hLine = size; + } + + int count = -1; for(int id = 0 ; id < size; id++){ - drawHorizontalLine(guiLeft + 2, guiLeft + xSize, guiTop + 14 + id * 30, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); - - Faction faction = playerFactions.get((page - 1) * 5 + id); - String name = faction.name; - String points = " : " + faction.defaultPoints; - - String standing = StatCollector.translateToLocal("faction.friendly"); - int color = 0x00FF00; - if(faction.defaultPoints < faction.neutralPoints){ - standing = StatCollector.translateToLocal("faction.unfriendly"); - color = 0xFF0000; - points += "/" + faction.neutralPoints; - } - else if(faction.defaultPoints < faction.friendlyPoints){ - standing = StatCollector.translateToLocal("faction.neutral"); - color = 0xF2FF00; - points += "/" + faction.friendlyPoints; - } - else{ - points += "/-"; - } + count++; - fontRendererObj.drawString(name, guiLeft + (xSize - fontRendererObj.getStringWidth(name)) / 2, guiTop + 19 + id * 30, faction.color); + Faction faction = playerFactions.get((page - 1) * 10 + id); + String name = faction.name; + String points = " : " + faction.defaultPoints; + + String standing = StatCollector.translateToLocal("faction.friendly"); + int color = 0x00FF00; + if(faction.defaultPoints < faction.neutralPoints){ + standing = StatCollector.translateToLocal("faction.unfriendly"); + color = 0xFF0000; + points += "/" + faction.neutralPoints; + } + else if(faction.defaultPoints < faction.friendlyPoints){ + standing = StatCollector.translateToLocal("faction.neutral"); + color = 0xF2FF00; + points += "/" + faction.friendlyPoints; + } + else{ + points += "/-"; + } + + drawVerticalLine(guiLeft + (xSize + 45) / 2, (guiTop + ySize - 15), guiTop + 13, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); + if(count < 5){ + drawHorizontalLine(guiLeft + 2, guiLeft + xSize + 35, guiTop + 14 + count * 30, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); + fontRendererObj.drawString(name, guiLeft + (xSize + 45 - fontRendererObj.getStringWidth(name)) / 4, guiTop + 19 + count * 30, faction.color); + + fontRendererObj.drawString(standing, (guiLeft + (xSize + 45) / 4) - fontRendererObj.getStringWidth(standing), guiTop + 33 + count * 30, color); + fontRendererObj.drawString(points, (guiLeft + (xSize + 45) / 4), guiTop + 33 + count * 30, CustomNpcResourceListener.DefaultTextColor); + } + else { + fontRendererObj.drawString(name, guiLeft + 3*(xSize + 45 - fontRendererObj.getStringWidth(name)) / 4, guiTop + 19 + (count - 5) * 30, faction.color); + + fontRendererObj.drawString(standing, (guiLeft + 3*(xSize + 45) / 4) - fontRendererObj.getStringWidth(standing) - 10, guiTop + 33 + (count - 5) * 30, color); + fontRendererObj.drawString(points, (guiLeft + 3*(xSize + 45) / 4) - 10, guiTop + 33 + (count - 5) * 30, CustomNpcResourceListener.DefaultTextColor); + } + + drawHorizontalLine(guiLeft + 2, guiLeft + xSize + 35, guiTop + 14 + hLine * 30, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); + } - fontRendererObj.drawString(standing, width / 2 - fontRendererObj.getStringWidth(standing) - 1, guiTop + 33 + id * 30, color); - fontRendererObj.drawString(points, width / 2, guiTop + 33 + id * 30, CustomNpcResourceListener.DefaultTextColor); - } - drawHorizontalLine(guiLeft + 2, guiLeft + xSize, guiTop + 14 + size * 30, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); - if(pages > 1){ String s = page +"/" + pages; - fontRendererObj.drawString(s, guiLeft + (xSize - fontRendererObj.getStringWidth(s)) / 2, guiTop + 203, CustomNpcResourceListener.DefaultTextColor); + fontRendererObj.drawString(s, guiLeft + (xSize + 45 - fontRendererObj.getStringWidth(s)) / 2, guiTop + 175, CustomNpcResourceListener.DefaultTextColor); } } @@ -183,7 +200,7 @@ public class GuiFaction extends GuiCNPCInventory implements IGuiData{ } } - pages = (playerFactions.size() - 1) / 5 ; + pages = (playerFactions.size() - 1) / 10 ; pages++; page = 1; From cdd3f2282696f01c56dac90d6e2db9064baa5bf0 Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 11 Jan 2024 18:24:33 -0600 Subject: [PATCH 25/25] Added functionality to the disband party button --- .../java/noppes/npcs/PacketHandlerServer.java | 9 +++++++++ .../client/gui/player/inventory/GuiParty.java | 8 ++++++++ .../noppes/npcs/constants/EnumPacketServer.java | 2 +- .../noppes/npcs/controllers/PartyController.java | 15 +++++++++++++-- .../java/noppes/npcs/controllers/data/Party.java | 4 ++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 403eefa1e..d163b7a7a 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -131,6 +131,15 @@ public class PacketHandlerServer{ } } Server.sendData(player, EnumPacketClient.GUI_DATA, compound); + } else if (type == EnumPacketServer.DisbandParty) { + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + if (playerData.partyUUID != null) { + PartyController.Instance().disbandParty(playerData.partyUUID); + } + + NBTTagCompound compound = new NBTTagCompound(); + compound.setBoolean("Disband", true); + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } if(type.needsNpc && npc == null){ diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java index c1e76f79a..ce7dcfd30 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java @@ -16,6 +16,7 @@ import org.lwjgl.opengl.GL11; import tconstruct.client.tabs.InventoryTabCustomNpc; import tconstruct.client.tabs.TabRegistry; +import java.util.ArrayList; import java.util.UUID; public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData { @@ -78,6 +79,7 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT playerScroll.setSize(150, 160); playerScroll.guiLeft = guiLeft + 5; playerScroll.guiTop = guiTop + 5; + playerScroll.setList(new ArrayList<>(party.getPlayerNames())); this.addScroll(playerScroll); //set leader button @@ -126,6 +128,10 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT Client.sendData(EnumPacketServer.CreateParty); receivedData = false; break; + case 335: + Client.sendData(EnumPacketServer.DisbandParty); + receivedData = false; + break; } initGui(); if (guibutton.id == 100 && activeTab != 0) { @@ -193,6 +199,8 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT party = ClientCacheHandler.party; } party.readFromNBT(compound); + } else if (compound.hasKey("Disband")) { + ClientCacheHandler.party = null; } initGui(); diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 11c4420e7..fb776be91 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -95,7 +95,7 @@ public enum EnumPacketServer { CustomGuiButton,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused, - CreateParty, GetPartyData, + CreateParty, GetPartyData, DisbandParty, ServerUpdateSkinOverlays; diff --git a/src/main/java/noppes/npcs/controllers/PartyController.java b/src/main/java/noppes/npcs/controllers/PartyController.java index 42c68989e..78540c4dd 100644 --- a/src/main/java/noppes/npcs/controllers/PartyController.java +++ b/src/main/java/noppes/npcs/controllers/PartyController.java @@ -1,6 +1,9 @@ package noppes.npcs.controllers; +import net.minecraft.entity.player.EntityPlayer; +import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.data.Party; +import noppes.npcs.controllers.data.PlayerData; import java.util.HashMap; import java.util.UUID; @@ -30,7 +33,15 @@ public class PartyController { return this.parties.get(partyUUID); } - public void deleteParty(UUID partyUUID) { - this.parties.remove(partyUUID); + public void disbandParty(UUID partyUUID) { + Party party = this.parties.get(partyUUID); + if (party != null) { + for (UUID uuid: party.getPlayerUUIDs()) { + EntityPlayer player = NoppesUtilServer.getPlayer(uuid); + PlayerData playerData = PlayerDataController.Instance.getPlayerData(player); + playerData.partyUUID = null; + } + this.parties.remove(partyUUID); + } } } diff --git a/src/main/java/noppes/npcs/controllers/data/Party.java b/src/main/java/noppes/npcs/controllers/data/Party.java index 0c3728ed6..3f9c95d75 100644 --- a/src/main/java/noppes/npcs/controllers/data/Party.java +++ b/src/main/java/noppes/npcs/controllers/data/Party.java @@ -152,6 +152,10 @@ public class Party { return this.partyMembers.values(); } + public Collection getPlayerUUIDs() { + return this.partyMembers.keySet(); + } + // To Be Called DURING Invite, Leave, Quest Switch, Leader Switch, etc. public static boolean validateQuest(int questID, Collection players){ IQuest quest = QuestController.Instance.get(questID);