Board Thread:General Mod Discussion/@comment-32515990-20170708131745/@comment-32515990-20170801093454

Is this good? Because these "func" texts are wrong, and won't work

package com.gruntx.gruntmod;

import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.util.HashMap; import java.util.Map; import javax.imageio.ImageIO; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResourceManager; import net.minecraft.client.settings.GameSettings; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StringUtils; import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.client.IItemRenderer.ItemRenderType; import net.minecraftforge.client.IItemRenderer.ItemRendererHelper; import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11;

public class RenderLargeItem implements IItemRenderer { private static Map sizeFolders = new HashMap;

static { sizeFolders.put("large", Float.valueOf(2.0F)); sizeFolders.put("large2", Float.valueOf(3.0F)); }

private static Map, ResourceLocation> largeItemTextures = new HashMap; private final Item theItem; private final ResourceLocation largeTexture;

private static ResourceLocation createLargeItemTexture(Item item, String folder) { return createLargeItemTexture(item, "", folder); }

private static ResourceLocation createLargeItemTexture(Item item, String extra, String folder) { String prefix = "lotr:"; String itemName = item.func_77658_a; itemName = itemName.substring(itemName.indexOf(prefix) + prefix.length); String s = prefix + "textures/items/" + folder + "/" + itemName; if (!StringUtils.func_151246_b(extra)) { s = s + "_" + extra; } s = s + ".png"; return new ResourceLocation(s); }

public static ResourceLocation getOrCreateLargeItemTexture(Item item, String folder) { return getOrCreateLargeItemTexture(item, "", folder); }

public static ResourceLocation getOrCreateLargeItemTexture(Item item, String extra, String folder) { if (StringUtils.func_151246_b(extra)) { extra = ""; }

Pair key = Pair.of(item, extra); ResourceLocation texture = (ResourceLocation)largeItemTextures.get(key); if (texture == null) { texture = createLargeItemTexture(item, extra, folder); largeItemTextures.put(key, texture); } return texture; }

public static RenderLargeItem getLargeIconSize(Item item) { for (String folder : sizeFolders.keySet) { float iconScale = ((Float)sizeFolders.get(folder)).floatValue; try { ResourceLocation resLoc = createLargeItemTexture(item, folder); IResource res = Minecraft.func_71410_x.func_110442_L.func_110536_a(resLoc); if (res != null) { try { InputStream is = res.func_110527_b; BufferedImage img = ImageIO.read(ImageIO.createImageInputStream(is)); if (img != null) { int width = img.getWidth; int height = img.getHeight; if (width == height) { return new RenderLargeItem(item, resLoc, folder, iconScale, width); }

System.out.println("LOTR: Large item texture " + item.func_77658_a + " width =/= height!"); }

} catch (IOException e) { System.out.println("LOTR: Error loading large item texture"); e.printStackTrace; } } } catch (IOException localIOException1) {} }

return null; }

private final String folderName;

private final float largeIconScale;

private final int largeIconSize; public RenderLargeItem(Item item, ResourceLocation res, String dir, float f, int i) { theItem = item; largeTexture = res; folderName = dir; largeIconScale = f; largeIconSize = i; }

private ResourceLocation getSubtypeTexture(String extra) { return getOrCreateLargeItemTexture(theItem, extra, folderName); }

private void doTransformations { GL11.glTranslatef(-(largeIconScale - 1.0F) / 2.0F, -(largeIconScale - 1.0F) / 2.0F, 0.0F); GL11.glScalef(largeIconScale, largeIconScale, 1.0F); }

public void renderLargeItem { renderLargeItem(null); }

public void renderLargeItem(String extra) { doTransformations; ResourceLocation res = extra == null ? largeTexture : getSubtypeTexture(extra); Minecraft.func_71410_x.func_110434_K.func_110577_a(res); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); Tessellator tessellator = Tessellator.field_78398_a; ItemRenderer.func_78439_a(tessellator, 1.0F, 0.0F, 0.0F, 1.0F, largeIconSize, largeIconSize, 0.0625F); }

public boolean handleRenderType(ItemStack itemstack, IItemRenderer.ItemRenderType type) { return (type == IItemRenderer.ItemRenderType.EQUIPPED) || (type == IItemRenderer.ItemRenderType.EQUIPPED_FIRST_PERSON); }

public boolean shouldUseRenderHelper(IItemRenderer.ItemRenderType type, ItemStack itemstack, IItemRenderer.ItemRendererHelper helper) { return false; }

public void renderItem(IItemRenderer.ItemRenderType type, ItemStack itemstack, Object... data) { GL11.glPushMatrix;

Entity holder = (Entity)data[1]; boolean isFirstPerson = (holder == func_71410_xfield_71439_g) && (func_71410_xfield_71474_y.field_74320_O == 0);

Item item = itemstack.func_77973_b; }

}