2013-02-22 04:03:54 +01:00
|
|
|
package mekanism.client;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
2013-04-23 02:14:00 +02:00
|
|
|
import java.util.HashMap;
|
2013-02-22 04:03:54 +01:00
|
|
|
|
2013-04-23 02:14:00 +02:00
|
|
|
import mekanism.api.EnumGas;
|
2013-03-11 18:49:01 +01:00
|
|
|
import mekanism.api.GasTransmission;
|
2013-02-22 04:03:54 +01:00
|
|
|
import mekanism.api.ITubeConnection;
|
2013-06-28 16:29:32 +02:00
|
|
|
import mekanism.api.Object3D;
|
2013-08-02 00:14:26 +02:00
|
|
|
import mekanism.client.MekanismRenderer.BooleanArray;
|
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-07-20 18:10:14 +02:00
|
|
|
import mekanism.common.MekanismUtils;
|
2013-06-28 16:29:32 +02:00
|
|
|
import mekanism.common.TileEntityGasTank;
|
2013-02-22 04:03:54 +01:00
|
|
|
import mekanism.common.TileEntityPressurizedTube;
|
2013-07-20 18:10:14 +02:00
|
|
|
import mekanism.common.MekanismUtils.ResourceType;
|
2013-04-23 02:14:00 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.renderer.GLAllocation;
|
2013-02-22 04:03:54 +01:00
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2013-04-23 02:14:00 +02:00
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-02-22 04:03:54 +01:00
|
|
|
|
2013-04-13 16:33:37 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-02-22 04:03:54 +01:00
|
|
|
public class RenderPressurizedTube extends TileEntitySpecialRenderer
|
|
|
|
{
|
2013-04-18 04:40:11 +02:00
|
|
|
private ModelTransmitter model = new ModelTransmitter();
|
2013-04-13 02:25:21 +02:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
private boolean[] connectable;
|
|
|
|
|
|
|
|
private HashMap<ForgeDirection, HashMap<EnumGas, DisplayInteger>> cachedSideGasses = new HashMap<ForgeDirection, HashMap<EnumGas, DisplayInteger>>();
|
|
|
|
private HashMap<BooleanArray, HashMap<EnumGas, DisplayInteger>> cachedCenterGasses = new HashMap<BooleanArray, HashMap<EnumGas, DisplayInteger>>();
|
2013-04-23 02:14:00 +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((TileEntityPressurizedTube)tileEntity, x, y, z, partialTick);
|
|
|
|
}
|
2013-02-22 04:03:54 +01:00
|
|
|
|
2013-06-28 16:29:32 +02:00
|
|
|
@SuppressWarnings("incomplete-switch")
|
2013-04-13 02:25:21 +02:00
|
|
|
public void renderAModelAt(TileEntityPressurizedTube tileEntity, double x, double y, double z, float partialTick)
|
2013-02-22 04:03:54 +01:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
func_110628_a(MekanismUtils.getResource(ResourceType.RENDER, "PressurizedTube.png"));
|
2013-02-22 04:03:54 +01:00
|
|
|
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-02-22 04:03:54 +01:00
|
|
|
GL11.glScalef(1.0F, -1F, -1F);
|
2013-08-01 00:22:48 +02:00
|
|
|
GL11.glDisable(GL11.GL_CULL_FACE);
|
2013-02-22 04:03:54 +01:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
connectable = new boolean[] {false, false, false, false, false, false};
|
2013-04-23 02:14:00 +02:00
|
|
|
|
2013-03-11 18:49:01 +01:00
|
|
|
ITubeConnection[] connections = GasTransmission.getConnections(tileEntity);
|
2013-02-22 04:03:54 +01:00
|
|
|
|
|
|
|
for(ITubeConnection connection : connections)
|
|
|
|
{
|
2013-03-11 18:49:01 +01:00
|
|
|
if(connection != null)
|
2013-02-22 04:03:54 +01:00
|
|
|
{
|
|
|
|
int side = Arrays.asList(connections).indexOf(connection);
|
|
|
|
|
|
|
|
if(connection.canTubeConnect(ForgeDirection.getOrientation(side).getOpposite()))
|
|
|
|
{
|
2013-04-23 02:14:00 +02:00
|
|
|
connectable[side] = true;
|
2013-02-22 04:03:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
model.renderCenter(connectable);
|
|
|
|
|
2013-08-19 13:55:47 +02:00
|
|
|
for(int i = 0; i < 6; i++)
|
2013-04-23 02:14:00 +02:00
|
|
|
{
|
2013-08-19 13:55:47 +02:00
|
|
|
TileEntity sideTile = Object3D.get(tileEntity).getFromSide(ForgeDirection.getOrientation(i)).getTileEntity(tileEntity.worldObj);
|
|
|
|
|
|
|
|
if(sideTile instanceof TileEntityGasTank && i != 0 && i != 1)
|
2013-04-23 02:14:00 +02:00
|
|
|
{
|
2013-08-19 13:55:47 +02:00
|
|
|
GL11.glPushMatrix();
|
2013-07-08 18:41:31 +02:00
|
|
|
|
2013-08-19 13:55:47 +02:00
|
|
|
switch(ForgeDirection.getOrientation(i))
|
2013-06-26 23:49:47 +02:00
|
|
|
{
|
2013-08-19 13:55:47 +02:00
|
|
|
case NORTH:
|
|
|
|
GL11.glScalef(1, 1, 1.63f);
|
|
|
|
GL11.glTranslatef(0, 0, -.073f);
|
|
|
|
break;
|
|
|
|
case SOUTH:
|
|
|
|
GL11.glScalef(1, 1, 1.63f);
|
|
|
|
GL11.glTranslatef(0, 0, .073f);
|
|
|
|
break;
|
|
|
|
case WEST:
|
|
|
|
GL11.glScalef(1.63f, 1, 1);
|
|
|
|
GL11.glTranslatef(.073f, 0, 0);
|
|
|
|
break;
|
|
|
|
case EAST:
|
|
|
|
GL11.glScalef(1.63f, 1, 1);
|
|
|
|
GL11.glTranslatef(-.073f, 0, 0);
|
|
|
|
break;
|
2013-06-26 23:49:47 +02:00
|
|
|
}
|
2013-08-19 13:55:47 +02:00
|
|
|
|
|
|
|
model.renderSide(ForgeDirection.getOrientation(i), connectable[i]);
|
|
|
|
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
model.renderSide(ForgeDirection.getOrientation(i), connectable[i]);
|
2013-04-23 02:14:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
GL11.glEnable(GL11.GL_CULL_FACE);
|
2013-02-22 04:03:54 +01:00
|
|
|
GL11.glPopMatrix();
|
2013-04-23 02:14:00 +02:00
|
|
|
|
|
|
|
if(tileEntity.gasScale > 0 && tileEntity.refGas != null && tileEntity.refGas.hasTexture())
|
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
push();
|
|
|
|
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, tileEntity.gasScale);
|
2013-07-20 18:10:14 +02:00
|
|
|
func_110628_a(tileEntity.refGas.texturePath);
|
2013-04-23 02:14:00 +02:00
|
|
|
GL11.glTranslatef((float)x, (float)y, (float)z);
|
|
|
|
|
2013-08-06 00:58:24 +02:00
|
|
|
if(tileEntity.gasScale > 0)
|
|
|
|
{
|
|
|
|
tileEntity.gasScale = Math.max(0, tileEntity.gasScale - .008F);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tileEntity.refGas = null;
|
|
|
|
}
|
|
|
|
|
2013-08-19 13:55:47 +02:00
|
|
|
for(int i = 0; i < 6; i++)
|
2013-04-23 02:14:00 +02:00
|
|
|
{
|
2013-08-19 13:55:47 +02:00
|
|
|
if(connectable[i])
|
2013-04-23 02:14:00 +02:00
|
|
|
{
|
2013-08-19 13:55:47 +02:00
|
|
|
getListAndRender(ForgeDirection.getOrientation(i), tileEntity.refGas).render();
|
2013-04-23 02:14:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
getListAndRender(ForgeDirection.UNKNOWN, tileEntity.refGas).render();
|
2013-04-23 02:14:00 +02:00
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
pop();
|
2013-04-23 02:14:00 +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, EnumGas type)
|
2013-04-23 02:14:00 +02:00
|
|
|
{
|
2013-08-02 00:14:26 +02:00
|
|
|
if(side == ForgeDirection.UNKNOWN)
|
|
|
|
{
|
|
|
|
if(cachedCenterGasses.containsKey(side) && cachedCenterGasses.get(side).containsKey(type))
|
|
|
|
{
|
|
|
|
return cachedCenterGasses.get(new BooleanArray(connectable)).get(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
Model3D toReturn = new Model3D();
|
|
|
|
toReturn.baseBlock = Block.waterStill;
|
2013-08-06 00:58:24 +02:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
toReturn.setTexture(type.gasIcon);
|
2013-08-06 00:58:24 +02:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
toReturn.minX = 0.3 + offset;
|
|
|
|
toReturn.minY = 0.3 + offset;
|
|
|
|
toReturn.minZ = 0.3 + offset;
|
|
|
|
|
|
|
|
toReturn.maxX = 0.7 - offset;
|
|
|
|
toReturn.maxY = 0.7 - offset;
|
|
|
|
toReturn.maxZ = 0.7 - offset;
|
|
|
|
|
|
|
|
for(ForgeDirection face : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
{
|
|
|
|
toReturn.setSideRender(face, !connectable[face.ordinal()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayInteger display = DisplayInteger.createAndStart();
|
|
|
|
MekanismRenderer.renderObject(toReturn);
|
|
|
|
DisplayInteger.endList();
|
|
|
|
|
|
|
|
if(cachedCenterGasses.containsKey(side))
|
|
|
|
{
|
|
|
|
cachedCenterGasses.get(side).put(type, display);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
HashMap<EnumGas, DisplayInteger> map = new HashMap<EnumGas, DisplayInteger>();
|
|
|
|
map.put(type, display);
|
2013-08-06 00:58:24 +02:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
cachedCenterGasses.put(new BooleanArray(connectable), map);
|
|
|
|
}
|
2013-08-06 00:58:24 +02:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
return display;
|
|
|
|
}
|
2013-08-06 00:58:24 +02:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
if(cachedSideGasses.containsKey(side) && cachedSideGasses.get(side).containsKey(type))
|
2013-04-23 02:14:00 +02:00
|
|
|
{
|
2013-08-02 00:14:26 +02:00
|
|
|
return cachedSideGasses.get(side).get(type);
|
2013-04-23 02:14:00 +02:00
|
|
|
}
|
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
Model3D toReturn = new Model3D();
|
2013-04-23 02:14:00 +02:00
|
|
|
toReturn.baseBlock = Block.waterStill;
|
2013-06-26 23:49:47 +02:00
|
|
|
toReturn.setTexture(type.gasIcon);
|
2013-04-23 02:14:00 +02:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
toReturn.setSideRender(side, false);
|
|
|
|
toReturn.setSideRender(side.getOpposite(), false);
|
2013-04-23 02:14:00 +02:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
DisplayInteger display = DisplayInteger.createAndStart();
|
|
|
|
|
|
|
|
if(cachedSideGasses.containsKey(side))
|
2013-04-23 02:14:00 +02:00
|
|
|
{
|
2013-08-02 00:14:26 +02:00
|
|
|
cachedSideGasses.get(side).put(type, display);
|
2013-04-23 02:14:00 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-06-20 18:29:39 +02:00
|
|
|
HashMap<EnumGas, DisplayInteger> map = new HashMap<EnumGas, DisplayInteger>();
|
|
|
|
map.put(type, display);
|
2013-08-02 00:14:26 +02:00
|
|
|
cachedSideGasses.put(side, map);
|
2013-04-23 02:14:00 +02:00
|
|
|
}
|
2013-08-02 00:14:26 +02:00
|
|
|
|
2013-04-23 02:14:00 +02:00
|
|
|
switch(side)
|
|
|
|
{
|
|
|
|
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-23 02:14:00 +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-23 02:14:00 +02:00
|
|
|
}
|
|
|
|
case UP:
|
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.minX = 0.3 + offset;
|
2013-08-02 00:14:26 +02:00
|
|
|
toReturn.minY = 0.7 - offset;
|
2013-06-20 18:29:39 +02:00
|
|
|
toReturn.minZ = 0.3 + offset;
|
2013-04-23 02:14:00 +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-23 02:14:00 +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-23 02:14:00 +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-23 02:14:00 +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-23 02:14:00 +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-23 02:14:00 +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-23 02:14:00 +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-23 02:14:00 +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-23 02:14:00 +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-23 02:14:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
MekanismRenderer.renderObject(toReturn);
|
2013-08-02 00:14:26 +02:00
|
|
|
DisplayInteger.endList();
|
2013-06-20 18:29:39 +02:00
|
|
|
|
|
|
|
return display;
|
2013-02-22 04:03:54 +01:00
|
|
|
}
|
|
|
|
}
|