2013-03-25 17:00:45 +01:00
|
|
|
package mekanism.client;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
2013-04-21 06:34:54 +02:00
|
|
|
import java.util.HashMap;
|
2013-03-25 17:00:45 +01:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
import mekanism.client.MekanismRenderer.DisplayInteger;
|
2013-05-20 00:43:01 +02:00
|
|
|
import mekanism.client.MekanismRenderer.Model3D;
|
2013-03-29 17:10:23 +01:00
|
|
|
import mekanism.common.CableUtils;
|
2013-03-25 17:00:45 +01:00
|
|
|
import mekanism.common.TileEntityUniversalCable;
|
2013-04-21 06:34:54 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.renderer.GLAllocation;
|
2013-03-25 17:00:45 +01:00
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2013-05-14 17:34:26 +02:00
|
|
|
import net.minecraft.util.Icon;
|
2013-04-21 06:34:54 +02:00
|
|
|
import net.minecraft.world.World;
|
2013-03-25 17:00:45 +01:00
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2013-05-14 17:34:26 +02:00
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
2013-04-13 16:33:37 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2013-03-25 17:00:45 +01:00
|
|
|
public class RenderUniversalCable extends TileEntitySpecialRenderer
|
|
|
|
{
|
2013-04-18 04:40:11 +02:00
|
|
|
private ModelTransmitter model = new ModelTransmitter();
|
2013-04-13 02:25:21 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
private HashMap<ForgeDirection, DisplayInteger> cachedLiquids = new HashMap<ForgeDirection, DisplayInteger>();
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-05-14 17:34:26 +02:00
|
|
|
private Icon renderIcon = FMLClientHandler.instance().getClient().renderEngine.textureMapItems.registerIcon("mekanism:LiquidEnergy");
|
|
|
|
|
2013-04-21 06:34:54 +02:00
|
|
|
private static final double offset = 0.015;
|
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
@Override
|
|
|
|
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
|
|
|
|
{
|
|
|
|
renderAModelAt((TileEntityUniversalCable)tileEntity, x, y, z, partialTick);
|
|
|
|
}
|
2013-03-25 17:00:45 +01:00
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
public void renderAModelAt(TileEntityUniversalCable tileEntity, double x, double y, double z, float partialTick)
|
2013-03-25 17:00:45 +01:00
|
|
|
{
|
|
|
|
bindTextureByName("/mods/mekanism/render/UniversalCable.png");
|
|
|
|
GL11.glPushMatrix();
|
2013-04-13 02:25:21 +02:00
|
|
|
GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
|
2013-03-25 17:00:45 +01:00
|
|
|
GL11.glScalef(1.0F, -1F, -1F);
|
2013-06-01 18:37:43 +02:00
|
|
|
GL11.glDisable(GL11.GL_CULL_FACE);
|
2013-03-25 17:00:45 +01:00
|
|
|
|
|
|
|
boolean[] connectable = new boolean[] {false, false, false, false, false, false};
|
|
|
|
|
2013-03-29 17:10:23 +01:00
|
|
|
TileEntity[] connectedAcceptors = CableUtils.getConnectedEnergyAcceptors(tileEntity);
|
|
|
|
TileEntity[] connectedCables = CableUtils.getConnectedCables(tileEntity);
|
|
|
|
TileEntity[] connectedOutputters = CableUtils.getConnectedOutputters(tileEntity);
|
2013-03-25 17:00:45 +01:00
|
|
|
|
|
|
|
for(TileEntity tile : connectedAcceptors)
|
|
|
|
{
|
|
|
|
int side = Arrays.asList(connectedAcceptors).indexOf(tile);
|
|
|
|
|
2013-03-29 17:10:23 +01:00
|
|
|
if(CableUtils.canConnectToAcceptor(ForgeDirection.getOrientation(side), tileEntity))
|
2013-03-25 17:00:45 +01:00
|
|
|
{
|
|
|
|
connectable[side] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(TileEntity tile : connectedOutputters)
|
|
|
|
{
|
|
|
|
if(tile != null)
|
|
|
|
{
|
|
|
|
int side = Arrays.asList(connectedOutputters).indexOf(tile);
|
|
|
|
|
|
|
|
connectable[side] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(TileEntity tile : connectedCables)
|
|
|
|
{
|
|
|
|
if(tile != null)
|
|
|
|
{
|
|
|
|
int side = Arrays.asList(connectedCables).indexOf(tile);
|
|
|
|
|
|
|
|
connectable[side] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
if(connectable[i])
|
|
|
|
{
|
|
|
|
model.renderSide(ForgeDirection.getOrientation(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
model.Center.render(0.0625F);
|
|
|
|
GL11.glPopMatrix();
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-04-23 02:14:00 +02:00
|
|
|
if(tileEntity.energyScale > 0)
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
push();
|
2013-05-23 19:47:05 +02:00
|
|
|
MekanismRenderer.glowOn();
|
2013-04-28 21:23:08 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, tileEntity.energyScale);
|
2013-04-21 06:34:54 +02:00
|
|
|
bindTextureByName("/mods/mekanism/textures/items/LiquidEnergy.png");
|
|
|
|
GL11.glTranslatef((float)x, (float)y, (float)z);
|
|
|
|
|
|
|
|
for(int i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
if(connectable[i])
|
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
int displayList = getListAndRender(ForgeDirection.getOrientation(i)).display;
|
|
|
|
GL11.glCallList(displayList);
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
int displayList = getListAndRender(ForgeDirection.UNKNOWN).display;
|
|
|
|
GL11.glCallList(displayList);
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-05-23 19:47:05 +02:00
|
|
|
MekanismRenderer.glowOff();
|
2013-06-20 18:29:39 +02:00
|
|
|
pop();
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
private void pop()
|
|
|
|
{
|
|
|
|
GL11.glPopAttrib();
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void push()
|
|
|
|
{
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
|
|
|
GL11.glEnable(GL11.GL_CULL_FACE);
|
|
|
|
GL11.glEnable(GL11.GL_BLEND);
|
|
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
|
|
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
}
|
|
|
|
|
|
|
|
private DisplayInteger getListAndRender(ForgeDirection side)
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
|
|
|
if(cachedLiquids.containsKey(side))
|
|
|
|
{
|
|
|
|
return cachedLiquids.get(side);
|
|
|
|
}
|
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
Model3D toReturn = new Model3D();
|
2013-04-21 06:34:54 +02:00
|
|
|
toReturn.baseBlock = Block.waterStill;
|
2013-05-14 17:34:26 +02:00
|
|
|
toReturn.texture = renderIcon;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
DisplayInteger display = new DisplayInteger();
|
|
|
|
|
|
|
|
cachedLiquids.put(side, display);
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
display.display = GLAllocation.generateDisplayLists(1);
|
|
|
|
GL11.glNewList(display.display, 4864);
|
2013-04-21 06:34:54 +02:00
|
|
|
|
|
|
|
switch(side)
|
|
|
|
{
|
|
|
|
case UNKNOWN:
|
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.minX = 0.3 + offset;
|
|
|
|
toReturn.minY = 0.3 + offset;
|
|
|
|
toReturn.minZ = 0.3 + offset;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.maxX = 0.7 - offset;
|
|
|
|
toReturn.maxY = 0.7 - offset;
|
|
|
|
toReturn.maxZ = 0.7 - offset;
|
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
case DOWN:
|
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.minX = 0.3 + offset;
|
|
|
|
toReturn.minY = 0.0;
|
|
|
|
toReturn.minZ = 0.3 + offset;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.maxX = 0.7 - offset;
|
|
|
|
toReturn.maxY = 0.3 + offset;
|
|
|
|
toReturn.maxZ = 0.7 - offset;
|
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
case UP:
|
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.minX = 0.3 + offset;
|
|
|
|
toReturn.minY = 0.3 - offset;
|
|
|
|
toReturn.minZ = 0.3 + offset;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.maxX = 0.7 - offset;
|
|
|
|
toReturn.maxY = 1.0;
|
|
|
|
toReturn.maxZ = 0.7 - offset;
|
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
case NORTH:
|
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.minX = 0.3 + offset;
|
|
|
|
toReturn.minY = 0.3 + offset;
|
|
|
|
toReturn.minZ = 0.0;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.maxX = 0.7 - offset;
|
|
|
|
toReturn.maxY = 0.7 - offset;
|
|
|
|
toReturn.maxZ = 0.3 + offset;
|
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
case SOUTH:
|
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.minX = 0.3 + offset;
|
|
|
|
toReturn.minY = 0.3 + offset;
|
|
|
|
toReturn.minZ = 0.7 - offset;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.maxX = 0.7 - offset;
|
|
|
|
toReturn.maxY = 0.7 - offset;
|
|
|
|
toReturn.maxZ = 1.0;
|
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
case WEST:
|
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.minX = 0.0;
|
|
|
|
toReturn.minY = 0.3 + offset;
|
|
|
|
toReturn.minZ = 0.3 + offset;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.maxX = 0.3 + offset;
|
|
|
|
toReturn.maxY = 0.7 - offset;
|
|
|
|
toReturn.maxZ = 0.7 - offset;
|
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
case EAST:
|
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.minX = 0.7 - offset;
|
|
|
|
toReturn.minY = 0.3 + offset;
|
|
|
|
toReturn.minZ = 0.3 + offset;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.maxX = 1.0;
|
|
|
|
toReturn.maxY = 0.7 - offset;
|
|
|
|
toReturn.maxZ = 0.7 - offset;
|
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
MekanismRenderer.renderObject(toReturn);
|
|
|
|
GL11.glEndList();
|
|
|
|
|
|
|
|
return display;
|
2013-03-25 17:00:45 +01:00
|
|
|
}
|
|
|
|
}
|