Skip to content

Commit f70179f

Browse files
committed
Add build config to simulator
1 parent fca9ae2 commit f70179f

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

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

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

20+
import com.lambda.config.groups.BuildConfig
2021
import com.lambda.config.groups.InteractionConfig
2122
import com.lambda.config.groups.InventoryConfig
2223
import com.lambda.context.SafeContext
@@ -70,16 +71,17 @@ object BuildSimulator {
7071
interact: InteractionConfig = TaskFlowModule.interact,
7172
rotation: RotationConfig = TaskFlowModule.rotation,
7273
inventory: InventoryConfig = TaskFlowModule.inventory,
74+
build: BuildConfig = TaskFlowModule.build,
7375
) = runSafe {
7476
structure.entries.flatMap { (pos, target) ->
75-
checkRequirements(pos, target)?.let {
77+
checkRequirements(pos, target, build)?.let {
7678
return@flatMap setOf(it)
7779
}
7880
checkPlaceResults(pos, target, eye, interact, rotation, inventory).let {
7981
if (it.isEmpty()) return@let
8082
return@flatMap it
8183
}
82-
checkBreakResults(pos, eye, interact, rotation, inventory).let {
84+
checkBreakResults(pos, eye, interact, rotation, inventory, build).let {
8385
if (it.isEmpty()) return@let
8486
return@flatMap it
8587
}
@@ -91,6 +93,7 @@ object BuildSimulator {
9193
private fun SafeContext.checkRequirements(
9294
pos: BlockPos,
9395
target: TargetState,
96+
build: BuildConfig
9497
): BuildResult? {/* the chunk is not loaded */
9598
if (!world.isChunkLoaded(pos)) {
9699
return BuildResult.ChunkNotLoaded(pos)
@@ -104,7 +107,7 @@ object BuildSimulator {
104107
}
105108

106109
/* block should be ignored */
107-
if (state.block in TaskFlowModule.build.ignoredBlocks && target.type == TargetState.Type.AIR) {
110+
if (state.block in build.ignoredBlocks && target.type == TargetState.Type.AIR) {
108111
return BuildResult.Ignored(pos)
109112
}
110113

@@ -314,13 +317,14 @@ object BuildSimulator {
314317
eye: Vec3d,
315318
interact: InteractionConfig,
316319
rotation: RotationConfig,
317-
inventory: InventoryConfig
320+
inventory: InventoryConfig,
321+
build: BuildConfig
318322
): Set<BuildResult> {
319323
val acc = mutableSetOf<BuildResult>()
320324
val state = pos.blockState(world)
321325

322326
/* is a block that will be destroyed by breaking adjacent blocks */
323-
if (TaskFlowModule.build.breakWeakBlocks && state.block.hardness == 0f && !state.isAir) {
327+
if (build.breakWeakBlocks && state.block.hardness == 0f && !state.isAir) {
324328
acc.add(BuildResult.Ignored(pos))
325329
return acc
326330
}

common/src/main/kotlin/com/lambda/interaction/construction/simulation/Simulation.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

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

20+
import com.lambda.config.groups.BuildConfig
2021
import com.lambda.config.groups.InteractionConfig
2122
import com.lambda.config.groups.InventoryConfig
2223
import com.lambda.context.SafeContext
@@ -40,6 +41,7 @@ data class Simulation(
4041
val interact: InteractionConfig = TaskFlowModule.interact,
4142
val rotation: RotationConfig = TaskFlowModule.rotation,
4243
val inventory: InventoryConfig = TaskFlowModule.inventory,
44+
val build: BuildConfig = TaskFlowModule.build,
4345
) {
4446
private val cache: MutableMap<FastVector, Set<BuildResult>> = mutableMapOf()
4547
private fun FastVector.toView(): Vec3d = toVec3d().add(0.5, ClientPlayerEntity.DEFAULT_EYE_HEIGHT.toDouble(), 0.5)
@@ -60,7 +62,7 @@ data class Simulation(
6062
) return@getOrPut emptySet()
6163
}
6264

63-
blueprint.simulate(view, interact, rotation, inventory)
65+
blueprint.simulate(view, interact, rotation, inventory, build)
6466
}
6567

6668
private fun SafeContext.playerFitsIn(pos: Vec3d): Boolean {

common/src/main/kotlin/com/lambda/task/tasks/BuildTask.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class BuildTask @Ta5kBuilder constructor(
6060
private val interact: InteractionConfig = TaskFlowModule.interact,
6161
private val inventory: InventoryConfig = TaskFlowModule.inventory,
6262
) : Task<Unit>() {
63-
override val name: String get() = "Building $blueprint with ${(placements / (age / 20.0 + 0.001)).string} p/s"
63+
override val name: String get() = "Building $blueprint with ${(placements / (age / 20.0 + 0.001)).string} p/s ${(breaks / (age / 20.0 + 0.001)).string} p/s"
6464

6565
private val pendingPlacements = ConcurrentLinkedQueue<PlaceContext>()
6666
private val pendingBreaks = ConcurrentLinkedQueue<BreakContext>()
@@ -99,7 +99,7 @@ class BuildTask @Ta5kBuilder constructor(
9999
}
100100

101101
// ToDo: Simulate for each pair player positions that work
102-
val results = blueprint.simulate(player.eyePos, interact, rotation, inventory)
102+
val results = blueprint.simulate(player.eyePos, interact, rotation, inventory, build)
103103
TaskFlowModule.drawables = results.filterIsInstance<Drawable>().plus(pendingPlacements.toList())
104104

105105
val instantResults = results.filterIsInstance<BreakResult.Break>()

common/src/main/kotlin/com/lambda/task/tasks/PlaceContainer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class PlaceContainer @Ta5kBuilder constructor(
4848
it.blockPos
4949
.toStructure(TargetState.Stack(startStack))
5050
.toBlueprint()
51-
.simulate(player.getCameraPosVec(mc.tickDelta))
51+
.simulate(player.eyePos)
5252
}
5353

5454
val succeeds = results.filterIsInstance<PlaceResult.Place>().filter {

0 commit comments

Comments
 (0)