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-10-23 03:13:23 +02:00
|
|
|
import mekanism.client.model.ModelTransmitter.Size;
|
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-10-23 03:13:23 +02:00
|
|
|
import mekanism.common.PipeUtils;
|
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-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
|
|
|
|
{
|
2013-11-24 22:44:16 +01:00
|
|
|
private ModelTransmitter model = new ModelTransmitter(Size.LARGE);
|
2013-04-18 04:40:11 +02:00
|
|
|
|
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
|
|
|
|
2013-11-24 22:44:16 +01:00
|
|
|
private static final int stages = 100;
|
|
|
|
private static final double height = 0.45;
|
2013-04-21 06:34:54 +02:00
|
|
|
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-11-25 06:00:26 +01:00
|
|
|
Fluid fluid = tileEntity.getTransmitterNetwork().refFluid;
|
|
|
|
float scale = tileEntity.getTransmitterNetwork().fluidScale;
|
|
|
|
|
|
|
|
if(scale > 0 && fluid != null)
|
2013-04-21 06:34:54 +02:00
|
|
|
{
|
2013-04-28 21:23:08 +02:00
|
|
|
push();
|
|
|
|
|
2013-11-25 06:00:26 +01:00
|
|
|
MekanismRenderer.glowOn(fluid.getLuminosity());
|
2013-05-23 19:47:05 +02:00
|
|
|
|
2013-11-24 19:12:42 +01:00
|
|
|
bindTexture(MekanismRenderer.getBlocksTexture());
|
2013-04-21 06:34:54 +02:00
|
|
|
GL11.glTranslatef((float)x, (float)y, (float)z);
|
|
|
|
|
2013-11-25 06:00:26 +01:00
|
|
|
boolean gas = fluid.isGaseous();
|
2013-11-24 22:44:16 +01:00
|
|
|
|
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-11-25 06:00:26 +01:00
|
|
|
DisplayInteger[] displayLists = getListAndRender(ForgeDirection.getOrientation(i), fluid);
|
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-11-24 22:44:16 +01:00
|
|
|
if(!gas)
|
|
|
|
{
|
2013-11-25 06:00:26 +01:00
|
|
|
displayLists[Math.max(0, (int)((float)scale*(stages-1)))].render();
|
2013-11-24 22:44:16 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-11-25 06:00:26 +01:00
|
|
|
GL11.glColor4f(1F, 1F, 1F, scale);
|
2013-11-24 22:44:16 +01:00
|
|
|
displayLists[stages-1].render();
|
|
|
|
}
|
2013-06-30 05:06:24 +02:00
|
|
|
}
|
2013-04-21 06:34:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-25 06:00:26 +01:00
|
|
|
DisplayInteger[] displayLists = getListAndRender(ForgeDirection.UNKNOWN, fluid);
|
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-11-24 22:44:16 +01:00
|
|
|
if(!gas)
|
|
|
|
{
|
2013-11-25 06:00:26 +01:00
|
|
|
displayLists[Math.max(3, (int)((float)scale*(stages-1)))].render();
|
2013-11-24 22:44:16 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-11-25 06:00:26 +01:00
|
|
|
GL11.glColor4f(1F, 1F, 1F, scale);
|
2013-11-24 22:44:16 +01:00
|
|
|
displayLists[stages-1].render();
|
|
|
|
}
|
2013-06-30 05:06:24 +02:00
|
|
|
}
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-11-24 22:44:16 +01:00
|
|
|
MekanismRenderer.glowOff();
|
2013-05-23 19:47:05 +02:00
|
|
|
|
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
|
|
|
{
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.minX = 0.25 + offset;
|
|
|
|
toReturn.minY = 0.25 + offset;
|
|
|
|
toReturn.minZ = 0.25 + offset;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.maxX = 0.75 - offset;
|
|
|
|
toReturn.maxY = 0.25 + offset + ((float)i / (float)stages)*height;
|
|
|
|
toReturn.maxZ = 0.75 - 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
|
|
|
{
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.minX = 0.5 - (((float)i / (float)stages)*height)/2;
|
2013-04-21 06:34:54 +02:00
|
|
|
toReturn.minY = 0.0;
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.minZ = 0.5 - (((float)i / (float)stages)*height)/2;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.maxX = 0.5 + (((float)i / (float)stages)*height)/2;
|
|
|
|
toReturn.maxY = 0.25 + offset;
|
|
|
|
toReturn.maxZ = 0.5 + (((float)i / (float)stages)*height)/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
|
|
|
{
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.minX = 0.5 - (((float)i / (float)stages)*height)/2;
|
|
|
|
toReturn.minY = 0.25 - offset + ((float)i / (float)stages)*height;
|
|
|
|
toReturn.minZ = 0.5 - (((float)i / (float)stages)*height)/2;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.maxX = 0.5 + (((float)i / (float)stages)*height)/2;
|
2013-04-21 06:34:54 +02:00
|
|
|
toReturn.maxY = 1.0;
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.maxZ = 0.5 + (((float)i / (float)stages)*height)/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
|
|
|
{
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.minX = 0.25 + offset;
|
|
|
|
toReturn.minY = 0.25 + offset;
|
2013-04-21 06:34:54 +02:00
|
|
|
toReturn.minZ = 0.0;
|
|
|
|
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.maxX = 0.75 - offset;
|
|
|
|
toReturn.maxY = 0.25 + offset + ((float)i / (float)stages)*height;
|
|
|
|
toReturn.maxZ = 0.25 + 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
|
|
|
{
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.minX = 0.25 + offset;
|
|
|
|
toReturn.minY = 0.25 + offset;
|
|
|
|
toReturn.minZ = 0.75 - offset;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.maxX = 0.75 - offset;
|
|
|
|
toReturn.maxY = 0.25 + offset + ((float)i / (float)stages)*height;
|
2013-04-21 06:34:54 +02:00
|
|
|
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;
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.minY = 0.25 + offset;
|
|
|
|
toReturn.minZ = 0.25 + offset;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.maxX = 0.25 + offset;
|
|
|
|
toReturn.maxY = 0.25 + offset + ((float)i / (float)stages)*height;
|
|
|
|
toReturn.maxZ = 0.75 - 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
|
|
|
{
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.minX = 0.75 - offset;
|
|
|
|
toReturn.minY = 0.25 + offset;
|
|
|
|
toReturn.minZ = 0.25 + offset;
|
2013-04-21 06:34:54 +02:00
|
|
|
|
|
|
|
toReturn.maxX = 1.0;
|
2013-11-24 22:44:16 +01:00
|
|
|
toReturn.maxY = 0.25 + offset + ((float)i / (float)stages)*height;
|
|
|
|
toReturn.maxZ = 0.75 - 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
|
|
|
}
|
|
|
|
}
|