-
Notifications
You must be signed in to change notification settings - Fork 497
/
RenderRefinery.java
227 lines (185 loc) · 6.36 KB
/
RenderRefinery.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/**
* 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 buildcraft.core.DefaultProps;
import buildcraft.core.IInventoryRenderer;
import buildcraft.core.fluids.Tank;
import buildcraft.core.render.FluidRenderer;
import buildcraft.factory.TileRefinery;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
public class RenderRefinery extends TileEntitySpecialRenderer implements IInventoryRenderer {
private static final ResourceLocation TEXTURE = new ResourceLocation(DefaultProps.TEXTURE_PATH_BLOCKS + "/refinery.png");
private static final float pixel = (float) (1.0 / 16.0);
private final ModelRenderer tank;
private final ModelRenderer magnet[] = new ModelRenderer[4];
private final ModelBase model = new ModelBase() {
};
public RenderRefinery() {
// constructor:
tank = new ModelRenderer(model, 0, 0);
tank.addBox(-4F, -8F, -4F, 8, 16, 8);
tank.rotationPointX = 8;
tank.rotationPointY = 8;
tank.rotationPointZ = 8;
// constructor:
for (int i = 0; i < 4; ++i) {
magnet[i] = new ModelRenderer(model, 32, i * 8);
magnet[i].addBox(0, -8F, -8F, 8, 4, 4);
magnet[i].rotationPointX = 8;
magnet[i].rotationPointY = 8;
magnet[i].rotationPointZ = 8;
}
setTileEntityRenderer(TileEntityRenderer.instance);
}
public RenderRefinery(String baseTexture) {
this();
}
@Override
public void inventoryRender(double x, double y, double z, float f, float f1) {
render(null, x, y, z);
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
render((TileRefinery) tileentity, x, y, z);
}
private void render(TileRefinery tile, double x, double y, double z) {
FluidStack liquid1 = null, liquid2 = null, liquidResult = null;
float anim = 0;
int angle = 0;
ModelRenderer theMagnet = magnet[0];
if (tile != null) {
if (tile.tank1.getFluid() != null) {
liquid1 = tile.tank1.getFluid();
}
if (tile.tank2.getFluid() != null) {
liquid2 = tile.tank2.getFluid();
}
if (tile.result.getFluid() != null) {
liquidResult = tile.result.getFluid();
}
anim = tile.getAnimationStage();
angle = 0;
switch (tile.worldObj.getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord)) {
case 2:
angle = 90;
break;
case 3:
angle = 270;
break;
case 4:
angle = 180;
break;
case 5:
angle = 0;
break;
}
if (tile.animationSpeed <= 1) {
theMagnet = magnet[0];
} else if (tile.animationSpeed <= 2.5) {
theMagnet = magnet[1];
} else if (tile.animationSpeed <= 4.5) {
theMagnet = magnet[2];
} else {
theMagnet = magnet[3];
}
}
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glTranslatef((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
GL11.glScalef(0.99F, 0.99F, 0.99F);
GL11.glRotatef(angle, 0, 1, 0);
func_110628_a(TEXTURE);
GL11.glPushMatrix();
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
GL11.glTranslatef(-4F * pixel, 0, -4F * pixel);
tank.render(pixel);
GL11.glTranslatef(4F * pixel, 0, 4F * pixel);
GL11.glTranslatef(-4F * pixel, 0, 4F * pixel);
tank.render(pixel);
GL11.glTranslatef(4F * pixel, 0, -4F * pixel);
GL11.glTranslatef(4F * pixel, 0, 0);
tank.render(pixel);
GL11.glTranslatef(-4F * pixel, 0, 0);
GL11.glPopMatrix();
float trans1, trans2;
if (anim <= 100) {
trans1 = 12F * pixel * anim / 100F;
trans2 = 0;
} else if (anim <= 200) {
trans1 = 12F * pixel - (12F * pixel * (anim - 100F) / 100F);
trans2 = 12F * pixel * (anim - 100F) / 100F;
} else {
trans1 = 12F * pixel * (anim - 200F) / 100F;
trans2 = 12F * pixel - (12F * pixel * (anim - 200F) / 100F);
}
GL11.glPushMatrix();
GL11.glScalef(0.99F, 0.99F, 0.99F);
GL11.glTranslatef(-0.51F, trans1 - 0.5F, -0.5F);
theMagnet.render(pixel);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glScalef(0.99F, 0.99F, 0.99F);
GL11.glTranslatef(-0.51F, trans2 - 0.5F, 12F * pixel - 0.5F);
theMagnet.render(pixel);
GL11.glPopMatrix();
if (tile != null) {
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
GL11.glScalef(0.5F, 1, 0.5F);
if (liquid1 != null && liquid1.amount > 0) {
int[] list1 = FluidRenderer.getFluidDisplayLists(liquid1, tile.worldObj, false);
if (list1 != null) {
func_110628_a(FluidRenderer.getFluidSheet(liquid1));
FluidRenderer.setColorForFluidStack(liquid1);
GL11.glCallList(list1[getDisplayListIndex(tile.tank1)]);
}
}
if (liquid2 != null && liquid2.amount > 0) {
int[] list2 = FluidRenderer.getFluidDisplayLists(liquid2, tile.worldObj, false);
if (list2 != null) {
GL11.glPushMatrix();
GL11.glTranslatef(0, 0, 1);
func_110628_a(FluidRenderer.getFluidSheet(liquid2));
FluidRenderer.setColorForFluidStack(liquid2);
GL11.glCallList(list2[getDisplayListIndex(tile.tank2)]);
GL11.glPopMatrix();
}
}
if (liquidResult != null && liquidResult.amount > 0) {
int[] list3 = FluidRenderer.getFluidDisplayLists(liquidResult, tile.worldObj, false);
if (list3 != null) {
GL11.glPushMatrix();
GL11.glTranslatef(1, 0, 0.5F);
func_110628_a(FluidRenderer.getFluidSheet(liquidResult));
FluidRenderer.setColorForFluidStack(liquidResult);
GL11.glCallList(list3[getDisplayListIndex(tile.result)]);
GL11.glPopMatrix();
}
}
GL11.glPopAttrib();
}
GL11.glPopAttrib();
GL11.glPopMatrix();
}
private int getDisplayListIndex(Tank tank) {
return Math.min((int) ((float) tank.getFluidAmount() / (float) tank.getCapacity() * (FluidRenderer.DISPLAY_STAGES - 1)), FluidRenderer.DISPLAY_STAGES - 1);
}
}