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-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-06-28 16:29:32 +02:00
|
|
|
import mekanism.common.TileEntityGasTank;
|
2013-02-22 04:03:54 +01:00
|
|
|
import mekanism.common.TileEntityPressurizedTube;
|
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-06-20 18:29:39 +02:00
|
|
|
private HashMap<ForgeDirection, HashMap<EnumGas, DisplayInteger>> cachedGasses = new HashMap<ForgeDirection, 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-03-18 17:23:57 +01:00
|
|
|
bindTextureByName("/mods/mekanism/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-04-23 02:14:00 +02:00
|
|
|
boolean[] connectable = new boolean[] {false, false, false, false, false, false};
|
|
|
|
|
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-06-26 23:49:47 +02:00
|
|
|
if(tileEntity.canTransferGas())
|
2013-04-23 02:14:00 +02:00
|
|
|
{
|
2013-06-26 23:49:47 +02:00
|
|
|
for(int i = 0; i < 6; i++)
|
2013-04-23 02:14:00 +02:00
|
|
|
{
|
2013-06-26 23:49:47 +02:00
|
|
|
if(connectable[i])
|
|
|
|
{
|
2013-06-28 16:29:32 +02:00
|
|
|
TileEntity sideTile = Object3D.get(tileEntity).getFromSide(ForgeDirection.getOrientation(i)).getTileEntity(tileEntity.worldObj);
|
|
|
|
|
|
|
|
if(sideTile instanceof TileEntityGasTank && i != 0 && i != 1)
|
|
|
|
{
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
|
|
|
|
switch(ForgeDirection.getOrientation(i))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
model.renderSide(ForgeDirection.getOrientation(i));
|
|
|
|
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
model.renderSide(ForgeDirection.getOrientation(i));
|
|
|
|
}
|
2013-06-26 23:49:47 +02:00
|
|
|
}
|
2013-04-23 02:14:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 04:03:54 +01:00
|
|
|
model.Center.render(0.0625F);
|
|
|
|
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-04-23 02:14:00 +02:00
|
|
|
bindTextureByName(tileEntity.refGas.texturePath);
|
|
|
|
GL11.glTranslatef((float)x, (float)y, (float)z);
|
|
|
|
|
2013-06-26 23:49:47 +02:00
|
|
|
if(tileEntity.canTransferGas())
|
2013-04-23 02:14:00 +02:00
|
|
|
{
|
2013-06-26 23:49:47 +02:00
|
|
|
for(int i = 0; i < 6; i++)
|
2013-04-23 02:14:00 +02:00
|
|
|
{
|
2013-06-26 23:49:47 +02:00
|
|
|
if(connectable[i])
|
|
|
|
{
|
|
|
|
int displayList = getListAndRender(ForgeDirection.getOrientation(i), tileEntity.refGas).display;
|
|
|
|
GL11.glCallList(displayList);
|
|
|
|
}
|
2013-04-23 02:14:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
int displayList = getListAndRender(ForgeDirection.UNKNOWN, tileEntity.refGas).display;
|
|
|
|
GL11.glCallList(displayList);
|
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
|
|
|
{
|
|
|
|
if(cachedGasses.containsKey(side) && cachedGasses.get(side).containsKey(type))
|
|
|
|
{
|
|
|
|
return cachedGasses.get(side).get(type);
|
|
|
|
}
|
|
|
|
|
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-06-20 18:29:39 +02:00
|
|
|
DisplayInteger display = new DisplayInteger();
|
2013-04-23 02:14:00 +02:00
|
|
|
|
|
|
|
if(cachedGasses.containsKey(side))
|
|
|
|
{
|
2013-06-20 18:29:39 +02:00
|
|
|
cachedGasses.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-04-23 02:14:00 +02:00
|
|
|
cachedGasses.put(side, map);
|
|
|
|
}
|
|
|
|
|
2013-06-20 18:29:39 +02:00
|
|
|
display.display = GLAllocation.generateDisplayLists(1);
|
|
|
|
GL11.glNewList(display.display, 4864);
|
|
|
|
|
2013-04-23 02:14:00 +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-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.7 - offset;
|
|
|
|
break;
|
2013-04-23 02:14:00 +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-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;
|
|
|
|
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.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);
|
|
|
|
GL11.glEndList();
|
|
|
|
|
|
|
|
return display;
|
2013-02-22 04:03:54 +01:00
|
|
|
}
|
|
|
|
}
|