Fixed URL support for scripted items, weird 3d visibility bug still present that needs to be fixed.

This commit is contained in:
Luis C.M committed 2023-03-19 02:04:47 -05:00
1 parent 7fdfd14174
commit 39a40c9603
6 files changed
+73 -50

No files matched your search

@@ -8,6 +8,7 @@ import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
import noppes.npcs.client.gui.OverlayQuestTracking;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.renderer.customitem.ItemImageData;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.data.SkinOverlay;
@@ -20,6 +21,7 @@ public class Client {
public static HashMap<Integer, OverlayCustom> customOverlays = new HashMap<>();
public static HashMap<UUID, HashMap<Integer, SkinOverlay>> skinOverlays = new HashMap<>();
public static HashMap<UUID, AnimationData> playerAnimations = new HashMap<>();
private static HashMap<String, ItemImageData> imageDataCache = new HashMap<>();
public static void sendData(EnumPacketServer enu, Object... obs) {
ByteBuf buffer = Unpooled.buffer();
@@ -31,4 +33,12 @@ public class Client {
e.printStackTrace();
}
}
public static ItemImageData getImageData(String directory) {
if (!imageDataCache.containsKey(directory)) {
ItemImageData downloadData = new ItemImageData(directory);
imageDataCache.put(directory, downloadData);
}
return imageDataCache.get(directory);
}
}
@@ -53,6 +53,7 @@ import noppes.npcs.client.gui.script.GuiScriptItem;
import noppes.npcs.client.model.*;
import noppes.npcs.client.renderer.*;
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;
@@ -1,4 +1,4 @@
package noppes.npcs.client.renderer;
package noppes.npcs.client.renderer.customitem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
@@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import noppes.npcs.client.Client;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.item.ScriptCustomItem;
import org.lwjgl.opengl.GL11;
@@ -46,28 +47,13 @@ public class CustomItemRenderer implements IItemRenderer {
@Override
public void renderItem(ItemRenderType type, ItemStack itemStack, Object... data) {
InputStream inputstream = null;
ScriptCustomItem scriptCustomItem = ItemScripted.GetWrapper(itemStack);
if(scriptCustomItem.width == -1 || scriptCustomItem.height == -1) {
try {
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(ItemScripted.getLocation(scriptCustomItem.texture));
inputstream = iresource.getInputStream();
BufferedImage bufferedimage = ImageIO.read(inputstream);
scriptCustomItem.width = bufferedimage.getWidth();
scriptCustomItem.height = bufferedimage.getHeight();
scriptCustomItem.saveItemData();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (inputstream != null) {
inputstream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
BufferedImage bufferedImage = Client.getImageData(scriptCustomItem.texture).getBufferedImage();
if ((scriptCustomItem.width == -1 || scriptCustomItem.height == -1) && bufferedImage != null) {
scriptCustomItem.width = bufferedImage.getWidth();
scriptCustomItem.height = bufferedImage.getHeight();
scriptCustomItem.saveItemData();
}
if(scriptCustomItem.width == -1 || scriptCustomItem.height == -1)
@@ -150,7 +136,7 @@ public class CustomItemRenderer implements IItemRenderer {
int pass = 0;
GL11.glPushMatrix();
ResourceLocation location = ItemScripted.getLocation(scriptCustomItem.texture);
ResourceLocation location = Client.getImageData(scriptCustomItem.texture).getLocation();
Minecraft.getMinecraft().getTextureManager().bindTexture(location);
Tessellator tessellator = Tessellator.instance;
@@ -305,7 +291,7 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glDisable(GL11.GL_LIGHTING); //Forge: Make sure that render states are reset, a renderEffect can derp them up.
GL11.glEnable(GL11.GL_ALPHA_TEST);
ResourceLocation location = ItemScripted.getLocation(scriptCustomItem.texture);
ResourceLocation location = Client.getImageData(scriptCustomItem.texture).getLocation();
Minecraft.getMinecraft().getTextureManager().bindTexture(location);
renderCustomItemSlot(0,0,16,16, itemRed, itemGreen, itemBlue);
@@ -381,7 +367,7 @@ public class CustomItemRenderer implements IItemRenderer {
TextureManager texturemanager = mc.getTextureManager();
int par3 = 0;
ResourceLocation location = ItemScripted.getLocation(scriptCustomItem.texture);
ResourceLocation location = Client.getImageData(scriptCustomItem.texture).getLocation();
texturemanager.bindTexture(location);
Tessellator tessellator = Tessellator.instance;
@@ -0,0 +1,51 @@
package noppes.npcs.client.renderer.customitem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IResource;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.renderer.ImageBufferDownloadAlt;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
public class ItemImageData {
private ResourceLocation location;
private final boolean isUrl;
private ImageDownloadAlt imageDownloadAlt = null;
private BufferedImage bufferedImage = null;
public ItemImageData(String directory) {
this.location = new ResourceLocation(directory);
if (directory.startsWith("https://")) {
this.isUrl = true;
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
this.imageDownloadAlt = new ImageDownloadAlt(null, directory, new ResourceLocation("customnpcs:textures/gui/invisible.png"), new ImageBufferDownloadAlt(true, false));
texturemanager.loadTexture(location, this.imageDownloadAlt);
} else {
this.isUrl = false;
}
}
public ResourceLocation getLocation() {
return this.isUrl && this.imageDownloadAlt.getBufferedImage() == null ? null : this.location;
}
public BufferedImage getBufferedImage() {
if (this.bufferedImage == null) {
if (!this.isUrl) {
try {
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(location);
InputStream inputstream = iresource.getInputStream();
this.bufferedImage = ImageIO.read(inputstream);
} catch (IOException ignored) {}
} else {
this.bufferedImage = this.imageDownloadAlt.getBufferedImage();
}
}
return this.bufferedImage;
}
}
@@ -4,9 +4,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -21,8 +19,7 @@ import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import noppes.npcs.EventHooks;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.renderer.ImageBufferDownloadAlt;
import noppes.npcs.client.renderer.customitem.ItemImageData;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.entity.EntityItemScripted;
@@ -31,12 +28,9 @@ import noppes.npcs.scripted.event.ItemEvent;
import noppes.npcs.scripted.item.ScriptCustomItem;
import org.lwjgl.opengl.GL11;
import java.io.IOException;
import java.util.HashMap;
public class ItemScripted extends Item implements ItemRenderInterface {
private static HashMap<String, ResourceLocation> resourceCache = new HashMap<>();
public ItemScripted() {
maxStackSize = 1;
setCreativeTab(CustomItems.tab);
@@ -193,17 +187,4 @@ public class ItemScripted extends Item implements ItemRenderInterface {
public void renderOffset(ScriptCustomItem scriptCustomItem) {
GL11.glTranslatef(0.135F * scriptCustomItem.scaleX, 0.2F * scriptCustomItem.scaleY, 0.07F * scriptCustomItem.scaleZ);
}
public static ResourceLocation getLocation(String directory) {
if (!resourceCache.containsKey(directory)) {
ResourceLocation location = new ResourceLocation(directory);
if (directory.startsWith("https://")) {
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
ImageDownloadAlt imageDownloadAlt = new ImageDownloadAlt(null, directory, new ResourceLocation("customnpcs:textures/gui/invisible.png"), new ImageBufferDownloadAlt(true, false));
texturemanager.loadTexture(location, imageDownloadAlt);
}
resourceCache.put(directory, location);
}
return resourceCache.get(directory);
}
}
@@ -393,9 +393,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IS
compound.setFloat("TranslateY",this.translateY);
compound.setFloat("TranslateZ",this.translateZ);
compound.setInteger("Width", this.width);
compound.setInteger("Height", this.height);
compound.setBoolean("IsTool", this.isTool);
compound.setInteger("DigSpeed", this.digSpeed);
compound.setInteger("ArmorType", this.armorType);
@@ -432,9 +429,6 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IS
this.translateY = compound.getFloat("TranslateY");
this.translateZ = compound.getFloat("TranslateZ");
this.width = compound.getInteger("Width");
this.height = compound.getInteger("Height");
this.isTool = compound.getBoolean("IsTool");
this.digSpeed = compound.getInteger("DigSpeed");
this.armorType = compound.getInteger("ArmorType");