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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
package kr.syeyoung.dungeonsguide.utils;
import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonDoor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3;
import org.lwjgl.opengl.GL11;
import javax.vecmath.Vector3f;
import java.awt.*;
import java.util.List;
public class RenderUtils {
public static void drawUnfilledBox(int left, int top, int right, int bottom, int color, boolean chroma)
{
if (left < right)
{
int i = left;
left = right;
right = i;
}
if (top < bottom)
{
int j = top;
top = bottom;
bottom = j;
}
float f3 = (float)(color >> 24 & 255) / 255.0F;
float f = (float)(color >> 16 & 255) / 255.0F;
float f1 = (float)(color >> 8 & 255) / 255.0F;
float f2 = (float)(color & 255) / 255.0F;
if (!chroma && f3 == 0) return;
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
if (!chroma) {
GlStateManager.color(f, f1, f2, f3);
worldrenderer.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION);
worldrenderer.pos((double) left, (double) bottom, 0.0D).endVertex();
worldrenderer.pos((double) right, (double) bottom, 0.0D).endVertex();
worldrenderer.pos((double) right, (double) top, 0.0D).endVertex();
worldrenderer.pos((double) left, (double) top, 0.0D).endVertex();
} else {
worldrenderer.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION_COLOR);
float blah = (System.currentTimeMillis() / 10) % 360;
;
GlStateManager.shadeModel(GL11.GL_SMOOTH);
color(worldrenderer.pos((double) left, (double) bottom, 0.0D), Color.HSBtoRGB((((blah + 20) % 360) / 360.0f), 1, 1)).endVertex();
color(worldrenderer.pos((double) right, (double) bottom, 0.0D), Color.HSBtoRGB((((blah + 40) % 360) / 360.0f), 1, 1)).endVertex();
color(worldrenderer.pos((double) right, (double) top, 0.0D), Color.HSBtoRGB((((blah + 20) % 360) / 360.0f), 1, 1)).endVertex();
color(worldrenderer.pos((double) left, (double) top, 0.0D), Color.HSBtoRGB(blah / 360.0f, 1, 1)).endVertex();
}
tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
public static WorldRenderer color(WorldRenderer worldRenderer, int color ){
return worldRenderer.color(((color >> 16) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, (color &0xFF) / 255.0f, ((color >> 24) & 0xFF) / 255.0f);
}
public static void renderDoor(DungeonDoor dungeonDoor, float partialTicks) {
Entity player = Minecraft.getMinecraft().thePlayer;
double playerX = player.prevPosX + (player.posX - player.prevPosX) * partialTicks;
double playerY = player.prevPosY + (player.posY - player.prevPosY) * partialTicks;
double playerZ = player.prevPosZ + (player.posZ - player.prevPosZ) * partialTicks;
//because of the way 3D rendering is done, all coordinates are relative to the camera. This "resets" the "0,0,0" position to the location that is (0,0,0) in the world.
GlStateManager.pushAttrib();
GlStateManager.pushMatrix();
GlStateManager.translate(-playerX, -playerY, -playerZ);
GlStateManager.disableTexture2D();
GlStateManager.disableCull();
GlStateManager.enableAlpha();
if (dungeonDoor.isExist())
GlStateManager.color(0,1,0,1);
else
GlStateManager.color(1,0,0,1);
double x = dungeonDoor.getPosition().getX() + 0.5;
double y = dungeonDoor.getPosition().getY() -0.99;
double z = dungeonDoor.getPosition().getZ() + 0.5;
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3d(x - 2.5, y, z - 2.5);
GL11.glVertex3d(x - 2.5, y, z + 2.5);
GL11.glVertex3d(x + 2.5, y, z + 2.5);
GL11.glVertex3d(x + 2.5, y, z - 2.5);
GL11.glEnd();
if (dungeonDoor.isExist()) {
GL11.glBegin(GL11.GL_QUADS);
GlStateManager.color(0,0,1,1);
if (dungeonDoor.isZDir()) {
GL11.glVertex3d(x - 0.5, y + 0.1, z - 2.5);
GL11.glVertex3d(x - 0.5, y+ 0.1, z + 2.5);
GL11.glVertex3d(x + 0.5, y+ 0.1, z + 2.5);
GL11.glVertex3d(x + 0.5, y+ 0.1, z - 2.5);
} else {
GL11.glVertex3d(x - 2.5, y+ 0.1, z - 0.5);
GL11.glVertex3d(x - 2.5, y+ 0.1, z + 0.5);
GL11.glVertex3d(x + 2.5, y+ 0.1, z + 0.5);
GL11.glVertex3d(x + 2.5, y+ 0.1, z - 0.5);
}
GL11.glEnd();
} else {
GL11.glLineWidth(5);
GL11.glBegin(GL11.GL_LINE_LOOP);
GL11.glVertex3d(x - 2.5, y, z - 2.5);
GL11.glVertex3d(x + 2.5, y + 5, z - 2.5);
GL11.glVertex3d(x + 2.5, y, z + 2.5);
GL11.glVertex3d(x - 2.5, y + 5, z + 2.5);
GL11.glEnd();
GL11.glBegin(GL11.GL_LINE_LOOP);
GL11.glVertex3d(x - 2.5, y +5, z - 2.5);
GL11.glVertex3d(x + 2.5, y, z - 2.5);
GL11.glVertex3d(x + 2.5, y + 5, z + 2.5);
GL11.glVertex3d(x - 2.5, y, z + 2.5);
GL11.glEnd();
GL11.glLineWidth(1);
}
// GlStateManager.disableAlpha();
GlStateManager.disableBlend();
GlStateManager.enableTexture2D();
GlStateManager.enableCull();
GlStateManager.popAttrib();
GlStateManager.popMatrix();
}
public static void drawLine(Vec3 pos1, Vec3 pos2, Color colour, float partialTicks , boolean depth) {
Entity render = Minecraft.getMinecraft().getRenderViewEntity();
WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer();
double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks;
double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks;
double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks;
GlStateManager.pushMatrix();
GlStateManager.translate(-realX, -realY, -realZ);
GlStateManager.disableTexture2D();
if (!depth) {
GlStateManager.disableDepth();
GlStateManager.depthMask(false);
}
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GL11.glLineWidth(2);
GlStateManager.color(colour.getRed() / 255f, colour.getGreen() / 255f, colour.getBlue()/ 255f, colour.getAlpha() / 255f);
worldRenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION);
worldRenderer.pos(pos1.xCoord, pos1.yCoord, pos1.zCoord).endVertex();
worldRenderer.pos(pos2.xCoord, pos2.yCoord, pos2.zCoord).endVertex();
Tessellator.getInstance().draw();
GlStateManager.translate(realX, realY, realZ);
GlStateManager.disableBlend();
if (!depth) {
GlStateManager.enableDepth();
GlStateManager.depthMask(true);
}
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.popMatrix();
}
public static void drawLines(List<BlockPos> poses, Color colour, float partialTicks, boolean depth) {
Entity render = Minecraft.getMinecraft().getRenderViewEntity();
WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer();
double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks;
double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks;
double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks;
GlStateManager.pushMatrix();
GlStateManager.translate(-realX, -realY, -realZ);
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
if (!depth) {
GlStateManager.disableDepth();
GlStateManager.depthMask(false);
}
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GL11.glLineWidth(2);
GlStateManager.color(colour.getRed() / 255f, colour.getGreen() / 255f, colour.getBlue()/ 255f, colour.getAlpha() / 255f);
worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION);
for (BlockPos pos:poses) {
worldRenderer.pos(pos.getX() +0.5, pos.getY() +0.5, pos.getZ() +0.5).endVertex();
}
Tessellator.getInstance().draw();
GlStateManager.translate(realX, realY, realZ);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
if (!depth) {
GlStateManager.enableDepth();
GlStateManager.depthMask(true);
}
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.popMatrix();
}
public static void highlightBlock(BlockPos blockpos, Color c, float partialTicks) {
highlightBlock(blockpos,c,partialTicks,false);
}
public static void highlightBlock(BlockPos blockpos, Color c, float partialTicks, boolean depth) {
Entity viewing_from = Minecraft.getMinecraft().getRenderViewEntity();
double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partialTicks);
double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partialTicks);
double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partialTicks);
GlStateManager.pushMatrix();
GlStateManager.pushAttrib();
GlStateManager.translate(-x_fix, -y_fix, -z_fix);
GlStateManager.disableLighting();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.disableTexture2D();
if (!depth) {
GlStateManager.disableDepth();
GlStateManager.depthMask(false);
}
GlStateManager.color(c.getRed() /255.0f, c.getGreen() / 255.0f, c.getBlue()/ 255.0f, c.getAlpha()/ 255.0f);
GlStateManager.translate(blockpos.getX(), blockpos.getY(), blockpos.getZ());
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3d(0, 0, 0);
GL11.glVertex3d(0, 0, 1);
GL11.glVertex3d(0, 1, 1);
GL11.glVertex3d(0, 1, 0); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT
GL11.glVertex3d(1, 0, 1);
GL11.glVertex3d(1, 0, 0);
GL11.glVertex3d(1, 1, 0);
GL11.glVertex3d(1, 1, 1);
GL11.glVertex3d(0, 1, 1);
GL11.glVertex3d(0, 0, 1);
GL11.glVertex3d(1, 0, 1);
GL11.glVertex3d(1, 1, 1); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT
GL11.glVertex3d(0, 0, 0);
GL11.glVertex3d(0, 1, 0);
GL11.glVertex3d(1, 1, 0);
GL11.glVertex3d(1, 0, 0);
GL11.glVertex3d(0,1,0);
GL11.glVertex3d(0,1,1);
GL11.glVertex3d(1,1,1);
GL11.glVertex3d(1,1,0);
GL11.glVertex3d(0,0,1);
GL11.glVertex3d(0,0,0);
GL11.glVertex3d(1,0,0);
GL11.glVertex3d(1,0,1);
GL11.glEnd();
if (!depth) {
GlStateManager.disableDepth();
GlStateManager.depthMask(true);
}
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
GlStateManager.enableLighting();
GlStateManager.popMatrix();
GlStateManager.popAttrib();
//...
}
public static void highlightBox(Entity entity, Color c, float partialTicks, boolean depth) {
Entity viewing_from = Minecraft.getMinecraft().getRenderViewEntity();
double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partialTicks);
double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partialTicks);
double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partialTicks);
GlStateManager.pushMatrix();
GlStateManager.pushAttrib();
GlStateManager.translate(-x_fix, -y_fix, -z_fix);
GlStateManager.disableLighting();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.disableTexture2D();
if (!depth) {
GlStateManager.disableDepth();
GlStateManager.depthMask(false);
}
GlStateManager.color(c.getRed()/ 255.0f, c.getGreen()/ 255.0f, c.getBlue()/ 255.0f, c.getAlpha()/ 255.0f);
AxisAlignedBB axisAlignedBB = AxisAlignedBB.fromBounds(-0.4,-1.5,-0.4,0.4,0,0.4);
GlStateManager.translate(-0.4 + entity.posX, -1.5 + entity.posY, -0.4 + entity.posZ);
double x = 0.8;
double y = 1.5;
double z = 0.8;
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3d(0, 0, 0);
GL11.glVertex3d(0, 0, z);
GL11.glVertex3d(0, y, z);
GL11.glVertex3d(0, y, 0); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT
GL11.glVertex3d(x, 0, z);
GL11.glVertex3d(x, 0, 0);
GL11.glVertex3d(x, y, 0);
GL11.glVertex3d(x, y, z);
GL11.glVertex3d(0, y, z);
GL11.glVertex3d(0, 0, z);
GL11.glVertex3d(x, 0, z);
GL11.glVertex3d(x, y, z); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT
GL11.glVertex3d(0, 0, 0);
GL11.glVertex3d(0, y, 0);
GL11.glVertex3d(x, y, 0);
GL11.glVertex3d(x, 0, 0);
GL11.glVertex3d(0,y,0);
GL11.glVertex3d(0,y,z);
GL11.glVertex3d(x,y,z);
GL11.glVertex3d(x,y,0);
GL11.glVertex3d(0,0,z);
GL11.glVertex3d(0,0,0);
GL11.glVertex3d(x,0,0);
GL11.glVertex3d(x,0,z);
GL11.glEnd();
if (!depth) {
GlStateManager.disableDepth();
GlStateManager.depthMask(true);
}
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
GlStateManager.enableLighting();
GlStateManager.popMatrix();
GlStateManager.popAttrib();
//...
}
public static void drawTextAtWorld(String text, float x, float y, float z, int color, float scale, boolean increase, boolean renderBlackBox, float partialTicks) {
float lScale = scale;
RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
Vector3f renderPos = getRenderPos(x, y, z, partialTicks);
if (increase) {
double distance = Math.sqrt(renderPos.x * renderPos.x + renderPos.y * renderPos.y + renderPos.z * renderPos.z);
double multiplier = distance / 120f; //mobs only render ~120 blocks away
lScale *= 0.45f * multiplier;
}
GlStateManager.color(1f, 1f, 1f, 0.5f);
GlStateManager.pushMatrix();
GlStateManager.translate(renderPos.x, renderPos.y, renderPos.z);
GlStateManager.rotate(-renderManager.playerViewY, 0.0f, 1.0f, 0.0f);
GlStateManager.rotate(renderManager.playerViewX, 1.0f, 0.0f, 0.0f);
GlStateManager.scale(-lScale, -lScale, lScale);
GlStateManager.disableLighting();
GlStateManager.depthMask(false);
GlStateManager.disableDepth();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
int textWidth = fontRenderer.getStringWidth(text);
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldRenderer = tessellator.getWorldRenderer();
if (renderBlackBox) {
double j = textWidth / 2;
GlStateManager.disableTexture2D();
worldRenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
worldRenderer.pos((double)(-j - 1), (double)(-1), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex();
worldRenderer.pos((double)(-j - 1), (double)8, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex();
worldRenderer.pos((double)(j + 1), (double)8, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex();
worldRenderer.pos((double)(j + 1), (double)(-1), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex();
tessellator.draw();
GlStateManager.enableTexture2D();
}
fontRenderer.drawString(text, -textWidth / 2, 0, color);
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
GlStateManager.depthMask(true);
GlStateManager.enableDepth();
GlStateManager.popMatrix();
}
private static Vector3f getRenderPos(float x, float y, float z, float partialTicks) {
EntityPlayerSP sp = Minecraft.getMinecraft().thePlayer;
return new Vector3f(
x - (float) (sp.lastTickPosX + (sp.posX - sp.lastTickPosX) * partialTicks),
y - (float) (sp.lastTickPosY + (sp.posY - sp.lastTickPosY) * partialTicks),
z - (float) (sp.lastTickPosZ + (sp.posZ - sp.lastTickPosZ) * partialTicks)
);
}
}
|