2013-08-27 00:57:08 +02:00
|
|
|
package mekanism.client.render.item;
|
2012-11-28 16:33:34 +01:00
|
|
|
|
2013-12-01 06:03:40 +01:00
|
|
|
import mekanism.api.EnumColor;
|
2013-11-03 02:19:01 +01:00
|
|
|
import mekanism.api.energy.IEnergizedItem;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.client.ClientProxy;
|
2013-11-03 02:19:01 +01:00
|
|
|
import mekanism.client.MekanismClient;
|
2013-11-03 02:07:55 +01:00
|
|
|
import mekanism.client.model.ModelEnergyCube;
|
2013-11-03 02:19:01 +01:00
|
|
|
import mekanism.client.model.ModelEnergyCube.ModelEnergyCore;
|
2013-11-03 17:38:36 +01:00
|
|
|
import mekanism.client.model.ModelGasTank;
|
|
|
|
import mekanism.client.model.ModelObsidianTNT;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.client.model.ModelRobit;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.client.render.MekanismRenderer;
|
2013-11-13 04:43:06 +01:00
|
|
|
import mekanism.client.render.tileentity.RenderBin;
|
2013-04-13 02:25:21 +02:00
|
|
|
import mekanism.common.IElectricChest;
|
2013-05-20 00:43:01 +02:00
|
|
|
import mekanism.common.IEnergyCube;
|
2012-11-28 16:33:34 +01:00
|
|
|
import mekanism.common.Mekanism;
|
2013-04-01 01:12:10 +02:00
|
|
|
import mekanism.common.Tier.EnergyCubeTier;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.common.block.BlockMachine.MachineType;
|
2013-11-13 04:43:06 +01:00
|
|
|
import mekanism.common.inventory.InventoryBin;
|
|
|
|
import mekanism.common.item.ItemBlockBasic;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.common.item.ItemBlockMachine;
|
|
|
|
import mekanism.common.item.ItemRobit;
|
2013-10-13 18:31:26 +02:00
|
|
|
import mekanism.common.item.ItemWalkieTalkie;
|
2013-11-13 04:43:06 +01:00
|
|
|
import mekanism.common.tileentity.TileEntityBin;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.common.util.MekanismUtils;
|
|
|
|
import mekanism.common.util.MekanismUtils.ResourceType;
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.block.Block;
|
2013-05-07 01:42:03 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2013-11-13 04:43:06 +01:00
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
2013-04-20 00:03:59 +02:00
|
|
|
import net.minecraft.client.model.ModelChest;
|
2013-11-13 04:43:06 +01:00
|
|
|
import net.minecraft.client.renderer.OpenGlHelper;
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
2013-11-13 04:43:06 +01:00
|
|
|
import net.minecraft.client.renderer.entity.RenderItem;
|
|
|
|
import net.minecraft.client.renderer.entity.RenderManager;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureManager;
|
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2013-11-13 20:59:11 +01:00
|
|
|
import net.minecraft.item.ItemBlock;
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2012-11-28 16:33:34 +01:00
|
|
|
import net.minecraftforge.client.IItemRenderer;
|
2013-11-13 04:43:06 +01:00
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
2012-11-28 16:33:34 +01:00
|
|
|
|
2012-12-20 22:53:39 +01:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2013-04-20 00:03:59 +02:00
|
|
|
import cpw.mods.fml.client.registry.RenderingRegistry;
|
2013-04-13 16:33:37 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2012-11-28 16:33:34 +01:00
|
|
|
public class ItemRenderingHandler implements IItemRenderer
|
|
|
|
{
|
2013-05-20 00:43:01 +02:00
|
|
|
public ModelRobit robit = new ModelRobit();
|
2013-07-19 20:59:01 +02:00
|
|
|
public ModelChest electricChest = new ModelChest();
|
2013-11-03 02:07:55 +01:00
|
|
|
public ModelEnergyCube energyCube = new ModelEnergyCube();
|
2013-11-03 02:19:01 +01:00
|
|
|
public ModelEnergyCore energyCore = new ModelEnergyCore();
|
2013-11-03 17:38:36 +01:00
|
|
|
public ModelGasTank gasTank = new ModelGasTank();
|
|
|
|
public ModelObsidianTNT obsidianTNT = new ModelObsidianTNT();
|
2013-05-20 00:43:01 +02:00
|
|
|
|
2013-11-13 04:43:06 +01:00
|
|
|
public RenderBin binRenderer = (RenderBin)TileEntityRenderer.instance.specialRendererMap.get(TileEntityBin.class);
|
|
|
|
private final RenderItem renderItem = (RenderItem)RenderManager.instance.getEntityClassRenderObject(EntityItem.class);
|
|
|
|
|
2012-11-28 16:33:34 +01:00
|
|
|
@Override
|
|
|
|
public boolean handleRenderType(ItemStack item, ItemRenderType type)
|
|
|
|
{
|
2013-10-13 18:31:26 +02:00
|
|
|
if(item.itemID == Mekanism.WalkieTalkie.itemID)
|
|
|
|
{
|
|
|
|
return type != ItemRenderType.INVENTORY;
|
|
|
|
}
|
|
|
|
|
2012-11-28 16:33:34 +01:00
|
|
|
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-11-13 04:43:06 +01:00
|
|
|
RenderBlocks renderBlocks = (RenderBlocks)data[0];
|
|
|
|
|
2013-05-14 17:34:26 +02:00
|
|
|
if(type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON)
|
2013-04-20 00:03:59 +02:00
|
|
|
{
|
|
|
|
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
|
|
|
}
|
|
|
|
|
2013-01-12 15:52:41 +01:00
|
|
|
if(item.getItem() instanceof IEnergyCube)
|
|
|
|
{
|
2013-03-31 00:13:59 +01:00
|
|
|
EnergyCubeTier tier = ((IEnergyCube)item.getItem()).getEnergyCubeTier(item);
|
2013-11-03 02:19:01 +01:00
|
|
|
IEnergizedItem energized = (IEnergizedItem)item.getItem();
|
2013-11-03 02:07:55 +01:00
|
|
|
Minecraft.getMinecraft().renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "EnergyCube" + tier.name + ".png"));
|
|
|
|
|
|
|
|
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
|
|
|
|
GL11.glRotatef(270F, 0.0F, -1.0F, 0.0F);
|
|
|
|
GL11.glTranslatef(0.0F, -1.0F, 0.0F);
|
|
|
|
|
|
|
|
energyCube.render(0.0625F);
|
2013-11-03 02:19:01 +01:00
|
|
|
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glTranslated(0.0, 1.0, 0.0);
|
|
|
|
Minecraft.getMinecraft().renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "EnergyCore.png"));
|
|
|
|
|
|
|
|
GL11.glShadeModel(GL11.GL_SMOOTH);
|
|
|
|
GL11.glEnable(GL11.GL_BLEND);
|
|
|
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
MekanismRenderer.glowOn();
|
|
|
|
|
|
|
|
EnumColor c = tier.color;
|
|
|
|
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glScalef(0.4F, 0.4F, 0.4F);
|
|
|
|
GL11.glColor4f(c.getColor(0), c.getColor(1), c.getColor(2), (float)(energized.getEnergy(item)/energized.getMaxEnergy(item)));
|
2013-11-13 04:43:06 +01:00
|
|
|
GL11.glTranslatef(0, (float)Math.sin(Math.toRadians((MekanismClient.ticksPassed + MekanismRenderer.getPartialTick()) * 3)) / 7, 0);
|
|
|
|
GL11.glRotatef((MekanismClient.ticksPassed + MekanismRenderer.getPartialTick()) * 4, 0, 1, 0);
|
|
|
|
GL11.glRotatef(36F + (MekanismClient.ticksPassed + MekanismRenderer.getPartialTick()) * 4, 0, 1, 1);
|
2013-11-03 02:19:01 +01:00
|
|
|
energyCore.render(0.0625F);
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
|
|
|
|
MekanismRenderer.glowOff();
|
|
|
|
|
|
|
|
GL11.glShadeModel(GL11.GL_FLAT);
|
|
|
|
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
|
|
|
GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
|
|
|
|
GL11.glDisable(GL11.GL_BLEND);
|
|
|
|
|
|
|
|
GL11.glPopMatrix();
|
2013-11-13 04:43:06 +01:00
|
|
|
}
|
|
|
|
else if(item.getItem() instanceof ItemBlockBasic && item.getItemDamage() == 6)
|
|
|
|
{
|
|
|
|
RenderingRegistry.instance().renderInventoryBlock((RenderBlocks)data[0], Block.blocksList[Mekanism.basicBlockID], item.getItemDamage(), ClientProxy.BASIC_RENDER_ID);
|
|
|
|
|
|
|
|
if(binRenderer == null || binRenderer.getFontRenderer() == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
InventoryBin inv = new InventoryBin(item);
|
|
|
|
ForgeDirection side = ForgeDirection.getOrientation(2);
|
|
|
|
|
|
|
|
String amount = "";
|
|
|
|
ItemStack itemStack = inv.getStack();
|
|
|
|
|
|
|
|
if(itemStack != null)
|
|
|
|
{
|
|
|
|
amount = Integer.toString(inv.getItemCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
|
|
|
|
|
|
|
|
if(itemStack != null)
|
|
|
|
{
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
|
2013-11-13 20:59:11 +01:00
|
|
|
if(!(itemStack.getItem() instanceof ItemBlock) || Block.blocksList[itemStack.itemID].getRenderType() != 0)
|
2013-11-13 04:43:06 +01:00
|
|
|
{
|
2013-11-13 20:59:11 +01:00
|
|
|
GL11.glRotatef(180, 0, 0, 1);
|
|
|
|
GL11.glTranslatef(-1.02F, -0.2F, 0);
|
|
|
|
|
|
|
|
if(type == ItemRenderType.INVENTORY)
|
|
|
|
{
|
|
|
|
GL11.glTranslatef(-0.45F, -0.4F, 0.0F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON || type == ItemRenderType.ENTITY)
|
|
|
|
{
|
|
|
|
GL11.glTranslatef(-0.22F, -0.2F, -0.22F);
|
2013-11-13 04:43:06 +01:00
|
|
|
}
|
|
|
|
|
2013-11-13 20:59:11 +01:00
|
|
|
GL11.glTranslated(0.73, 0.08, 0.44);
|
2013-11-13 04:43:06 +01:00
|
|
|
GL11.glRotatef(90, 0, 1, 0);
|
|
|
|
|
|
|
|
float scale = 0.03125F;
|
|
|
|
float scaler = 0.9F;
|
|
|
|
|
|
|
|
GL11.glScalef(scale*scaler, scale*scaler, 0);
|
|
|
|
|
|
|
|
TextureManager renderEngine = Minecraft.getMinecraft().renderEngine;
|
|
|
|
|
2013-11-14 13:48:18 +01:00
|
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
2013-11-13 20:59:11 +01:00
|
|
|
|
2013-11-14 14:12:09 +01:00
|
|
|
renderItem.renderItemAndEffectIntoGUI(binRenderer.getFontRenderer(), renderEngine, itemStack, 0, 0);
|
2013-11-13 04:43:06 +01:00
|
|
|
|
2013-11-14 13:48:18 +01:00
|
|
|
GL11.glEnable(GL11.GL_LIGHTING);
|
2013-11-13 04:43:06 +01:00
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(amount != "")
|
|
|
|
{
|
|
|
|
float maxScale = 0.02F;
|
|
|
|
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
|
|
|
|
GL11.glPolygonOffset(-10, -10);
|
|
|
|
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
|
|
|
|
|
|
|
|
float displayWidth = 1 - (2 / 16);
|
|
|
|
float displayHeight = 1 - (2 / 16);
|
|
|
|
GL11.glTranslatef(0, -0.31F, 0);
|
|
|
|
|
2013-11-13 20:59:11 +01:00
|
|
|
if(type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON || type == ItemRenderType.ENTITY)
|
2013-11-13 04:43:06 +01:00
|
|
|
{
|
2013-11-13 20:59:11 +01:00
|
|
|
GL11.glTranslated(-0.5, -0.4, -0.5);
|
2013-11-13 04:43:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GL11.glTranslatef(0, 0.9F, 1);
|
|
|
|
GL11.glRotatef(90, 0, 1, 0);
|
|
|
|
GL11.glRotatef(90, 1, 0, 0);
|
|
|
|
|
|
|
|
GL11.glTranslatef(displayWidth / 2, 1F, displayHeight / 2);
|
|
|
|
GL11.glRotatef(-90, 1, 0, 0);
|
|
|
|
|
|
|
|
FontRenderer fontRenderer = binRenderer.getFontRenderer();
|
|
|
|
|
|
|
|
int requiredWidth = Math.max(fontRenderer.getStringWidth(amount), 1);
|
|
|
|
int lineHeight = fontRenderer.FONT_HEIGHT + 2;
|
|
|
|
int requiredHeight = lineHeight * 1;
|
|
|
|
float scaler = 0.4F;
|
|
|
|
float scaleX = (displayWidth / requiredWidth);
|
|
|
|
float scale = scaleX * scaler;
|
|
|
|
|
|
|
|
if(maxScale > 0)
|
|
|
|
{
|
|
|
|
scale = Math.min(scale, maxScale);
|
|
|
|
}
|
|
|
|
|
|
|
|
GL11.glScalef(scale, -scale, scale);
|
|
|
|
GL11.glDepthMask(false);
|
|
|
|
|
|
|
|
int offsetX;
|
|
|
|
int offsetY;
|
|
|
|
int realHeight = (int)Math.floor(displayHeight / scale);
|
|
|
|
int realWidth = (int)Math.floor(displayWidth / scale);
|
|
|
|
|
|
|
|
offsetX = (realWidth - requiredWidth) / 2;
|
|
|
|
offsetY = (realHeight - requiredHeight) / 2;
|
|
|
|
|
|
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
|
|
|
fontRenderer.drawString("\u00a7f" + amount, offsetX - (realWidth / 2), 1 + offsetY - (realHeight / 2), 1);
|
|
|
|
GL11.glEnable(GL11.GL_LIGHTING);
|
|
|
|
GL11.glDepthMask(true);
|
|
|
|
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
|
|
|
|
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
2013-10-13 18:31:26 +02:00
|
|
|
}
|
2013-11-03 17:38:36 +01:00
|
|
|
else if(item.itemID == Mekanism.gasTankID)
|
|
|
|
{
|
|
|
|
Minecraft.getMinecraft().renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "GasTank.png"));
|
|
|
|
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
|
|
|
|
GL11.glRotatef(270F, 0.0F, -1.0F, 0.0F);
|
|
|
|
GL11.glTranslatef(0.0F, -1.0F, 0.0F);
|
|
|
|
gasTank.render(0.0625F);
|
|
|
|
}
|
|
|
|
else if(item.itemID == Mekanism.obsidianTNTID)
|
|
|
|
{
|
|
|
|
Minecraft.getMinecraft().renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "ObsidianTNT.png"));
|
|
|
|
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
|
|
|
|
GL11.glRotatef(180F, 0.0F, -1.0F, 0.0F);
|
|
|
|
GL11.glTranslatef(0.0F, -1.0F, 0.0F);
|
|
|
|
obsidianTNT.render(0.0625F);
|
|
|
|
}
|
2013-10-13 18:31:26 +02:00
|
|
|
else if(item.getItem() instanceof ItemWalkieTalkie)
|
|
|
|
{
|
2013-10-14 22:13:32 +02:00
|
|
|
if(((ItemWalkieTalkie)item.getItem()).getOn(item))
|
|
|
|
{
|
|
|
|
MekanismRenderer.glowOn();
|
|
|
|
}
|
|
|
|
|
2013-10-14 04:50:21 +02:00
|
|
|
MekanismRenderer.renderItem(item);
|
2013-10-14 22:13:32 +02:00
|
|
|
|
|
|
|
if(((ItemWalkieTalkie)item.getItem()).getOn(item))
|
|
|
|
{
|
|
|
|
MekanismRenderer.glowOff();
|
|
|
|
}
|
2013-01-12 15:52:41 +01:00
|
|
|
}
|
2013-11-27 22:17:10 +01:00
|
|
|
else if(MachineType.get(item) == MachineType.ELECTRIC_CHEST)
|
2013-04-20 00:03:59 +02:00
|
|
|
{
|
|
|
|
IElectricChest chest = (IElectricChest)item.getItem();
|
|
|
|
|
|
|
|
GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
|
|
|
|
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
|
|
|
|
GL11.glTranslatef(0, 1.0F, 1.0F);
|
|
|
|
GL11.glScalef(1.0F, -1F, -1F);
|
2013-07-20 18:10:14 +02:00
|
|
|
|
2013-09-28 03:59:47 +02:00
|
|
|
Minecraft.getMinecraft().renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "ElectricChest.png"));
|
2013-04-20 00:03:59 +02:00
|
|
|
|
2013-11-13 04:43:06 +01:00
|
|
|
float lidangle = chest.getPrevLidAngle(item) + (chest.getLidAngle(item) - chest.getPrevLidAngle(item)) * MekanismRenderer.getPartialTick();
|
2013-04-20 00:03:59 +02:00
|
|
|
lidangle = 1.0F - lidangle;
|
|
|
|
lidangle = 1.0F - lidangle * lidangle * lidangle;
|
|
|
|
electricChest.chestLid.rotateAngleX = -((lidangle * 3.141593F) / 2.0F);
|
|
|
|
|
|
|
|
electricChest.renderAll();
|
|
|
|
}
|
2013-05-20 00:43:01 +02:00
|
|
|
else if(item.getItem() instanceof ItemRobit)
|
|
|
|
{
|
|
|
|
GL11.glRotatef(180, 0.0F, 0.0F, 1.0F);
|
|
|
|
GL11.glRotatef(90, 0.0F, -1.0F, 0.0F);
|
|
|
|
GL11.glTranslatef(0.0F, -1.5F, 0.0F);
|
2013-10-13 18:31:26 +02:00
|
|
|
Minecraft.getMinecraft().renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "Robit.png"));
|
2013-05-20 00:43:01 +02:00
|
|
|
robit.render(0.08F);
|
|
|
|
}
|
2013-04-20 00:03:59 +02:00
|
|
|
else {
|
2013-11-13 04:43:06 +01:00
|
|
|
if(item.getItem() instanceof ItemBlockMachine)
|
|
|
|
{
|
2013-11-15 20:59:26 +01:00
|
|
|
RenderingRegistry.instance().renderInventoryBlock((RenderBlocks)data[0], Block.blocksList[item.itemID], item.getItemDamage(), ClientProxy.MACHINE_RENDER_ID);
|
2013-11-13 04:43:06 +01:00
|
|
|
}
|
|
|
|
else if(item.getItem() instanceof ItemBlockBasic)
|
|
|
|
{
|
2013-11-15 20:59:26 +01:00
|
|
|
RenderingRegistry.instance().renderInventoryBlock((RenderBlocks)data[0], Block.blocksList[item.itemID], item.getItemDamage(), ClientProxy.BASIC_RENDER_ID);
|
2013-11-13 04:43:06 +01:00
|
|
|
}
|
2013-04-20 00:03:59 +02:00
|
|
|
}
|
2012-11-28 16:33:34 +01:00
|
|
|
}
|
|
|
|
}
|