From f0f83d19ba8c5490b3b11f51c52390ad1723c190 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 16 Nov 2023 15:08:25 -0500 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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); } } }