1818package com.lambda.graphics.esp
1919
2020import com.lambda.graphics.mc.RegionShapeBuilder
21- import com.lambda.graphics.mc.RegionVertexCollector
2221import com.lambda.graphics.mc.RenderRegion
2322import com.lambda.graphics.renderer.esp.DirectionMask
2423import com.lambda.graphics.renderer.esp.DynamicAABB
2524import net.minecraft.block.BlockState
2625import net.minecraft.util.math.BlockPos
2726import net.minecraft.util.math.Box
28- import net.minecraft.util.math.MathHelper
2927import net.minecraft.util.math.Vec3d
3028import net.minecraft.util.shape.VoxelShape
3129import java.awt.Color
3230
3331@EspDsl
34- class ShapeScope (val region : RenderRegion , val collectShapes : Boolean = false ) {
32+ class ShapeScope (val region : RenderRegion ) {
3533 internal val builder = RegionShapeBuilder (region)
36- internal val shapes = if (collectShapes) mutableListOf<EspShape >() else null
3734
3835 /* * Start building a box. */
39- fun box (box : Box , id : Any? = null, block : BoxScope .() -> Unit ) {
36+ fun box (box : Box , block : BoxScope .() -> Unit ) {
4037 val scope = BoxScope (box, this )
4138 scope.apply (block)
42- if (collectShapes) {
43- shapes?.add(
44- EspShape .BoxShape (
45- id?.hashCode() ? : box.hashCode(),
46- box,
47- scope.filledColor,
48- scope.outlineColor,
49- scope.sides,
50- scope.outlineMode,
51- scope.thickness
52- )
53- )
54- }
5539 }
5640
5741 /* * Draw a line between two points. */
58- fun line (start : Vec3d , end : Vec3d , color : Color , width : Float = 1.0f, id : Any? = null ) {
42+ fun line (start : Vec3d , end : Vec3d , color : Color , width : Float = 1.0f) {
5943 builder.line(start, end, color, width)
60- if (collectShapes) {
61- shapes?.add(
62- EspShape .LineShape (
63- id?.hashCode() ? : (start.hashCode() xor end.hashCode()),
64- start,
65- end,
66- color,
67- width
68- )
69- )
70- }
7144 }
7245
7346 /* * Draw a tracer. */
74- fun tracer (from : Vec3d , to : Vec3d , id : Any? = null , block : LineScope .() -> Unit = {}) {
47+ fun line (from : Vec3d , to : Vec3d , block : LineScope .() -> Unit = {}) {
7548 val scope = LineScope (from, to, this )
7649 scope.apply (block)
7750 scope.draw()
78- if (collectShapes) {
79- shapes?.add(
80- EspShape .LineShape (
81- id?.hashCode() ? : (from.hashCode() xor to.hashCode()),
82- from,
83- to,
84- scope.lineColor,
85- scope.lineWidth,
86- scope.lineDashLength,
87- scope.lineGapLength
88- )
89- )
90- }
9151 }
9252
9353 /* * Draw a simple filled box. */
9454 fun filled (box : Box , color : Color , sides : Int = DirectionMask .ALL ) {
9555 builder.filled(box, color, sides)
96- if (collectShapes) {
97- shapes?.add(EspShape .BoxShape (box.hashCode(), box, color, null , sides))
98- }
9956 }
10057
10158 /* * Draw a simple outlined box. */
10259 fun outline (box : Box , color : Color , sides : Int = DirectionMask .ALL , thickness : Float = builder.lineWidth) {
10360 builder.outline(box, color, sides, thickness = thickness)
104- if (collectShapes) {
105- shapes?.add(EspShape .BoxShape (box.hashCode(), box, null , color, sides, thickness = thickness))
106- }
10761 }
10862
10963 fun filled (box : DynamicAABB , color : Color , sides : Int = DirectionMask .ALL ) {
11064 builder.filled(box, color, sides)
111- if (collectShapes) {
112- box.pair?.second?.let {
113- shapes?.add(EspShape .BoxShape (it.hashCode(), it, color, null , sides))
114- }
115- }
11665 }
11766
11867 fun outline (box : DynamicAABB , color : Color , sides : Int = DirectionMask .ALL , thickness : Float = builder.lineWidth) {
11968 builder.outline(box, color, sides, thickness = thickness)
120- if (collectShapes) {
121- box.pair?.second?.let {
122- shapes?.add(EspShape .BoxShape (it.hashCode(), it, null , color, sides, thickness = thickness))
123- }
124- }
12569 }
12670
12771 fun filled (pos : BlockPos , color : Color , sides : Int = DirectionMask .ALL ) {
12872 builder.filled(pos, color, sides)
129- if (collectShapes) {
130- shapes?.add(EspShape .BoxShape (pos.hashCode(), Box (pos), color, null , sides))
131- }
13273 }
13374
13475 fun outline (pos : BlockPos , color : Color , sides : Int = DirectionMask .ALL , thickness : Float = builder.lineWidth) {
13576 builder.outline(pos, color, sides, thickness = thickness)
136- if (collectShapes) {
137- shapes?.add(EspShape .BoxShape (pos.hashCode(), Box (pos), null , color, sides, thickness = thickness))
138- }
13977 }
14078
14179 fun filled (pos : BlockPos , state : BlockState , color : Color , sides : Int = DirectionMask .ALL ) {
14280 builder.filled(pos, state, color, sides)
143- if (collectShapes) {
144- shapes?.add(EspShape .BoxShape (pos.hashCode(), Box (pos), color, null , sides))
145- }
14681 }
14782
14883 fun outline (pos : BlockPos , state : BlockState , color : Color , sides : Int = DirectionMask .ALL , thickness : Float = builder.lineWidth) {
14984 builder.outline(pos, state, color, sides, thickness = thickness)
150- if (collectShapes) {
151- shapes?.add(EspShape .BoxShape (pos.hashCode(), Box (pos), null , color, sides, thickness = thickness))
152- }
15385 }
15486
15587 fun filled (shape : VoxelShape , color : Color , sides : Int = DirectionMask .ALL ) {
15688 builder.filled(shape, color, sides)
157- if (collectShapes) {
158- shape.boundingBoxes.forEach {
159- shapes?.add(EspShape .BoxShape (it.hashCode(), it, color, null , sides))
160- }
161- }
16289 }
16390
16491 fun outline (shape : VoxelShape , color : Color , sides : Int = DirectionMask .ALL , thickness : Float = builder.lineWidth) {
16592 builder.outline(shape, color, sides, thickness = thickness)
166- if (collectShapes) {
167- shape.boundingBoxes.forEach {
168- shapes?.add(EspShape .BoxShape (it.hashCode(), it, null , color, sides, thickness = thickness))
169- }
170- }
17193 }
17294
17395 fun box (
@@ -180,9 +102,6 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
180102 thickness : Float = builder.lineWidth
181103 ) {
182104 builder.box(pos, state, filled, outline, sides, mode, thickness = thickness)
183- if (collectShapes) {
184- shapes?.add(EspShape .BoxShape (pos.hashCode(), Box (pos), filled, outline, sides, mode, thickness = thickness))
185- }
186105 }
187106
188107 fun box (
@@ -194,9 +113,6 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
194113 thickness : Float = builder.lineWidth
195114 ) {
196115 builder.box(pos, filled, outline, sides, mode, thickness = thickness)
197- if (collectShapes) {
198- shapes?.add(EspShape .BoxShape (pos.hashCode(), Box (pos), filled, outline, sides, mode, thickness = thickness))
199- }
200116 }
201117
202118 fun box (
@@ -208,9 +124,6 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
208124 thickness : Float = builder.lineWidth
209125 ) {
210126 builder.box(box, filledColor, outlineColor, sides, mode, thickness = thickness)
211- if (collectShapes) {
212- shapes?.add(EspShape .BoxShape (box.hashCode(), box, filledColor, outlineColor, sides, mode, thickness = thickness))
213- }
214127 }
215128
216129 fun box (
@@ -222,13 +135,6 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
222135 thickness : Float = builder.lineWidth
223136 ) {
224137 builder.box(box, filledColor, outlineColor, sides, mode, thickness = thickness)
225- if (collectShapes) {
226- box.pair?.second?.let {
227- shapes?.add(
228- EspShape .BoxShape (it.hashCode(), it, filledColor, outlineColor, sides, mode, thickness = thickness)
229- )
230- }
231- }
232138 }
233139
234140 fun box (
@@ -240,19 +146,6 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
240146 thickness : Float = builder.lineWidth
241147 ) {
242148 builder.box(entity, filled, outline, sides, mode, thickness = thickness)
243- if (collectShapes) {
244- shapes?.add(
245- EspShape .BoxShape (
246- entity.pos.hashCode(),
247- Box (entity.pos),
248- filled,
249- outline,
250- sides,
251- mode,
252- thickness = thickness
253- )
254- )
255- }
256149 }
257150
258151 fun box (
@@ -264,19 +157,6 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
264157 thickness : Float = builder.lineWidth
265158 ) {
266159 builder.box(entity, filled, outline, sides, mode, thickness = thickness)
267- if (collectShapes) {
268- shapes?.add(
269- EspShape .BoxShape (
270- entity.hashCode(),
271- entity.boundingBox,
272- filled,
273- outline,
274- sides,
275- mode,
276- thickness = thickness
277- )
278- )
279- }
280160 }
281161}
282162
@@ -339,78 +219,3 @@ class LineScope(val from: Vec3d, val to: Vec3d, val parent: ShapeScope) {
339219 }
340220 }
341221}
342-
343- sealed class EspShape (val id : Int ) {
344- abstract fun renderInterpolated (
345- prev : EspShape ,
346- tickDelta : Float ,
347- collector : RegionVertexCollector ,
348- region : RenderRegion
349- )
350-
351- class BoxShape (
352- id : Int ,
353- val box : Box ,
354- val filledColor : Color ? ,
355- val outlineColor : Color ? ,
356- val sides : Int = DirectionMask .ALL ,
357- val outlineMode : DirectionMask .OutlineMode = DirectionMask .OutlineMode .And ,
358- val thickness : Float = 1.0f
359- ) : EspShape(id) {
360- override fun renderInterpolated (
361- prev : EspShape ,
362- tickDelta : Float ,
363- collector : RegionVertexCollector ,
364- region : RenderRegion
365- ) {
366- val interpBox =
367- if (prev is BoxShape ) {
368- Box (
369- MathHelper .lerp(tickDelta.toDouble(), prev.box.minX, box.minX),
370- MathHelper .lerp(tickDelta.toDouble(), prev.box.minY, box.minY),
371- MathHelper .lerp(tickDelta.toDouble(), prev.box.minZ, box.minZ),
372- MathHelper .lerp(tickDelta.toDouble(), prev.box.maxX, box.maxX),
373- MathHelper .lerp(tickDelta.toDouble(), prev.box.maxY, box.maxY),
374- MathHelper .lerp(tickDelta.toDouble(), prev.box.maxZ, box.maxZ)
375- )
376- } else box
377-
378- val shapeBuilder = RegionShapeBuilder (region)
379- filledColor?.let { shapeBuilder.filled(interpBox, it, sides) }
380- outlineColor?.let { shapeBuilder.outline(interpBox, it, sides, outlineMode, thickness = thickness) }
381-
382- collector.faceVertices.addAll(shapeBuilder.collector.faceVertices)
383- collector.edgeVertices.addAll(shapeBuilder.collector.edgeVertices)
384- }
385- }
386-
387- class LineShape (
388- id : Int ,
389- val from : Vec3d ,
390- val to : Vec3d ,
391- val color : Color ,
392- val width : Float ,
393- val dashLength : Double? = null ,
394- val gapLength : Double? = null
395- ) : EspShape(id) {
396- override fun renderInterpolated (
397- prev : EspShape ,
398- tickDelta : Float ,
399- collector : RegionVertexCollector ,
400- region : RenderRegion
401- ) {
402- val iFrom = if (prev is LineShape ) prev.from.lerp(from, tickDelta.toDouble()) else from
403- val iTo = if (prev is LineShape ) prev.to.lerp(to, tickDelta.toDouble()) else to
404-
405- val shapeBuilder = RegionShapeBuilder (region)
406- if (dashLength != null && gapLength != null ) {
407- shapeBuilder.dashedLine(iFrom, iTo, color, dashLength, gapLength, width)
408- } else {
409- shapeBuilder.line(iFrom, iTo, color, width)
410- }
411-
412- collector.faceVertices.addAll(shapeBuilder.collector.faceVertices)
413- collector.edgeVertices.addAll(shapeBuilder.collector.edgeVertices)
414- }
415- }
416- }
0 commit comments