-
Notifications
You must be signed in to change notification settings - Fork 497
/
RenderEngine.java
188 lines (145 loc) · 5.46 KB
/
RenderEngine.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
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* 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.energy.render;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftCore.RenderMode;
import buildcraft.core.IInventoryRenderer;
import buildcraft.energy.TileEngine;
public class RenderEngine extends TileEntitySpecialRenderer implements IInventoryRenderer {
private static final float[] angleMap = new float[6];
static {
angleMap[ForgeDirection.EAST.ordinal()] = (float) -Math.PI / 2;
angleMap[ForgeDirection.WEST.ordinal()] = (float) Math.PI / 2;
angleMap[ForgeDirection.UP.ordinal()] = 0;
angleMap[ForgeDirection.DOWN.ordinal()] = (float) Math.PI;
angleMap[ForgeDirection.SOUTH.ordinal()] = (float) Math.PI / 2;
angleMap[ForgeDirection.NORTH.ordinal()] = (float) -Math.PI / 2;
}
private ModelBase model = new ModelBase() {
};
private ModelRenderer box;
private ModelRenderer trunk;
private ModelRenderer movingBox;
private ModelRenderer chamber;
private ResourceLocation baseTexture;
private ResourceLocation chamberTexture;
private ResourceLocation trunkTexture;
public RenderEngine() {
box = new ModelRenderer(model, 0, 1);
box.addBox(-8F, -8F, -8F, 16, 4, 16);
box.rotationPointX = 8;
box.rotationPointY = 8;
box.rotationPointZ = 8;
trunk = new ModelRenderer(model, 1, 1);
trunk.addBox(-4F, -4F, -4F, 8, 12, 8);
trunk.rotationPointX = 8F;
trunk.rotationPointY = 8F;
trunk.rotationPointZ = 8F;
movingBox = new ModelRenderer(model, 0, 1);
movingBox.addBox(-8F, -4, -8F, 16, 4, 16);
movingBox.rotationPointX = 8F;
movingBox.rotationPointY = 8F;
movingBox.rotationPointZ = 8F;
chamber = new ModelRenderer(model, 1, 1);
chamber.addBox(-5F, -4, -5F, 10, 2, 10);
chamber.rotationPointX = 8F;
chamber.rotationPointY = 8F;
chamber.rotationPointZ = 8F;
}
public RenderEngine(ResourceLocation baseTexture, ResourceLocation chamberTexture, ResourceLocation trunkTexture) {
this();
this.baseTexture = baseTexture;
this.chamberTexture = chamberTexture;
this.trunkTexture = trunkTexture;
field_147501_a = TileEntityRendererDispatcher.instance;
}
@Override
public void inventoryRender(double x, double y, double z, float f, float f1) {
render(0.25F, ForgeDirection.UP, baseTexture, chamberTexture, trunkTexture, x, y, z);
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
TileEngine engine = (TileEngine) tileentity;
if (engine != null) {
render(engine.progress, engine.orientation, engine.getBaseTexture(), engine.getChamberTexture(), engine.getTrunkTexture(engine.getEnergyStage()), x, y, z);
}
}
private void render(float progress, ForgeDirection orientation, ResourceLocation baseTexture, ResourceLocation chamberTexture, ResourceLocation trunkTexture, double x, double y, double z) {
if (BuildCraftCore.render == RenderMode.NoDynamic) {
return;
}
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glColor3f(1, 1, 1);
GL11.glTranslatef((float) x, (float) y, (float) z);
float step;
if (progress > 0.5) {
step = 7.99F - (progress - 0.5F) * 2F * 7.99F;
} else {
step = progress * 2F * 7.99F;
}
float translatefact = step / 16;
float[] angle = {0, 0, 0};
float[] translate = {orientation.offsetX, orientation.offsetY, orientation.offsetZ};
switch (orientation) {
case EAST:
case WEST:
case DOWN:
angle[2] = angleMap[orientation.ordinal()];
break;
case SOUTH:
case NORTH:
default:
angle[0] = angleMap[orientation.ordinal()];
break;
}
box.rotateAngleX = angle[0];
box.rotateAngleY = angle[1];
box.rotateAngleZ = angle[2];
trunk.rotateAngleX = angle[0];
trunk.rotateAngleY = angle[1];
trunk.rotateAngleZ = angle[2];
movingBox.rotateAngleX = angle[0];
movingBox.rotateAngleY = angle[1];
movingBox.rotateAngleZ = angle[2];
chamber.rotateAngleX = angle[0];
chamber.rotateAngleY = angle[1];
chamber.rotateAngleZ = angle[2];
float factor = (float) (1.0 / 16.0);
bindTexture(baseTexture);
box.render(factor);
GL11.glTranslatef(translate[0] * translatefact, translate[1] * translatefact, translate[2] * translatefact);
movingBox.render(factor);
GL11.glTranslatef(-translate[0] * translatefact, -translate[1] * translatefact, -translate[2] * translatefact);
bindTexture(chamberTexture);
float chamberf = 2F / 16F;
for (int i = 0; i <= step + 2; i += 2) {
chamber.render(factor);
GL11.glTranslatef(translate[0] * chamberf, translate[1] * chamberf, translate[2] * chamberf);
}
for (int i = 0; i <= step + 2; i += 2) {
GL11.glTranslatef(-translate[0] * chamberf, -translate[1] * chamberf, -translate[2] * chamberf);
}
bindTexture(trunkTexture);
trunk.render(factor);
GL11.glPopAttrib();
GL11.glPopMatrix();
}
}