Mekanism-tilera-Edition/common/mekanism/client/render/tileentity/RenderLogisticalTransporter.java

313 lines
8.6 KiB
Java
Raw Normal View History

package mekanism.client.render.tileentity;
import java.util.HashMap;
2013-12-01 05:19:24 +01:00
import mekanism.api.Object3D;
import mekanism.client.model.ModelTransmitter;
import mekanism.client.model.ModelTransmitter.Size;
2013-10-24 02:34:33 +02:00
import mekanism.client.model.ModelTransporterBox;
2013-10-26 03:34:55 +02:00
import mekanism.client.render.MekanismRenderer;
import mekanism.client.render.MekanismRenderer.DisplayInteger;
import mekanism.client.render.MekanismRenderer.Model3D;
import mekanism.common.item.ItemConfigurator;
import mekanism.common.tileentity.TileEntityDiversionTransporter;
import mekanism.common.tileentity.TileEntityLogisticalTransporter;
2013-10-25 14:51:13 +02:00
import mekanism.common.transporter.TransporterStack;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import mekanism.common.util.TransporterUtils;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
2013-08-06 05:58:44 +02:00
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
2013-11-26 00:10:21 +01:00
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
2013-08-06 05:58:44 +02:00
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
2013-08-06 05:58:44 +02:00
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
2013-08-06 05:58:44 +02:00
public class RenderLogisticalTransporter extends TileEntitySpecialRenderer
{
private ModelTransmitter model = new ModelTransmitter(Size.LARGE);
2013-10-24 02:34:33 +02:00
private ModelTransporterBox modelBox = new ModelTransporterBox();
2013-08-06 05:58:44 +02:00
private HashMap<ForgeDirection, HashMap<Integer, DisplayInteger>> cachedOverlays = new HashMap<ForgeDirection, HashMap<Integer, DisplayInteger>>();
private Minecraft mc = Minecraft.getMinecraft();
private EntityItem entityItem = new EntityItem(null);
private RenderItem renderer = (RenderItem)RenderManager.instance.getEntityClassRenderObject(EntityItem.class);
2013-08-06 05:58:44 +02:00
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
{
renderAModelAt((TileEntityLogisticalTransporter)tileEntity, x, y, z, partialTick);
}
2013-08-06 05:58:44 +02:00
public void renderAModelAt(TileEntityLogisticalTransporter tileEntity, double x, double y, double z, float partialTick)
{
int meta = Object3D.get(tileEntity).getMetadata(tileEntity.worldObj);
if(meta == 3)
{
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "LogisticalTransporter.png"));
}
else if(meta == 4)
{
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "RestrictiveTransporter.png"));
}
2013-11-22 22:18:17 +01:00
else if(meta == 5)
{
2013-11-23 21:01:18 +01:00
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "DiversionTransporter.png"));
2013-11-22 22:18:17 +01:00
}
2013-08-06 05:58:44 +02:00
GL11.glPushMatrix();
GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
GL11.glDisable(GL11.GL_CULL_FACE);
2013-10-24 02:34:33 +02:00
if(tileEntity.color != null)
{
GL11.glColor4f(tileEntity.color.getColor(0), tileEntity.color.getColor(1), tileEntity.color.getColor(2), 1.0F);
}
2013-08-06 05:58:44 +02:00
boolean[] connectable = TransporterUtils.getConnections(tileEntity);
model.renderCenter(connectable);
for(int i = 0; i < 6; i++)
{
model.renderSide(ForgeDirection.getOrientation(i), connectable[i]);
}
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glPopMatrix();
2013-10-22 05:03:54 +02:00
entityItem.age = 0;
entityItem.hoverStart = 0;
entityItem.setPosition(tileEntity.xCoord + 0.5, tileEntity.yCoord + 0.5, tileEntity.zCoord + 0.5);
entityItem.worldObj = tileEntity.worldObj;
for(TransporterStack stack : tileEntity.transit)
{
if(stack != null)
2013-10-24 02:34:33 +02:00
{
GL11.glPushMatrix();
entityItem.setEntityItemStack(stack.itemStack);
float[] pos = TransporterUtils.getStackPosition(tileEntity, stack, partialTick*TileEntityLogisticalTransporter.SPEED);
GL11.glTranslated(x + pos[0], y + pos[1] - entityItem.yOffset, z + pos[2]);
GL11.glScalef(0.75F, 0.75F, 0.75F);
renderer.doRenderItem(entityItem, 0, 0, 0, 0, 0);
2013-10-24 02:34:33 +02:00
GL11.glPopMatrix();
if(stack.color != null)
{
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "TransporterBox.png"));
GL11.glPushMatrix();
MekanismRenderer.glowOn();
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glColor4f(stack.color.getColor(0), stack.color.getColor(1), stack.color.getColor(2), 1.0F);
2013-11-26 00:10:21 +01:00
GL11.glTranslatef((float)(x + pos[0]), (float)(y + pos[1] - entityItem.yOffset - ((stack.itemStack.getItem() instanceof ItemBlock) ? 0.1 : 0)), (float)(z + pos[2]));
modelBox.render(0.0625F);
MekanismRenderer.glowOff();
GL11.glPopMatrix();
}
2013-10-24 02:34:33 +02:00
}
}
if(meta == 5)
{
EntityPlayer player = mc.thePlayer;
World world = mc.thePlayer.worldObj;
ItemStack itemStack = player.getCurrentEquippedItem();
MovingObjectPosition pos = player.rayTrace(8.0D, 1.0F);
if(pos != null && itemStack != null && itemStack.getItem() instanceof ItemConfigurator)
{
int xPos = MathHelper.floor_double(pos.blockX);
int yPos = MathHelper.floor_double(pos.blockY);
int zPos = MathHelper.floor_double(pos.blockZ);
Object3D obj = new Object3D(xPos, yPos, zPos);
if(obj.equals(Object3D.get(tileEntity)))
{
int mode = ((TileEntityDiversionTransporter)tileEntity).modes[pos.sideHit];
ForgeDirection side = ForgeDirection.getOrientation(pos.sideHit);
push();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.8F);
bindTexture(mode == 0 ? MekanismRenderer.getItemsTexture() : MekanismRenderer.getBlocksTexture());
GL11.glTranslatef((float)x, (float)y, (float)z);
GL11.glScalef(0.5F, 0.5F, 0.5F);
2013-11-29 19:04:39 +01:00
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
int display = getOverlayDisplay(world, side, mode).display;
GL11.glCallList(display);
pop();
}
}
}
}
private void pop()
{
GL11.glPopAttrib();
MekanismRenderer.glowOff();
MekanismRenderer.blendOff();
GL11.glPopMatrix();
}
private void push()
{
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_LIGHTING);
MekanismRenderer.glowOn();
MekanismRenderer.blendOn();
}
private DisplayInteger getOverlayDisplay(World world, ForgeDirection side, int mode)
{
if(cachedOverlays.containsKey(side) && cachedOverlays.get(side).containsKey(mode))
{
return cachedOverlays.get(side).get(mode);
}
Icon icon = null;
switch(mode)
{
case 0:
icon = Item.gunpowder.getIcon(new ItemStack(Item.gunpowder), 0);
break;
case 1:
icon = Block.torchRedstoneActive.getIcon(0, 0);
break;
case 2:
icon = Block.torchRedstoneIdle.getIcon(0, 0);
break;
}
Model3D toReturn = new Model3D();
toReturn.baseBlock = Block.stone;
toReturn.setTexture(icon);
DisplayInteger display = new DisplayInteger();
if(cachedOverlays.containsKey(side))
{
cachedOverlays.get(side).put(mode, display);
}
else {
HashMap<Integer, DisplayInteger> map = new HashMap<Integer, DisplayInteger>();
map.put(mode, display);
cachedOverlays.put(side, map);
}
display.display = GLAllocation.generateDisplayLists(1);
GL11.glNewList(display.display, 4864);
switch(side)
{
case DOWN:
{
toReturn.minY = -0.01;
toReturn.maxY = 0;
toReturn.minX = 0;
toReturn.minZ = 0;
toReturn.maxX = 1;
toReturn.maxZ = 1;
break;
}
case UP:
{
toReturn.minY = 1;
toReturn.maxY = 1.01;
toReturn.minX = 0;
toReturn.minZ = 0;
toReturn.maxX = 1;
toReturn.maxZ = 1;
break;
}
case NORTH:
{
toReturn.minZ = -0.01;
toReturn.maxZ = 0;
toReturn.minX = 0;
toReturn.minY = 0;
toReturn.maxX = 1;
toReturn.maxY = 1;
break;
}
case SOUTH:
{
toReturn.minZ = 1;
toReturn.maxZ = 1.01;
toReturn.minX = 0;
toReturn.minY = 0;
toReturn.maxX = 1;
toReturn.maxY = 1;
break;
}
case WEST:
{
toReturn.minX = -0.01;
toReturn.maxX = 0;
toReturn.minY = 0;
toReturn.minZ = 0;
toReturn.maxY = 1;
toReturn.maxZ = 1;
break;
}
case EAST:
{
toReturn.minX = 1;
toReturn.maxX = 1.01;
toReturn.minY = 0;
toReturn.minZ = 0;
toReturn.maxY = 1;
toReturn.maxZ = 1;
break;
}
default:
{
break;
}
}
MekanismRenderer.renderObject(toReturn);
GL11.glEndList();
return display;
2013-08-06 05:58:44 +02:00
}
}