1+ package com.lambda.graphics.renderer.esp
2+
3+ import com.lambda.Lambda.mc
4+ import com.lambda.event.EventFlow.post
5+ import com.lambda.event.events.RenderEvent
6+ import com.lambda.event.events.TickEvent
7+ import com.lambda.event.listener.SafeListener.Companion.listener
8+ import com.lambda.graphics.buffer.vao.VAO
9+ import com.lambda.graphics.buffer.vao.vertex.VertexAttrib
10+ import com.lambda.graphics.buffer.vao.vertex.VertexMode
11+ import com.lambda.graphics.renderer.esp.DirectionMask.DOWN
12+ import com.lambda.graphics.renderer.esp.DirectionMask.EAST
13+ import com.lambda.graphics.renderer.esp.DirectionMask.NORTH
14+ import com.lambda.graphics.renderer.esp.DirectionMask.SOUTH
15+ import com.lambda.graphics.renderer.esp.DirectionMask.UP
16+ import com.lambda.graphics.renderer.esp.DirectionMask.WEST
17+ import com.lambda.graphics.renderer.esp.DirectionMask.hasDirection
18+ import com.lambda.graphics.shader.Shader
19+ import com.lambda.util.primitives.extension.max
20+ import com.lambda.util.primitives.extension.min
21+ import com.lambda.util.primitives.extension.partialTicks
22+ import com.lambda.util.primitives.extension.prevPos
23+ import net.minecraft.entity.Entity
24+ import net.minecraft.util.math.Box
25+ import java.awt.Color
26+
27+ object EntityEspRenderer {
28+ private val filled = VAO (VertexMode .TRIANGLES , VertexAttrib .Group .DYNAMIC_RENDERER )
29+ private val outline = VAO (VertexMode .LINES , VertexAttrib .Group .DYNAMIC_RENDERER )
30+ private val shader = Shader (" renderer/pos_color" , " renderer/box_dynamic" )
31+
32+ fun buildFilled (entity : Entity , color : Color , sides : Int ) = filled.use {
33+ val box = entity.boundingBox
34+
35+ val delta = entity.prevPos.subtract(entity.pos)
36+ val prevBox = Box (box.min.add(delta), box.max.add(delta))
37+
38+ val pos11 = prevBox.min
39+ val pos12 = prevBox.max
40+ val pos21 = box.min
41+ val pos22 = box.max
42+
43+ grow(8 )
44+
45+ val blb by lazy { vec3(pos11.x, pos11.y, pos11.z).vec3(pos21.x, pos21.y, pos21.z).color(color).end() }
46+ val blf by lazy { vec3(pos11.x, pos11.y, pos12.z).vec3(pos21.x, pos21.y, pos22.z).color(color).end() }
47+ val brb by lazy { vec3(pos12.x, pos11.y, pos11.z).vec3(pos22.x, pos21.y, pos21.z).color(color).end() }
48+ val brf by lazy { vec3(pos12.x, pos11.y, pos12.z).vec3(pos22.x, pos21.y, pos22.z).color(color).end() }
49+ val tlb by lazy { vec3(pos11.x, pos12.y, pos11.z).vec3(pos21.x, pos22.y, pos21.z).color(color).end() }
50+ val tlf by lazy { vec3(pos11.x, pos12.y, pos12.z).vec3(pos21.x, pos22.y, pos22.z).color(color).end() }
51+ val trb by lazy { vec3(pos12.x, pos12.y, pos11.z).vec3(pos22.x, pos22.y, pos21.z).color(color).end() }
52+ val trf by lazy { vec3(pos12.x, pos12.y, pos12.z).vec3(pos22.x, pos22.y, pos22.z).color(color).end() }
53+
54+ if (sides.hasDirection(EAST )) putQuad(brb, brf, trf, trb)
55+ if (sides.hasDirection(WEST )) putQuad(blb, blf, tlf, tlb)
56+ if (sides.hasDirection(UP )) putQuad(tlb, tlf, trf, trb)
57+ if (sides.hasDirection(DOWN )) putQuad(blb, brb, brf, blf)
58+ if (sides.hasDirection(SOUTH )) putQuad(blf, brf, trf, tlf)
59+ if (sides.hasDirection(NORTH )) putQuad(blb, brb, trb, tlb)
60+ }
61+
62+ fun buildOutline (entity : Entity , color : Color , sides : Int , outlineMode : DirectionMask .OutlineMode ) = outline.use {
63+ val box = entity.boundingBox
64+
65+ val delta = entity.prevPos.subtract(entity.pos)
66+ val prevBox = Box (box.min.add(delta), box.max.add(delta))
67+
68+ val pos11 = prevBox.min
69+ val pos12 = prevBox.max
70+ val pos21 = box.min
71+ val pos22 = box.max
72+
73+ grow(8 )
74+
75+ val blb by lazy { vec3(pos11.x, pos11.y, pos11.z).vec3(pos21.x, pos21.y, pos21.z).color(color).end() }
76+ val blf by lazy { vec3(pos11.x, pos11.y, pos12.z).vec3(pos21.x, pos21.y, pos22.z).color(color).end() }
77+ val brb by lazy { vec3(pos12.x, pos11.y, pos11.z).vec3(pos22.x, pos21.y, pos21.z).color(color).end() }
78+ val brf by lazy { vec3(pos12.x, pos11.y, pos12.z).vec3(pos22.x, pos21.y, pos22.z).color(color).end() }
79+ val tlb by lazy { vec3(pos11.x, pos12.y, pos11.z).vec3(pos21.x, pos22.y, pos21.z).color(color).end() }
80+ val tlf by lazy { vec3(pos11.x, pos12.y, pos12.z).vec3(pos21.x, pos22.y, pos22.z).color(color).end() }
81+ val trb by lazy { vec3(pos12.x, pos12.y, pos11.z).vec3(pos22.x, pos22.y, pos21.z).color(color).end() }
82+ val trf by lazy { vec3(pos12.x, pos12.y, pos12.z).vec3(pos22.x, pos22.y, pos22.z).color(color).end() }
83+
84+ val hasEast = sides.hasDirection(EAST )
85+ val hasWest = sides.hasDirection(WEST )
86+ val hasUp = sides.hasDirection(UP )
87+ val hasDown = sides.hasDirection(DOWN )
88+ val hasSouth = sides.hasDirection(SOUTH )
89+ val hasNorth = sides.hasDirection(NORTH )
90+
91+ if (outlineMode.check(hasUp, hasNorth)) putLine(tlb, trb)
92+ if (outlineMode.check(hasUp, hasSouth)) putLine(tlf, trf)
93+ if (outlineMode.check(hasUp, hasWest)) putLine(tlb, tlf)
94+ if (outlineMode.check(hasUp, hasEast)) putLine(trf, trb)
95+
96+ if (outlineMode.check(hasDown, hasNorth)) putLine(blb, brb)
97+ if (outlineMode.check(hasDown, hasSouth)) putLine(blf, brf)
98+ if (outlineMode.check(hasDown, hasWest)) putLine(blb, blf)
99+ if (outlineMode.check(hasDown, hasEast)) putLine(brb, brf)
100+
101+ if (outlineMode.check(hasWest, hasNorth)) putLine(tlb, blb)
102+ if (outlineMode.check(hasNorth, hasEast)) putLine(trb, brb)
103+ if (outlineMode.check(hasEast, hasSouth)) putLine(trf, brf)
104+ if (outlineMode.check(hasSouth, hasWest)) putLine(tlf, blf)
105+ }
106+
107+ fun render () {
108+ shader.use()
109+ shader[" u_TickDelta" ] = mc.partialTicks
110+ shader[" u_CameraPosition" ] = mc.gameRenderer.camera.pos
111+
112+ filled.render()
113+ outline.render()
114+ }
115+
116+ init {
117+ listener<TickEvent .Post > {
118+ filled.clear()
119+ outline.clear()
120+
121+ RenderEvent .EntityESP ().post()
122+
123+ filled.upload()
124+ outline.upload()
125+ }
126+ }
127+ }
0 commit comments