2013-08-27 00:57:08 +02:00
|
|
|
package mekanism.client.render.tileentity;
|
2013-04-18 04:40:11 +02:00
|
|
|
|
2013-04-21 06:34:54 +02:00
|
|
|
import java.util.HashMap;
|
2013-04-18 04:40:11 +02:00
|
|
|
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.client.model.ModelTransmitter;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.client.render.MekanismRenderer;
|
|
|
|
import mekanism.client.render.MekanismRenderer.DisplayInteger;
|
|
|
|
import mekanism.client.render.MekanismRenderer.Model3D;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.common.tileentity.TileEntityMechanicalPipe;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.common.util.MekanismUtils;
|
|
|
|
import mekanism.common.util.MekanismUtils.ResourceType;
|
2013-04-18 04:40:11 +02:00
|
|
|
import mekanism.common.PipeUtils;
|
2013-04-21 06:34:54 +02:00
|
|
|
import net.minecraft.block.Block;
|
2013-04-18 04:40:11 +02:00
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
2013-07-20 18:10:14 +02:00
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
import net.minecraftforge.fluids.FluidRegistry;
|
2013-04-18 04:40:11 +02:00
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public class RenderMechanicalPipe extends TileEntitySpecialRenderer
|
|
|
|
{
|
|
|
|
private ModelTransmitter model = new ModelTransmitter();
|
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
private HashMap<ForgeDirection, HashMap<Fluid, DisplayInteger[]>> cachedLiquids = new HashMap<ForgeDirection, HashMap<Fluid, DisplayInteger[]>>();
|
2013-04-21 06:34:54 +02:00
|
|
|
|
|
|
|
private static final int stages = 40;
|
|
|
|
|
|
|
|
private static final double offset = 0.015;
|
|
|
|
|
2013-04-18 04:40:11 +02:00
|
|
|
@Override
|
|
|
|
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
|
|
|
|
{
|
|
|
|
renderAModelAt((TileEntityMechanicalPipe)tileEntity, x, y, z, partialTick);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void renderAModelAt(TileEntityMechanicalPipe tileEntity, double x, double y, double z, float partialTick)
|
|
|
|
{
|
2013-09-28 03:59:47 +02:00
|
|
|
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "MechanicalPipe" + (tileEntity.isActive ? "Active" : "") + ".png"));
|
2013-04-18 04:40:11 +02:00
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
|
|
|
|
GL11.glScalef(1.0F, -1F, -1F);
|
2013-08-01 00:22:48 +02:00
|
|
|
GL11.glDisable(GL11.GL_CULL_FACE);
|
2013-04-18 04:40:11 +02:00
|
|
|
|
2013-06-27 17:03:50 +02:00
|
|
|
boolean[] connectable = PipeUtils.getConnections(tileEntity);
|
2013-04-18 04:40:11 +02:00
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
model.renderCenter(connectable);
|
2013-08-06 00:58:24 +02:00
|
|
|
|
2013-06-29 23:24:54 +02:00
|
|
|
for(int i = 0; i < 6; i++)
|
2013-04-18 04:40:11 +02:00
|
|
|
{
|
2013-07-08 18:41:31 +02:00
|
|
|
model.renderSide(ForgeDirection.getOrientation(i), connectable[i]);
|
2013-04-18 04:40:11 +02:00
|
|
|
}
|
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
GL11.glEnable(GL11.GL_CULL_FACE);
|
2013-04-18 04:40:11 +02:00
|
|
|
GL11.glPopMatrix();
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
if(tileEntity.fluidScale > 0 && tileEntity.refFluid != null)
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
2013-04-28 21:23:08 +02:00
|
|
|
push();
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
if(tileEntity.refFluid.getFluid() == FluidRegistry.LAVA)
|
2013-05-23 19:47:05 +02:00
|
|
|
{
|
|
|
|
MekanismRenderer.glowOn();
|
|
|
|
}
|
|
|
|
|
2013-09-28 03:59:47 +02:00
|
|
|
bindTexture(MekanismRenderer.getLiquidTexture());
|
2013-04-21 06:34:54 +02:00
|
|
|
GL11.glTranslatef((float)x, (float)y, (float)z);
|
|
|
|
|
2013-06-29 23:24:54 +02:00
|
|
|
for(int i = 0; i < 6; i++)
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
2013-06-29 23:24:54 +02:00
|
|
|
if(connectable[i])
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
2013-08-02 00:14:26 +02:00
|
|
|
DisplayInteger[] displayLists = getListAndRender(ForgeDirection.getOrientation(i), tileEntity.refFluid.getFluid());
|
2013-06-30 05:06:24 +02:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
if(displayLists != null)
|
2013-06-30 05:06:24 +02:00
|
|
|
{
|
2013-08-02 00:14:26 +02:00
|
|
|
displayLists[Math.max(3, (int)((float)tileEntity.fluidScale*(stages-1)))].render();
|
2013-06-30 05:06:24 +02:00
|
|
|
}
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
DisplayInteger[] displayLists = getListAndRender(ForgeDirection.UNKNOWN, tileEntity.refFluid.getFluid());
|
2013-06-30 05:06:24 +02:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
if(displayLists != null)
|
2013-06-30 05:06:24 +02:00
|
|
|
{
|
2013-08-02 00:14:26 +02:00
|
|
|
displayLists[Math.max(3, (int)((float)tileEntity.fluidScale*(stages-1)))].render();
|
2013-06-30 05:06:24 +02:00
|
|
|
}
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
if(tileEntity.refFluid.getFluid() == FluidRegistry.LAVA)
|
2013-05-23 19:47:05 +02:00
|
|
|
{
|
|
|
|
MekanismRenderer.glowOff();
|
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
pop();
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:08 +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);
|
|
|
|
}
|
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
private DisplayInteger[] getListAndRender(ForgeDirection side, Fluid fluid)
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(side == null || fluid == null || fluid.getIcon() == null)
|
2013-06-30 05:06:24 +02:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
if(cachedLiquids.containsKey(side) && cachedLiquids.get(side).containsKey(fluid))
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
return cachedLiquids.get(side).get(fluid);
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
|
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-07-20 18:10:14 +02:00
|
|
|
toReturn.setTexture(fluid.getIcon());
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
toReturn.setSideRender(side, false);
|
|
|
|
toReturn.setSideRender(side.getOpposite(), false);
|
|
|
|
|
|
|
|
DisplayInteger[] displays = new DisplayInteger[stages];
|
2013-04-21 06:34:54 +02:00
|
|
|
|
|
|
|
if(cachedLiquids.containsKey(side))
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
cachedLiquids.get(side).put(fluid, displays);
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-08-02 00:14:26 +02:00
|
|
|
HashMap<Fluid, DisplayInteger[]> map = new HashMap<Fluid, DisplayInteger[]>();
|
2013-07-20 18:10:14 +02:00
|
|
|
map.put(fluid, displays);
|
2013-04-21 06:34:54 +02:00
|
|
|
cachedLiquids.put(side, map);
|
|
|
|
}
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
MekanismRenderer.colorFluid(fluid);
|
2013-06-25 18:28:40 +02:00
|
|
|
|
2013-06-27 17:03:50 +02:00
|
|
|
for(int i = 0; i < stages; i++)
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
2013-08-02 00:14:26 +02:00
|
|
|
displays[i] = DisplayInteger.createAndStart();
|
2013-06-27 17:03:50 +02:00
|
|
|
|
|
|
|
switch(side)
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
2013-06-27 17:03:50 +02:00
|
|
|
case UNKNOWN:
|
2013-04-21 06:34:54 +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.3 - offset + ((float)i / (float)100);
|
|
|
|
toReturn.maxZ = 0.7 - offset;
|
2013-06-27 17:03:50 +02:00
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
2013-06-27 17:03:50 +02:00
|
|
|
case DOWN:
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
|
|
|
toReturn.minX = 0.5 + offset - ((float)i / (float)100)/2;
|
|
|
|
toReturn.minY = 0.0;
|
|
|
|
toReturn.minZ = 0.5 + offset - ((float)i / (float)100)/2;
|
|
|
|
|
|
|
|
toReturn.maxX = 0.5 - offset + ((float)i / (float)100)/2;
|
|
|
|
toReturn.maxY = 0.3 + offset;
|
|
|
|
toReturn.maxZ = 0.5 - offset + ((float)i / (float)100)/2;
|
2013-06-27 17:03:50 +02:00
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
2013-06-27 17:03:50 +02:00
|
|
|
case UP:
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
|
|
|
toReturn.minX = 0.5 + offset - ((float)i / (float)100)/2;
|
|
|
|
toReturn.minY = 0.3 - offset + ((float)i / (float)100);
|
|
|
|
toReturn.minZ = 0.5 + offset - ((float)i / (float)100)/2;
|
|
|
|
|
|
|
|
toReturn.maxX = 0.5 - offset + ((float)i / (float)100)/2;
|
|
|
|
toReturn.maxY = 1.0;
|
|
|
|
toReturn.maxZ = 0.5 - offset + ((float)i / (float)100)/2;
|
2013-06-27 17:03:50 +02:00
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
2013-06-27 17:03:50 +02:00
|
|
|
case NORTH:
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
|
|
|
toReturn.minX = 0.3 + offset;
|
|
|
|
toReturn.minY = 0.3 + offset;
|
|
|
|
toReturn.minZ = 0.0;
|
|
|
|
|
|
|
|
toReturn.maxX = 0.7 - offset;
|
|
|
|
toReturn.maxY = 0.3 - offset + ((float)i / (float)100);
|
|
|
|
toReturn.maxZ = 0.3 + offset;
|
2013-06-27 17:03:50 +02:00
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
2013-06-27 17:03:50 +02:00
|
|
|
case SOUTH:
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
|
|
|
toReturn.minX = 0.3 + offset;
|
|
|
|
toReturn.minY = 0.3 + offset;
|
|
|
|
toReturn.minZ = 0.7 - offset;
|
|
|
|
|
|
|
|
toReturn.maxX = 0.7 - offset;
|
|
|
|
toReturn.maxY = 0.3 - offset + ((float)i / (float)100);
|
|
|
|
toReturn.maxZ = 1.0;
|
2013-06-27 17:03:50 +02:00
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
2013-06-27 17:03:50 +02:00
|
|
|
case WEST:
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
|
|
|
toReturn.minX = 0.0;
|
|
|
|
toReturn.minY = 0.3 + offset;
|
|
|
|
toReturn.minZ = 0.3 + offset;
|
|
|
|
|
|
|
|
toReturn.maxX = 0.3 + offset;
|
|
|
|
toReturn.maxY = 0.3 - offset + ((float)i / (float)100);
|
|
|
|
toReturn.maxZ = 0.7 - offset;
|
2013-06-27 17:03:50 +02:00
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
2013-06-27 17:03:50 +02:00
|
|
|
case EAST:
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
|
|
|
toReturn.minX = 0.7 - offset;
|
|
|
|
toReturn.minY = 0.3 + offset;
|
|
|
|
toReturn.minZ = 0.3 + offset;
|
|
|
|
|
|
|
|
toReturn.maxX = 1.0;
|
|
|
|
toReturn.maxY = 0.3 - offset + ((float)i / (float)100);
|
|
|
|
toReturn.maxZ = 0.7 - offset;
|
2013-06-27 17:03:50 +02:00
|
|
|
break;
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-27 17:03:50 +02:00
|
|
|
|
|
|
|
MekanismRenderer.renderObject(toReturn);
|
2013-08-02 00:14:26 +02:00
|
|
|
DisplayInteger.endList();
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
|
2013-06-25 18:28:40 +02:00
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
|
2013-06-27 17:03:50 +02:00
|
|
|
return displays;
|
2013-04-18 04:40:11 +02:00
|
|
|
}
|
|
|
|
}
|