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] 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();