2013-08-27 00:57:08 +02:00
|
|
|
package mekanism.client.render.tileentity;
|
2013-04-28 21:23:08 +02:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import mekanism.api.Object3D;
|
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-04-28 21:23:08 +02:00
|
|
|
import mekanism.common.SynchronizedTankData.ValveData;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.common.tileentity.TileEntityDynamicTank;
|
2013-04-28 21:23:08 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.renderer.GLAllocation;
|
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
2013-07-20 18:10:14 +02:00
|
|
|
import net.minecraftforge.fluids.Fluid;
|
2013-08-06 00:58:24 +02:00
|
|
|
import net.minecraftforge.fluids.FluidRegistry;
|
2013-04-28 21:23:08 +02:00
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2013-05-29 17:35:30 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2013-04-28 21:23:08 +02:00
|
|
|
public class RenderDynamicTank extends TileEntitySpecialRenderer
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
private static Map<RenderData, HashMap<Fluid, int[]>> cachedCenterFluids = new HashMap<RenderData, HashMap<Fluid, int[]>>();
|
|
|
|
private static Map<ValveRenderData, HashMap<Fluid, DisplayInteger>> cachedValveFluids = new HashMap<ValveRenderData, HashMap<Fluid, DisplayInteger>>();
|
2013-04-28 21:23:08 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
|
|
|
|
{
|
|
|
|
renderAModelAt((TileEntityDynamicTank)tileEntity, x, y, z, partialTick);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void renderAModelAt(TileEntityDynamicTank tileEntity, double x, double y, double z, float partialTick)
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(tileEntity.clientHasStructure && tileEntity.isRendering && tileEntity.structure != null && tileEntity.structure.fluidStored != null && tileEntity.structure.fluidStored.amount != 0)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
RenderData data = new RenderData();
|
|
|
|
|
|
|
|
data.location = tileEntity.structure.renderLocation;
|
|
|
|
data.height = tileEntity.structure.volHeight;
|
|
|
|
data.length = tileEntity.structure.volLength;
|
|
|
|
data.width = tileEntity.structure.volWidth;
|
|
|
|
|
2013-09-28 03:59:47 +02:00
|
|
|
bindTexture(MekanismRenderer.getLiquidTexture());
|
2013-04-28 21:23:08 +02:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
if(data.location != null && data.height > 0 && tileEntity.structure.fluidStored.getFluid() != null)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
push();
|
2013-06-15 17:35:14 +02:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
GL11.glTranslated(getX(data.location.xCoord), getY(data.location.yCoord), getZ(data.location.zCoord));
|
|
|
|
|
2013-08-06 00:58:24 +02:00
|
|
|
if(tileEntity.structure.fluidStored.getFluid() == FluidRegistry.LAVA)
|
|
|
|
{
|
|
|
|
MekanismRenderer.glowOn();
|
|
|
|
}
|
|
|
|
|
2013-08-23 00:55:06 +02:00
|
|
|
boolean gas = tileEntity.structure.fluidStored.getFluid().isGaseous();
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
int[] displayList = getListAndRender(data, tileEntity.structure.fluidStored.getFluid(), tileEntity.worldObj);
|
2013-08-23 00:55:06 +02:00
|
|
|
if(gas)
|
|
|
|
{
|
|
|
|
GL11.glColor4f(1.F, 1.F, 1.F, (float)tileEntity.structure.fluidStored.amount / (float)tileEntity.clientCapacity);
|
|
|
|
GL11.glCallList(displayList[getStages(data.height)-1]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GL11.glCallList(displayList[(int)(((float)tileEntity.structure.fluidStored.amount/(float)tileEntity.clientCapacity)*((float)getStages(data.height)-1))]);
|
|
|
|
}
|
2013-06-15 17:35:14 +02:00
|
|
|
|
2013-08-06 00:58:24 +02:00
|
|
|
if(tileEntity.structure.fluidStored.getFluid() == FluidRegistry.LAVA)
|
|
|
|
{
|
|
|
|
MekanismRenderer.glowOff();
|
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
pop();
|
|
|
|
|
|
|
|
for(ValveData valveData : tileEntity.valveViewing.keySet())
|
|
|
|
{
|
|
|
|
if(tileEntity.valveViewing.get(valveData) > 0)
|
|
|
|
{
|
|
|
|
push();
|
|
|
|
|
|
|
|
GL11.glTranslated(getX(valveData.location.xCoord), getY(valveData.location.yCoord), getZ(valveData.location.zCoord));
|
|
|
|
|
2013-08-06 00:58:24 +02:00
|
|
|
if(tileEntity.structure.fluidStored.getFluid() == FluidRegistry.LAVA)
|
|
|
|
{
|
|
|
|
MekanismRenderer.glowOn();
|
|
|
|
}
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
int display = getValveDisplay(ValveRenderData.get(data, valveData), tileEntity.structure.fluidStored.getFluid(), tileEntity.worldObj).display;
|
2013-04-28 21:23:08 +02:00
|
|
|
GL11.glCallList(display);
|
|
|
|
|
2013-08-06 00:58:24 +02:00
|
|
|
if(tileEntity.structure.fluidStored.getFluid() == FluidRegistry.LAVA)
|
|
|
|
{
|
|
|
|
MekanismRenderer.glowOff();
|
|
|
|
}
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-20 18:10:14 +02:00
|
|
|
private int[] getListAndRender(RenderData data, Fluid fluid, World world)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(cachedCenterFluids.containsKey(data) && cachedCenterFluids.get(data).containsKey(fluid))
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
return cachedCenterFluids.get(data).get(fluid);
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Model3D toReturn = new Model3D();
|
|
|
|
toReturn.baseBlock = Block.waterStill;
|
2013-07-20 18:10:14 +02:00
|
|
|
toReturn.setTexture(fluid.getIcon());
|
2013-04-28 21:23:08 +02:00
|
|
|
|
|
|
|
final int stages = getStages(data.height);
|
|
|
|
int[] displays = new int[stages];
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
if(cachedCenterFluids.containsKey(data))
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
cachedCenterFluids.get(data).put(fluid, displays);
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-07-20 18:10:14 +02:00
|
|
|
HashMap<Fluid, int[]> map = new HashMap<Fluid, int[]>();
|
|
|
|
map.put(fluid, displays);
|
|
|
|
cachedCenterFluids.put(data, map);
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
MekanismRenderer.colorFluid(fluid);
|
2013-06-25 18:28:40 +02:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
for(int i = 0; i < stages; i++)
|
|
|
|
{
|
|
|
|
displays[i] = GLAllocation.generateDisplayLists(1);
|
|
|
|
GL11.glNewList(displays[i], 4864);
|
|
|
|
|
|
|
|
toReturn.minX = 0 + .01;
|
|
|
|
toReturn.minY = 0 + .01;
|
|
|
|
toReturn.minZ = 0 + .01;
|
|
|
|
|
|
|
|
toReturn.maxX = data.length-2 - .01;
|
|
|
|
toReturn.maxY = ((float)i/(float)stages)*(data.height-2) - .01;
|
|
|
|
toReturn.maxZ = data.width-2 - .01;
|
|
|
|
|
2013-06-02 23:44:59 +02:00
|
|
|
MekanismRenderer.renderObject(toReturn);
|
2013-04-28 21:23:08 +02:00
|
|
|
GL11.glEndList();
|
|
|
|
}
|
|
|
|
|
2013-06-25 18:28:40 +02:00
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
return displays;
|
|
|
|
}
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
private DisplayInteger getValveDisplay(ValveRenderData data, Fluid fluid, World world)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
if(cachedValveFluids.containsKey(data) && cachedValveFluids.get(data).containsKey(fluid))
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
return cachedValveFluids.get(data).get(fluid);
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Model3D toReturn = new Model3D();
|
|
|
|
toReturn.baseBlock = Block.waterStill;
|
2013-07-20 18:10:14 +02:00
|
|
|
toReturn.setTexture(fluid.getFlowingIcon());
|
2013-04-28 21:23:08 +02:00
|
|
|
|
2013-05-23 19:30:12 +02:00
|
|
|
DisplayInteger display = new DisplayInteger();
|
2013-04-28 21:23:08 +02:00
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
if(cachedValveFluids.containsKey(data))
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
cachedValveFluids.get(data).put(fluid, display);
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-07-20 18:10:14 +02:00
|
|
|
HashMap<Fluid, DisplayInteger> map = new HashMap<Fluid, DisplayInteger>();
|
|
|
|
map.put(fluid, display);
|
|
|
|
cachedValveFluids.put(data, map);
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
MekanismRenderer.colorFluid(fluid);
|
2013-06-26 23:49:47 +02:00
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
display.display = GLAllocation.generateDisplayLists(1);
|
|
|
|
GL11.glNewList(display.display, 4864);
|
|
|
|
|
|
|
|
switch(data.side)
|
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
{
|
|
|
|
toReturn.minX = .3;
|
|
|
|
toReturn.minY = 1 + .01;
|
|
|
|
toReturn.minZ = .3;
|
|
|
|
|
|
|
|
toReturn.maxX = .7;
|
|
|
|
toReturn.maxY = 1.4 + .1;
|
|
|
|
toReturn.maxZ = .7;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case UP:
|
|
|
|
{
|
|
|
|
toReturn.minX = .3;
|
|
|
|
toReturn.minY = -(data.height-2) - .01;
|
|
|
|
toReturn.minZ = .3;
|
|
|
|
|
|
|
|
toReturn.maxX = .7;
|
|
|
|
toReturn.maxY = -.01;
|
|
|
|
toReturn.maxZ = .7;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NORTH:
|
|
|
|
{
|
|
|
|
toReturn.minX = .3;
|
2013-07-20 18:10:14 +02:00
|
|
|
toReturn.minY = -(getValveFluidHeight(data)) + .01;
|
2013-04-28 21:23:08 +02:00
|
|
|
toReturn.minZ = 1 + .02;
|
|
|
|
|
|
|
|
toReturn.maxX = .7;
|
|
|
|
toReturn.maxY = .7;
|
|
|
|
toReturn.maxZ = 1.4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SOUTH:
|
|
|
|
{
|
|
|
|
toReturn.minX = .3;
|
2013-07-20 18:10:14 +02:00
|
|
|
toReturn.minY = -(getValveFluidHeight(data)) + .01;
|
2013-04-28 21:23:08 +02:00
|
|
|
toReturn.minZ = -.4;
|
|
|
|
|
|
|
|
toReturn.maxX = .7;
|
|
|
|
toReturn.maxY = .7;
|
|
|
|
toReturn.maxZ = -.02;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WEST:
|
|
|
|
{
|
|
|
|
toReturn.minX = 1 + .02;
|
2013-07-20 18:10:14 +02:00
|
|
|
toReturn.minY = -(getValveFluidHeight(data)) + .01;
|
2013-04-28 21:23:08 +02:00
|
|
|
toReturn.minZ = .3;
|
|
|
|
|
|
|
|
toReturn.maxX = 1.4;
|
|
|
|
toReturn.maxY = .7;
|
|
|
|
toReturn.maxZ = .7;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EAST:
|
|
|
|
{
|
|
|
|
toReturn.minX = -.4;
|
2013-07-20 18:10:14 +02:00
|
|
|
toReturn.minY = -(getValveFluidHeight(data)) + .01;
|
2013-04-28 21:23:08 +02:00
|
|
|
toReturn.minZ = .3;
|
|
|
|
|
|
|
|
toReturn.maxX = -.02;
|
|
|
|
toReturn.maxY = .7;
|
|
|
|
toReturn.maxZ = .7;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 23:44:59 +02:00
|
|
|
MekanismRenderer.renderObject(toReturn);
|
2013-04-28 21:23:08 +02:00
|
|
|
GL11.glEndList();
|
|
|
|
|
2013-06-27 17:03:50 +02:00
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
|
2013-04-28 21:23:08 +02:00
|
|
|
return display;
|
|
|
|
}
|
|
|
|
|
2013-07-20 18:10:14 +02:00
|
|
|
private int getValveFluidHeight(ValveRenderData data)
|
2013-04-28 21:23:08 +02:00
|
|
|
{
|
|
|
|
return data.valveLocation.yCoord - data.location.yCoord;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getStages(int height)
|
|
|
|
{
|
2013-05-07 01:42:03 +02:00
|
|
|
return (height-2)*1600;
|
2013-04-28 21:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private double getX(int x)
|
|
|
|
{
|
|
|
|
return x - TileEntityRenderer.staticPlayerX;
|
|
|
|
}
|
|
|
|
|
|
|
|
private double getY(int y)
|
|
|
|
{
|
|
|
|
return y - TileEntityRenderer.staticPlayerY;
|
|
|
|
}
|
|
|
|
|
|
|
|
private double getZ(int z)
|
|
|
|
{
|
|
|
|
return z - TileEntityRenderer.staticPlayerZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class RenderData
|
|
|
|
{
|
|
|
|
public Object3D location;
|
|
|
|
|
|
|
|
public int height;
|
|
|
|
public int length;
|
|
|
|
public int width;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode()
|
|
|
|
{
|
|
|
|
int code = 1;
|
|
|
|
code = 31 * code + location.hashCode();
|
|
|
|
code = 31 * code + height;
|
|
|
|
code = 31 * code + length;
|
|
|
|
code = 31 * code + width;
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object data)
|
|
|
|
{
|
|
|
|
return data instanceof RenderData && ((RenderData)data).location.equals(location) && ((RenderData)data).height == height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class ValveRenderData extends RenderData
|
|
|
|
{
|
|
|
|
public ForgeDirection side;
|
|
|
|
public Object3D valveLocation;
|
|
|
|
|
|
|
|
public static ValveRenderData get(RenderData renderData, ValveData valveData)
|
|
|
|
{
|
|
|
|
ValveRenderData data = new ValveRenderData();
|
|
|
|
|
|
|
|
data.location = renderData.location;
|
|
|
|
data.height = renderData.height;
|
|
|
|
data.length = renderData.length;
|
|
|
|
data.width = renderData.width;
|
|
|
|
|
|
|
|
data.side = valveData.side;
|
|
|
|
data.valveLocation = valveData.location;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object data)
|
|
|
|
{
|
|
|
|
return data instanceof ValveRenderData && super.equals(data) && ((ValveRenderData)data).side.equals(side);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode()
|
|
|
|
{
|
|
|
|
int code = 1;
|
|
|
|
code = 31 * code + super.hashCode();
|
|
|
|
code = 31 * code + side.ordinal();
|
|
|
|
code = 31 * code + valveLocation.hashCode();
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|