2014-06-04 21:44:48 -08:00
|
|
|
package tconstruct.util;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
2014-06-06 19:46:05 -08:00
|
|
|
|
2014-06-04 21:44:48 -08:00
|
|
|
import net.minecraft.block.Block;
|
2014-06-06 19:46:05 -08:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
|
import net.minecraft.client.renderer.texture.TextureMap;
|
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2014-06-04 21:44:48 -08:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-06-06 19:46:05 -08:00
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
|
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
2014-08-04 19:29:38 -03:00
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
2014-06-04 21:44:48 -08:00
|
|
|
import tconstruct.TConstruct;
|
|
|
|
|
|
|
|
|
|
public class ItemHelper
|
|
|
|
|
{
|
|
|
|
|
public static Object getStaticItem (String name, String classPackage)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Class clazz = Class.forName(classPackage);
|
|
|
|
|
Field field = clazz.getDeclaredField(name);
|
|
|
|
|
Object ret = field.get(null);
|
|
|
|
|
if (ret != null && (ret instanceof ItemStack || ret instanceof Item))
|
|
|
|
|
return ret;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
TConstruct.logger.warn("Could not find " + name + "from " + classPackage);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 19:46:05 -08:00
|
|
|
public static void addDrops (LivingDropsEvent event, ItemStack dropStack)
|
|
|
|
|
{
|
|
|
|
|
EntityItem entityitem = new EntityItem(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, dropStack);
|
|
|
|
|
entityitem.delayBeforeCanPickup = 10;
|
|
|
|
|
event.drops.add(entityitem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void renderStandardInvBlock (RenderBlocks renderblocks, Block block, int meta)
|
|
|
|
|
{
|
|
|
|
|
Tessellator tessellator = Tessellator.instance;
|
|
|
|
|
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(0.0F, -1F, 0.0F);
|
|
|
|
|
renderblocks.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(0, meta)));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(0.0F, 1.0F, 0.0F);
|
|
|
|
|
renderblocks.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(1, meta)));// block.getIcon(1, meta));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(0.0F, 0.0F, -1F);
|
|
|
|
|
renderblocks.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(2, meta)));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(0.0F, 0.0F, 1.0F);
|
|
|
|
|
renderblocks.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(3, meta)));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(-1F, 0.0F, 0.0F);
|
|
|
|
|
renderblocks.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(4, meta)));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(1.0F, 0.0F, 0.0F);
|
|
|
|
|
renderblocks.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(5, meta)));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void renderInvBlockFace (RenderBlocks renderblocks, Block block, int meta)
|
|
|
|
|
{
|
|
|
|
|
Tessellator tessellator = Tessellator.instance;
|
|
|
|
|
GL11.glScalef(2f, 2f, 2f);
|
|
|
|
|
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
|
|
|
|
|
GL11.glRotatef(45, 0, 1, 0);
|
|
|
|
|
GL11.glRotatef(60, 1, 0, 0);
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(0.0F, -1F, 0.0F);
|
|
|
|
|
renderblocks.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(0, meta)));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(0.0F, 1.0F, 0.0F);
|
|
|
|
|
renderblocks.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(1, meta)));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(0.0F, 0.0F, -1F);
|
|
|
|
|
renderblocks.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(2, meta)));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(0.0F, 0.0F, 1.0F);
|
|
|
|
|
renderblocks.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(3, meta)));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(-1F, 0.0F, 0.0F);
|
|
|
|
|
renderblocks.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(4, meta)));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
|
tessellator.setNormal(1.0F, 0.0F, 0.0F);
|
|
|
|
|
renderblocks.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, ItemHelper.getIconSafe(block.getIcon(5, meta)));
|
|
|
|
|
tessellator.draw();
|
|
|
|
|
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IIcon getIconSafe (IIcon icon)
|
|
|
|
|
{
|
|
|
|
|
if (icon != null)
|
|
|
|
|
return icon;
|
|
|
|
|
return ((TextureMap) Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite("missingno");
|
|
|
|
|
}
|
2014-06-04 21:44:48 -08:00
|
|
|
}
|