2012-11-28 16:33:34 +01:00
|
|
|
package mekanism.client;
|
|
|
|
|
|
|
|
import mekanism.api.IEnergyCube;
|
2012-12-19 21:23:55 +01:00
|
|
|
import mekanism.api.Tier.EnergyCubeTier;
|
2012-11-28 16:33:34 +01:00
|
|
|
import mekanism.common.Mekanism;
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2012-11-28 16:33:34 +01:00
|
|
|
import net.minecraftforge.client.ForgeHooksClient;
|
|
|
|
import net.minecraftforge.client.IItemRenderer;
|
|
|
|
|
2012-12-20 22:53:39 +01:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2012-11-28 16:33:34 +01:00
|
|
|
public class ItemRenderingHandler implements IItemRenderer
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean handleRenderType(ItemStack item, ItemRenderType type)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
|
|
|
|
{
|
2013-01-12 15:52:41 +01:00
|
|
|
if(item.getItem() instanceof IEnergyCube)
|
|
|
|
{
|
|
|
|
EnergyCubeTier tier = ((IEnergyCube)item.getItem()).getTier(item);
|
|
|
|
|
|
|
|
ForgeHooksClient.bindTexture(item.getItem().getTextureFile(), 0);
|
|
|
|
|
|
|
|
if(type == ItemRenderType.EQUIPPED)
|
|
|
|
{
|
|
|
|
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
|
|
|
}
|
|
|
|
|
2013-01-21 02:15:59 +01:00
|
|
|
renderItem((RenderBlocks)data[0], tier == EnergyCubeTier.BASIC ? 0 : (tier == EnergyCubeTier.ADVANCED ? 1 : (tier == EnergyCubeTier.ELITE ? 2 : 0)));
|
2013-01-12 15:52:41 +01:00
|
|
|
}
|
2012-11-28 16:33:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleaned-up snip of RenderBlocks.renderBlockAsItem() -- used for rendering an item as an entity,
|
|
|
|
* in a player's inventory, and in a player's hand.
|
|
|
|
* @param renderer - RenderBlocks renderer to render the item with
|
|
|
|
* @param metadata - block/item metadata
|
|
|
|
* @param block - block to render
|
|
|
|
*/
|
|
|
|
public void renderItem(RenderBlocks renderer, int metadata)
|
|
|
|
{
|
|
|
|
Block block = Block.blocksList[Mekanism.energyCubeID];
|
2013-01-21 02:15:59 +01:00
|
|
|
renderer.setRenderBoundsFromBlock(block);
|
2012-11-28 16:33:34 +01:00
|
|
|
block.setBlockBoundsForItemRender();
|
|
|
|
|
|
|
|
if (renderer.useInventoryTint)
|
|
|
|
{
|
|
|
|
int renderColor = block.getRenderColor(metadata);
|
|
|
|
float red = (float)(renderColor >> 16 & 255) / 255.0F;
|
|
|
|
float green = (float)(renderColor >> 8 & 255) / 255.0F;
|
|
|
|
float blue = (float)(renderColor & 255) / 255.0F;
|
|
|
|
GL11.glColor4f(red, green, blue, 1.0F);
|
|
|
|
}
|
|
|
|
|
|
|
|
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
|
|
|
|
Tessellator tessellator = Tessellator.instance;
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
tessellator.setNormal(0.0F, -1.0F, 0.0F);
|
|
|
|
renderer.renderBottomFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(0, metadata));
|
|
|
|
tessellator.draw();
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
tessellator.setNormal(0.0F, 1.0F, 0.0F);
|
|
|
|
renderer.renderTopFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(1, metadata));
|
|
|
|
tessellator.draw();
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
tessellator.setNormal(0.0F, 0.0F, -1.0F);
|
|
|
|
renderer.renderEastFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(2, metadata));
|
|
|
|
tessellator.draw();
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
tessellator.setNormal(0.0F, 0.0F, 1.0F);
|
|
|
|
renderer.renderWestFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(3, metadata));
|
|
|
|
tessellator.draw();
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
tessellator.setNormal(-1.0F, 0.0F, 0.0F);
|
|
|
|
renderer.renderNorthFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(4, metadata));
|
|
|
|
tessellator.draw();
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
tessellator.setNormal(1.0F, 0.0F, 0.0F);
|
|
|
|
renderer.renderSouthFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(5, metadata));
|
|
|
|
tessellator.draw();
|
|
|
|
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
|
|
|
}
|
|
|
|
}
|