From 7000b525f397ceeffb6f223e6ee266dfd99b77c6 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Wed, 31 May 2023 18:55:06 -0500 Subject: [PATCH 1/9] Fixed entity custom item rendering, and rendering of textures for custom GUI buttons and rectangles. --- .../custom/components/CustomGuiButton.java | 11 ----- .../components/CustomGuiTexturedRect.java | 12 +---- .../customitem/CustomItemRenderer.java | 14 +++--- .../client/renderer/customitem/ImageData.java | 45 +++++++------------ .../npcs/scripted/item/ScriptCustomItem.java | 2 - 5 files changed, 23 insertions(+), 61 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java index 29b918291..f9ed294cd 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java @@ -9,25 +9,14 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.texture.ITextureObject; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.client.resources.IResource; -import net.minecraft.util.ResourceLocation; import noppes.npcs.api.gui.ICustomGuiComponent; import noppes.npcs.client.Client; -import noppes.npcs.client.ImageDownloadAlt; import noppes.npcs.client.gui.custom.GuiCustom; import noppes.npcs.client.gui.custom.interfaces.IClickListener; -import noppes.npcs.client.renderer.ImageBufferDownloadAlt; import noppes.npcs.client.renderer.customitem.ImageData; import noppes.npcs.scripted.gui.ScriptGuiButton; import org.lwjgl.opengl.GL11; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; - public class CustomGuiButton extends GuiButton implements IClickListener { GuiCustom parent; diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java index 241a6e2f5..622c06b26 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java @@ -6,27 +6,16 @@ package noppes.npcs.client.gui.custom.components; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.client.resources.IResource; -import net.minecraft.util.ResourceLocation; import noppes.npcs.api.gui.ICustomGuiComponent; import noppes.npcs.client.Client; -import noppes.npcs.client.ImageDownloadAlt; import noppes.npcs.client.gui.custom.GuiCustom; import noppes.npcs.client.gui.custom.interfaces.IGuiComponent; -import noppes.npcs.client.renderer.ImageBufferDownloadAlt; import noppes.npcs.client.renderer.customitem.ImageData; import noppes.npcs.scripted.gui.ScriptGuiTexturedRect; import org.lwjgl.opengl.GL11; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; - public class CustomGuiTexturedRect extends Gui implements IGuiComponent { GuiCustom parent; @@ -95,6 +84,7 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent { GL11.glRotatef(this.rotation, 0.0F, 0.0F, 1.0F); GL11.glScalef(this.scale, this.scale, this.scale); + this.imageData.bindTexture(); Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.setColorOpaque_F(1, 1, 1); diff --git a/src/main/java/noppes/npcs/client/renderer/customitem/CustomItemRenderer.java b/src/main/java/noppes/npcs/client/renderer/customitem/CustomItemRenderer.java index ec0e670d2..50680a41d 100644 --- a/src/main/java/noppes/npcs/client/renderer/customitem/CustomItemRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/customitem/CustomItemRenderer.java @@ -49,15 +49,10 @@ public class CustomItemRenderer implements IItemRenderer { public void renderItem(ItemRenderType type, ItemStack itemStack, Object... data) { ScriptCustomItem scriptCustomItem = ItemScripted.GetWrapper(itemStack); - BufferedImage bufferedImage = Client.getImageData(scriptCustomItem.texture).getBufferedImage(); - if (bufferedImage != null && (scriptCustomItem.width != bufferedImage.getWidth() || scriptCustomItem.height != bufferedImage.getHeight())) { - scriptCustomItem.width = bufferedImage.getWidth(); - scriptCustomItem.height = bufferedImage.getHeight(); - scriptCustomItem.saveItemData(); - } - - if(scriptCustomItem.width < 1 || scriptCustomItem.height < 1) + ImageData imageData = Client.getImageData(scriptCustomItem.texture); + if (!imageData.imageLoaded()) { return; + } if (type == ItemRenderType.INVENTORY) { GL11.glPushMatrix(); @@ -80,7 +75,6 @@ public class CustomItemRenderer implements IItemRenderer { GL11.glRotatef(scriptCustomItem.rotationYRate * entityRenderTicks%360, 0, 1, 0); GL11.glRotatef(scriptCustomItem.rotationZRate * entityRenderTicks%360, 0, 0, 1); - GL11.glScalef(scriptCustomItem.scaleX, scriptCustomItem.scaleY, scriptCustomItem.scaleZ); GL11.glTranslatef(0.0F, bobbingY, 0.0F); int color = scriptCustomItem.getColor(); @@ -184,6 +178,7 @@ public class CustomItemRenderer implements IItemRenderer { b0 = 4; } + GL11.glScalef(scriptCustomItem.scaleX, scriptCustomItem.scaleY, scriptCustomItem.scaleZ); GL11.glTranslatef(-f7, -f8, -((f9 + f10) * (float)b0 / 2.0F)); for (int k = 0; k < b0; ++k) @@ -253,6 +248,7 @@ public class CustomItemRenderer implements IItemRenderer { for (int l = 0; l < b0; ++l) { GL11.glPushMatrix(); + GL11.glScalef(scriptCustomItem.scaleX, scriptCustomItem.scaleY, scriptCustomItem.scaleZ); if (l > 0) { diff --git a/src/main/java/noppes/npcs/client/renderer/customitem/ImageData.java b/src/main/java/noppes/npcs/client/renderer/customitem/ImageData.java index 1be88063a..2e1e69172 100644 --- a/src/main/java/noppes/npcs/client/renderer/customitem/ImageData.java +++ b/src/main/java/noppes/npcs/client/renderer/customitem/ImageData.java @@ -36,6 +36,15 @@ public class ImageData { } public boolean imageLoaded() { + if (!this.gotWidthHeight) { + try { + if (!this.isUrl) { + this.getWidthHeight(); + } else { + this.getURLWidthHeight(); + } + } catch (Exception ignored) {} + } return !this.invalid && this.location != null && this.gotWidthHeight; } @@ -70,6 +79,10 @@ public class ImageData { } private void getWidthHeight() throws IOException { + if (this.invalid) { + return; + } + InputStream inputstream = null; try { @@ -81,7 +94,7 @@ public class ImageData { this.totalHeight = bufferedimage.getHeight(); correctWidthHeight(); } catch (Exception e) { - e.printStackTrace(); + this.invalid = true; } finally { if (inputstream != null) { inputstream.close(); @@ -90,7 +103,7 @@ public class ImageData { } private void getURLWidthHeight(){ - if(this.imageDownloadAlt.getBufferedImage() != null) { + if(this.imageDownloadAlt.getBufferedImage() != null && !this.invalid) { this.gotWidthHeight = true; this.totalWidth = this.imageDownloadAlt.getBufferedImage().getWidth(); this.totalHeight = this.imageDownloadAlt.getBufferedImage().getHeight(); @@ -104,34 +117,10 @@ public class ImageData { } public int getTotalWidth() { - if (!this.gotWidthHeight) { - try { - if (!this.isUrl) { - this.getWidthHeight(); - } else { - this.getURLWidthHeight(); - } - } catch (Exception ignored) {} - if (!this.gotWidthHeight) { - return -1; - } - } - return this.totalWidth; + return this.gotWidthHeight ? this.totalWidth : -1; } public int getTotalHeight() { - if (!this.gotWidthHeight) { - try { - if (!this.isUrl) { - this.getWidthHeight(); - } else { - this.getURLWidthHeight(); - } - } catch (Exception ignored) {} - if (!this.gotWidthHeight) { - return -1; - } - } - return this.totalHeight; + return this.gotWidthHeight ? this.totalHeight : -1; } } diff --git a/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java b/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java index dbc2e0059..3ef35244f 100644 --- a/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java +++ b/src/main/java/noppes/npcs/scripted/item/ScriptCustomItem.java @@ -42,8 +42,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IS public float rotationX, rotationY, rotationZ; public float rotationXRate, rotationYRate, rotationZRate; - public int width = -1, height = -1; - public ScriptCustomItem(ItemStack item) { super(item); loadItemData(); From 0c25d7ec1ca69c4a1452c4054c720da6393a99df Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Wed, 31 May 2023 19:59:20 -0500 Subject: [PATCH 2/9] Reverted changes to saving/loading player data from previous commit to --- src/main/java/noppes/npcs/ServerEventsHandler.java | 11 ++++------- .../java/noppes/npcs/controllers/data/PlayerData.java | 2 -- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index e65f46567..b9e4570e6 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -360,13 +360,10 @@ public class ServerEventsHandler { questData.checkQuestCompletion(playerData, EnumQuestType.Item); } - @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onEntityConstructing(EntityEvent.EntityConstructing event) { - if (event.entity instanceof EntityPlayerMP) { - PlayerData data = new PlayerData(); - data.player = (EntityPlayer) event.entity; - event.entity.registerExtendedProperties("CustomNpcsData", data); - } + @SubscribeEvent + public void world(PlayerEvent.SaveToFile event){ + PlayerData data = PlayerDataController.instance.getPlayerData((EntityPlayer) event.entity); + data.save(); } @SubscribeEvent diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index 80f9c9666..ba9deab99 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -51,12 +51,10 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { @Override public void saveNBTData(NBTTagCompound nbtTagCompound) { - this.save(); } @Override public void loadNBTData(NBTTagCompound compound) { - this.load(); } public void setNBT(NBTTagCompound data){ From 0e9ddd75b645923db36b5356db968183120fc9e2 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Wed, 31 May 2023 20:21:00 -0500 Subject: [PATCH 3/9] Fixed index out of bounds error on custom GUI slot clicks. --- src/main/java/noppes/npcs/containers/ContainerCustomGui.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/noppes/npcs/containers/ContainerCustomGui.java b/src/main/java/noppes/npcs/containers/ContainerCustomGui.java index e195ee609..1432bab76 100644 --- a/src/main/java/noppes/npcs/containers/ContainerCustomGui.java +++ b/src/main/java/noppes/npcs/containers/ContainerCustomGui.java @@ -108,6 +108,11 @@ public class ContainerCustomGui extends Container { public ItemStack slotClick(int slotId, int dragType, int clickTypeIn, EntityPlayer player) { if(slotId < 0) return super.slotClick(slotId, dragType, clickTypeIn, player); + + if (slotId >= this.inventorySlots.size()) { + return null; + } + Slot mcSlot = (Slot)this.inventorySlots.get(slotId); if(!player.worldObj.isRemote && mcSlot != null) { IItemSlot slot = null; From a8a05282753b24083a4a38d80ecf82f3b4bd2077 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Wed, 31 May 2023 23:59:11 -0500 Subject: [PATCH 4/9] ScriptWorld: -Increased the accuracy of rayCastPos(). --- .../java/noppes/npcs/scripted/NpcAPI.java | 19 +- .../noppes/npcs/scripted/ScriptWorld.java | 241 ++++++++++++++++-- .../scripted/entity/ScriptLivingBase.java | 6 +- 3 files changed, 234 insertions(+), 32 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 05aea2598..264f1fbb7 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -248,10 +248,14 @@ public class NpcAPI extends AbstractNpcAPI { } public IBlock getIBlock(IWorld world, IPos pos) { - return this.getIBlock(world, pos.getX(),pos.getY(),pos.getZ()); + return pos == null ? null : this.getIBlock(world, pos.getX(),pos.getY(),pos.getZ()); } public ITileEntity getITileEntity(IWorld world, IPos pos) { + if (pos == null) { + return null; + } + TileEntity tileEntity = world.getMCWorld().getTileEntity(pos.getX(), pos.getY(),pos.getZ()); return this.getITileEntity(tileEntity); } @@ -282,11 +286,13 @@ public class NpcAPI extends AbstractNpcAPI { } public IPos[] getAllInBox(IPos from, IPos to, boolean sortByDistance) { - Iterator posIterable = BlockPos.getAllInBox(from.getMCPos(),to.getMCPos()).iterator(); ArrayList list = new ArrayList<>(); - posIterable.forEachRemaining(BlockPos -> list.add(this.getIPos(BlockPos))); - if (sortByDistance) { - list.sort(Comparator.comparingDouble(pos -> pos.distanceTo(from))); + if (from != null && to != null) { + Iterator posIterable = BlockPos.getAllInBox(from.getMCPos(),to.getMCPos()).iterator(); + posIterable.forEachRemaining(BlockPos -> list.add(this.getIPos(BlockPos))); + if (sortByDistance) { + list.sort(Comparator.comparingDouble(pos -> pos.distanceTo(from))); + } } return list.toArray(new IPos[0]); } @@ -333,6 +339,9 @@ public class NpcAPI extends AbstractNpcAPI { } public ICustomNpc spawnNPC(IWorld world, IPos pos) { + if (pos == null) { + return null; + } return this.spawnNPC(world, pos.getX(), pos.getY(), pos.getZ()); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index eddce617c..03ae89023 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -1,7 +1,9 @@ package noppes.npcs.scripted; import net.minecraft.block.Block; +import net.minecraft.block.BlockAir; import net.minecraft.block.BlockLiquid; +import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.player.EntityPlayer; @@ -15,6 +17,8 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -520,36 +524,229 @@ public class ScriptWorld implements IWorld { return this.isBreakCancelled(pos.getX(),pos.getY(),pos.getZ()); } + public MovingObjectPosition func_147447_a(Vec3 startVec, Vec3 endVec, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) + { + if (!Double.isNaN(startVec.xCoord) && !Double.isNaN(startVec.yCoord) && !Double.isNaN(startVec.zCoord)) + { + if (!Double.isNaN(endVec.xCoord) && !Double.isNaN(endVec.yCoord) && !Double.isNaN(endVec.zCoord)) + { + int endX = MathHelper.floor_double(endVec.xCoord); + int endY = MathHelper.floor_double(endVec.yCoord); + int endZ = MathHelper.floor_double(endVec.zCoord); + int l = MathHelper.floor_double(startVec.xCoord); + int i1 = MathHelper.floor_double(startVec.yCoord); + int j1 = MathHelper.floor_double(startVec.zCoord); + Block block = this.world.getBlock(l, i1, j1); + int k1 = this.world.getBlockMetadata(l, i1, j1); + + if (block.canCollideCheck(k1, false)) + { + MovingObjectPosition movingobjectposition = block.collisionRayTrace(this.world, l, i1, j1, startVec, endVec); + + if (movingobjectposition != null) + { + return movingobjectposition; + } + } + + k1 = 200; + + while (k1-- >= 0) + { + if (Double.isNaN(startVec.xCoord) || Double.isNaN(startVec.yCoord) || Double.isNaN(startVec.zCoord)) + { + return null; + } + + if (l == endX && i1 == endY && j1 == endZ) + { + return null; + } + + boolean flag6 = true; + boolean flag3 = true; + boolean flag4 = true; + double d0 = 999.0D; + double d1 = 999.0D; + double d2 = 999.0D; + + if (endX > l) + { + d0 = (double)l + 1.0D; + } + else if (endX < l) + { + d0 = (double)l + 0.0D; + } + else + { + flag6 = false; + } + + if (endY > i1) + { + d1 = (double)i1 + 1.0D; + } + else if (endY < i1) + { + d1 = (double)i1 + 0.0D; + } + else + { + flag3 = false; + } + + if (endZ > j1) + { + d2 = (double)j1 + 1.0D; + } + else if (endZ < j1) + { + d2 = (double)j1 + 0.0D; + } + else + { + flag4 = false; + } + + double d3 = 999.0D; + double d4 = 999.0D; + double d5 = 999.0D; + double d6 = endVec.xCoord - startVec.xCoord; + double d7 = endVec.yCoord - startVec.yCoord; + double d8 = endVec.zCoord - startVec.zCoord; + + if (flag6) + { + d3 = (d0 - startVec.xCoord) / d6; + } + + if (flag3) + { + d4 = (d1 - startVec.yCoord) / d7; + } + + if (flag4) + { + d5 = (d2 - startVec.zCoord) / d8; + } + + byte b0; + + if (d3 < d4 && d3 < d5) + { + if (endX > l) + { + b0 = 4; + } + else + { + b0 = 5; + } + + startVec.xCoord = d0; + startVec.yCoord += d7 * d3; + startVec.zCoord += d8 * d3; + } + else if (d4 < d5) + { + if (endY > i1) + { + b0 = 0; + } + else + { + b0 = 1; + } + + startVec.xCoord += d6 * d4; + startVec.yCoord = d1; + startVec.zCoord += d8 * d4; + } + else + { + if (endZ > j1) + { + b0 = 2; + } + else + { + b0 = 3; + } + + startVec.xCoord += d6 * d5; + startVec.yCoord += d7 * d5; + startVec.zCoord = d2; + } + + Vec3 vec32 = Vec3.createVectorHelper(startVec.xCoord, startVec.yCoord, startVec.zCoord); + l = (int)(vec32.xCoord = (double)MathHelper.floor_double(startVec.xCoord)); + + if (b0 == 5) + { + --l; + ++vec32.xCoord; + } + + i1 = (int)(vec32.yCoord = (double)MathHelper.floor_double(startVec.yCoord)); + + if (b0 == 1) + { + --i1; + ++vec32.yCoord; + } + + j1 = (int)(vec32.zCoord = (double)MathHelper.floor_double(startVec.zCoord)); + + if (b0 == 3) + { + --j1; + ++vec32.zCoord; + } + + Block block1 = this.world.getBlock(l, i1, j1); + int l1 = this.world.getBlockMetadata(l, i1, j1); + + MovingObjectPosition movingobjectposition1 = block1.collisionRayTrace(this.world, l, i1, j1, startVec, endVec); + if (movingobjectposition1 != null) + { + if (block1.canCollideCheck(l1, false) && stopOnBlock || + block1.getMaterial().isLiquid() && stopOnLiquid || + !(block1 instanceof BlockAir) && block1.getCollisionBoundingBoxFromPool(this.world,l,i1,j1) == null && !stopOnCollision) + { + return movingobjectposition1; + } + } + } + + return null; + } + else + { + return null; + } + } + else + { + return null; + } + } + public IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) { if (startPos.length != 3 || lookVector.length != 3) { return null; } - IPos pos; - Vec3 currentPos = Vec3.createVectorHelper(startPos[0], startPos[1], startPos[2]); int rep = 0; + Vec3 startVec = Vec3.createVectorHelper(startPos[0], startPos[1], startPos[2]); + Vec3 endVec = startVec.addVector(lookVector[0]*maxDistance,lookVector[1]*maxDistance,lookVector[2]*maxDistance); - while (rep++ < maxDistance + 10) { - currentPos = currentPos.addVector(lookVector[0], lookVector[1], lookVector[2]); - pos = NpcAPI.Instance().getIPos(currentPos.xCoord, currentPos.yCoord, currentPos.zCoord); - - IBlock block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); - if (block != null && stopOnBlock) { - if ((!stopOnLiquid || block.getMCBlock() instanceof BlockLiquid) - && (!stopOnCollision || block.canCollide())) - return pos; - } - - double distance = Math.pow( - Math.pow(currentPos.xCoord-startPos[0],2) - +Math.pow(currentPos.yCoord-startPos[1],2) - +Math.pow(currentPos.zCoord-startPos[2],2) - , 0.5); - if (distance > maxDistance) { - return pos; - } + IPos endPos = NpcAPI.Instance().getIPos(endVec.xCoord,endVec.yCoord,endVec.zCoord); + if (!stopOnBlock && !stopOnLiquid && !stopOnCollision) { + return endPos; } - return null; + MovingObjectPosition mob = this.func_147447_a(startVec,endVec,stopOnBlock,stopOnLiquid,stopOnCollision); + return mob != null ? NpcAPI.Instance().getIPos(mob.blockX,mob.blockY,mob.blockZ) : endPos; } public IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance) { diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index 88c877018..484fa7d6a 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -162,11 +162,7 @@ public class ScriptLivingBase extends ScriptEntity Date: Thu, 1 Jun 2023 00:36:40 -0500 Subject: [PATCH 5/9] ScriptLivingBase: -Slightly improved getLookingAtPos() results --- src/api | 2 +- src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api b/src/api index f07e76b56..8c61d07b1 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit f07e76b567671a5f8bfc12d0160cfe857aefea29 +Subproject commit 8c61d07b10d15c4b6a6107d581f16b885cba70da diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index 484fa7d6a..0a7b14709 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -172,7 +172,7 @@ public class ScriptLivingBase extends ScriptEntity Date: Thu, 1 Jun 2023 00:49:33 -0500 Subject: [PATCH 6/9] ScriptLivingBase: -Reverted previous change, not worth the inaccuracies it would cause on servers --- src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index 0a7b14709..561f05ed6 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -172,7 +172,7 @@ public class ScriptLivingBase extends ScriptEntity Date: Thu, 1 Jun 2023 12:29:16 -0400 Subject: [PATCH 7/9] Save NPC Quick Tags properly on Close --- .../java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java | 4 ++++ .../java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java | 8 +------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java index ad5cc9795..c6d0d6e1d 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java @@ -172,6 +172,10 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall @Override public void subGuiClosed(SubGuiInterface subgui) { + if(subgui instanceof SubGuiClonerNPCTags){ + close(); + return; + } initGui(); } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java b/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java index 3a7b608dd..52e69763d 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java @@ -86,6 +86,7 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc tagNames.clear(); } if (guibutton.id == 66) { + save(); close(); } initGui(); @@ -154,11 +155,4 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc } return list; } - - @Override - public void close() { - save(); - super.close(); - } - } From bf78c1be0fceaa3b4c4117cd232051e2e506d421 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 1 Jun 2023 12:29:28 -0400 Subject: [PATCH 8/9] Display Selected Wand Tags in Cloner --- .../client/gui/SubGuiClonerQuickTags.java | 41 ++++++++++++++----- .../assets/customnpcs/lang/en_US.lang | 2 +- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java b/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java index fc9331318..b9e99a88e 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java @@ -1,14 +1,9 @@ package noppes.npcs.client.gui; import net.minecraft.client.gui.GuiButton; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraft.util.StatCollector; -import noppes.npcs.client.Client; import noppes.npcs.client.gui.util.*; -import noppes.npcs.constants.EnumPacketServer; -import noppes.npcs.controllers.data.Tag; -import noppes.npcs.controllers.data.TagMap; +import org.lwjgl.Sys; import java.util.*; @@ -16,6 +11,7 @@ public class SubGuiClonerQuickTags extends SubGuiInterface implements IScrollDat { public GuiNpcMobSpawnerAdd parent; public GuiCustomScroll quickScroll = new GuiCustomScroll(this,0); + public GuiCustomScroll selectedScroll = new GuiCustomScroll(this,5); private static String quickSearch = ""; public SubGuiClonerQuickTags(GuiNpcMobSpawnerAdd par){ @@ -36,35 +32,60 @@ public class SubGuiClonerQuickTags extends SubGuiInterface implements IScrollDat quickScroll.setSelectedList(GuiNpcMobSpawnerAdd.addTags); this.addScroll(quickScroll); - addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("cloner.wandtags"), guiLeft + 7, guiTop + 7)); + addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("cloner.wandTags"), guiLeft + 7, guiTop + 7)); addScroll(quickScroll); addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 4, guiTop + 190, 140, 20, quickSearch)); addButton(new GuiNpcButton(10, guiLeft + 150, guiTop + 20, 120, 20, "gui.selectAll")); addButton(new GuiNpcButton(11, guiLeft + 150, guiTop + 43, 120, 20, "gui.deselectAll")); - addButton(new GuiNpcButton(66, guiLeft + 240, guiTop + 175, 60, 20, "gui.done")); + selectedScroll.clear(); + selectedScroll.setSize(145, 103); + selectedScroll.guiLeft = guiLeft + 150; + selectedScroll.guiTop = guiTop + 82; + selectedScroll.setUnselectable(); + this.addScroll(selectedScroll); - getSelected(); + addLabel(new GuiNpcLabel(3, StatCollector.translateToLocal("tags.selectedTags"), guiLeft + 153, guiTop + 68)); + addScroll(selectedScroll); + + addButton(new GuiNpcButton(66, guiLeft + 240, guiTop + 190, 60, 20, "gui.done")); + + setSelected(); + refreshSelected(); } protected void actionPerformed(GuiButton guibutton){ if (guibutton.id == 10) { GuiNpcMobSpawnerAdd.addTags = new HashSet<>(parent.allTags); quickScroll.setSelectedList(GuiNpcMobSpawnerAdd.addTags); + refreshSelected(); } if (guibutton.id == 11) { GuiNpcMobSpawnerAdd.addTags = new HashSet<>(); quickScroll.setSelectedList(GuiNpcMobSpawnerAdd.addTags); + refreshSelected(); } if (guibutton.id == 66) { close(); } } - public void getSelected(){ + @Override + public void mouseClicked(int i, int j, int k) + { + super.mouseClicked(i, j, k); + refreshSelected(); + } + + public void setSelected(){ quickScroll.setList(getQuickTags()); } + public void refreshSelected(){ + List sortedList = new ArrayList<>(new TreeSet<>(GuiNpcMobSpawnerAdd.addTags)); + selectedScroll.setList(sortedList); + } + @Override public void keyTyped(char c, int i) { diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 4e3e8a6ff..bd2a7017d 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -410,13 +410,13 @@ cloner.tagFilters=Tag Filters cloner.tagVisibility=Tag Visibility cloner.wandTags=Wand Tags cloner.npcTags=NPC Tags +cloner.selectedTags=Selected Tags cloner.order=Sort Order cloner.ascending=Ascending cloner.descending=Descending cloner.type=Sort Type cloner.name=Name cloner.date=Date -cloner.wandtags=Wand Tags cloner.wandtagsapplied=Wand Tags will be applied tags.allTags=All Tags From f213cab2610167c9289a97bb1dd86c72e186f4e7 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 1 Jun 2023 16:10:38 -0400 Subject: [PATCH 9/9] Add Search to Manage Banks --- .../npcs/client/gui/SubGuiClonerNPCTags.java | 2 +- .../client/gui/global/GuiNPCManageBanks.java | 34 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java b/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java index 52e69763d..b1c0634c8 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java @@ -30,8 +30,8 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc setBackground("menubg.png"); xSize = 305; ySize = 220; - closeOnEsc = false; this.npc = npc; + closeOnEsc = false; } public void initGui() diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageBanks.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageBanks.java index c66fbc557..261480fad 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageBanks.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageBanks.java @@ -10,7 +10,9 @@ import noppes.npcs.containers.ContainerManageBanks; import noppes.npcs.controllers.data.Bank; import noppes.npcs.entity.EntityNPCInterface; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Vector; public class GuiNPCManageBanks extends GuiContainerNPCInterface2 implements IScrollData,ICustomScrollListener,ITextfieldListener, IGuiData @@ -20,6 +22,7 @@ public class GuiNPCManageBanks extends GuiContainerNPCInterface2 implements IScr private ContainerManageBanks container; private Bank bank = new Bank(); private String selected = null; + private String search = ""; public GuiNPCManageBanks(EntityNPCInterface npc,ContainerManageBanks container) { @@ -61,6 +64,8 @@ public class GuiNPCManageBanks extends GuiContainerNPCInterface2 implements IScr addTextField(new GuiNpcTextField(2,this, this.fontRendererObj, guiLeft+10, guiTop + 110, 16, 16, "")); getTextField(2).integersOnly = true; getTextField(2).setMaxStringLength(1); + + addTextField(new GuiNpcTextField(33, this, fontRendererObj, guiLeft + 174, guiTop + 8 + 3 + 180, 160, 20, search)); } public void drawScreen(int x, int y, float f) @@ -137,12 +142,37 @@ public class GuiNPCManageBanks extends GuiContainerNPCInterface2 implements IScr } setSelected(bank.name); } - + + public void keyTyped(char c, int i) + { + super.keyTyped(c, i); + if(getTextField(33) != null){ + if(getTextField(33).isFocused()){ + if(search.equals(getTextField(33).getText())) + return; + search = getTextField(33).getText().toLowerCase(); + scroll.setList(getSearchList()); + } + } + } + + private List getSearchList(){ + if(search.isEmpty()){ + return new ArrayList(this.data.keySet()); + } + List list = new ArrayList(); + for(String name : this.data.keySet()){ + if(name.toLowerCase().contains(search)) + list.add(name); + } + return list; + } + @Override public void setData(Vector list, HashMap data) { String name = scroll.getSelected(); this.data = data; - scroll.setList(list); + scroll.setList(getSearchList()); if(name != null) scroll.setSelected(name);