Skip to content

Commit 5c60e43

Browse files
committed
Reworked the Drawable
1 parent 6d09bda commit 5c60e43

File tree

11 files changed

+104
-129
lines changed

11 files changed

+104
-129
lines changed

src/main/kotlin/com/lambda/graphics/renderer/esp/ShapeDsl.kt

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

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

20-
import com.lambda.context.SafeContext
2120
import com.lambda.graphics.pipeline.VertexBuilder
2221
import com.lambda.graphics.renderer.esp.DirectionMask.hasDirection
22+
import com.lambda.threading.runSafe
2323
import com.lambda.util.BlockUtils.blockState
2424
import com.lambda.util.extension.max
2525
import com.lambda.util.extension.min
@@ -98,33 +98,33 @@ class ShapeBuilder(
9898
}
9999

100100
@ShapeDsl
101-
fun SafeContext.filled(
101+
fun filled(
102102
pos : BlockPos,
103103
state : BlockState,
104104
color : Color,
105105
sides : Int = DirectionMask.ALL,
106-
) = faces.apply {
106+
) = runSafe { faces.apply {
107107
val shape = state.getOutlineShape(world, pos)
108108
filled(shape, color, sides)
109-
}
109+
} }
110110

111111
@ShapeDsl
112-
fun SafeContext.filled(
112+
fun filled(
113113
pos : BlockPos,
114114
color : Color,
115115
sides : Int = DirectionMask.ALL,
116-
) = faces.apply {
116+
) = runSafe { faces.apply {
117117
val shape = blockState(pos).getOutlineShape(world, pos)
118118
filled(shape, color, sides)
119-
}
119+
} }
120120

121121
@ShapeDsl
122-
fun SafeContext.filled(
122+
fun filled(
123123
pos : BlockPos,
124124
entity : BlockEntity,
125125
color : Color,
126126
sides : Int = DirectionMask.ALL,
127-
) {
127+
) = runSafe {
128128
val shape = outlineShape(entity.cachedState, pos)
129129
filled(shape, color, sides)
130130
}
@@ -236,36 +236,36 @@ class ShapeBuilder(
236236
}
237237

238238
@ShapeDsl
239-
fun SafeContext.outline(
239+
fun outline(
240240
pos : BlockPos,
241241
state : BlockState,
242242
color : Color,
243243
sides : Int = DirectionMask.ALL,
244244
mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR,
245-
) {
245+
) = runSafe {
246246
val shape = state.getOutlineShape(world, pos)
247247
outline(shape, color, sides, mode)
248248
}
249249

250250
@ShapeDsl
251-
fun SafeContext.outline(
251+
fun outline(
252252
pos : BlockPos,
253253
color : Color,
254254
sides : Int = DirectionMask.ALL,
255255
mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR,
256-
) {
256+
) = runSafe {
257257
val shape = blockState(pos).getOutlineShape(world, pos)
258258
outline(shape, color, sides, mode)
259259
}
260260

261261
@ShapeDsl
262-
fun SafeContext.outline(
262+
fun outline(
263263
pos : BlockPos,
264264
entity : BlockEntity,
265265
color : Color,
266266
sides : Int = DirectionMask.ALL,
267267
mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR,
268-
) {
268+
) = runSafe {
269269
val shape = outlineShape(entity.cachedState, pos)
270270
outline(shape, color, sides, mode)
271271
}
@@ -291,6 +291,32 @@ class ShapeBuilder(
291291
outline(box, color, color, sides, mode)
292292
}
293293

294+
@ShapeDsl
295+
fun box(
296+
pos : BlockPos,
297+
state : BlockState,
298+
filled : Color,
299+
outline : Color,
300+
sides : Int = DirectionMask.ALL,
301+
mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR,
302+
) = runSafe {
303+
val shape = state.getOutlineShape(world, pos)
304+
filled(shape, filled, sides)
305+
outline(shape, outline, sides, mode)
306+
}
307+
308+
@ShapeDsl
309+
fun box(
310+
pos : BlockPos,
311+
filled : Color,
312+
outline : Color,
313+
sides : Int = DirectionMask.ALL,
314+
mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR,
315+
) = runSafe {
316+
filled(pos, filled, sides)
317+
outline(pos, outline, sides, mode)
318+
}
319+
294320
@ShapeDsl
295321
fun box(
296322
box : DynamicAABB,
@@ -316,23 +342,23 @@ class ShapeBuilder(
316342
}
317343

318344
@ShapeDsl
319-
fun SafeContext.box(
345+
fun box(
320346
entity : BlockEntity,
321347
color : Color,
322348
sides : Int = DirectionMask.ALL,
323349
mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR,
324-
) {
350+
) = runSafe {
325351
filled(entity.pos, entity, color, sides)
326352
outline(entity.pos, entity, color, sides, mode)
327353
}
328354

329355
@ShapeDsl
330-
fun SafeContext.box(
356+
fun box(
331357
entity : Entity,
332358
color : Color,
333359
sides : Int = DirectionMask.ALL,
334360
mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR,
335-
) {
361+
) = runSafe {
336362
filled(entity.boundingBox, color, sides)
337363
outline(entity.boundingBox, color, sides, mode)
338364
}

src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
package com.lambda.interaction.construction.context
1919

20-
import com.lambda.context.SafeContext
2120
import com.lambda.graphics.renderer.esp.DirectionMask
2221
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
22+
import com.lambda.graphics.renderer.esp.ShapeBuilder
2323
import com.lambda.interaction.material.StackSelection
2424
import com.lambda.interaction.request.breaking.BreakConfig
2525
import com.lambda.interaction.request.breaking.BreakRequest
@@ -72,9 +72,8 @@ data class BreakContext(
7272
}
7373
}
7474

75-
override fun SafeContext.buildRenderer() {
76-
withState(cachedState, blockPos, baseColor, DirectionMask.ALL.exclude(result.side))
77-
withState(cachedState, blockPos, sideColor, result.side)
75+
override fun ShapeBuilder.buildRenderer() {
76+
box(blockPos, cachedState, baseColor, sideColor, DirectionMask.ALL.exclude(result.side))
7877
}
7978

8079
fun requestSwap(breakRequest: BreakRequest, minKeepTicks: Int = 0): Boolean =
@@ -83,4 +82,4 @@ data class BreakContext(
8382
breakRequest.hotbar,
8483
breakRequest.hotbar.keepTicks.coerceAtLeast(minKeepTicks)
8584
).submit(false).done
86-
}
85+
}

src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717

1818
package com.lambda.interaction.construction.context
1919

20-
import com.lambda.context.SafeContext
21-
import com.lambda.graphics.renderer.esp.DirectionMask
22-
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
20+
import com.lambda.graphics.renderer.esp.DirectionMask.mask
21+
import com.lambda.graphics.renderer.esp.ShapeBuilder
2322
import com.lambda.interaction.request.Request.Companion.submit
2423
import com.lambda.interaction.request.hotbar.HotbarManager
2524
import com.lambda.interaction.request.hotbar.HotbarRequest
2625
import com.lambda.interaction.request.interacting.InteractRequest
2726
import com.lambda.interaction.request.rotating.RotationRequest
2827
import com.lambda.util.BlockUtils
29-
import com.lambda.util.BlockUtils.blockState
3028
import net.minecraft.block.BlockState
3129
import net.minecraft.util.hit.BlockHitResult
3230
import net.minecraft.util.math.BlockPos
@@ -61,14 +59,13 @@ class InteractionContext(
6159
else -> 1
6260
}
6361

64-
override fun SafeContext.buildRenderer() {
65-
withState(expectedState, blockPos, baseColor, DirectionMask.ALL.exclude(result.side.opposite))
66-
withState(blockState(result.blockPos), result.blockPos, sideColor, result.side)
62+
override fun ShapeBuilder.buildRenderer() {
63+
box(blockPos, expectedState, baseColor, sideColor, result.side.mask)
6764
}
6865

6966
fun requestDependencies(request: InteractRequest): Boolean {
7067
val hotbarRequest = submit(HotbarRequest(hotbarIndex, request.hotbar), false)
7168
val validRotation = if (request.rotate) submit(rotation, false).done else true
7269
return hotbarRequest.done && validRotation
7370
}
74-
}
71+
}

src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import com.lambda.Lambda.mc
2121
import com.lambda.context.SafeContext
2222
import com.lambda.graphics.renderer.esp.DirectionMask
2323
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
24+
import com.lambda.graphics.renderer.esp.DirectionMask.mask
25+
import com.lambda.graphics.renderer.esp.ShapeBuilder
2426
import com.lambda.interaction.request.Request.Companion.submit
2527
import com.lambda.interaction.request.hotbar.HotbarManager
2628
import com.lambda.interaction.request.hotbar.HotbarRequest
@@ -70,9 +72,8 @@ data class PlaceContext(
7072
else -> 1
7173
}
7274

73-
override fun SafeContext.buildRenderer() {
74-
withState(expectedState, blockPos, baseColor, DirectionMask.ALL.exclude(result.side.opposite))
75-
withState(blockState(result.blockPos), result.blockPos, sideColor, result.side)
75+
override fun ShapeBuilder.buildRenderer() {
76+
box(blockPos, expectedState, baseColor, sideColor, result.side.mask)
7677
}
7778

7879
fun requestDependencies(request: PlaceRequest): Boolean {

src/main/kotlin/com/lambda/interaction/construction/result/BreakResult.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ package com.lambda.interaction.construction.result
1919

2020
import baritone.api.pathing.goals.GoalBlock
2121
import baritone.api.pathing.goals.GoalInverted
22-
import com.lambda.context.SafeContext
22+
import com.lambda.graphics.renderer.esp.DirectionMask.mask
23+
import com.lambda.graphics.renderer.esp.ShapeBuilder
2324
import com.lambda.interaction.construction.context.BreakContext
2425
import com.lambda.interaction.material.StackSelection.Companion.selectStack
2526
import com.lambda.interaction.material.container.ContainerManager.transfer
@@ -44,7 +45,7 @@ sealed class BreakResult : BuildResult() {
4445
) : Drawable, Contextual, BreakResult() {
4546
override val rank = Rank.BREAK_SUCCESS
4647

47-
override fun SafeContext.buildRenderer() {
48+
override fun ShapeBuilder.buildRenderer() {
4849
with(context) { buildRenderer() }
4950
}
5051

@@ -68,8 +69,8 @@ sealed class BreakResult : BuildResult() {
6869
override val rank = Rank.BREAK_NOT_EXPOSED
6970
private val color = Color(46, 0, 0, 30)
7071

71-
override fun SafeContext.buildRenderer() {
72-
withPos(blockPos, color, side)
72+
override fun ShapeBuilder.buildRenderer() {
73+
box(blockPos, color, color, side.mask)
7374
}
7475

7576
override fun compareTo(other: ComparableResult<Rank>): Int {
@@ -108,8 +109,8 @@ sealed class BreakResult : BuildResult() {
108109
)
109110
}
110111

111-
override fun SafeContext.buildRenderer() {
112-
withPos(blockPos, color)
112+
override fun ShapeBuilder.buildRenderer() {
113+
box(blockPos, color, color)
113114
}
114115

115116
override fun compareTo(other: ComparableResult<Rank>): Int {
@@ -132,8 +133,8 @@ sealed class BreakResult : BuildResult() {
132133
override val rank = Rank.BREAK_SUBMERGE
133134
private val color = Color(114, 27, 255, 100)
134135

135-
override fun SafeContext.buildRenderer() {
136-
withPos(blockPos, color)
136+
override fun ShapeBuilder.buildRenderer() {
137+
box(blockPos, color, color)
137138
}
138139
}
139140

@@ -147,8 +148,8 @@ sealed class BreakResult : BuildResult() {
147148
override val rank = Rank.BREAK_IS_BLOCKED_BY_FLUID
148149
private val color = Color(50, 12, 112, 100)
149150

150-
override fun SafeContext.buildRenderer() {
151-
withPos(blockPos, color)
151+
override fun ShapeBuilder.buildRenderer() {
152+
box(blockPos, color, color)
152153
}
153154
}
154155

@@ -164,8 +165,8 @@ sealed class BreakResult : BuildResult() {
164165

165166
override val goal = GoalInverted(GoalBlock(blockPos))
166167

167-
override fun SafeContext.buildRenderer() {
168-
withPos(blockPos, color)
168+
override fun ShapeBuilder.buildRenderer() {
169+
box(blockPos, color, color)
169170
}
170171
}
171172
}

0 commit comments

Comments
 (0)