@@ -23,6 +23,7 @@ import com.lambda.config.groups.InventoryConfig
2323import com.lambda.context.SafeContext
2424import com.lambda.interaction.construction.blueprint.Blueprint
2525import com.lambda.interaction.construction.result.BuildResult
26+ import com.lambda.interaction.construction.result.Drawable
2627import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
2728import com.lambda.interaction.request.rotation.RotationConfig
2829import com.lambda.module.modules.client.TaskFlowModule
@@ -32,9 +33,11 @@ import com.lambda.util.world.FastVector
3233import com.lambda.util.world.toBlockPos
3334import com.lambda.util.world.toVec3d
3435import net.minecraft.client.network.ClientPlayerEntity
36+ import net.minecraft.util.math.BlockPos
3537import net.minecraft.util.math.Box
3638import net.minecraft.util.math.Direction
3739import net.minecraft.util.math.Vec3d
40+ import java.awt.Color
3841
3942data class Simulation (
4043 val blueprint : Blueprint ,
@@ -47,31 +50,37 @@ data class Simulation(
4750 private fun FastVector.toView (): Vec3d = toVec3d().add(0.5 , ClientPlayerEntity .DEFAULT_EYE_HEIGHT .toDouble(), 0.5 )
4851
4952 fun simulate (
50- pos : FastVector
51- ) =
52- cache.getOrPut(pos) {
53- val view = pos.toView()
54- runSafe {
55- if (blueprint.isOutOfBounds(view) && blueprint.getClosestPointTo(view)
56- .distanceTo(view) > 10.0
57- ) return @getOrPut emptySet()
58- val blockPos = pos.toBlockPos()
59- if (! playerFitsIn(Vec3d .ofBottomCenter(blockPos))) return @getOrPut emptySet()
60- if (! blockPos.down().blockState(world)
61- .isSideSolidFullSquare(world, blockPos, Direction .UP )
62- ) return @getOrPut emptySet()
63- }
53+ pos : FastVector ,
54+ ) = cache.getOrPut(pos) {
55+ val view = pos.toView()
56+ val isOutOfBounds = blueprint.isOutOfBounds(view)
57+ val isTooFar = blueprint.getClosestPointTo(view).distanceTo(view) > 10.0
58+ runSafe {
59+ if (isOutOfBounds && isTooFar) return @getOrPut emptySet()
60+ val blockPos = pos.toBlockPos()
61+ val isWalkable = blockPos.down().blockState(world).isSideSolidFullSquare(world, blockPos, Direction .UP )
62+ if (! isWalkable) return @getOrPut emptySet()
63+ if (! playerFitsIn(blockPos)) return @getOrPut emptySet()
64+ }
65+
66+ blueprint.simulate(view, interact, rotation, inventory, build)
67+ }
6468
65- blueprint.simulate(view, interact, rotation, inventory, build)
69+ fun goodPositions () = cache.filter { it.value.any { it.rank.ordinal < 4 } }.map { PossiblePos (it.key.toBlockPos()) }
70+
71+ class PossiblePos (val pos : BlockPos ): Drawable {
72+ override fun SafeContext.buildRenderer () {
73+ withBox(Vec3d .ofBottomCenter(pos).playerBox(), Color (0 , 255 , 0 , 50 ))
6674 }
75+ }
6776
68- private fun SafeContext.playerFitsIn (pos : Vec3d ): Boolean {
69- val pBox = player.boundingBox
70- val aabb = Box (pBox.minX, pBox.minY - 1 .0E- 6 , pBox.minZ, pBox.maxX, pBox.minY, pBox.maxZ)
71- return world.isSpaceEmpty(aabb.offset(pos))
77+ private fun SafeContext.playerFitsIn (pos : BlockPos ): Boolean {
78+ return world.isSpaceEmpty(Vec3d .ofBottomCenter(pos).playerBox())
7279 }
7380
7481 companion object {
82+ fun Vec3d.playerBox (): Box = Box (x - 0.3 , y, z - 0.3 , x + 0.3 , y + 1.8 , z + 0.3 ).contract(1 .0E- 6 )
83+
7584 fun Blueprint.simulation (
7685 interact : InteractionConfig = TaskFlowModule .interact,
7786 rotation : RotationConfig = TaskFlowModule .rotation,
0 commit comments