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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
|
package rosegoldaddons.utils;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.ScaledResolution;
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.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.*;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL14;
import rosegoldaddons.Main;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
import static java.lang.Math.*;
import static org.lwjgl.opengl.GL11.*;
public class RenderUtils {
private static final Map<Integer, Boolean> glCapMap = new HashMap<>();
private static final int[] DISPLAY_LISTS_2D = new int[4];
private static final Minecraft mc = Main.mc;
static {
for (int i = 0; i < DISPLAY_LISTS_2D.length; i++) {
DISPLAY_LISTS_2D[i] = glGenLists(1);
}
glNewList(DISPLAY_LISTS_2D[0], GL_COMPILE);
quickDrawRect(-7F, 2F, -4F, 3F);
quickDrawRect(4F, 2F, 7F, 3F);
quickDrawRect(-7F, 0.5F, -6F, 3F);
quickDrawRect(6F, 0.5F, 7F, 3F);
glEndList();
glNewList(DISPLAY_LISTS_2D[1], GL_COMPILE);
quickDrawRect(-7F, 3F, -4F, 3.3F);
quickDrawRect(4F, 3F, 7F, 3.3F);
quickDrawRect(-7.3F, 0.5F, -7F, 3.3F);
quickDrawRect(7F, 0.5F, 7.3F, 3.3F);
glEndList();
glNewList(DISPLAY_LISTS_2D[2], GL_COMPILE);
quickDrawRect(4F, -20F, 7F, -19F);
quickDrawRect(-7F, -20F, -4F, -19F);
quickDrawRect(6F, -20F, 7F, -17.5F);
quickDrawRect(-7F, -20F, -6F, -17.5F);
glEndList();
glNewList(DISPLAY_LISTS_2D[3], GL_COMPILE);
quickDrawRect(7F, -20F, 7.3F, -17.5F);
quickDrawRect(-7.3F, -20F, -7F, -17.5F);
quickDrawRect(4F, -20.3F, 7.3F, -20F);
quickDrawRect(-7.3F, -20.3F, -4F, -20F);
glEndList();
}
public static void drawBlockBox(final BlockPos blockPos, final Color color, final int width, float partialTicks) {
if(width == 0) return;
final RenderManager renderManager = mc.getRenderManager();
final double x = blockPos.getX() - renderManager.viewerPosX;
final double y = blockPos.getY() - renderManager.viewerPosY;
final double z = blockPos.getZ() - renderManager.viewerPosZ;
AxisAlignedBB axisAlignedBB = new AxisAlignedBB(x, y, z, x + 1.0, y + 1.0, z + 1.0);
final Block block = mc.theWorld.getBlockState(blockPos).getBlock();
if (block != null) {
final EntityPlayer player = mc.thePlayer;
final double posX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
final double posY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
final double posZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
block.setBlockBoundsBasedOnState(mc.theWorld, blockPos);
axisAlignedBB = block.getSelectedBoundingBox(mc.theWorld, blockPos)
.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D)
.offset(-posX, -posY, -posZ);
}
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
enableGlCap(GL_BLEND);
disableGlCap(GL_TEXTURE_2D, GL_DEPTH_TEST);
glDepthMask(false);
glColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() != 255 ? color.getAlpha() : 26);
//drawFilledBox(axisAlignedBB);
glLineWidth((float) width);
enableGlCap(GL_LINE_SMOOTH);
glColor(color);
drawSelectionBoundingBox(axisAlignedBB);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glDepthMask(true);
resetCaps();
}
public static void drawPixelBox(final Vec3 vec, final Color color, final double size, float partialTicks) {
final RenderManager renderManager = mc.getRenderManager();
final double x = vec.xCoord - renderManager.viewerPosX;
final double y = vec.yCoord - renderManager.viewerPosY;
final double z = vec.zCoord - renderManager.viewerPosZ;
AxisAlignedBB axisAlignedBB = new AxisAlignedBB(x, y, z, x + size, y + size, z + size);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
enableGlCap(GL_BLEND);
disableGlCap(GL_TEXTURE_2D, GL_DEPTH_TEST);
glDepthMask(false);
glColor(color.getRed(), color.getGreen(), color.getBlue(), 35);
//drawFilledBox(axisAlignedBB);
glLineWidth(3F);
enableGlCap(GL_LINE_SMOOTH);
glColor(color);
drawSelectionBoundingBox(axisAlignedBB);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glDepthMask(true);
resetCaps();
}
public static void drawSelectionBoundingBox(AxisAlignedBB boundingBox) {
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
worldrenderer.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION);
// Lower Rectangle
worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).endVertex();
worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).endVertex();
worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).endVertex();
worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).endVertex();
worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).endVertex();
// Upper Rectangle
worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).endVertex();
worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).endVertex();
worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).endVertex();
worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).endVertex();
worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).endVertex();
// Upper Rectangle
worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).endVertex();
worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).endVertex();
worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).endVertex();
worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).endVertex();
worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).endVertex();
worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).endVertex();
tessellator.draw();
}
public static void drawEntityBox(final Entity entity, final Color color, final int width, float partialTicks) {
if(width == 0) return;
final RenderManager renderManager = mc.getRenderManager();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
enableGlCap(GL_BLEND);
disableGlCap(GL_TEXTURE_2D, GL_DEPTH_TEST);
glDepthMask(false);
final double x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks
- renderManager.viewerPosX;
final double y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks
- renderManager.viewerPosY;
final double z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks
- renderManager.viewerPosZ;
final AxisAlignedBB entityBox = entity.getEntityBoundingBox();
final AxisAlignedBB axisAlignedBB = new AxisAlignedBB(
entityBox.minX - entity.posX + x - 0.05D,
entityBox.minY - entity.posY + y,
entityBox.minZ - entity.posZ + z - 0.05D,
entityBox.maxX - entity.posX + x + 0.05D,
entityBox.maxY - entity.posY + y + 0.15D,
entityBox.maxZ - entity.posZ + z + 0.05D
);
glLineWidth((float) width);
enableGlCap(GL_LINE_SMOOTH);
glColor(color.getRed(), color.getGreen(), color.getBlue(), 95);
drawSelectionBoundingBox(axisAlignedBB);
glColor(color.getRed(), color.getGreen(), color.getBlue(), 26);
//drawFilledBox(axisAlignedBB);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glDepthMask(true);
resetCaps();
}
public static void drawAxisAlignedBB(final AxisAlignedBB axisAlignedBB, final Color color) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glLineWidth(2F);
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDepthMask(false);
glColor(color);
drawFilledBox(axisAlignedBB);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDepthMask(true);
glDisable(GL_BLEND);
}
public static void drawPlatform(final double y, final Color color, final double size) {
final RenderManager renderManager = mc.getRenderManager();
final double renderY = y - renderManager.viewerPosY;
drawAxisAlignedBB(new AxisAlignedBB(size, renderY + 0.02D, size, -size, renderY, -size), color);
}
public static void drawPlatform(final Entity entity, final Color color, float partialTicks) {
final RenderManager renderManager = mc.getRenderManager();
final double x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks
- renderManager.viewerPosX;
final double y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks
- renderManager.viewerPosY;
final double z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks
- renderManager.viewerPosZ;
final AxisAlignedBB axisAlignedBB = entity.getEntityBoundingBox()
.offset(-entity.posX, -entity.posY, -entity.posZ)
.offset(x, y, z);
drawAxisAlignedBB(
new AxisAlignedBB(axisAlignedBB.minX, axisAlignedBB.maxY + 0.2, axisAlignedBB.minZ, axisAlignedBB.maxX, axisAlignedBB.maxY + 0.26, axisAlignedBB.maxZ),
color
);
}
public static void drawFilledBox(final AxisAlignedBB axisAlignedBB) {
final Tessellator tessellator = Tessellator.getInstance();
final WorldRenderer worldRenderer = tessellator.getWorldRenderer();
worldRenderer.begin(7, DefaultVertexFormats.POSITION);
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex();
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
tessellator.draw();
}
public static void quickDrawRect(final float x, final float y, final float x2, final float y2) {
glBegin(GL_QUADS);
glVertex2d(x2, y);
glVertex2d(x, y);
glVertex2d(x, y2);
glVertex2d(x2, y2);
glEnd();
}
public static void drawRect(final float x, final float y, final float x2, final float y2, final int color) {
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glColor(color);
glBegin(GL_QUADS);
glVertex2f(x2, y);
glVertex2f(x, y);
glVertex2f(x, y2);
glVertex2f(x2, y2);
glEnd();
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
}
public static void drawRect(final int x, final int y, final int x2, final int y2, final int color) {
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glColor(color);
glBegin(GL_QUADS);
glVertex2i(x2, y);
glVertex2i(x, y);
glVertex2i(x, y2);
glVertex2i(x2, y2);
glEnd();
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
}
/**
* Like {@link #drawRect(float, float, float, float, int)}, but without setup
*/
public static void quickDrawRect(final float x, final float y, final float x2, final float y2, final int color) {
glColor(color);
glBegin(GL_QUADS);
glVertex2d(x2, y);
glVertex2d(x, y);
glVertex2d(x, y2);
glVertex2d(x2, y2);
glEnd();
}
public static void drawRect(final float x, final float y, final float x2, final float y2, final Color color) {
drawRect(x, y, x2, y2, color.getRGB());
}
public static void drawBorderedRect(final float x, final float y, final float x2, final float y2, final float width,
final int color1, final int color2) {
drawRect(x, y, x2, y2, color2);
drawBorder(x, y, x2, y2, width, color1);
}
public static void drawBorder(float x, float y, float x2, float y2, float width, int color1) {
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glColor(color1);
glLineWidth(width);
glBegin(GL_LINE_LOOP);
glVertex2d(x2, y);
glVertex2d(x, y);
glVertex2d(x, y2);
glVertex2d(x2, y2);
glEnd();
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
}
public static void quickDrawBorderedRect(final float x, final float y, final float x2, final float y2, final float width, final int color1, final int color2) {
quickDrawRect(x, y, x2, y2, color2);
glColor(color1);
glLineWidth(width);
glBegin(GL_LINE_LOOP);
glVertex2d(x2, y);
glVertex2d(x, y);
glVertex2d(x, y2);
glVertex2d(x2, y2);
glEnd();
}
public static void drawLoadingCircle(float x, float y) {
for (int i = 0; i < 4; i++) {
int rot = (int) ((System.nanoTime() / 5000000 * i) % 360);
drawCircle(x, y, i * 10, rot - 180, rot);
}
}
public static void drawCircle(float x, float y, float radius, int start, int end) {
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
glColor(Color.WHITE);
glEnable(GL_LINE_SMOOTH);
glLineWidth(2F);
glBegin(GL_LINE_STRIP);
for (float i = end; i >= start; i -= (360 / 90.0f)) {
glVertex2f((float) (x + (cos(i * PI / 180) * (radius * 1.001F))), (float) (y + (sin(i * PI / 180) * (radius * 1.001F))));
}
glEnd();
glDisable(GL_LINE_SMOOTH);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
public static void drawFilledCircle(final int xx, final int yy, final float radius, final Color color) {
int sections = 50;
double dAngle = 2 * Math.PI / sections;
float x, y;
glPushAttrib(GL_ENABLE_BIT);
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glBegin(GL_TRIANGLE_FAN);
for (int i = 0; i < sections; i++) {
x = (float) (radius * Math.sin((i * dAngle)));
y = (float) (radius * Math.cos((i * dAngle)));
glColor4f(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, color.getAlpha() / 255F);
glVertex2f(xx + x, yy + y);
}
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnd();
glPopAttrib();
}
public static void drawImage(ResourceLocation image, int x, int y, int width, int height) {
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glDepthMask(false);
GL14.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(image);
drawModalRectWithCustomSizedTexture(x, y, 0, 0, width, height, width, height);
glDepthMask(true);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}
/**
* Draws a textured rectangle at z = 0. Args: x, y, u, v, width, height, textureWidth, textureHeight
*/
public static void drawModalRectWithCustomSizedTexture(float x, float y, float u, float v, float width, float height, float textureWidth, float textureHeight) {
float f = 1.0F / textureWidth;
float f1 = 1.0F / textureHeight;
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
worldrenderer.begin(7, DefaultVertexFormats.POSITION);
worldrenderer.pos(x, y + height, 0.0D).tex(u * f, (v + height) * f1).endVertex();
worldrenderer.pos(x + width, y + height, 0.0D).tex((u + width) * f, (v + height) * f1).endVertex();
worldrenderer.pos(x + width, y, 0.0D).tex((u + width) * f, v * f1).endVertex();
worldrenderer.pos(x, y, 0.0D).tex(u * f, v * f1).endVertex();
tessellator.draw();
}
public static void glColor(final int red, final int green, final int blue, final int alpha) {
GL11.glColor4f(red / 255F, green / 255F, blue / 255F, alpha / 255F);
}
public static void glColor(final Color color) {
glColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}
private static void glColor(final int hex) {
glColor(hex >> 16 & 0xFF, hex >> 8 & 0xFF, hex & 0xFF, hex >> 24 & 0xFF);
}
public static void draw2D(final EntityLivingBase entity, final double posX, final double posY, final double posZ, final int color, final int backgroundColor) {
GL11.glPushMatrix();
GL11.glTranslated(posX, posY, posZ);
GL11.glRotated(-mc.getRenderManager().viewerPosY, 0F, 1F, 0F);
GL11.glScaled(-0.1D, -0.1D, 0.1D);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GL11.glDepthMask(true);
glColor(color);
glCallList(DISPLAY_LISTS_2D[0]);
glColor(backgroundColor);
glCallList(DISPLAY_LISTS_2D[1]);
GL11.glTranslated(0, 21 + -(entity.getEntityBoundingBox().maxY - entity.getEntityBoundingBox().minY) * 12, 0);
glColor(color);
glCallList(DISPLAY_LISTS_2D[2]);
glColor(backgroundColor);
glCallList(DISPLAY_LISTS_2D[3]);
// Stop render
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
GL11.glPopMatrix();
}
public static void draw2D(final BlockPos blockPos, final int color, final int backgroundColor) {
final RenderManager renderManager = mc.getRenderManager();
final double posX = (blockPos.getX() + 0.5) - renderManager.viewerPosX;
final double posY = blockPos.getY() - renderManager.viewerPosY;
final double posZ = (blockPos.getZ() + 0.5) - renderManager.viewerPosZ;
GL11.glPushMatrix();
GL11.glTranslated(posX, posY, posZ);
GL11.glRotated(-mc.getRenderManager().playerViewY, 0F, 1F, 0F);
GL11.glScaled(-0.1D, -0.1D, 0.1D);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GL11.glDepthMask(true);
glColor(color);
glCallList(DISPLAY_LISTS_2D[0]);
glColor(backgroundColor);
glCallList(DISPLAY_LISTS_2D[1]);
GL11.glTranslated(0, 9, 0);
glColor(color);
glCallList(DISPLAY_LISTS_2D[2]);
glColor(backgroundColor);
glCallList(DISPLAY_LISTS_2D[3]);
// Stop render
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
GL11.glPopMatrix();
}
public static void renderNameTag(final String string, final double x, final double y, final double z) {
final RenderManager renderManager = mc.getRenderManager();
glPushMatrix();
glTranslated(x - renderManager.viewerPosX, y - renderManager.viewerPosY, z - renderManager.viewerPosZ);
glNormal3f(0F, 1F, 0F);
glRotatef(-mc.getRenderManager().playerViewY, 0F, 1F, 0F);
glRotatef(mc.getRenderManager().playerViewX, 1F, 0F, 0F);
glScalef(-0.05F, -0.05F, 0.05F);
setGlCap(GL_LIGHTING, false);
setGlCap(GL_DEPTH_TEST, false);
setGlCap(GL_BLEND, true);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
final int width = mc.fontRendererObj.getStringWidth(string) / 2;
drawRect(-width - 1, -1, width + 1, mc.fontRendererObj.FONT_HEIGHT, Integer.MIN_VALUE);
mc.fontRendererObj.drawString(string, -width, 1.5F, Color.WHITE.getRGB(), true);
resetCaps();
glColor4f(1F, 1F, 1F, 1F);
glPopMatrix();
}
public static void drawLine(final double x, final double y, final double x1, final double y1, final float width) {
glDisable(GL_TEXTURE_2D);
glLineWidth(width);
glBegin(GL_LINES);
glVertex2d(x, y);
glVertex2d(x1, y1);
glEnd();
glEnable(GL_TEXTURE_2D);
}
public static void makeScissorBox(final float x, final float y, final float x2, final float y2) {
final ScaledResolution scaledResolution = new ScaledResolution(mc);
final int factor = scaledResolution.getScaleFactor();
glScissor((int) (x * factor), (int) ((scaledResolution.getScaledHeight() - y2) * factor), (int) ((x2 - x) * factor), (int) ((y2 - y) * factor));
}
/**
* Modified from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
* https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE
*/
public static void renderWaypointText(String str, double X, double Y, double Z, float partialTicks) {
GlStateManager.alphaFunc(516, 0.1F);
GlStateManager.pushMatrix();
Entity viewer = Main.mc.getRenderViewEntity();
double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks;
double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks;
double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks;
double x = X - viewerX;
double y = Y - viewerY - viewer.getEyeHeight();
double z = Z - viewerZ;
double distSq = x * x + y * y + z * z;
double dist = Math.sqrt(distSq);
if (distSq > 144) {
x *= 12 / dist;
y *= 12 / dist;
z *= 12 / dist;
}
GlStateManager.translate(x, y, z);
GlStateManager.translate(0, viewer.getEyeHeight(), 0);
drawNametag(str);
GlStateManager.rotate(-Main.mc.getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(Main.mc.getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
GlStateManager.translate(0, -0.25f, 0);
GlStateManager.rotate(-Main.mc.getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(Main.mc.getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
drawNametag(EnumChatFormatting.YELLOW.toString() + Math.round(dist) + " blocks");
GlStateManager.popMatrix();
GlStateManager.disableLighting();
}
public static void drawNametag(String str) {
FontRenderer fontrenderer = Main.mc.fontRendererObj;
float f = 1.6F;
float f1 = 0.016666668F * f;
GlStateManager.pushMatrix();
GL11.glNormal3f(0.0F, 1.0F, 0.0F);
GlStateManager.rotate(-Main.mc.getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(Main.mc.getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
GlStateManager.scale(-f1, -f1, f1);
GlStateManager.disableLighting();
GlStateManager.depthMask(false);
GlStateManager.disableDepth();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
int i = 0;
int j = fontrenderer.getStringWidth(str) / 2;
GlStateManager.disableTexture2D();
worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
worldrenderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
worldrenderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
worldrenderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
worldrenderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
tessellator.draw();
GlStateManager.enableTexture2D();
fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127);
GlStateManager.depthMask(true);
fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1);
GlStateManager.enableDepth();
GlStateManager.enableBlend();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.popMatrix();
}
/**
* GL CAP MANAGER
* <p>
* TODO: Remove gl cap manager and replace by something better
*/
public static void resetCaps() {
glCapMap.forEach(RenderUtils::setGlState);
}
public static void enableGlCap(final int cap) {
setGlCap(cap, true);
}
public static void enableGlCap(final int... caps) {
for (final int cap : caps)
setGlCap(cap, true);
}
public static void disableGlCap(final int cap) {
setGlCap(cap, true);
}
public static void disableGlCap(final int... caps) {
for (final int cap : caps)
setGlCap(cap, false);
}
public static void setGlCap(final int cap, final boolean state) {
glCapMap.put(cap, glGetBoolean(cap));
setGlState(cap, state);
}
public static void setGlState(final int cap, final boolean state) {
if (state)
glEnable(cap);
else
glDisable(cap);
}
public static void drawScaledCustomSizeModalRect(int x, int y, float u, float v, int uWidth, int vHeight, int width, int height, float tileWidth, float tileHeight) {
float f = 1.0F / tileWidth;
float f1 = 1.0F / tileHeight;
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
worldrenderer.begin(7, DefaultVertexFormats.POSITION);
worldrenderer.pos(x, y + height, 0.0D).tex(u * f, (v + (float) vHeight) * f1).endVertex();
worldrenderer.pos(x + width, y + height, 0.0D).tex((u + (float) uWidth) * f, (v + (float) vHeight) * f1).endVertex();
worldrenderer.pos(x + width, y, 0.0D).tex((u + (float) uWidth) * f, v * f1).endVertex();
worldrenderer.pos(x, y, 0.0D).tex(u * f, v * f1).endVertex();
tessellator.draw();
}
public static void enableChams() {
GL11.glEnable(32823);
GlStateManager.enablePolygonOffset();
GlStateManager.doPolygonOffset(1.0F, -1000000.0F);
}
public static void disableChams() {
GL11.glDisable(32823);
GlStateManager.doPolygonOffset(1.0F, 1000000.0F);
GlStateManager.disablePolygonOffset();
}
}
|