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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
package tectech.rendering.EOH;
import static java.lang.Math.pow;
import static tectech.Reference.MODID;
import static tectech.rendering.EOH.EOHTileEntitySR.STAR_LAYER_0;
import static tectech.rendering.EOH.EOHTileEntitySR.STAR_LAYER_1;
import static tectech.rendering.EOH.EOHTileEntitySR.STAR_LAYER_2;
import static tectech.rendering.EOH.EOHTileEntitySR.spaceModel;
import static tectech.rendering.EOH.EOHTileEntitySR.starModel;
import java.awt.Color;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.client.FMLClientHandler;
public abstract class EOHRenderingUtils {
public static void renderStar(IItemRenderer.ItemRenderType type, Color color, int size) {
GL11.glPushMatrix();
if (type == IItemRenderer.ItemRenderType.INVENTORY) GL11.glRotated(180, 0, 1, 0);
else if (type == IItemRenderer.ItemRenderType.EQUIPPED
|| type == IItemRenderer.ItemRenderType.EQUIPPED_FIRST_PERSON) {
GL11.glTranslated(0.5, 0.5, 0.5);
if (type == IItemRenderer.ItemRenderType.EQUIPPED) GL11.glRotated(90, 0, 1, 0);
}
// Render star stuff.
renderStarLayer(0, STAR_LAYER_0, color, 1.0f, size);
renderStarLayer(1, STAR_LAYER_1, color, 0.4f, size);
renderStarLayer(2, STAR_LAYER_2, color, 0.2f, size);
GL11.glPopMatrix();
}
public static void renderStar(IItemRenderer.ItemRenderType type, int size) {
renderStar(type, new Color(1.0f, 0.4f, 0.05f, 1.0f), size);
}
public static void renderStarLayer(int layer, ResourceLocation texture, Color color, float alpha, int size) {
// Begin animation.
GL11.glPushMatrix();
// OpenGL settings, not sure exactly what these do.
// Disables lighting, so star is always lit (I think).
GL11.glDisable(GL11.GL_LIGHTING);
// Culls triangles/quads facing away from the camera
GL11.glEnable(GL11.GL_CULL_FACE);
// Allows alpha blending to occur (transparency-based color mixing)
GL11.glEnable(GL11.GL_BLEND);
// ???
if (alpha < 1.0f) {
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
} else {
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
// Bind image to layer of star.
FMLClientHandler.instance()
.getClient()
.getTextureManager()
.bindTexture(texture);
// 0.01f magic number to shrink sphere obj down.
// Size obtained from the multis current recipe.
float scale = 0.01f * size;
// Put each subsequent layer further out.
scale *= pow(1.04f, layer);
// Scale the star up in the x, y and z directions.
GL11.glScalef(scale, scale, scale);
switch (layer) {
case 0 -> GL11.glRotatef(130 + (System.currentTimeMillis() / 64) % 360, 0F, 1F, 1F);
case 1 -> GL11.glRotatef(-49 + (System.currentTimeMillis() / 64) % 360, 1F, 1F, 0F);
case 2 -> GL11.glRotatef(67 + (System.currentTimeMillis() / 64) % 360, 1F, 0F, 1F);
}
// Set colour and alpha (transparency) of the star layer.
final float red = color.getRed() / 255.0f;
final float green = color.getGreen() / 255.0f;
final float blue = color.getBlue() / 255.0f;
GL11.glColor4f(red, green, blue, alpha);
starModel.renderAll();
GL11.glDisable(GL11.GL_BLEND);
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
// Finish animation.
GL11.glPopMatrix();
}
public static void beginRenderingBlocksInWorld(final float blockSize) {
final Tessellator tes = Tessellator.instance;
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glDisable(GL11.GL_LIGHTING);
tes.setColorOpaque_F(1f, 1f, 1f);
tes.startDrawingQuads();
GL11.glScalef(blockSize, blockSize, blockSize);
}
public static void endRenderingBlocksInWorld() {
Tessellator.instance.draw();
GL11.glPopAttrib();
GL11.glPopMatrix();
}
static final double[] BLOCK_X = { -0.5, -0.5, +0.5, +0.5, +0.5, +0.5, -0.5, -0.5 };
static final double[] BLOCK_Y = { +0.5, -0.5, -0.5, +0.5, +0.5, -0.5, -0.5, +0.5 };
static final double[] BLOCK_Z = { +0.5, +0.5, +0.5, +0.5, -0.5, -0.5, -0.5, -0.5 };
public static void addRenderedBlockInWorld(final Block block, final int meta, final double x, final double y,
final double z) {
final Tessellator tes = Tessellator.instance;
IIcon texture;
double minU;
double maxU;
double minV;
double maxV;
{
texture = block.getIcon(4, meta);
minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();
tes.addVertexWithUV(x + BLOCK_X[1], y + BLOCK_Y[1], z + BLOCK_Z[1], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[0], y + BLOCK_Y[0], z + BLOCK_Z[0], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[7], y + BLOCK_Y[7], z + BLOCK_Z[7], minU, minV);
tes.addVertexWithUV(x + BLOCK_X[6], y + BLOCK_Y[6], z + BLOCK_Z[6], minU, maxV);
}
{
// Bottom face.
texture = block.getIcon(0, meta);
minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();
tes.addVertexWithUV(x + BLOCK_X[5], y + BLOCK_Y[5], z + BLOCK_Z[5], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[2], y + BLOCK_Y[2], z + BLOCK_Z[2], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[1], y + BLOCK_Y[1], z + BLOCK_Z[1], minU, maxV);
tes.addVertexWithUV(x + BLOCK_X[6], y + BLOCK_Y[6], z + BLOCK_Z[6], minU, minV);
}
{
texture = block.getIcon(2, meta);
minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();
tes.addVertexWithUV(x + BLOCK_X[6], y + BLOCK_Y[6], z + BLOCK_Z[6], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[7], y + BLOCK_Y[7], z + BLOCK_Z[7], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[4], y + BLOCK_Y[4], z + BLOCK_Z[4], minU, minV);
tes.addVertexWithUV(x + BLOCK_X[5], y + BLOCK_Y[5], z + BLOCK_Z[5], minU, maxV);
}
{
texture = block.getIcon(5, meta);
minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();
tes.addVertexWithUV(x + BLOCK_X[5], y + BLOCK_Y[5], z + BLOCK_Z[5], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[4], y + BLOCK_Y[4], z + BLOCK_Z[4], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[3], y + BLOCK_Y[3], z + BLOCK_Z[3], minU, minV);
tes.addVertexWithUV(x + BLOCK_X[2], y + BLOCK_Y[2], z + BLOCK_Z[2], minU, maxV);
}
{
texture = block.getIcon(1, meta);
minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();
tes.addVertexWithUV(x + BLOCK_X[3], y + BLOCK_Y[3], z + BLOCK_Z[3], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[4], y + BLOCK_Y[4], z + BLOCK_Z[4], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[7], y + BLOCK_Y[7], z + BLOCK_Z[7], minU, minV);
tes.addVertexWithUV(x + BLOCK_X[0], y + BLOCK_Y[0], z + BLOCK_Z[0], minU, maxV);
}
{
texture = block.getIcon(3, meta);
minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();
tes.addVertexWithUV(x + BLOCK_X[2], y + BLOCK_Y[2], z + BLOCK_Z[2], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[3], y + BLOCK_Y[3], z + BLOCK_Z[3], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[0], y + BLOCK_Y[0], z + BLOCK_Z[0], minU, minV);
tes.addVertexWithUV(x + BLOCK_X[1], y + BLOCK_Y[1], z + BLOCK_Z[1], minU, maxV);
}
}
public static void renderBlockInWorld(final Block block, final int meta, final float blockSize) {
beginRenderingBlocksInWorld(blockSize);
addRenderedBlockInWorld(block, meta, 0, 0, 0);
endRenderingBlocksInWorld();
}
public static void renderOuterSpaceShell() {
// Save current OpenGL state.
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
// Begin animation.
GL11.glPushMatrix();
// Disables lighting, so star is always lit.
GL11.glDisable(GL11.GL_LIGHTING);
// Merges colors of the various layers of the star.
// GL11.glEnable(GL11.GL_BLEND);
// Bind animation to layer of star.
FMLClientHandler.instance()
.getClient()
.getTextureManager()
.bindTexture(new ResourceLocation(MODID, "models/spaceLayer.png"));
final float scale = 0.01f * 17.5f;
// Scale the star up in the x, y and z directions.
GL11.glScalef(scale, scale, scale);
GL11.glColor4f(1, 1, 1, 1);
spaceModel.renderAll();
// Finish animation.
GL11.glPopMatrix();
// Restore previous OpenGL state.
GL11.glPopAttrib();
}
}
|