Skip to content

Commit 10bd793

Browse files
committed
added property ignores and more pre-processors
1 parent 3feb026 commit 10bd793

File tree

11 files changed

+180
-43
lines changed

11 files changed

+180
-43
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/processing/PlacementProcessor.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ import net.minecraft.block.BlockState
2121

2222
abstract class PlacementProcessor {
2323
abstract fun acceptsState(state: BlockState): Boolean
24-
abstract fun preProcess(state: BlockState, accumulator: PreprocessingInfoAccumulator)
25-
}
26-
24+
abstract fun preProcess(state: BlockState, accumulator: PreProcessingInfoAccumulator)
25+
}

common/src/main/kotlin/com/lambda/interaction/construction/processing/PreprocessingInfo.kt renamed to common/src/main/kotlin/com/lambda/interaction/construction/processing/PreProcessingInfo.kt

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

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

20+
import com.lambda.interaction.construction.processing.ProcessorRegistry.postProcessedProperties
2021
import com.lambda.interaction.construction.verify.SurfaceScan
2122
import net.minecraft.state.property.Property
2223
import net.minecraft.util.math.Direction
@@ -25,10 +26,11 @@ import net.minecraft.util.math.Direction
2526
private annotation class InfoAccumulator
2627

2728
@InfoAccumulator
28-
data class PreprocessingInfoAccumulator(
29+
data class PreProcessingInfoAccumulator(
2930
private var surfaceScan: SurfaceScan = SurfaceScan.DEFAULT,
30-
private val ignore: MutableSet<Property<*>> = mutableSetOf(),
31+
private val ignore: MutableSet<Property<*>> = postProcessedProperties.toMutableSet(),
3132
private val sides: MutableSet<Direction> = Direction.entries.toMutableSet(),
33+
var shouldBeOmitted: Boolean = false
3234
) {
3335
@InfoAccumulator
3436
fun offerSurfaceScan(scan: SurfaceScan) {
@@ -38,8 +40,8 @@ data class PreprocessingInfoAccumulator(
3840
}
3941

4042
@InfoAccumulator
41-
fun addIgnores(ignores: Set<Property<*>>) {
42-
ignore.addAll(ignores)
43+
fun addIgnores(vararg properties: Property<*>) {
44+
ignore.addAll(properties)
4345
}
4446

4547
@InfoAccumulator
@@ -53,15 +55,16 @@ data class PreprocessingInfoAccumulator(
5355
}
5456

5557
@InfoAccumulator
56-
fun complete() = PreprocessingInfo(surfaceScan, ignore, sides)
58+
fun complete() = PreProcessingInfo(surfaceScan, ignore, sides, shouldBeOmitted)
5759
}
5860

59-
data class PreprocessingInfo(
61+
data class PreProcessingInfo(
6062
val surfaceScan: SurfaceScan,
6163
val ignore: Set<Property<*>>,
62-
val sides: Set<Direction>
64+
val sides: Set<Direction>,
65+
val shouldBeOmitted: Boolean
6366
) {
6467
companion object {
65-
val DEFAULT = PreprocessingInfo(SurfaceScan.DEFAULT, emptySet(), emptySet())
68+
val DEFAULT = PreProcessingInfo(SurfaceScan.DEFAULT, emptySet(), emptySet(), false)
6669
}
6770
}

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

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,91 @@ 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.state.property.Properties
2425

2526
object ProcessorRegistry : Loadable {
2627
private val processors = getInstances<PlacementProcessor>()
27-
private val processorCache = mutableMapOf<BlockState, PreprocessingInfo>()
28+
private val processorCache = mutableMapOf<BlockState, PreProcessingInfo>()
29+
30+
val postProcessedProperties = setOf(
31+
Properties.EXTENDED,
32+
Properties.EYE,
33+
Properties.HAS_BOOK,
34+
Properties.HAS_BOTTLE_0, Properties.HAS_BOTTLE_1, Properties.HAS_BOTTLE_2,
35+
Properties.HAS_RECORD,
36+
Properties.INVERTED,
37+
Properties.LIT,
38+
Properties.LOCKED,
39+
Properties.OCCUPIED,
40+
Properties.OPEN,
41+
Properties.POWERED,
42+
Properties.SIGNAL_FIRE,
43+
Properties.SNOWY,
44+
Properties.TRIGGERED,
45+
Properties.UNSTABLE,
46+
Properties.WATERLOGGED,
47+
Properties.BERRIES,
48+
Properties.BLOOM,
49+
Properties.SHRIEKING,
50+
Properties.CAN_SUMMON,
51+
Properties.FLOWER_AMOUNT,
52+
Properties.EAST_WALL_SHAPE, Properties.SOUTH_WALL_SHAPE, Properties.WEST_WALL_SHAPE, Properties.NORTH_WALL_SHAPE,
53+
Properties.EAST_WIRE_CONNECTION, Properties.SOUTH_WIRE_CONNECTION, Properties.WEST_WIRE_CONNECTION, Properties.NORTH_WIRE_CONNECTION,
54+
Properties.AGE_1,
55+
Properties.AGE_2,
56+
Properties.AGE_3,
57+
Properties.AGE_4,
58+
Properties.AGE_5,
59+
Properties.AGE_7,
60+
Properties.AGE_15,
61+
Properties.AGE_25,
62+
Properties.BITES,
63+
Properties.CANDLES,
64+
Properties.DELAY,
65+
Properties.EGGS,
66+
Properties.HATCH,
67+
Properties.LAYERS,
68+
Properties.LEVEL_3,
69+
Properties.LEVEL_8,
70+
Properties.LEVEL_1_8,
71+
Properties.HONEY_LEVEL,
72+
Properties.LEVEL_15,
73+
Properties.MOISTURE,
74+
Properties.NOTE,
75+
Properties.PICKLES,
76+
Properties.POWER,
77+
Properties.STAGE,
78+
Properties.CHARGES,
79+
Properties.CHEST_TYPE,
80+
Properties.COMPARATOR_MODE,
81+
Properties.INSTRUMENT,
82+
Properties.STAIR_SHAPE,
83+
Properties.TILT,
84+
Properties.THICKNESS,
85+
Properties.SCULK_SENSOR_PHASE,
86+
Properties.SLOT_0_OCCUPIED, Properties.SLOT_1_OCCUPIED, Properties.SLOT_2_OCCUPIED, Properties.SLOT_3_OCCUPIED, Properties.SLOT_4_OCCUPIED, Properties.SLOT_5_OCCUPIED,
87+
Properties.DUSTED,
88+
Properties.CRAFTING,
89+
Properties.TRIAL_SPAWNER_STATE,
90+
Properties.DISARMED,
91+
Properties.ATTACHED,
92+
Properties.DRAG,
93+
Properties.ENABLED,
94+
Properties.IN_WALL,
95+
Properties.UP,
96+
Properties.DOWN,
97+
Properties.NORTH,
98+
Properties.EAST,
99+
Properties.SOUTH,
100+
Properties.WEST,
101+
)
28102

29103
override fun load() = "Loaded ${processors.size} pre processors"
30104

31-
fun TargetState.getProcessingInfo(): PreprocessingInfo =
105+
fun TargetState.getProcessingInfo(): PreProcessingInfo =
32106
(this as? TargetState.State)?.let { state ->
33107
processorCache.getOrPut(state.blockState) {
34-
val infoAccumulator = PreprocessingInfoAccumulator()
108+
val infoAccumulator = PreProcessingInfoAccumulator()
35109

36110
processors.forEach {
37111
if (!it.acceptsState(state.blockState)) return@forEach
@@ -40,5 +114,5 @@ object ProcessorRegistry : Loadable {
40114

41115
return infoAccumulator.complete()
42116
}
43-
} ?: PreprocessingInfo.DEFAULT
117+
} ?: PreProcessingInfo.DEFAULT
44118
}

common/src/main/kotlin/com/lambda/interaction/construction/processing/processors/AttachmentPreprocessor.kt renamed to common/src/main/kotlin/com/lambda/interaction/construction/processing/preprocessors/AttachmentPreProcessor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package com.lambda.interaction.construction.processing.processors
18+
package com.lambda.interaction.construction.processing.preprocessors
1919

2020
import com.lambda.interaction.construction.processing.PlacementProcessor
21-
import com.lambda.interaction.construction.processing.PreprocessingInfoAccumulator
21+
import com.lambda.interaction.construction.processing.PreProcessingInfoAccumulator
2222
import net.minecraft.block.BlockState
2323
import net.minecraft.block.enums.Attachment
2424
import net.minecraft.state.property.Properties
2525
import net.minecraft.util.math.Direction
2626

2727
// Collected using reflections and then accessed from a collection in ProcessorRegistry
2828
@Suppress("unused")
29-
object AttachmentPreprocessor : PlacementProcessor() {
29+
object AttachmentPreProcessor : PlacementProcessor() {
3030
override fun acceptsState(state: BlockState) =
3131
state.properties.contains(Properties.ATTACHMENT)
3232

33-
override fun preProcess(state: BlockState, accumulator: PreprocessingInfoAccumulator) {
33+
override fun preProcess(state: BlockState, accumulator: PreProcessingInfoAccumulator) {
3434
val attachment = state.get(Properties.ATTACHMENT) ?: return
3535
with (accumulator) {
3636
when (attachment) {

common/src/main/kotlin/com/lambda/interaction/construction/processing/processors/AxisPreprocessor.kt renamed to common/src/main/kotlin/com/lambda/interaction/construction/processing/preprocessors/AxisPreProcessor.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Lambda
2+
* Copyright 2025 Lambda
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -15,20 +15,20 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package com.lambda.interaction.construction.processing.processors
18+
package com.lambda.interaction.construction.processing.preprocessors
1919

2020
import com.lambda.interaction.construction.processing.PlacementProcessor
21-
import com.lambda.interaction.construction.processing.PreprocessingInfoAccumulator
21+
import com.lambda.interaction.construction.processing.PreProcessingInfoAccumulator
2222
import net.minecraft.block.BlockState
2323
import net.minecraft.state.property.Properties
2424

2525
// Collected using reflections and then accessed from a collection in ProcessorRegistry
2626
@Suppress("unused")
27-
object AxisPreprocessor : PlacementProcessor() {
27+
object AxisPreProcessor : PlacementProcessor() {
2828
override fun acceptsState(state: BlockState) =
2929
state.getOrEmpty(Properties.AXIS).isPresent
3030

31-
override fun preProcess(state: BlockState, accumulator: PreprocessingInfoAccumulator) {
31+
override fun preProcess(state: BlockState, accumulator: PreProcessingInfoAccumulator) {
3232
val axis = state.get(Properties.AXIS)
3333
accumulator.retainSides { side ->
3434
side.axis == axis

common/src/main/kotlin/com/lambda/interaction/construction/processing/processors/BlockFaceProcessor.kt renamed to common/src/main/kotlin/com/lambda/interaction/construction/processing/preprocessors/BlockFacePreProcessor.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Lambda
2+
* Copyright 2025 Lambda
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -15,22 +15,22 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package com.lambda.interaction.construction.processing.processors
18+
package com.lambda.interaction.construction.processing.preprocessors
1919

2020
import com.lambda.interaction.construction.processing.PlacementProcessor
21-
import com.lambda.interaction.construction.processing.PreprocessingInfoAccumulator
21+
import com.lambda.interaction.construction.processing.PreProcessingInfoAccumulator
2222
import net.minecraft.block.BlockState
2323
import net.minecraft.block.enums.BlockFace
2424
import net.minecraft.state.property.Properties
2525
import net.minecraft.util.math.Direction
2626

2727
// Collected using reflections and then accessed from a collection in ProcessorRegistry
2828
@Suppress("unused")
29-
object BlockFaceProcessor : PlacementProcessor() {
29+
object BlockFacePreProcessor : PlacementProcessor() {
3030
override fun acceptsState(state: BlockState) =
3131
state.getOrEmpty(Properties.BLOCK_FACE).isPresent
3232

33-
override fun preProcess(state: BlockState, accumulator: PreprocessingInfoAccumulator) {
33+
override fun preProcess(state: BlockState, accumulator: PreProcessingInfoAccumulator) {
3434
val property = state.get(Properties.BLOCK_FACE) ?: return
3535
with (accumulator) {
3636
when (property) {

common/src/main/kotlin/com/lambda/interaction/construction/processing/processors/BlockHalfProcessor.kt renamed to common/src/main/kotlin/com/lambda/interaction/construction/processing/preprocessors/BlockHalfPreProcessor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package com.lambda.interaction.construction.processing.processors
18+
package com.lambda.interaction.construction.processing.preprocessors
1919

2020
import com.lambda.interaction.construction.processing.PlacementProcessor
21-
import com.lambda.interaction.construction.processing.PreprocessingInfoAccumulator
21+
import com.lambda.interaction.construction.processing.PreProcessingInfoAccumulator
2222
import com.lambda.interaction.construction.verify.ScanMode
2323
import com.lambda.interaction.construction.verify.SurfaceScan
2424
import net.minecraft.block.BlockState
@@ -28,11 +28,11 @@ import net.minecraft.util.math.Direction
2828

2929
// Collected using reflections and then accessed from a collection in ProcessorRegistry
3030
@Suppress("unused")
31-
object BlockHalfProcessor : PlacementProcessor() {
31+
object BlockHalfPreProcessor : PlacementProcessor() {
3232
override fun acceptsState(state: BlockState) =
3333
state.getOrEmpty(Properties.BLOCK_HALF).isPresent
3434

35-
override fun preProcess(state: BlockState, accumulator: PreprocessingInfoAccumulator) {
35+
override fun preProcess(state: BlockState, accumulator: PreProcessingInfoAccumulator) {
3636
val slab = state.get(Properties.BLOCK_HALF) ?: return
3737

3838
val surfaceScan = when (slab) {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.interaction.construction.processing.preprocessors
19+
20+
import com.lambda.interaction.construction.processing.PlacementProcessor
21+
import com.lambda.interaction.construction.processing.PreProcessingInfoAccumulator
22+
import com.lambda.interaction.construction.verify.ScanMode
23+
import com.lambda.interaction.construction.verify.SurfaceScan
24+
import com.lambda.threading.runSafe
25+
import net.minecraft.block.BlockState
26+
import net.minecraft.block.enums.DoorHinge
27+
import net.minecraft.state.property.Properties
28+
import net.minecraft.util.math.Direction
29+
30+
// Collected using reflections and then accessed from a collection in ProcessorRegistry
31+
@Suppress("unused")
32+
object DoorHingePreProcessor : PlacementProcessor() {
33+
override fun acceptsState(state: BlockState) =
34+
state.properties.contains(Properties.DOOR_HINGE)
35+
36+
override fun preProcess(state: BlockState, accumulator: PreProcessingInfoAccumulator) =
37+
runSafe {
38+
val side = state.get(Properties.DOOR_HINGE) ?: return@runSafe
39+
val scanner = when (state.get(Properties.HORIZONTAL_FACING) ?: return@runSafe) {
40+
Direction.NORTH ->
41+
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.LESSER_HALF, Direction.Axis.X)
42+
else SurfaceScan(ScanMode.GREATER_HALF, Direction.Axis.X)
43+
Direction.EAST ->
44+
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.LESSER_HALF, Direction.Axis.Z)
45+
else SurfaceScan(ScanMode.GREATER_HALF, Direction.Axis.Z)
46+
Direction.SOUTH ->
47+
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.GREATER_HALF, Direction.Axis.X)
48+
else SurfaceScan(ScanMode.LESSER_HALF, Direction.Axis.X)
49+
Direction.DOWN,
50+
Direction.UP,
51+
Direction.WEST ->
52+
if (side == DoorHinge.LEFT) SurfaceScan(ScanMode.GREATER_HALF, Direction.Axis.Z)
53+
else SurfaceScan(ScanMode.LESSER_HALF, Direction.Axis.Z)
54+
}
55+
accumulator.offerSurfaceScan(scanner)
56+
} ?: Unit
57+
}

common/src/main/kotlin/com/lambda/interaction/construction/processing/processors/HopperFacingPreprocessor.kt renamed to common/src/main/kotlin/com/lambda/interaction/construction/processing/preprocessors/HopperFacingPreProcessor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
package com.lambda.interaction.construction.processing.processors
18+
package com.lambda.interaction.construction.processing.preprocessors
1919

2020
import com.lambda.interaction.construction.processing.PlacementProcessor
21-
import com.lambda.interaction.construction.processing.PreprocessingInfoAccumulator
21+
import com.lambda.interaction.construction.processing.PreProcessingInfoAccumulator
2222
import net.minecraft.block.BlockState
2323
import net.minecraft.state.property.Properties
2424
import net.minecraft.util.math.Direction
2525

2626
// Collected using reflections and then accessed from a collection in ProcessorRegistry
2727
@Suppress("unused")
28-
object HopperFacingPreprocessor : PlacementProcessor() {
28+
object HopperFacingPreProcessor : PlacementProcessor() {
2929
override fun acceptsState(state: BlockState) =
3030
state.properties.contains(Properties.HOPPER_FACING)
3131

32-
override fun preProcess(state: BlockState, accumulator: PreprocessingInfoAccumulator) {
32+
override fun preProcess(state: BlockState, accumulator: PreProcessingInfoAccumulator) {
3333
val facing = state.get(Properties.HOPPER_FACING) ?: return
3434
when {
3535
facing.axis == Direction.Axis.Y -> accumulator.retainSides { it.axis == Direction.Axis.Y }

0 commit comments

Comments
 (0)