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
804
|
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.config.core.config.Position
import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils.drawStringScaled
import at.hannibal2.skyhanni.data.GuiEditManager
import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsX_
import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY_
import at.hannibal2.skyhanni.utils.NEUItems.renderOnScreen
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.FontRenderer
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.vertex.DefaultVertexFormats
import net.minecraft.entity.Entity
import net.minecraft.inventory.Slot
import net.minecraft.item.ItemStack
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.MathHelper
import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.event.RenderWorldLastEvent
import org.lwjgl.opengl.GL11
import java.awt.Color
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt
object RenderUtils {
val beaconBeam = ResourceLocation("textures/entity/beacon_beam.png")
infix fun Slot.highlight(color: LorenzColor) {
highlight(color.toColor())
}
infix fun Slot.highlight(color: Color) {
val lightingState = GL11.glIsEnabled(GL11.GL_LIGHTING)
GlStateManager.disableLighting()
GlStateManager.color(1f, 1f, 1f, 1f)
GlStateManager.pushMatrix()
// TODO don't use z
GlStateManager.translate(0f, 0f, 110 + Minecraft.getMinecraft().renderItem.zLevel)
Gui.drawRect(
this.xDisplayPosition,
this.yDisplayPosition,
this.xDisplayPosition + 16,
this.yDisplayPosition + 16,
color.rgb
)
GlStateManager.popMatrix()
if (lightingState) GlStateManager.enableLighting()
}
fun RenderWorldLastEvent.drawColor(
location: LorenzVec,
color: LorenzColor,
beacon: Boolean = false,
alpha: Float = -1f,
) {
val (viewerX, viewerY, viewerZ) = getViewerPos(partialTicks)
val x = location.x - viewerX
val y = location.y - viewerY
val z = location.z - viewerZ
val distSq = x * x + y * y + z * z
val realAlpha = if (alpha == -1f) {
(0.1f + 0.005f * distSq.toFloat()).coerceAtLeast(0.2f)
} else {
alpha
}
GlStateManager.disableDepth()
GlStateManager.disableCull()
drawFilledBoundingBox(
AxisAlignedBB(x, y, z, x + 1, y + 1, z + 1).expandBlock(),
color.toColor(),
realAlpha
)
GlStateManager.disableTexture2D()
if (distSq > 5 * 5 && beacon) renderBeaconBeam(x, y + 1, z, color.toColor().rgb, 1.0f, partialTicks)
GlStateManager.disableLighting()
GlStateManager.enableTexture2D()
GlStateManager.enableDepth()
GlStateManager.enableCull()
}
fun getViewerPos(partialTicks: Float): LorenzVec {
val viewer = Minecraft.getMinecraft().renderViewEntity
val viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks
val viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks
val viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks
return LorenzVec(viewerX, viewerY, viewerZ)
}
/**
* Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
* https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE
* @author Moulberry
* @author Mojang
*/
fun drawFilledBoundingBox(aabb: AxisAlignedBB, c: Color, alphaMultiplier: Float = 1f) {
GlStateManager.enableBlend()
GlStateManager.disableLighting()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
GlStateManager.disableTexture2D()
val tessellator = Tessellator.getInstance()
val worldRenderer = tessellator.worldRenderer
GlStateManager.color(c.red / 255f, c.green / 255f, c.blue / 255f, c.alpha / 255f * alphaMultiplier)
//vertical
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex()
tessellator.draw()
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex()
tessellator.draw()
GlStateManager.color(
c.red / 255f * 0.8f,
c.green / 255f * 0.8f,
c.blue / 255f * 0.8f,
c.alpha / 255f * alphaMultiplier
)
//x
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex()
tessellator.draw()
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex()
tessellator.draw()
GlStateManager.color(
c.red / 255f * 0.9f,
c.green / 255f * 0.9f,
c.blue / 255f * 0.9f,
c.alpha / 255f * alphaMultiplier
)
//z
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex()
tessellator.draw()
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex()
tessellator.draw()
GlStateManager.enableTexture2D()
GlStateManager.disableBlend()
}
fun AxisAlignedBB.expandBlock() = expand(0.0020000000949949026, 0.0020000000949949026, 0.0020000000949949026)
/**
* Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
* https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE
* @author Moulberry
* @author Mojang
*/
fun renderBeaconBeam(x: Double, y: Double, z: Double, rgb: Int, alphaMultiplier: Float, partialTicks: Float) {
val height = 300
val bottomOffset = 0
val topOffset = bottomOffset + height
val tessellator = Tessellator.getInstance()
val worldrenderer = tessellator.worldRenderer
Minecraft.getMinecraft().textureManager.bindTexture(beaconBeam)
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, 10497.0f)
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, 10497.0f)
GlStateManager.disableLighting()
GlStateManager.enableCull()
GlStateManager.enableTexture2D()
GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0)
GlStateManager.enableBlend()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
val time = Minecraft.getMinecraft().theWorld.totalWorldTime + partialTicks.toDouble()
val d1 = MathHelper.func_181162_h(
-time * 0.2 - MathHelper.floor_double(-time * 0.1)
.toDouble()
)
val r = (rgb shr 16 and 0xFF) / 255f
val g = (rgb shr 8 and 0xFF) / 255f
val b = (rgb and 0xFF) / 255f
val d2 = time * 0.025 * -1.5
val d4 = 0.5 + cos(d2 + 2.356194490192345) * 0.2
val d5 = 0.5 + sin(d2 + 2.356194490192345) * 0.2
val d6 = 0.5 + cos(d2 + Math.PI / 4.0) * 0.2
val d7 = 0.5 + sin(d2 + Math.PI / 4.0) * 0.2
val d8 = 0.5 + cos(d2 + 3.9269908169872414) * 0.2
val d9 = 0.5 + sin(d2 + 3.9269908169872414) * 0.2
val d10 = 0.5 + cos(d2 + 5.497787143782138) * 0.2
val d11 = 0.5 + sin(d2 + 5.497787143782138) * 0.2
val d14 = -1.0 + d1
val d15 = height.toDouble() * 2.5 + d14
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR)
worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(1.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(0.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(1.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(0.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(1.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(0.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(1.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(0.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
tessellator.draw()
GlStateManager.disableCull()
val d12 = -1.0 + d1
val d13 = height + d12
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR)
worldrenderer.pos(x + 0.2, y + topOffset, z + 0.2).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.2).tex(1.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.2).tex(0.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.8, y + topOffset, z + 0.2).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.8, y + topOffset, z + 0.8).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.8).tex(1.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.8).tex(0.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.2, y + topOffset, z + 0.8).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.8, y + topOffset, z + 0.2).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.2).tex(1.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.8).tex(0.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.8, y + topOffset, z + 0.8).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.2, y + topOffset, z + 0.8).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.8).tex(1.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.2).tex(0.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.2, y + topOffset, z + 0.2).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
tessellator.draw()
}
fun RenderWorldLastEvent.drawString(
location: LorenzVec,
text: String,
seeThroughBlocks: Boolean = false,
color: Color? = null,
) {
GlStateManager.alphaFunc(516, 0.1f)
GlStateManager.pushMatrix()
val viewer = Minecraft.getMinecraft().renderViewEntity
val renderManager = Minecraft.getMinecraft().renderManager
var x = location.x - renderManager.viewerPosX
var y = location.y - renderManager.viewerPosY - viewer.eyeHeight
var z = location.z - renderManager.viewerPosZ
val distSq = x * x + y * y + z * z
val dist = sqrt(distSq)
if (distSq > 144) {
x *= 12 / dist
y *= 12 / dist
z *= 12 / dist
}
if (seeThroughBlocks) {
GlStateManager.disableDepth()
GlStateManager.disableCull()
}
GlStateManager.translate(x, y, z)
GlStateManager.translate(0f, viewer.eyeHeight, 0f)
drawNametag(text, color)
GlStateManager.rotate(-renderManager.playerViewY, 0.0f, 1.0f, 0.0f)
GlStateManager.rotate(renderManager.playerViewX, 1.0f, 0.0f, 0.0f)
GlStateManager.translate(0f, -0.25f, 0f)
GlStateManager.rotate(-renderManager.playerViewX, 1.0f, 0.0f, 0.0f)
GlStateManager.rotate(renderManager.playerViewY, 0.0f, 1.0f, 0.0f)
// RenderUtil.drawNametag(EnumChatFormatting.YELLOW.toString() + dist.roundToInt() + "m")
GlStateManager.popMatrix()
GlStateManager.disableLighting()
if (seeThroughBlocks) {
GlStateManager.enableDepth()
GlStateManager.enableCull()
}
}
/**
* @author Mojang
*/
fun drawNametag(str: String, color: Color?) {
val fontRenderer = Minecraft.getMinecraft().fontRendererObj
val f1 = 0.02666667f
GlStateManager.pushMatrix()
GL11.glNormal3f(0.0f, 1.0f, 0.0f)
GlStateManager.rotate(-Minecraft.getMinecraft().renderManager.playerViewY, 0.0f, 1.0f, 0.0f)
GlStateManager.rotate(
Minecraft.getMinecraft().renderManager.playerViewX,
1.0f,
0.0f,
0.0f
)
GlStateManager.scale(-f1, -f1, f1)
GlStateManager.disableLighting()
GlStateManager.depthMask(false)
GlStateManager.enableBlend()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
val tessellator = Tessellator.getInstance()
val worldrenderer = tessellator.worldRenderer
val i = 0
val j = fontRenderer.getStringWidth(str) / 2
GlStateManager.disableTexture2D()
worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR)
worldrenderer.pos((-j - 1).toDouble(), (-1 + i).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
worldrenderer.pos((-j - 1).toDouble(), (8 + i).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
worldrenderer.pos((j + 1).toDouble(), (8 + i).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
worldrenderer.pos((j + 1).toDouble(), (-1 + i).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
tessellator.draw()
GlStateManager.enableTexture2D()
val colorCode = color?.rgb ?: 553648127
fontRenderer.drawString(str, -j, i, colorCode)
GlStateManager.depthMask(true)
fontRenderer.drawString(str, -j, i, -1)
GlStateManager.enableBlend()
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
GlStateManager.popMatrix()
}
/**
* @author Mojang
*/
fun drawLabel(
pos: LorenzVec,
text: String,
partialTicks: Float,
shadow: Boolean = false,
scale: Float = 1f,
yOff: Float = 0f,
debug: Boolean = false,
) {
val minecraft = Minecraft.getMinecraft()
val player = minecraft.thePlayer
val x =
pos.x - player.lastTickPosX + (pos.x - player.posX - (pos.x - player.lastTickPosX)) * partialTicks
val y =
pos.y - player.lastTickPosY + (pos.y - player.posY - (pos.y - player.lastTickPosY)) * partialTicks
val z =
pos.z - player.lastTickPosZ + (pos.z - player.posZ - (pos.z - player.lastTickPosZ)) * partialTicks
//7 - 25
val translate = LorenzVec(x, y, z)
val length = translate.length().toFloat()
var finalText = text
var factor = 1f
var finalScale = scale
if (debug) {
// if (tick++ % 60 == 0) {
finalText = "$text ${length.toInt()}"
// println("translate: $length")
// }
if (length < 8) {
factor = 8 / length
// translate = translate.multiply(8 / length)
}
if (length > 15) {
factor = 15 / length
// translate = translate.multiply(15 / length)
}
// val finalScale = scale * (1 / factor)
finalScale = scale * sqrt(factor.toDouble()).toFloat()
}
val f1 = 0.0266666688
val width = minecraft.fontRendererObj.getStringWidth(finalText) / 2
GlStateManager.pushMatrix()
GlStateManager.translate(x, y, z)
GL11.glNormal3f(0f, 1f, 0f)
val renderManager = minecraft.renderManager
GlStateManager.rotate(-renderManager.playerViewY, 0f, 1f, 0f)
GlStateManager.rotate(renderManager.playerViewX, 1f, 0f, 0f)
GlStateManager.scale(-f1, -f1, -f1)
// GlStateManager.scale(scale, scale, scale)
GlStateManager.scale(finalScale, finalScale, finalScale)
// GlStateManager.scale(finalScale, finalScale, finalScale)
GlStateManager.enableBlend()
GlStateManager.disableLighting()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
GlStateManager.enableTexture2D()
minecraft.fontRendererObj.drawString(
finalText,
(-width).toFloat(),
yOff,
LorenzColor.WHITE.toColor().rgb,
shadow
)
GlStateManager.disableBlend()
GlStateManager.popMatrix()
}
fun interpolate(currentValue: Double, lastValue: Double, multiplier: Float): Double {
return lastValue + (currentValue - lastValue) * multiplier
}
fun Position.renderString(string: String?, offsetX: Int = 0, offsetY: Int = 0, posLabel: String) {
if (string == null) return
if (string == "") return
val x = renderString0(string, offsetX, offsetY)
GuiEditManager.add(this, posLabel, x, 10)
}
private fun Position.renderString0(string: String?, offsetX: Int = 0, offsetY: Int = 0): Int {
val display = "§f$string"
GlStateManager.pushMatrix()
val minecraft = Minecraft.getMinecraft()
val renderer = minecraft.renderManager.fontRenderer
val x = getAbsX_() + offsetX
val y = getAbsY_() + offsetY
GlStateManager.translate(x + 1.0, y + 1.0, 0.0)
renderer.drawStringWithShadow(display, 0f, 0f, 0)
GlStateManager.popMatrix()
return renderer.getStringWidth(display)
}
fun Position.renderStrings(list: List<String>, extraSpace: Int = 0, posLabel: String) {
if (list.isEmpty()) return
var offsetY = 0
var longestX = 0
for (s in list) {
val x = renderString0(s, offsetY = offsetY)
if (x > longestX) {
longestX = x
}
offsetY += 10 + extraSpace
}
GuiEditManager.add(this, posLabel, longestX, offsetY)
}
/**
* Accepts a list of lines to print.
* Each line is a list of things to print. Can print String or ItemStack objects.
*/
fun Position.renderStringsAndItems(
list: List<List<Any?>>,
extraSpace: Int = 0,
itemScale: Double = 1.0,
posLabel: String,
) {
if (list.isEmpty()) return
var offsetY = 0
var longestX = 0
try {
for (line in list) {
val x = renderLine(line, offsetY, itemScale)
if (x > longestX) {
longestX = x
}
offsetY += 10 + extraSpace + 2
}
} catch (e: NullPointerException) {
println(" ")
for (innerList in list) {
println("new inner list:")
for (any in innerList) {
println("any: '$any'")
}
}
e.printStackTrace()
LorenzUtils.debug("NPE in renderStringsAndItems!")
}
GuiEditManager.add(this, posLabel, longestX, offsetY)
}
/**
* Accepts a single line to print.
* This line is a list of things to print. Can print String or ItemStack objects.
*/
fun Position.renderSingleLineWithItems(list: List<Any?>, itemScale: Double = 1.0, posLabel: String) {
if (list.isEmpty()) return
val longestX = renderLine(list, 0, itemScale)
GuiEditManager.add(this, posLabel, longestX, 10)
}
private fun Position.renderLine(line: List<Any?>, offsetY: Int, itemScale: Double = 1.0): Int {
val renderer = Minecraft.getMinecraft().fontRendererObj
var offsetX = 0
for (any in line) {
if (any == null) {
offsetX += 12
continue
}
if (any is String) {
renderString0(any, offsetX, offsetY)
val width = renderer.getStringWidth(any)
offsetX += width
} else if (any is ItemStack) {
val isX = getAbsX_() + offsetX
val isY = getAbsY_() + offsetY
any.renderOnScreen(isX.toFloat(), isY.toFloat(), itemScale)
offsetX += 12
} else {
throw RuntimeException("Unknown render object: $any")
}
}
return offsetX
}
// totally not modified Autumn Client's TargetStrafe
fun drawCircle(entity: Entity, partialTicks: Float, rad: Double, color: Color) {
GlStateManager.pushMatrix()
GL11.glNormal3f(0.0f, 1.0f, 0.0f)
GlStateManager.enableDepth()
GlStateManager.enableBlend()
GlStateManager.depthFunc(GL11.GL_LEQUAL)
GlStateManager.disableCull()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
GlStateManager.enableAlpha()
GlStateManager.disableTexture2D()
GlStateManager.disableDepth()
var il = 0.0
val tessellator = Tessellator.getInstance()
val worldRenderer = tessellator.worldRenderer
while (il < 0.05) {
GlStateManager.pushMatrix()
GlStateManager.disableTexture2D()
GL11.glLineWidth(2F)
worldRenderer.begin(1, DefaultVertexFormats.POSITION)
val renderManager = Minecraft.getMinecraft().renderManager
val x: Double =
entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks - renderManager.viewerPosX
val y: Double =
entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks - renderManager.viewerPosY
val z: Double =
entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks - renderManager.viewerPosZ
val pix2 = Math.PI * 2.0
for (i in 0..90) {
color.bindColor()
worldRenderer.pos(x + rad * cos(i * pix2 / 45.0), y + il, z + rad * sin(i * pix2 / 45.0)).endVertex()
}
tessellator.draw()
GlStateManager.enableTexture2D()
GlStateManager.popMatrix()
il += 0.0006
}
GlStateManager.enableDepth()
GlStateManager.enableCull()
GlStateManager.enableTexture2D()
GlStateManager.enableDepth()
GlStateManager.disableBlend()
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
GlStateManager.popMatrix()
}
fun drawCylinderInWorld(
color: Color,
x: Double,
y: Double,
z: Double,
radius: Float,
height: Float,
partialTicks: Float,
) {
GlStateManager.pushMatrix()
GL11.glNormal3f(0.0f, 1.0f, 0.0f)
GlStateManager.enableDepth()
GlStateManager.enableBlend()
GlStateManager.depthFunc(GL11.GL_LEQUAL)
GlStateManager.disableCull()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
GlStateManager.enableAlpha()
GlStateManager.disableTexture2D()
color.bindColor()
var x1 = x
var y1 = y
var z1 = z
val renderViewEntity = Minecraft.getMinecraft().renderViewEntity
val viewX =
renderViewEntity.prevPosX + (renderViewEntity.posX - renderViewEntity.prevPosX) * partialTicks.toDouble()
val viewY =
renderViewEntity.prevPosY + (renderViewEntity.posY - renderViewEntity.prevPosY) * partialTicks.toDouble()
val viewZ =
renderViewEntity.prevPosZ + (renderViewEntity.posZ - renderViewEntity.prevPosZ) * partialTicks.toDouble()
x1 -= viewX
y1 -= viewY
z1 -= viewZ
val tessellator = Tessellator.getInstance()
val worldrenderer = tessellator.worldRenderer
worldrenderer.begin(GL11.GL_QUAD_STRIP, DefaultVertexFormats.POSITION)
var currentAngle = 0f
val angleStep = 0.1f
while (currentAngle < 2 * Math.PI) {
val xOffset = radius * cos(currentAngle.toDouble()).toFloat()
val zOffset = radius * sin(currentAngle.toDouble()).toFloat()
worldrenderer.pos(x1 + xOffset, y1 + height, z1 + zOffset).endVertex()
worldrenderer.pos(x1 + xOffset, y1 + 0, z1 + zOffset).endVertex()
currentAngle += angleStep
}
worldrenderer.pos(x1 + radius, y1 + height, z1).endVertex()
worldrenderer.pos(x1 + radius, y1 + 0.0, z1).endVertex()
tessellator.draw()
GlStateManager.enableCull()
GlStateManager.enableTexture2D()
GlStateManager.enableDepth()
GlStateManager.disableBlend()
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
GlStateManager.popMatrix()
}
private fun Color.bindColor() =
GlStateManager.color(this.red / 255f, this.green / 255f, this.blue / 255f, this.alpha / 255f)
fun drawStringScaledMaxWidth(
str: String?,
fr: FontRenderer,
x: Float,
y: Float,
shadow: Boolean,
len: Int,
colour: Int,
) {
val strLen = fr.getStringWidth(str)
var factor = len / strLen.toFloat()
factor = Math.min(1f, factor)
drawStringScaled(str, fr, x, y, shadow, colour, factor)
}
fun RenderWorldLastEvent.drawDynamicText(
location: LorenzVec,
text: String,
scaleMultiplier: Double,
yOff: Float = 0f,
hideTooCloseAt: Double = 4.5,
smallestDistanceVew: Double = 5.0,
ignoreBlocks: Boolean = true,
) {
val thePlayer = Minecraft.getMinecraft().thePlayer
val x = location.x
val y = location.y
val z = location.z
val render = Minecraft.getMinecraft().renderViewEntity
val renderOffsetX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks
val renderOffsetY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks
val renderOffsetZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks
val eyeHeight = thePlayer.eyeHeight
val distToPlayerSq =
(x - renderOffsetX) * (x - renderOffsetX) + (y - (renderOffsetY + eyeHeight)) * (y - (renderOffsetY + eyeHeight)) + (z - renderOffsetZ) * (z - renderOffsetZ)
var distToPlayer = sqrt(distToPlayerSq)
//TODO this is optional maybe?
distToPlayer = distToPlayer.coerceAtLeast(smallestDistanceVew)
if (distToPlayer < hideTooCloseAt) return
val distRender = distToPlayer.coerceAtMost(50.0)
val resultX = renderOffsetX + (x + 0.5 - renderOffsetX) / (distToPlayer / distRender)
val resultY =
(renderOffsetY + eyeHeight) + (y + 20 * distToPlayer / 300 - (renderOffsetY + eyeHeight)) / (distToPlayer / distRender)
val resultZ = renderOffsetZ + (z + 0.5 - renderOffsetZ) / (distToPlayer / distRender)
val renderLocation = LorenzVec(resultX, resultY, resultZ)
var scale = distRender / 12
scale *= scaleMultiplier
render(renderLocation, "§f$text", scale, !ignoreBlocks, true, yOff)
}
private fun render(
location: LorenzVec,
text: String,
scale: Double,
depthTest: Boolean,
shadow: Boolean,
yOff: Float,
) {
if (!depthTest) {
GL11.glDisable(GL11.GL_DEPTH_TEST)
GL11.glDepthMask(false)
}
GlStateManager.pushMatrix()
GlStateManager.enableBlend()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
val minecraft = Minecraft.getMinecraft()
val fontRenderer = minecraft.fontRendererObj
val renderManager = minecraft.renderManager
GlStateManager.translate(
location.x - renderManager.viewerPosX,
location.y - renderManager.viewerPosY,
location.z - renderManager.viewerPosZ
)
GlStateManager.color(1f, 1f, 1f, 0.5f)
GlStateManager.rotate(-renderManager.playerViewY, 0.0f, 1.0f, 0.0f)
GlStateManager.rotate(renderManager.playerViewX, 1.0f, 0.0f, 0.0f)
GlStateManager.scale(-scale / 25, -scale / 25, scale / 25)
val stringWidth = fontRenderer.getStringWidth(text)
if (shadow) {
fontRenderer.drawStringWithShadow(
text,
(-stringWidth / 2).toFloat(),
yOff,
0
)
} else {
fontRenderer.drawString(
text,
-stringWidth / 2,
0,
0
)
}
GlStateManager.color(1f, 1f, 1f)
GlStateManager.disableBlend()
GlStateManager.popMatrix()
if (!depthTest) {
GL11.glEnable(GL11.GL_DEPTH_TEST)
GL11.glDepthMask(true)
}
}
fun RenderWorldLastEvent.draw3DLine(p1: LorenzVec, p2: LorenzVec, color: Color, lineWidth: Int, depth: Boolean) {
GlStateManager.disableDepth()
GlStateManager.disableCull()
val render = Minecraft.getMinecraft().renderViewEntity
val worldRenderer = Tessellator.getInstance().worldRenderer
val realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks
val realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks
val realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks
GlStateManager.pushMatrix()
GlStateManager.translate(-realX, -realY, -realZ)
GlStateManager.disableTexture2D()
GlStateManager.enableBlend()
GlStateManager.disableAlpha()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
GL11.glLineWidth(lineWidth.toFloat())
if (!depth) {
GL11.glDisable(GL11.GL_DEPTH_TEST)
GlStateManager.depthMask(false)
}
GlStateManager.color(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f)
worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION)
worldRenderer.pos(p1.x, p1.y, p1.z).endVertex()
worldRenderer.pos(p2.x, p2.y, p2.z).endVertex()
Tessellator.getInstance().draw()
GlStateManager.translate(realX, realY, realZ)
if (!depth) {
GL11.glEnable(GL11.GL_DEPTH_TEST)
GlStateManager.depthMask(true)
}
GlStateManager.disableBlend()
GlStateManager.enableAlpha()
GlStateManager.enableTexture2D()
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
GlStateManager.popMatrix()
GlStateManager.disableLighting()
GlStateManager.enableDepth()
}
}
|