Skip to content

Commit e91b21c

Browse files
authored
Build Simulator Rework (159)
1 parent b2446b0 commit e91b21c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2004
-1561
lines changed

src/main/kotlin/com/lambda/config/groups/BreakSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ class BreakSettings(
7676
// Block
7777
override val avoidLiquids by c.setting("Avoid Liquids", true, "Avoids breaking blocks that would cause liquid to spill", visibility = vis).group(baseGroup, Group.General)
7878
override val avoidSupporting by c.setting("Avoid Supporting", true, "Avoids breaking the block supporting the player", visibility = vis).group(baseGroup, Group.General)
79-
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)", visibility = vis).group(baseGroup, Group.General)
8079
override val ignoredBlocks by c.setting("Ignored Blocks", allSigns, description = "Blocks that wont be broken", visibility = vis).group(baseGroup, Group.General)
8180

8281
// Tool
82+
override val efficientOnly by c.setting("Efficient Tools Only", true, "Only use tools suitable for the given block (will get the item drop)") { vis() && swapMode.isEnabled() }.group(baseGroup, Group.General)
8383
override val suitableToolsOnly by c.setting("Suitable Tools Only", true, "Only use tools suitable for the given block (will get the item drop)") { vis() && swapMode.isEnabled() }.group(baseGroup, Group.General)
8484
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks") { vis() && swapMode.isEnabled() }.group(baseGroup, Group.General)
8585
override val forceFortunePickaxe by c.setting("Force Fortune Pickaxe", false, "Force fortune pickaxe when breaking blocks") { vis() && swapMode.isEnabled() }.group(baseGroup, Group.General)

src/main/kotlin/com/lambda/config/groups/BuildSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class BuildSettings(
4747

4848
override val scanReach: Double get() = max(attackReach, interactReach)
4949

50-
override val strictRayCast by c.setting("Strict Raycast", false, "Whether to include the environment to the ray cast context", vis).group(*baseGroup, Group.Scan)
5150
override val checkSideVisibility by c.setting("Visibility Check", true, "Whether to check if an AABB side is visible", vis).group(*baseGroup, Group.Scan)
51+
override val strictRayCast by c.setting("Strict Raycast", false, "Whether to include the environment to the ray cast context", vis).group(*baseGroup, Group.Scan)
5252
override val resolution by c.setting("Resolution", 5, 1..20, 1, "The amount of grid divisions per surface of the hit box", "", vis).group(*baseGroup, Group.Scan)
5353
override val pointSelection by c.setting("Point Selection", PointSelection.Optimum, "The strategy to select the best hit point", vis).group(*baseGroup, Group.Scan)
5454

src/main/kotlin/com/lambda/context/AutomationConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ object AutomationConfig : Configurable(LambdaConfig), Automated {
6262
val showAllEntries by setting("Show All Entries", false, "Show all entries in the task tree").group(Group.Debug)
6363
val shrinkFactor by setting("Shrink Factor", 0.001, 0.0..1.0, 0.001).group(Group.Debug)
6464
val ignoreItemDropWarnings by setting("Ignore Drop Warnings", false, "Hides the item drop warnings from the break manager").group(Group.Debug)
65+
val maxSimDependencies by setting("Max Sim Dependencies", 3, 0..10, 1, "Maximum dependency build results").group(Group.Debug)
6566

6667
@Volatile
6768
var drawables = listOf<Drawable>()

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,34 @@ import kotlin.math.sqrt
4141
import kotlin.random.Random
4242

4343
data class BreakContext(
44-
override val result: BlockHitResult,
45-
override val rotation: RotationRequest,
46-
override var hotbarIndex: Int,
47-
var itemSelection: StackSelection,
48-
var instantBreak: Boolean,
44+
override val hitResult: BlockHitResult,
45+
override val rotationRequest: RotationRequest,
46+
override val hotbarIndex: Int,
47+
val itemSelection: StackSelection,
48+
val instantBreak: Boolean,
4949
override var cachedState: BlockState,
50-
val sortMode: BreakConfig.SortMode,
5150
private val automated: Automated
5251
) : BuildContext(), LogContext, Automated by automated {
5352
private val baseColor = Color(222, 0, 0, 25)
5453
private val sideColor = Color(222, 0, 0, 100)
5554

56-
override val blockPos: BlockPos = result.blockPos
55+
override val blockPos: BlockPos = hitResult.blockPos
5756
override val expectedState = cachedState.emptyState
5857

5958
val random = Random.nextDouble()
6059

6160
override fun compareTo(other: BuildContext): Int = runSafe {
6261
return when (other) {
6362
is BreakContext -> compareByDescending<BreakContext> {
64-
if (sortMode == BreakConfig.SortMode.Tool) it.hotbarIndex == HotbarManager.serverSlot
63+
if (breakConfig.sorter == BreakConfig.SortMode.Tool)
64+
it.hotbarIndex == HotbarManager.serverSlot
6565
else 0
6666
}.thenBy {
67-
when (sortMode) {
67+
when (breakConfig.sorter) {
6868
BreakConfig.SortMode.Tool,
69-
BreakConfig.SortMode.Closest -> player.eyePos.distance(it.result.pos, it.cachedState.block)
70-
BreakConfig.SortMode.Farthest -> -player.eyePos.distance(it.result.pos, it.cachedState.block)
71-
BreakConfig.SortMode.Rotation -> it.rotation.target.angleDistance
69+
BreakConfig.SortMode.Closest -> player.eyePos.distance(it.hitResult.pos, it.cachedState.block)
70+
BreakConfig.SortMode.Farthest -> -player.eyePos.distance(it.hitResult.pos, it.cachedState.block)
71+
BreakConfig.SortMode.Rotation -> it.rotationRequest.target.angleDistance
7272
BreakConfig.SortMode.Random -> it.random
7373
}
7474
}.thenByDescending {
@@ -92,19 +92,18 @@ data class BreakContext(
9292
}
9393

9494
override fun ShapeBuilder.buildRenderer() {
95-
box(blockPos, cachedState, baseColor, sideColor, DirectionMask.ALL.exclude(result.side))
95+
box(blockPos, cachedState, baseColor, sideColor, DirectionMask.ALL.exclude(hitResult.side))
9696
}
9797

9898
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
9999
group("Break Context") {
100100
text(blockPos.getLogContextBuilder())
101-
text(result.getLogContextBuilder())
102-
text(rotation.getLogContextBuilder())
101+
text(hitResult.getLogContextBuilder())
102+
text(rotationRequest.getLogContextBuilder())
103103
value("Hotbar Index", hotbarIndex)
104104
value("Instant Break", instantBreak)
105105
value("Cached State", cachedState)
106106
value("Expected State", expectedState)
107-
value("Sort Mode", sortMode)
108107
}
109108
}
110109
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ import net.minecraft.util.hit.BlockHitResult
2626
import net.minecraft.util.math.BlockPos
2727

2828
abstract class BuildContext : Comparable<BuildContext>, Drawable, Automated {
29-
abstract val result: BlockHitResult
30-
abstract val rotation: RotationRequest
29+
abstract val hitResult: BlockHitResult
30+
abstract val rotationRequest: RotationRequest
3131
abstract val hotbarIndex: Int
3232
abstract val cachedState: BlockState
3333
abstract val expectedState: BlockState
3434
abstract val blockPos: BlockPos
3535

3636
val distance by lazy {
37-
runSafe { player.eyePos.distanceTo(result.pos) } ?: Double.MAX_VALUE
37+
runSafe { player.eyePos.distanceTo(hitResult.pos) } ?: Double.MAX_VALUE
3838
}
3939
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import net.minecraft.util.math.BlockPos
3535
import java.awt.Color
3636

3737
class InteractionContext(
38-
override val result: BlockHitResult,
39-
override val rotation: RotationRequest,
38+
override val hitResult: BlockHitResult,
39+
override val rotationRequest: RotationRequest,
4040
override var hotbarIndex: Int,
4141
override var cachedState: BlockState,
4242
override val expectedState: BlockState,
@@ -45,7 +45,7 @@ class InteractionContext(
4545
private val baseColor = Color(35, 254, 79, 25)
4646
private val sideColor = Color(35, 254, 79, 100)
4747

48-
override val blockPos: BlockPos = result.blockPos
48+
override val blockPos: BlockPos = hitResult.blockPos
4949

5050
override fun compareTo(other: BuildContext) =
5151
when {
@@ -54,7 +54,7 @@ class InteractionContext(
5454
}.thenByDescending {
5555
it.cachedState.fluidState.level
5656
}.thenBy {
57-
it.rotation.target.angleDistance
57+
it.rotationRequest.target.angleDistance
5858
}.thenBy {
5959
it.hotbarIndex == HotbarManager.serverSlot
6060
}.thenBy {
@@ -65,20 +65,20 @@ class InteractionContext(
6565
}
6666

6767
override fun ShapeBuilder.buildRenderer() {
68-
box(blockPos, expectedState, baseColor, sideColor, result.side.mask)
68+
box(blockPos, expectedState, baseColor, sideColor, hitResult.side.mask)
6969
}
7070

7171
fun requestDependencies(request: InteractRequest): Boolean {
7272
val hotbarRequest = submit(HotbarRequest(hotbarIndex, request), false)
73-
val validRotation = if (request.interactConfig.rotate) submit(rotation, false).done else true
73+
val validRotation = if (request.interactConfig.rotate) submit(rotationRequest, false).done else true
7474
return hotbarRequest.done && validRotation
7575
}
7676

7777
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
7878
group("Interaction Context") {
7979
text(blockPos.getLogContextBuilder())
80-
text(result.getLogContextBuilder())
81-
text(rotation.getLogContextBuilder())
80+
text(hitResult.getLogContextBuilder())
81+
text(rotationRequest.getLogContextBuilder())
8282
value("Hotbar Index", hotbarIndex)
8383
value("Cached State", cachedState)
8484
value("Expected State", expectedState)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import net.minecraft.util.math.BlockPos
3636
import java.awt.Color
3737

3838
data class PlaceContext(
39-
override val result: BlockHitResult,
40-
override val rotation: RotationRequest,
39+
override val hitResult: BlockHitResult,
40+
override val rotationRequest: RotationRequest,
4141
override var hotbarIndex: Int,
4242
override val blockPos: BlockPos,
4343
override var cachedState: BlockState,
@@ -61,7 +61,7 @@ data class PlaceContext(
6161
}.thenBy {
6262
it.sneak == (mc.player?.isSneaking ?: false)
6363
}.thenBy {
64-
it.rotation.target.angleDistance
64+
it.rotationRequest.target.angleDistance
6565
}.thenBy {
6666
it.hotbarIndex == HotbarManager.serverSlot
6767
}.thenBy {
@@ -74,22 +74,22 @@ data class PlaceContext(
7474
}
7575

7676
override fun ShapeBuilder.buildRenderer() {
77-
box(blockPos, expectedState, baseColor, sideColor, result.side.mask)
77+
box(blockPos, expectedState, baseColor, sideColor, hitResult.side.mask)
7878
}
7979

8080
fun requestDependencies(request: PlaceRequest): Boolean {
8181
val hotbarRequest = submit(HotbarRequest(hotbarIndex, this), false)
8282
val validRotation = if (request.placeConfig.rotateForPlace) {
83-
submit(rotation, false).done && currentDirIsValid
83+
submit(rotationRequest, false).done && currentDirIsValid
8484
} else true
8585
return hotbarRequest.done && validRotation
8686
}
8787

8888
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
8989
group("Place Context") {
9090
text(blockPos.getLogContextBuilder())
91-
text(result.getLogContextBuilder())
92-
text(rotation.getLogContextBuilder())
91+
text(hitResult.getLogContextBuilder())
92+
text(rotationRequest.getLogContextBuilder())
9393
value("Hotbar Index", hotbarIndex)
9494
value("Cached State", cachedState)
9595
value("Expected State", expectedState)

src/main/kotlin/com/lambda/interaction/construction/processing/ProcessorRegistry.kt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ import com.lambda.core.Loadable
2121
import com.lambda.interaction.construction.verify.TargetState
2222
import com.lambda.util.reflections.getInstances
2323
import net.minecraft.block.BlockState
24-
import net.minecraft.block.SlabBlock
25-
import net.minecraft.block.enums.SlabType
2624
import net.minecraft.state.property.Properties
2725
import net.minecraft.util.math.BlockPos
26+
import java.util.*
2827

2928
object ProcessorRegistry : Loadable {
3029
private val processors = getInstances<PlacementProcessor>()
31-
private val processorCache = mutableMapOf<BlockState, PreProcessingInfo?>()
30+
private val processorCache = Collections.synchronizedMap<BlockState, PreProcessingInfo?>(mutableMapOf())
3231

3332
val postProcessedProperties = setOf(
3433
Properties.EXTENDED,
@@ -107,30 +106,21 @@ object ProcessorRegistry : Loadable {
107106

108107
override fun load() = "Loaded ${processors.size} pre processors"
109108

110-
fun TargetState.getProcessingInfo(pos: BlockPos) =
111-
if (this is TargetState.State) {
109+
fun TargetState.getProcessingInfo(pos: BlockPos): PreProcessingInfo? =
110+
if (this !is TargetState.State) PreProcessingInfo.DEFAULT
111+
else {
112112
val get: () -> PreProcessingInfo? = get@{
113113
val infoAccumulator = PreProcessingInfoAccumulator()
114114

115115
processors.forEach { processor ->
116116
if (!processor.acceptsState(blockState)) return@forEach
117117
processor.preProcess(blockState, pos, infoAccumulator)
118-
if (infoAccumulator.shouldBeOmitted) {
118+
if (infoAccumulator.shouldBeOmitted)
119119
return@get null
120-
}
121120
}
122121

123122
infoAccumulator.complete()
124123
}
125-
if (isExemptFromCache()) {
126-
get()
127-
} else {
128-
processorCache.getOrPut(blockState, get)
129-
}
130-
} else {
131-
PreProcessingInfo.DEFAULT
124+
processorCache.getOrPut(blockState, get)
132125
}
133-
134-
private fun TargetState.State.isExemptFromCache() =
135-
blockState.block is SlabBlock && blockState.get(Properties.SLAB_TYPE) == SlabType.DOUBLE
136126
}

src/main/kotlin/com/lambda/interaction/construction/processing/preprocessors/BlockHalfPreProcessor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ object BlockHalfPreProcessor : PlacementProcessor() {
3737
val slab = state.get(Properties.BLOCK_HALF) ?: return
3838

3939
val surfaceScan = when (slab) {
40-
BlockHalf.BOTTOM -> SurfaceScan(ScanMode.LESSER_BLOCK_HALF, Direction.Axis.Y)
41-
BlockHalf.TOP -> SurfaceScan(ScanMode.GREATER_BLOCK_HALF, Direction.Axis.Y)
40+
BlockHalf.BOTTOM -> SurfaceScan(ScanMode.LesserBlockHalf, Direction.Axis.Y)
41+
BlockHalf.TOP -> SurfaceScan(ScanMode.GreaterBlockHalf, Direction.Axis.Y)
4242
}
4343

4444
accumulator.offerSurfaceScan(surfaceScan)

src/main/kotlin/com/lambda/interaction/construction/processing/preprocessors/DoorHingePreProcessor.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ object DoorHingePreProcessor : PlacementProcessor() {
3939
val side = state.get(Properties.DOOR_HINGE) ?: return@runSafe
4040
val scanner = when (state.get(Properties.HORIZONTAL_FACING) ?: return@runSafe) {
4141
Direction.NORTH ->
42-
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.LESSER_BLOCK_HALF, Direction.Axis.X)
43-
else SurfaceScan(ScanMode.GREATER_BLOCK_HALF, Direction.Axis.X)
42+
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.LesserBlockHalf, Direction.Axis.X)
43+
else SurfaceScan(ScanMode.GreaterBlockHalf, Direction.Axis.X)
4444
Direction.EAST ->
45-
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.LESSER_BLOCK_HALF, Direction.Axis.Z)
46-
else SurfaceScan(ScanMode.GREATER_BLOCK_HALF, Direction.Axis.Z)
45+
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.LesserBlockHalf, Direction.Axis.Z)
46+
else SurfaceScan(ScanMode.GreaterBlockHalf, Direction.Axis.Z)
4747
Direction.SOUTH ->
48-
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.GREATER_BLOCK_HALF, Direction.Axis.X)
49-
else SurfaceScan(ScanMode.LESSER_BLOCK_HALF, Direction.Axis.X)
48+
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.GreaterBlockHalf, Direction.Axis.X)
49+
else SurfaceScan(ScanMode.LesserBlockHalf, Direction.Axis.X)
5050
Direction.DOWN,
5151
Direction.UP,
5252
Direction.WEST ->
53-
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.GREATER_BLOCK_HALF, Direction.Axis.Z)
54-
else SurfaceScan(ScanMode.LESSER_BLOCK_HALF, Direction.Axis.Z)
53+
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.GreaterBlockHalf, Direction.Axis.Z)
54+
else SurfaceScan(ScanMode.LesserBlockHalf, Direction.Axis.Z)
5555
}
5656
accumulator.offerSurfaceScan(scanner)
5757
} ?: Unit

0 commit comments

Comments
 (0)