Skip to content

Commit fa8e50a

Browse files
committed
pass origin position to scanner to correctly check everything regardless of block position. This is important when the place sim scans hits on a block next to the origin placement. The scan mode must correctly min max the new shape instead of clamping the origin position. Works but needs improving
1 parent c6fe30d commit fa8e50a

File tree

11 files changed

+70
-76
lines changed

11 files changed

+70
-76
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ interface PreProcessingInfo {
2525
val surfaceScan: SurfaceScan
2626
val ignore: Set<Property<*>>
2727
val sides: Set<Direction>
28-
val shouldBeOmitted: Boolean
2928

3029
companion object {
3130
val DEFAULT = object : PreProcessingInfo {
3231
override val surfaceScan = SurfaceScan.DEFAULT
3332
override val ignore = setOf<Property<*>>()
3433
override val sides = Direction.entries.toSet()
35-
override val shouldBeOmitted = false
3634
}
3735
}
3836
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class PreProcessingInfoAccumulator(
2525
override var surfaceScan: SurfaceScan = SurfaceScan.DEFAULT,
2626
override val ignore: MutableSet<Property<*>> = ProcessorRegistry.postProcessedProperties.toMutableSet(),
2727
override val sides: MutableSet<Direction> = Direction.entries.toMutableSet(),
28-
override var shouldBeOmitted: Boolean = false
2928
) : PreProcessingInfo {
3029
@InfoAccumulator
3130
fun offerSurfaceScan(scan: SurfaceScan) {
@@ -49,11 +48,6 @@ class PreProcessingInfoAccumulator(
4948
this.sides.retainAll(sides.toSet())
5049
}
5150

52-
@InfoAccumulator
53-
fun omitPlacement() {
54-
shouldBeOmitted = true
55-
}
56-
5751
@InfoAccumulator
5852
fun complete() = this as PreProcessingInfo
5953

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,22 @@ object ProcessorRegistry : Loadable {
142142
* each pre-processor checking if the state can be accepted. If so, the state is passed through the pre-processor
143143
* which can call the functions within the [PreProcessingInfoAccumulator] DSL to modify the information.
144144
*/
145-
fun TargetState.getProcessingInfo(pos: BlockPos): PreProcessingInfo? =
146-
if (this !is TargetState.State) PreProcessingInfo.DEFAULT
147-
else {
148-
val get: () -> PreProcessingInfo? = get@{
149-
val infoAccumulator = PreProcessingInfoAccumulator()
145+
fun TargetState.getProcessingInfo(pos: BlockPos): PreProcessingData? {
146+
if (this !is TargetState.State) return PreProcessingData(PreProcessingInfo.DEFAULT, pos)
150147

151-
processors.forEach { processor ->
152-
if (!processor.acceptsState(blockState)) return@forEach
153-
processor.preProcess(blockState, pos, infoAccumulator)
154-
if (infoAccumulator.shouldBeOmitted)
155-
return@get null
156-
}
148+
val get: () -> PreProcessingInfo? = get@{
149+
val infoAccumulator = PreProcessingInfoAccumulator()
157150

158-
infoAccumulator.complete()
151+
processors.forEach { processor ->
152+
if (!processor.acceptsState(blockState)) return@forEach
153+
processor.preProcess(blockState, pos, infoAccumulator)
159154
}
160-
processorCache.getOrPut(blockState, get)
155+
156+
infoAccumulator.complete()
161157
}
158+
val preProcessingInfo = processorCache.getOrPut(blockState, get) ?: return null
159+
return PreProcessingData(preProcessingInfo, pos)
160+
}
162161

163162
/**
164163
* Contains the starting initial block placement and any subsequent intermediary processes to transform the placement
@@ -196,3 +195,5 @@ object ProcessorRegistry : Loadable {
196195
val sides: Set<Direction> = Direction.entries.toSet()
197196
)
198197
}
198+
199+
data class PreProcessingData(val info: PreProcessingInfo, val pos: BlockPos)

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

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

2020
import com.lambda.context.Automated
2121
import com.lambda.context.AutomatedSafeContext
22-
import com.lambda.interaction.construction.processing.PreProcessingInfo
22+
import com.lambda.interaction.construction.processing.PreProcessingData
2323
import com.lambda.interaction.construction.processing.ProcessorRegistry.getProcessingInfo
2424
import com.lambda.interaction.construction.processing.ProcessorRegistry.intermediaryBlockMap
2525
import com.lambda.interaction.construction.result.BuildResult
@@ -38,13 +38,13 @@ interface ISimInfo : Automated {
3838
val pos: BlockPos
3939
val state: BlockState
4040
val targetState: TargetState
41-
val preProcessing: PreProcessingInfo
41+
val preProcessing: PreProcessingData
4242
val pov: Vec3d
4343
val concurrentResults: MutableSet<BuildResult>
4444
val dependencyStack: Stack<Sim<*>>
4545

4646
fun AutomatedSafeContext.matchesTarget(state: BlockState = [email protected], complete: Boolean = true): Boolean {
47-
if (targetState.matches(state, pos, if (!complete) preProcessing.ignore else emptySet())) return true
47+
if (targetState.matches(state, pos, if (!complete) preProcessing.info.ignore else emptySet())) return true
4848
else if (complete) return false
4949

5050
intermediaryBlockMap[targetState.getState(pos).block]?.let { intermediaryInfo ->
@@ -102,7 +102,7 @@ data class SimInfo(
102102
override val pos: BlockPos,
103103
override val state: BlockState,
104104
override val targetState: TargetState,
105-
override val preProcessing: PreProcessingInfo,
105+
override val preProcessing: PreProcessingData,
106106
override val pov: Vec3d,
107107
override val dependencyStack: Stack<Sim<*>>,
108108
override val concurrentResults: MutableSet<BuildResult>,

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

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

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

20-
import com.lambda.interaction.construction.processing.PreProcessingInfo
20+
import com.lambda.interaction.construction.processing.PreProcessingData
2121
import com.lambda.interaction.construction.result.BuildResult
2222
import com.lambda.interaction.construction.result.results.GenericResult
2323
import com.lambda.interaction.request.rotating.Rotation.Companion.rotationTo
@@ -91,7 +91,7 @@ abstract class Sim<T : BuildResult> : Results<T> {
9191
voxelShape: VoxelShape,
9292
pos: BlockPos,
9393
sides: Set<Direction>,
94-
preProcessing: PreProcessingInfo
94+
preProcessing: PreProcessingData
9595
): Set<CheckedHit>? {
9696
val boxes = voxelShape.boundingBoxes.map { it.offset(pos) }
9797

@@ -108,7 +108,7 @@ abstract class Sim<T : BuildResult> : Results<T> {
108108
else sides
109109

110110
if (!buildConfig.strictRayCast) {
111-
box.getClosestPoints(pov, sides, preProcessing.surfaceScan, placeConfig.airPlace.isEnabled) { vec, side ->
111+
box.getClosestPoints(pov, sides, preProcessing, placeConfig.airPlace.isEnabled) { vec, side ->
112112
if (pov distSq vec > reachSq)
113113
misses.add(Pair(vec, side))
114114
else {
@@ -120,7 +120,7 @@ abstract class Sim<T : BuildResult> : Results<T> {
120120
)
121121
}
122122
}
123-
} else box.scanSurfaces(sides, buildConfig.resolution, preProcessing.surfaceScan, false) { side, vec ->
123+
} else box.scanSurfaces(sides, buildConfig.resolution, preProcessing, false) { side, vec ->
124124
if (pov distSq vec > reachSq) {
125125
misses.add(Pair(vec, side))
126126
return@scanSurfaces

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class PlaceSim private constructor(simInfo: ISimInfo)
9090

9191
private suspend fun AutomatedSafeContext.simPlacements() =
9292
supervisorScope {
93-
preProcessing.sides.forEach { side ->
93+
preProcessing.info.sides.forEach { side ->
9494
val neighborPos = pos.offset(side)
9595
val neighborSide = side.opposite
9696
launch { testBlock(neighborPos, neighborSide, this@supervisorScope) }

src/main/kotlin/com/lambda/interaction/construction/verify/SurfaceScan.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import net.minecraft.util.math.Direction
2121

2222
data class SurfaceScan(
2323
val mode: ScanMode,
24-
val axis: Direction.Axis,
24+
val axis: Direction.Axis
2525
) {
2626
companion object {
2727
val DEFAULT = SurfaceScan(ScanMode.Full, Direction.Axis.Y)

src/main/kotlin/com/lambda/interaction/request/rotating/visibilty/RotationTargets.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.lambda.interaction.request.rotating.visibilty
1919

2020
import com.lambda.context.Automated
2121
import com.lambda.context.SafeContext
22-
import com.lambda.interaction.construction.verify.SurfaceScan
2322
import com.lambda.interaction.request.rotating.Rotation
2423
import com.lambda.interaction.request.rotating.Rotation.Companion.dist
2524
import com.lambda.interaction.request.rotating.RotationManager
@@ -83,7 +82,7 @@ fun lookAtHit(hit: RequestedHit, rotation: SafeContext.() -> Rotation?) =
8382
@RotationDsl
8483
fun Automated.lookAtHit(hit: HitResult): RotationTarget? {
8584
return when (hit) {
86-
is BlockHitResult -> lookAtBlock(hit.blockPos, setOf(hit.side), SurfaceScan.DEFAULT)
85+
is BlockHitResult -> lookAtBlock(hit.blockPos, setOf(hit.side))
8786
is EntityHitResult -> lookAtEntity(hit.entity as? LivingEntity ?: return null)
8887
else -> null
8988
}
@@ -107,7 +106,7 @@ fun Automated.lookAtEntity(entity: LivingEntity): RotationTarget {
107106
buildConfig.attackReach,
108107
player.eyePos,
109108
ALL_SIDES,
110-
SurfaceScan.DEFAULT,
109+
null,
111110
false,
112111
InteractionMask.Entity
113112
) { requestedHit.verifyHit(hit) }?.rotation
@@ -127,7 +126,6 @@ fun Automated.lookAtEntity(entity: LivingEntity): RotationTarget {
127126
fun Automated.lookAtBlock(
128127
pos: BlockPos,
129128
sides: Set<Direction> = ALL_SIDES,
130-
surfaceScan: SurfaceScan = SurfaceScan.DEFAULT
131129
): RotationTarget {
132130
val requestedHit = blockHit(pos, sides, buildConfig.interactReach)
133131

@@ -138,7 +136,7 @@ fun Automated.lookAtBlock(
138136
buildConfig.interactReach,
139137
player.eyePos,
140138
sides,
141-
surfaceScan,
139+
null,
142140
false,
143141
InteractionMask.Block
144142
) { requestedHit.verifyHit(hit) }?.rotation

0 commit comments

Comments
 (0)