Skip to content

Commit a08e64f

Browse files
committed
Some cleanup
1 parent c0d7733 commit a08e64f

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

common/src/main/kotlin/com/lambda/graphics/renderer/esp/DynamicAABB.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class DynamicAABB {
4848
return null
4949
}
5050

51+
fun center() = curr?.center ?: prev?.center ?: throw NullPointerException("No box is set")
52+
5153
companion object {
5254
val Entity.dynamicBox
5355
get() = DynamicAABB().apply {

common/src/main/kotlin/com/lambda/graphics/renderer/esp/builders/DynamicESPLineBuilders.kt

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
package com.lambda.graphics.renderer.esp.builders
1919

20+
import com.lambda.Lambda.mc
2021
import com.lambda.graphics.RenderMain
2122
import com.lambda.graphics.renderer.esp.DynamicAABB
2223
import com.lambda.graphics.renderer.esp.impl.DynamicESPRenderer
2324
import com.lambda.graphics.renderer.gui.LineRenderer
25+
import com.lambda.util.math.minus
2426
import net.minecraft.util.math.Vec3d
2527
import java.awt.Color
2628
import org.joml.Vector2d
@@ -121,34 +123,21 @@ fun DynamicESPRenderer.drawLineBetweenBoxes(
121123
dashiness: Double = 1.0,
122124
dashPeriod: Double = 1.0
123125
) {
124-
val box1Pair = box1.getBoxPair() ?: return
125-
val box2Pair = box2.getBoxPair() ?: return
126-
127-
val center1 = Vec3d(
128-
(box1Pair.first.minX + box1Pair.first.maxX) / 2,
129-
(box1Pair.first.minY + box1Pair.first.maxY) / 2,
130-
(box1Pair.first.minZ + box1Pair.first.maxZ) / 2
131-
)
132-
133-
val center2 = Vec3d(
134-
(box2Pair.first.minX + box2Pair.first.maxX) / 2,
135-
(box2Pair.first.minY + box2Pair.first.maxY) / 2,
136-
(box2Pair.first.minZ + box2Pair.first.maxZ) / 2
137-
)
138-
139-
drawLine(center1, center2, color, color, width, dashiness, dashPeriod)
126+
drawLine(box1.center(), box2.center(), color, color, width, dashiness, dashPeriod)
140127
}
141128

142129
/**
143130
* Projects a 3D point to 2D screen coordinates.
144131
* Returns null if the point is behind the camera or outside the screen.
145132
*/
146133
private fun project3DTo2D(point: Vec3d): Vector2d? {
134+
val transformedPoint = point - mc.gameRenderer.camera.pos
135+
147136
// Create a 4D vector from the 3D point
148137
val vec4 = Vector4f(
149-
point.x.toFloat(),
150-
point.y.toFloat(),
151-
point.z.toFloat(),
138+
transformedPoint.x.toFloat(),
139+
transformedPoint.y.toFloat(),
140+
transformedPoint.z.toFloat(),
152141
1f
153142
)
154143

common/src/main/kotlin/com/lambda/module/modules/debug/RenderTest.kt

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,24 @@ object RenderTest : Module(
6969
private val lineColor = Color(255, 100, 100).setAlpha(0.8)
7070

7171
init {
72-
listen<RenderEvent.DynamicESP> {
73-
val entities = entitySearch<LivingEntity>(8.0).toList()
72+
listen<RenderEvent.DynamicESP> { event ->
73+
val entities = entitySearch<LivingEntity>(8.0).sortedBy { it.distanceTo(player) }
7474

7575
// Draw boxes around entities
7676
entities.forEach { entity ->
77-
it.renderer.ofBox(entity.dynamicBox, filledColor, outlineColor)
77+
event.renderer.ofBox(entity.dynamicBox, filledColor, outlineColor)
7878
}
7979

80-
// Example of drawing lines between entities using the new drawLineBetweenBoxes function
81-
if (drawLines && entities.size >= 2) {
82-
for (i in 0 until entities.size - 1) {
83-
val entity1 = entities[i]
84-
val entity2 = entities[i + 1]
85-
86-
it.renderer.drawLineBetweenBoxes(
87-
entity1.dynamicBox,
88-
entity2.dynamicBox,
89-
lineColor,
90-
lineWidth,
91-
dashiness,
92-
dashPeriod
93-
)
94-
}
80+
entities.firstOrNull()?.let { first ->
81+
// Example of drawing lines between entities using the new drawLineBetweenBoxes function
82+
event.renderer.drawLineBetweenBoxes(
83+
player.dynamicBox,
84+
first.dynamicBox,
85+
lineColor,
86+
lineWidth,
87+
dashiness,
88+
dashPeriod
89+
)
9590
}
9691
}
9792

0 commit comments

Comments
 (0)