-
Notifications
You must be signed in to change notification settings - Fork 497
/
RenderTank.java
104 lines (73 loc) · 2.82 KB
/
RenderTank.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.factory.render;
import java.util.HashMap;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
import org.lwjgl.opengl.GL11;
import buildcraft.core.render.RenderEntityBlock;
import buildcraft.core.render.RenderEntityBlock.BlockInterface;
import buildcraft.factory.TileTank;
public class RenderTank extends TileEntitySpecialRenderer {
final static private int displayStages = 100;
private final HashMap<LiquidStack, int[]> stage = new HashMap<LiquidStack, int[]>();
private int[] getDisplayLists(LiquidStack liquid, World world) {
if (stage.containsKey(liquid)) {
return stage.get(liquid);
}
int[] d = new int[displayStages];
stage.put(liquid, d);
BlockInterface block = new BlockInterface();
block.baseBlock = Block.waterStill;
block.texture = liquid.getRenderingIcon();
String spriteSet = liquid.getTextureSheet();
if (liquid.itemID < Block.blocksList.length && Block.blocksList[liquid.itemID] != null) {
block.baseBlock = Block.blocksList[liquid.itemID];
}
for (int s = 0; s < displayStages; ++s) {
d[s] = GLAllocation.generateDisplayLists(1);
GL11.glNewList(d[s], 4864 /* GL_COMPILE */);
Minecraft.getMinecraft().renderEngine.bindTexture(spriteSet);
block.minX = 0.125 + 0.01;
block.minY = 0;
block.minZ = 0.125 + 0.01;
block.maxX = 0.875 - 0.01;
block.maxY = (float) s / (float) displayStages;
block.maxZ = 0.875 - 0.01;
RenderEntityBlock.renderBlock(block, world, 0, 0, 0, false, true);
GL11.glEndList();
}
return d;
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
TileTank tank = ((TileTank) tileentity);
LiquidStack liquid = tank.tank.getLiquid();
if (liquid == null)
return;
LiquidStack refLiquid = liquid.canonical();
if (refLiquid == null || liquid.amount <= 0)
return;
int[] displayList = getDisplayLists(refLiquid, tileentity.worldObj);
if (displayList == null)
return;
GL11.glPushMatrix();
GL11.glDisable(2896 /* GL_LIGHTING */);
GL11.glTranslatef((float) x, (float) y, (float) z);
GL11.glCallList(displayList[(int) ((float) liquid.amount / (float) (tank.tank.getCapacity()) * (displayStages - 1))]);
GL11.glEnable(2896 /* GL_LIGHTING */);
GL11.glPopMatrix();
}
}