Skip to content

Commit 77e9e87

Browse files
committed
air place renders and nametag fixes
1 parent 9fa25ec commit 77e9e87

File tree

4 files changed

+53
-50
lines changed

4 files changed

+53
-50
lines changed

src/main/kotlin/com/lambda/graphics/mc/BoxBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BoxBuilder(lineConfig: LineConfig?) {
2727
var fillSides: Int = DirectionMask.ALL
2828

2929
var outlineMode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And
30-
var lineWidth = lineConfig?.width ?: 0.005f
30+
var lineWidth = lineConfig?.width ?: -0.0005f
3131

3232
var dashStyle: LineDashStyle? = lineConfig?.getDashStyle()
3333

src/main/kotlin/com/lambda/graphics/mc/RenderBuilder.kt

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,6 @@ class RenderBuilder(private val cameraPos: Vec3d, var depthTest: Boolean = false
9595

9696
private var activeOutlineId: Int? = null
9797

98-
fun withOutline(style: OutlineStyle, block: RenderBuilder.() -> Unit) {
99-
val previousId = activeOutlineId
100-
activeOutlineId = collector.registerCustomOutline(style, depthTest = depthTest)
101-
try {
102-
block()
103-
} finally {
104-
activeOutlineId = previousId
105-
}
106-
}
107-
10898
fun box(
10999
box: Box,
110100
lineConfig: LineConfig? = null,
@@ -171,7 +161,7 @@ class RenderBuilder(private val cameraPos: Vec3d, var depthTest: Boolean = false
171161
fun lineGradient(
172162
startPos: Vec3d, startColor: Color,
173163
endPos: Vec3d, endColor: Color,
174-
width: Float,
164+
width: Float = -0.0005f,
175165
dashStyle: LineDashStyle? = null
176166
) = lineGradient(
177167
startPos.x, startPos.y, startPos.z, startColor,
@@ -183,22 +173,22 @@ class RenderBuilder(private val cameraPos: Vec3d, var depthTest: Boolean = false
183173
fun lineGradient(
184174
x1: Double, y1: Double, z1: Double, c1: Color,
185175
x2: Double, y2: Double, z2: Double, c2: Color,
186-
width: Float,
176+
width: Float = -0.0005f,
187177
dashStyle: LineDashStyle? = null
188178
) = line(x1, y1, z1, x2, y2, z2, c1, c2, width, dashStyle)
189179

190180
fun line(
191181
start: Vec3d,
192182
end: Vec3d,
193183
color: Color,
194-
width: Float,
184+
width: Float = -0.0005f,
195185
dashStyle: LineDashStyle? = null
196186
) = line(start.x, start.y, start.z, end.x, end.y, end.z, color, color, width, dashStyle)
197187

198188
fun polyline(
199189
points: List<Vec3d>,
200190
color: Color,
201-
width: Float,
191+
width: Float = -0.0005f,
202192
dashStyle: LineDashStyle? = null
203193
) {
204194
if (points.size < 2) return
@@ -213,7 +203,7 @@ class RenderBuilder(private val cameraPos: Vec3d, var depthTest: Boolean = false
213203
p2: Vec3d,
214204
color: Color,
215205
segments: Int = 16,
216-
width: Float,
206+
width: Float = -0.0005f,
217207
dashStyle: LineDashStyle? = null
218208
) {
219209
val points = CurveUtils.quadraticBezierPoints(p0, p1, p2, segments)
@@ -227,7 +217,7 @@ class RenderBuilder(private val cameraPos: Vec3d, var depthTest: Boolean = false
227217
p3: Vec3d,
228218
color: Color,
229219
segments: Int = 32,
230-
width: Float,
220+
width: Float = -0.0005f,
231221
dashStyle: LineDashStyle? = null
232222
) {
233223
val points = CurveUtils.cubicBezierPoints(p0, p1, p2, p3, segments)
@@ -238,7 +228,7 @@ class RenderBuilder(private val cameraPos: Vec3d, var depthTest: Boolean = false
238228
controlPoints: List<Vec3d>,
239229
color: Color,
240230
segmentsPerSection: Int = 16,
241-
width: Float,
231+
width: Float = -0.0005f,
242232
dashStyle: LineDashStyle? = null
243233
) {
244234
val points = CurveUtils.catmullRomSplinePoints(controlPoints, segmentsPerSection)
@@ -249,13 +239,39 @@ class RenderBuilder(private val cameraPos: Vec3d, var depthTest: Boolean = false
249239
waypoints: List<Vec3d>,
250240
color: Color,
251241
segmentsPerSection: Int = 16,
252-
width: Float,
242+
width: Float = -0.0005f,
253243
dashStyle: LineDashStyle? = null
254244
) {
255245
val points = CurveUtils.smoothPath(waypoints, segmentsPerSection)
256246
polyline(points, color, width, dashStyle)
257247
}
258248

249+
fun circleLine(
250+
center: Vec3d,
251+
radius: Double,
252+
normal: Vec3d = Vec3d(0.0, 1.0, 0.0),
253+
color: Color,
254+
segments: Int = 32,
255+
width: Float = -0.0005f,
256+
dashStyle: LineDashStyle? = null
257+
) {
258+
val up =
259+
if (kotlin.math.abs(normal.y) < 0.99) Vec3d(0.0, 1.0, 0.0)
260+
else Vec3d(1.0, 0.0, 0.0)
261+
val u = normal.crossProduct(up).normalize()
262+
val v = u.crossProduct(normal).normalize()
263+
264+
val points =
265+
(0..segments).map { i ->
266+
val angle = 2.0 * Math.PI * i / segments
267+
val x = cos(angle) * radius
268+
val y = sin(angle) * radius
269+
center.add(u.multiply(x)).add(v.multiply(y))
270+
}
271+
272+
polyline(points, color, width, dashStyle)
273+
}
274+
259275
@JvmName("worldOutline1")
260276
fun worldOutline(
261277
entity: Entity,
@@ -284,30 +300,14 @@ class RenderBuilder(private val cameraPos: Vec3d, var depthTest: Boolean = false
284300
OutlineManager.setBlockOutline(it, style, depthTest = depthTest)
285301
}
286302

287-
fun circleLine(
288-
center: Vec3d,
289-
radius: Double,
290-
normal: Vec3d = Vec3d(0.0, 1.0, 0.0),
291-
color: Color,
292-
segments: Int = 32,
293-
width: Float,
294-
dashStyle: LineDashStyle? = null
295-
) {
296-
val up =
297-
if (kotlin.math.abs(normal.y) < 0.99) Vec3d(0.0, 1.0, 0.0)
298-
else Vec3d(1.0, 0.0, 0.0)
299-
val u = normal.crossProduct(up).normalize()
300-
val v = u.crossProduct(normal).normalize()
301-
302-
val points =
303-
(0..segments).map { i ->
304-
val angle = 2.0 * Math.PI * i / segments
305-
val x = cos(angle) * radius
306-
val y = sin(angle) * radius
307-
center.add(u.multiply(x)).add(v.multiply(y))
308-
}
309-
310-
polyline(points, color, width, dashStyle)
303+
fun withOutline(style: OutlineStyle, block: RenderBuilder.() -> Unit) {
304+
val previousId = activeOutlineId
305+
activeOutlineId = collector.registerCustomOutline(style, depthTest = depthTest)
306+
try {
307+
block()
308+
} finally {
309+
activeOutlineId = previousId
310+
}
311311
}
312312

313313
fun worldText(
@@ -1462,7 +1462,7 @@ class RenderBuilder(private val cameraPos: Vec3d, var depthTest: Boolean = false
14621462
x2: Double, y2: Double, z2: Double,
14631463
color1: Color,
14641464
color2: Color,
1465-
width: Float,
1465+
width: Float = -0.0005f,
14661466
dashStyle: LineDashStyle? = null
14671467
) {
14681468
val rx1 = (x1 - cameraPos.x).toFloat()

src/main/kotlin/com/lambda/module/modules/player/AirPlace.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ object AirPlace : Module(
107107
val boxes = placementState?.getOutlineShape(safeContext.world, pos)?.boundingBoxes
108108
?: listOf(Box(0.0, 0.0, 0.0, 1.0, 1.0, 1.0))
109109
boxes.forEach { box ->
110-
box(box) { hideFill() }
110+
box(box.offset(pos)) { hideFill() }
111111
}
112112
}
113113
}

src/main/kotlin/com/lambda/module/modules/render/Nametags.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ object Nametags : Module(
134134
if (background) {
135135
screenRect(anchorX - halfNameWidth - trueBGSizeX, anchorY - trueBGSizeY, nameWidth + (trueBGSizeX * 2), textSize + (trueBGSizeY * 2), backgroundColor)
136136
}
137-
screenText(nameText, anchorX, anchorY + (textSize / 2f), textSize, style = textStyle, centered = true)
137+
screenText(nameText, anchorX, anchorY, textSize, style = textStyle, centered = true)
138138
return@forEach
139139
}
140140

@@ -153,18 +153,20 @@ object Nametags : Module(
153153
var combinedWidth = nameWidth + healthWidth + pingWidth
154154
val nameX = anchorX - (combinedWidth * 0.5f)
155155

156+
val itemName = itemName && !entity.mainHandStack.isEmpty
156157
val itemNameText = if (itemName) entity.mainHandStack.name.string else ""
157158
val itemNameSize = if (itemName) textSize * itemNameScale else 0f
158159

159160
if (background) {
160161
anchorY += trueBGSizeY
162+
val itemNameWidth = getDefaultFont().getStringWidthNormalized(itemNameText, itemNameSize)
161163
val maxWidth =
162-
if (itemName) max(getDefaultFont().getStringWidthNormalized(itemNameText, itemNameSize), combinedWidth)
163-
else nameWidth
164+
if (itemName) max(itemNameWidth, combinedWidth)
165+
else combinedWidth
164166
screenRect(nameX - trueBGSizeX, anchorY - trueBGSizeY, maxWidth + (trueBGSizeX * 2), textSize + itemNameSize + trueSpacingY + (trueBGSizeY * 2), backgroundColor)
165167
}
166168

167-
if (itemName && !entity.mainHandStack.isEmpty) {
169+
if (itemName) {
168170
screenText(itemNameText, anchorX, anchorY, itemNameSize, centered = true)
169171
anchorY += (itemNameSize * 1.1f) + trueSpacingY
170172
}
@@ -183,8 +185,9 @@ object Nametags : Module(
183185
if (background) anchorY += trueBGSizeY
184186

185187
if (EquipmentSlot.entries.none { it.index in 1..4 && !entity.getEquippedStack(it).isEmpty }) {
188+
anchorY -= textSize * 0.5f
186189
if (mainItem && !entity.mainHandStack.isEmpty)
187-
renderItem(entity.mainHandStack, nameX - trueItemScaleX - trueSpacingX - (trueItemScaleX * 0.1f), anchorY)
190+
renderItem(entity.mainHandStack, nameX - trueItemScaleX - trueSpacingX, anchorY)
188191
if (offhandItem && !entity.offHandStack.isEmpty)
189192
renderItem(entity.offHandStack, anchorX + (combinedWidth * 0.5f) + trueSpacingX, anchorY)
190193
} else drawArmorAndItems(entity, anchorX, anchorY + textSize + trueSpacingY)

0 commit comments

Comments
 (0)