Fixed entity custom item rendering, and rendering of textures for custom GUI buttons and rectangles.

This commit is contained in:
Luis C.M committed 2023-05-31 18:55:06 -05:00
1 parent 895d20335f
commit 7000b525f3
5 files changed
+23 -61

No files matched your search

@@ -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;
@@ -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);
@@ -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)
{
@@ -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;
}
}
@@ -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();