2014-01-17 03:55:29 +01:00
|
|
|
package mekanism.client.render.tileentity;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import mekanism.api.Coord4D;
|
|
|
|
import mekanism.client.render.MekanismRenderer;
|
|
|
|
import mekanism.client.render.MekanismRenderer.DisplayInteger;
|
|
|
|
import mekanism.client.render.MekanismRenderer.Model3D;
|
|
|
|
import mekanism.common.tank.TankUpdateProtocol;
|
|
|
|
import mekanism.common.tile.TileEntitySalinationController;
|
|
|
|
import mekanism.common.util.MekanismUtils;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
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;
|
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public class RenderSalinationController extends TileEntitySpecialRenderer
|
|
|
|
{
|
|
|
|
private static Map<SalinationRenderData, HashMap<Fluid, DisplayInteger[]>> cachedCenterFluids = new HashMap<SalinationRenderData, HashMap<Fluid, DisplayInteger[]>>();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
@Override
|
|
|
|
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
|
|
|
|
{
|
|
|
|
renderAModelAt((TileEntitySalinationController)tileEntity, x, y, z, partialTick);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
public void renderAModelAt(TileEntitySalinationController tileEntity, double x, double y, double z, float partialTick)
|
2014-03-08 02:00:25 +01:00
|
|
|
{
|
2014-01-17 04:12:51 +01:00
|
|
|
if(tileEntity.structured && tileEntity.waterTank.getFluid() != null)
|
2014-01-17 03:55:29 +01:00
|
|
|
{
|
|
|
|
SalinationRenderData data = new SalinationRenderData();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
data.height = tileEntity.height-2;
|
2014-01-17 04:12:51 +01:00
|
|
|
data.side = ForgeDirection.getOrientation(tileEntity.facing);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
bindTexture(MekanismRenderer.getBlocksTexture());
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 04:49:48 +01:00
|
|
|
if(data.height >= 2 && tileEntity.waterTank.getCapacity() > 0)
|
2014-01-17 03:55:29 +01:00
|
|
|
{
|
|
|
|
Coord4D renderLoc = tileEntity.getRenderLocation();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
push();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
GL11.glTranslated(getX(renderLoc.xCoord), getY(renderLoc.yCoord), getZ(renderLoc.zCoord));
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
MekanismRenderer.glowOn(tileEntity.waterTank.getFluid().getFluid().getLuminosity());
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 04:12:51 +01:00
|
|
|
DisplayInteger[] displayList = getListAndRender(data, tileEntity.waterTank.getFluid().getFluid());
|
2014-01-17 04:49:48 +01:00
|
|
|
displayList[(int)(((float)tileEntity.waterTank.getFluidAmount()/tileEntity.waterTank.getCapacity())*((float)getStages(data.height)-1))].render();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
MekanismRenderer.glowOff();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
pop();
|
|
|
|
}
|
2014-01-17 04:12:51 +01:00
|
|
|
}
|
2014-01-17 03:55:29 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
private void pop()
|
|
|
|
{
|
|
|
|
GL11.glPopAttrib();
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
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);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 04:12:51 +01:00
|
|
|
@SuppressWarnings("incomplete-switch")
|
|
|
|
private DisplayInteger[] getListAndRender(SalinationRenderData data, Fluid fluid)
|
2014-01-17 03:55:29 +01:00
|
|
|
{
|
|
|
|
if(cachedCenterFluids.containsKey(data) && cachedCenterFluids.get(data).containsKey(fluid))
|
|
|
|
{
|
|
|
|
return cachedCenterFluids.get(data).get(fluid);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
Model3D toReturn = new Model3D();
|
|
|
|
toReturn.baseBlock = Block.waterStill;
|
|
|
|
toReturn.setTexture(fluid.getIcon());
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
final int stages = getStages(data.height);
|
|
|
|
DisplayInteger[] displays = new DisplayInteger[stages];
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
if(cachedCenterFluids.containsKey(data))
|
|
|
|
{
|
|
|
|
cachedCenterFluids.get(data).put(fluid, displays);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
HashMap<Fluid, DisplayInteger[]> map = new HashMap<Fluid, DisplayInteger[]>();
|
|
|
|
map.put(fluid, displays);
|
|
|
|
cachedCenterFluids.put(data, map);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
MekanismRenderer.colorFluid(fluid);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
for(int i = 0; i < stages; i++)
|
|
|
|
{
|
|
|
|
displays[i] = DisplayInteger.createAndStart();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
if(fluid.getIcon() != null)
|
|
|
|
{
|
2014-01-17 04:12:51 +01:00
|
|
|
switch(data.side)
|
|
|
|
{
|
|
|
|
case NORTH:
|
2014-01-17 04:49:48 +01:00
|
|
|
toReturn.minX = 0 + .01;
|
2014-01-17 04:12:51 +01:00
|
|
|
toReturn.minY = 0 + .01;
|
|
|
|
toReturn.minZ = 0 + .01;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 04:12:51 +01:00
|
|
|
toReturn.maxX = 2 - .01;
|
2014-01-17 04:49:48 +01:00
|
|
|
toReturn.maxY = ((float)i/(float)stages)*data.height - .01;
|
2014-01-17 04:12:51 +01:00
|
|
|
toReturn.maxZ = 2 - .01;
|
|
|
|
break;
|
|
|
|
case SOUTH:
|
2014-01-17 04:49:48 +01:00
|
|
|
toReturn.minX = -1 + .01;
|
|
|
|
toReturn.minY = 0 + .01;
|
|
|
|
toReturn.minZ = -1 + .01;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 04:49:48 +01:00
|
|
|
toReturn.maxX = 1 - .01;
|
|
|
|
toReturn.maxY = ((float)i/(float)stages)*data.height - .01;
|
|
|
|
toReturn.maxZ = 1 - .01;
|
2014-01-17 04:12:51 +01:00
|
|
|
break;
|
|
|
|
case WEST:
|
2014-01-17 04:49:48 +01:00
|
|
|
toReturn.minX = 0 + .01;
|
|
|
|
toReturn.minY = 0 + .01;
|
|
|
|
toReturn.minZ = -1 + .01;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 04:49:48 +01:00
|
|
|
toReturn.maxX = 2 - .01;
|
|
|
|
toReturn.maxY = ((float)i/(float)stages)*data.height - .01;
|
|
|
|
toReturn.maxZ = 1 - .01;
|
2014-01-17 04:12:51 +01:00
|
|
|
break;
|
|
|
|
case EAST:
|
2014-01-17 04:49:48 +01:00
|
|
|
toReturn.minX = -1 + .01;
|
|
|
|
toReturn.minY = 0 + .01;
|
|
|
|
toReturn.minZ = 0 + .01;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 04:49:48 +01:00
|
|
|
toReturn.maxX = 1 - .01;
|
|
|
|
toReturn.maxY = ((float)i/(float)stages)*data.height - .01;
|
|
|
|
toReturn.maxZ = 2 - .01;
|
2014-01-17 04:12:51 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 04:49:48 +01:00
|
|
|
MekanismRenderer.renderObject(toReturn);
|
2014-01-17 03:55:29 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 04:12:51 +01:00
|
|
|
displays[i].endList();
|
2014-01-17 03:55:29 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
return displays;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
private int getStages(int height)
|
|
|
|
{
|
2014-01-17 04:49:48 +01:00
|
|
|
return height*(TankUpdateProtocol.FLUID_PER_TANK/10);
|
2014-01-17 03:55:29 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
private double getX(int x)
|
|
|
|
{
|
|
|
|
return x - TileEntityRenderer.staticPlayerX;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
private double getY(int y)
|
|
|
|
{
|
|
|
|
return y - TileEntityRenderer.staticPlayerY;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
private double getZ(int z)
|
|
|
|
{
|
|
|
|
return z - TileEntityRenderer.staticPlayerZ;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
public static class SalinationRenderData
|
|
|
|
{
|
|
|
|
public int height;
|
2014-01-17 04:12:51 +01:00
|
|
|
public ForgeDirection side;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public int hashCode()
|
2014-01-17 03:55:29 +01:00
|
|
|
{
|
|
|
|
int code = 1;
|
|
|
|
code = 31 * code + height;
|
|
|
|
return code;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 03:55:29 +01:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object data)
|
|
|
|
{
|
2014-01-17 04:12:51 +01:00
|
|
|
return data instanceof SalinationRenderData && ((SalinationRenderData)data).height == height &&
|
|
|
|
((SalinationRenderData)data).side == side;
|
2014-01-17 03:55:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|