Skip to content

Commit 1973152

Browse files
committed
less bulky build result renders
1 parent 1377e2f commit 1973152

File tree

9 files changed

+89
-39
lines changed

9 files changed

+89
-39
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
package com.lambda.interaction.construction.context
1919

2020
import com.lambda.context.Automated
21-
import com.lambda.graphics.renderer.esp.DirectionMask
22-
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2321
import com.lambda.graphics.renderer.esp.ShapeBuilder
2422
import com.lambda.interaction.material.StackSelection
2523
import com.lambda.interaction.request.LogContext
@@ -32,6 +30,7 @@ import net.minecraft.block.BlockState
3230
import net.minecraft.block.FallingBlock
3331
import net.minecraft.util.hit.BlockHitResult
3432
import net.minecraft.util.math.BlockPos
33+
import net.minecraft.util.math.Box
3534
import java.awt.Color
3635
import kotlin.math.sqrt
3736

@@ -65,7 +64,13 @@ data class BreakContext(
6564
override val sorter get() = breakConfig.sorter
6665

6766
override fun ShapeBuilder.buildRenderer() {
68-
box(blockPos, cachedState, baseColor, sideColor, DirectionMask.ALL.exclude(hitResult.side))
67+
val box = with(hitResult.pos) {
68+
Box(
69+
x - 0.05, y - 0.05, z - 0.05,
70+
x + 0.05, y + 0.05, z + 0.05,
71+
).offset(hitResult.side.doubleVector.multiply(0.05))
72+
}
73+
box(box, baseColor, sideColor)
6974
}
7075

7176
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.lambda.interaction.construction.context
1919

2020
import com.lambda.context.Automated
21-
import com.lambda.graphics.renderer.esp.DirectionMask.mask
2221
import com.lambda.graphics.renderer.esp.ShapeBuilder
2322
import com.lambda.interaction.request.LogContext
2423
import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder
@@ -30,6 +29,7 @@ import com.lambda.interaction.request.rotating.RotationRequest
3029
import net.minecraft.block.BlockState
3130
import net.minecraft.util.hit.BlockHitResult
3231
import net.minecraft.util.math.BlockPos
32+
import net.minecraft.util.math.Box
3333
import java.awt.Color
3434

3535
class InteractContext(
@@ -48,7 +48,13 @@ class InteractContext(
4848
override val sorter get() = interactConfig.sorter
4949

5050
override fun ShapeBuilder.buildRenderer() {
51-
box(blockPos, expectedState, baseColor, sideColor, hitResult.side.mask)
51+
val box = with(hitResult.pos) {
52+
Box(
53+
x - 0.05, y - 0.05, z - 0.05,
54+
x + 0.05, y + 0.05, z + 0.05,
55+
).offset(hitResult.side.doubleVector.multiply(0.05))
56+
}
57+
box(box, baseColor, sideColor)
5258
}
5359

5460
fun requestDependencies(request: InteractRequest): Boolean {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.lambda.interaction.construction.context
1919

2020
import com.lambda.context.Automated
21-
import com.lambda.graphics.renderer.esp.DirectionMask.mask
2221
import com.lambda.graphics.renderer.esp.ShapeBuilder
2322
import com.lambda.interaction.request.LogContext
2423
import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder
@@ -30,6 +29,7 @@ import com.lambda.interaction.request.rotating.RotationRequest
3029
import net.minecraft.block.BlockState
3130
import net.minecraft.util.hit.BlockHitResult
3231
import net.minecraft.util.math.BlockPos
32+
import net.minecraft.util.math.Box
3333
import java.awt.Color
3434

3535
data class PlaceContext(
@@ -43,13 +43,19 @@ data class PlaceContext(
4343
val currentDirIsValid: Boolean = false,
4444
private val automated: Automated
4545
) : BuildContext(), LogContext, Automated by automated {
46-
private val baseColor = Color(35, 188, 254, 25)
46+
private val baseColor = Color(35, 188, 254, 50)
4747
private val sideColor = Color(35, 188, 254, 100)
4848

4949
override val sorter get() = placeConfig.sorter
5050

5151
override fun ShapeBuilder.buildRenderer() {
52-
box(blockPos, expectedState, baseColor, sideColor, hitResult.side.mask)
52+
val box = with(hitResult.pos) {
53+
Box(
54+
x - 0.05, y - 0.05, z - 0.05,
55+
x + 0.05, y + 0.05, z + 0.05,
56+
).offset(hitResult.side.doubleVector.multiply(0.05))
57+
}
58+
box(box, baseColor, sideColor)
5359
}
5460

5561
fun requestDependencies(request: PlaceRequest): Boolean {

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import com.lambda.interaction.material.container.containers.MainHandContainer
3838
import net.minecraft.block.BlockState
3939
import net.minecraft.item.Item
4040
import net.minecraft.util.math.BlockPos
41+
import net.minecraft.util.math.Box
4142
import net.minecraft.util.math.Direction
4243
import java.awt.Color
4344

@@ -91,9 +92,8 @@ sealed class BreakResult : BuildResult() {
9192
override val pos: BlockPos,
9293
val blockState: BlockState,
9394
val badItem: Item
94-
) : Drawable, Resolvable, BreakResult() {
95+
) : Resolvable, BreakResult() {
9596
override val rank = Rank.BreakItemCantMine
96-
private val color = Color(255, 0, 0, 100)
9797

9898
context(automated: Automated)
9999
override fun resolve() =
@@ -108,10 +108,6 @@ sealed class BreakResult : BuildResult() {
108108
)
109109
}
110110

111-
override fun ShapeBuilder.buildRenderer() {
112-
box(pos, color, color)
113-
}
114-
115111
override fun compareResult(other: ComparableResult<Rank>) =
116112
when (other) {
117113
is ItemCantMine -> badItem.name.string.compareTo(other.badItem.name.string)
@@ -141,12 +137,18 @@ sealed class BreakResult : BuildResult() {
141137
data class BlockedByFluid(
142138
override val pos: BlockPos,
143139
val blockState: BlockState,
140+
val affectedFluids: Set<BlockPos>
144141
) : Drawable, BreakResult() {
145142
override val rank = Rank.BreakIsBlockedByFluid
146143
private val color = Color(50, 12, 112, 100)
147144

148145
override fun ShapeBuilder.buildRenderer() {
149-
box(pos, color, color)
146+
val center = pos.toCenterPos()
147+
val box = Box(
148+
center.x - 0.1, center.y - 0.1, center.z - 0.1,
149+
center.x + 0.1, center.y + 0.1, center.z + 0.1
150+
)
151+
box(box, color, color)
150152
}
151153
}
152154

src/main/kotlin/com/lambda/interaction/construction/result/results/GenericResult.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ import com.lambda.interaction.material.StackSelection
3030
import com.lambda.interaction.material.container.ContainerManager.transfer
3131
import com.lambda.interaction.material.container.MaterialContainer
3232
import com.lambda.interaction.material.container.containers.MainHandContainer
33+
import net.minecraft.client.data.TextureMap.side
3334
import net.minecraft.item.ItemStack
3435
import net.minecraft.util.math.BlockPos
36+
import net.minecraft.util.math.Box
37+
import net.minecraft.util.math.Direction
3538
import net.minecraft.util.math.Vec3d
3639
import java.awt.Color
3740

@@ -51,7 +54,13 @@ sealed class GenericResult : BuildResult() {
5154
private val color = Color(46, 0, 0, 80)
5255

5356
override fun ShapeBuilder.buildRenderer() {
54-
box(pos, color, color)
57+
val box = with(pos) {
58+
Box(
59+
x - 0.05, y - 0.05, z - 0.05,
60+
x + 0.05, y + 0.05, z + 0.05,
61+
).offset(pos)
62+
}
63+
box(box, color, color)
5564
}
5665

5766
override fun compareResult(other: ComparableResult<Rank>): Int {
@@ -96,7 +105,12 @@ sealed class GenericResult : BuildResult() {
96105
)
97106

98107
override fun ShapeBuilder.buildRenderer() {
99-
box(pos, color, color)
108+
val center = pos.toCenterPos()
109+
val box = Box(
110+
center.x - 0.1, center.y - 0.1, center.z - 0.1,
111+
center.x + 0.1, center.y + 0.1, center.z + 0.1
112+
)
113+
box(box, color, color)
100114
}
101115
}
102116

@@ -109,20 +123,25 @@ sealed class GenericResult : BuildResult() {
109123
data class OutOfReach(
110124
override val pos: BlockPos,
111125
val pov: Vec3d,
112-
val misses: Set<Vec3d>,
126+
val misses: Set<Pair<Vec3d, Direction>>,
113127
) : Navigable, Drawable, GenericResult() {
114128
override val name: String get() = "Out of reach at $pos."
115129
override val rank = Rank.OutOfReach
116130
private val color = Color(252, 3, 207, 25)
117131

118132
val distance: Double by lazy {
119-
misses.minOfOrNull { pov.distanceTo(it) } ?: 0.0
133+
misses.minOfOrNull { pov.distanceTo(it.first) } ?: 0.0
120134
}
121135

122136
override val goal = GoalNear(pos, 3)
123137

124138
override fun ShapeBuilder.buildRenderer() {
125-
box(pos, color, color)
139+
val center = pos.toCenterPos()
140+
val box = Box(
141+
center.x - 0.1, center.y - 0.1, center.z - 0.1,
142+
center.x + 0.1, center.y + 0.1, center.z + 0.1
143+
)
144+
box(box, color, color)
126145
}
127146

128147
override fun compareResult(other: ComparableResult<Rank>): Int {

src/main/kotlin/com/lambda/interaction/construction/result/results/PlaceResult.kt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ import net.minecraft.entity.Entity
3535
import net.minecraft.item.ItemPlacementContext
3636
import net.minecraft.item.ItemStack
3737
import net.minecraft.util.math.BlockPos
38+
import net.minecraft.util.math.Box
39+
import net.minecraft.util.math.Direction
40+
import net.minecraft.util.math.Vec3d
3841
import java.awt.Color
3942

4043
/**
@@ -83,7 +86,13 @@ sealed class PlaceResult : BuildResult() {
8386
private val color = Color(252, 3, 3, 100)
8487

8588
override fun ShapeBuilder.buildRenderer() {
86-
box(pos, expected, color, color)
89+
val box = with(simulated.hitPos) {
90+
Box(
91+
x - 0.05, y - 0.05, z - 0.05,
92+
x + 0.05, y + 0.05, z + 0.05,
93+
).offset(simulated.side.doubleVector.multiply(0.05))
94+
}
95+
box(box, color, color)
8796
}
8897
}
8998

@@ -94,30 +103,33 @@ sealed class PlaceResult : BuildResult() {
94103
*/
95104
data class BlockedBySelf(
96105
override val pos: BlockPos
97-
) : Drawable, Navigable, PlaceResult() {
106+
) : Navigable, PlaceResult() {
98107
override val rank = Rank.PlaceBlockedByPlayer
99-
private val color = Color(252, 3, 3, 100)
100108
override val goal = GoalInverted(GoalBlock(pos))
101-
102-
override fun ShapeBuilder.buildRenderer() {
103-
box(pos, color, color)
104-
}
105109
}
106110

107111
/**
108-
* Represents a scenario where block placement is obstructed by an entity.
112+
* Represents a scenario where the block placement is obstructed by an entity.
109113
*
110114
* @property pos The position of the block that was attempted to be placed.
111115
*/
112116
data class BlockedByEntity(
113117
override val pos: BlockPos,
114-
val entities: List<Entity>
118+
val entities: List<Entity>,
119+
val hitPos: Vec3d,
120+
val side: Direction
115121
) : Drawable, PlaceResult() {
116122
override val rank = Rank.PlaceBlockedByEntity
117123
private val color = Color(252, 3, 3, 100)
118124

119125
override fun ShapeBuilder.buildRenderer() {
120-
entities.forEach { box(it, color) }
126+
val box = with(hitPos) {
127+
Box(
128+
x - 0.05, y - 0.05, z - 0.05,
129+
x + 0.05, y + 0.05, z + 0.05,
130+
).offset(side.doubleVector.multiply(0.05))
131+
}
132+
box(box, color, color)
121133
}
122134
}
123135

@@ -141,7 +153,6 @@ sealed class PlaceResult : BuildResult() {
141153
* Represents a placement result indicating that the scaffolding placement has exceeded the allowed limits.
142154
*
143155
* @property pos The position of the block where the placement attempt occurred.
144-
* @property simulated The context of the simulated item placement attempt.
145156
*/
146157
data class ScaffoldExceeded(
147158
override val pos: BlockPos

src/main/kotlin/com/lambda/interaction/construction/simulation/Sim.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ abstract class Sim<T : BuildResult> : Results<T> {
9898
val reachSq = buildConfig.interactReach.pow(2)
9999

100100
val validHits = ConcurrentSet<CheckedHit>()
101-
val misses = ConcurrentSet<Vec3d>()
101+
val misses = ConcurrentSet<Pair<Vec3d, Direction>>()
102102

103103
supervisorScope {
104104
boxes.forEach { box ->
@@ -109,7 +109,7 @@ abstract class Sim<T : BuildResult> : Results<T> {
109109

110110
scanSurfaces(box, sides, buildConfig.resolution, preProcessing.surfaceScan) { side, vec ->
111111
if (pov distSq vec > reachSq) {
112-
misses.add(vec)
112+
misses.add(Pair(vec, side))
113113
return@scanSurfaces
114114
}
115115

@@ -118,7 +118,9 @@ abstract class Sim<T : BuildResult> : Results<T> {
118118
val hit = if (buildConfig.strictRayCast) {
119119
newRotation.rayCast(buildConfig.interactReach, pov)?.blockResult ?: return@scanSurfaces
120120
} else {
121-
val hitVec = newRotation.castBox(box, buildConfig.interactReach, pov) ?: return@scanSurfaces
121+
val hitVec =
122+
if (buildConfig.checkSideVisibility) newRotation.castBox(box, buildConfig.interactReach, pov) ?: return@scanSurfaces
123+
else vec
122124
BlockHitResult(hitVec, side, pos, false)
123125
}
124126

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/BreakSim.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class BreakSim private constructor(simInfo: ISimInfo)
246246
return@fold accumulator
247247
}
248248

249-
if (offsetState.block is Waterloggable && !fluidState.isEmpty) {
249+
if (offsetState.block is Waterloggable) {
250250
accumulator[offsetPos] = offsetState
251251
return@fold accumulator
252252
}
@@ -278,7 +278,7 @@ class BreakSim private constructor(simInfo: ISimInfo)
278278
result(BreakResult.Submerge(liquidPos, liquidState))
279279
sim(liquidPos, liquidState, TargetState.Solid(emptySet())) { simPlacement() }
280280
}
281-
result(BreakResult.BlockedByFluid(pos, state))
281+
result(BreakResult.BlockedByFluid(pos, state, affectedFluids.keys))
282282
return true
283283
}
284284

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/PlaceSim.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ class PlaceSim private constructor(simInfo: ISimInfo)
238238
private suspend fun AutomatedSafeContext.testPlaceState(context: ItemPlacementContext): PlaceTest {
239239
val resultState = context.stack.blockItem.getPlacementState(context)
240240
?: run {
241-
val blockingEntities = handleEntityBlockage(context)
242-
result(PlaceResult.BlockedByEntity(pos, blockingEntities))
241+
handleEntityBlockage(context)
243242
return PlaceTest(state, PlaceTestResult.BlockedByEntity)
244243
}
245244

@@ -279,7 +278,7 @@ class PlaceSim private constructor(simInfo: ISimInfo)
279278
.forEach { support ->
280279
sim(support, blockState(support), TargetState.Empty) { simBreak() }
281280
}
282-
result(PlaceResult.BlockedByEntity(pos, collidingEntities))
281+
result(PlaceResult.BlockedByEntity(pos, collidingEntities, context.hitPos, context.side))
283282
}
284283

285284
return collidingEntities

0 commit comments

Comments
 (0)