mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 01:27:27 +00:00
Scripted items now support URLs
This commit is contained in:
1 parent
45217f3afc
commit
7fdfd14174
2 files changed
+27
-4
No files matched your search
@@ -51,7 +51,7 @@ public class CustomItemRenderer implements IItemRenderer {
|
||||
|
||||
if(scriptCustomItem.width == -1 || scriptCustomItem.height == -1) {
|
||||
try {
|
||||
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation(scriptCustomItem.texture));
|
||||
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(ItemScripted.getLocation(scriptCustomItem.texture));
|
||||
inputstream = iresource.getInputStream();
|
||||
BufferedImage bufferedimage = ImageIO.read(inputstream);
|
||||
scriptCustomItem.width = bufferedimage.getWidth();
|
||||
@@ -150,7 +150,7 @@ public class CustomItemRenderer implements IItemRenderer {
|
||||
int pass = 0;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
ResourceLocation location = new ResourceLocation(scriptCustomItem.texture);
|
||||
ResourceLocation location = ItemScripted.getLocation(scriptCustomItem.texture);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(location);
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
@@ -305,7 +305,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 = new ResourceLocation(scriptCustomItem.texture);
|
||||
ResourceLocation location = ItemScripted.getLocation(scriptCustomItem.texture);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(location);
|
||||
renderCustomItemSlot(0,0,16,16, itemRed, itemGreen, itemBlue);
|
||||
|
||||
@@ -381,7 +381,7 @@ public class CustomItemRenderer implements IItemRenderer {
|
||||
TextureManager texturemanager = mc.getTextureManager();
|
||||
int par3 = 0;
|
||||
|
||||
ResourceLocation location = new ResourceLocation(scriptCustomItem.texture);
|
||||
ResourceLocation location = ItemScripted.getLocation(scriptCustomItem.texture);
|
||||
texturemanager.bindTexture(location);
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
@@ -4,7 +4,9 @@ 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;
|
||||
@@ -13,11 +15,14 @@ import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
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.config.ConfigScript;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.entity.EntityItemScripted;
|
||||
@@ -26,7 +31,12 @@ 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);
|
||||
@@ -183,4 +193,17 @@ 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user