Skip to content

Commit 226c8b7

Browse files
committed
chest placements
1 parent daad564 commit 226c8b7

File tree

15 files changed

+118
-22
lines changed

15 files changed

+118
-22
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,16 @@ class InteractSim private constructor(simInfo: InteractSimInfo)
110110
val fakePlayer = copyPlayer(player).apply {
111111
val newPos = pov - (this.eyePos - this.pos)
112112
setPos(newPos.x, newPos.y, newPos.z)
113-
if (testBlockState.block::class in BlockUtils.interactionBlocks && preProcessing.info.placing) {
114-
input.sneaking = true
115-
updatePose()
113+
if (preProcessing.info.sneak == false) {
114+
if (testBlockState.block::class in BlockUtils.interactionBlocks) return
115+
input.sneaking = false
116+
updatePose()
117+
} else {
118+
val shouldNotInteract = testBlockState.block::class in BlockUtils.interactionBlocks && preProcessing.info.placing
119+
if (shouldNotInteract || preProcessing.info.sneak == true) {
120+
input.sneaking = true
121+
updatePose()
122+
}
116123
}
117124
}
118125
val pov = fakePlayer.eyePos

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ interface StateProcessor {
3535

3636
interface PropertyPreProcessor {
3737
fun acceptsState(targetState: BlockState): Boolean
38-
fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState)
38+
39+
context(safeContext: SafeContext)
40+
fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState, pos: BlockPos)
3941
}
4042

4143
interface PropertyPostProcessor {

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ interface PreProcessingInfo {
3333
val item: Item?
3434
val expectedState: BlockState
3535
val placing: Boolean
36+
val sneak: Boolean?
3637
val noCaching: Boolean
3738

3839
companion object {
@@ -44,6 +45,7 @@ interface PreProcessingInfo {
4445
override val item = targetState.getStack(pos).item
4546
override val expectedState = targetState.getState(pos)
4647
override val placing = true
48+
override val sneak = null
4749
override val noCaching = true
4850
}
4951
}
@@ -56,6 +58,7 @@ class PreProcessingInfoAccumulator(
5658
override val ignore: MutableSet<Property<*>> = ProcessorRegistry.postProcessedProperties.toMutableSet(),
5759
override val sides: MutableSet<Direction> = Direction.entries.toMutableSet(),
5860
override var placing: Boolean = true,
61+
override var sneak: Boolean? = null,
5962
override var noCaching: Boolean = false,
6063
var omitInteraction: Boolean = false
6164
) : PreProcessingInfo {
@@ -99,13 +102,19 @@ class PreProcessingInfoAccumulator(
99102
this.placing = placing
100103
}
101104

105+
@InfoAccumulator
106+
@JvmName("setSneak1")
107+
fun setSneak(sneak: Boolean) {
108+
this.sneak = sneak
109+
}
110+
102111
@InfoAccumulator
103112
fun noCaching() {
104113
noCaching = true
105114
}
106115

107116
@InfoAccumulator
108-
fun omitPlacement() {
117+
fun omitInteraction() {
109118
omitInteraction = true
110119
}
111120

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ object ProcessorRegistry : Loadable {
119119
Properties.DELAY,
120120
Properties.COMPARATOR_MODE,
121121
Properties.OPEN,
122-
Properties.NOTE,
123-
124-
)
122+
Properties.NOTE
123+
)
125124

126125
override fun load() = "Loaded ${propertyPreProcessors.size} pre processors"
127126

@@ -154,13 +153,12 @@ object ProcessorRegistry : Loadable {
154153
with(processor) { preProcess(state, targetState, pos) }
155154
}
156155
}
157-
if (omitInteraction) return@run complete()
158156
if (!stateProcessing) {
159157
if (state.block != expectedState.block) {
160158
if (!state.isReplaceable) return@run null
161159
propertyPreProcessors.forEach { processor ->
162160
if (processor.acceptsState(targetState))
163-
with(processor) { preProcess(state, expectedState) }
161+
with(processor) { preProcess(state, expectedState, pos) }
164162
}
165163
} else {
166164
propertyPostProcessors.forEach { processor ->
@@ -171,6 +169,7 @@ object ProcessorRegistry : Loadable {
171169
if (!state.matches(targetState, ignore)) return@run null
172170
}
173171
}
172+
if (omitInteraction) return@run null
174173
complete()
175174
}
176175
}

src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/property/placement/pre/AttachmentPreProcessor.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
package com.lambda.interaction.construction.simulation.processing.preprocessors.property.placement.pre
1919

20+
import com.lambda.context.SafeContext
2021
import com.lambda.interaction.construction.simulation.processing.PreProcessingInfoAccumulator
2122
import com.lambda.interaction.construction.simulation.processing.PropertyPreProcessor
2223
import net.minecraft.block.BlockState
2324
import net.minecraft.block.enums.Attachment
2425
import net.minecraft.state.property.Properties
26+
import net.minecraft.util.math.BlockPos
2527
import net.minecraft.util.math.Direction
2628

2729
// Collected using reflections and then accessed from a collection in ProcessorRegistry
@@ -30,7 +32,8 @@ object AttachmentPreProcessor : PropertyPreProcessor {
3032
override fun acceptsState(targetState: BlockState) =
3133
Properties.ATTACHMENT in targetState
3234

33-
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState) {
35+
context(safeContext: SafeContext)
36+
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState, pos: BlockPos) {
3437
val attachment = targetState.get(Properties.ATTACHMENT) ?: return
3538
when (attachment) {
3639
Attachment.FLOOR -> retainSides(Direction.DOWN)

src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/property/placement/pre/AxisPreProcessor.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@
1717

1818
package com.lambda.interaction.construction.simulation.processing.preprocessors.property.placement.pre
1919

20+
import com.lambda.context.SafeContext
2021
import com.lambda.interaction.construction.simulation.processing.PreProcessingInfoAccumulator
2122
import com.lambda.interaction.construction.simulation.processing.PropertyPreProcessor
2223
import net.minecraft.block.BlockState
2324
import net.minecraft.state.property.Properties
25+
import net.minecraft.util.math.BlockPos
2426

2527
// Collected using reflections and then accessed from a collection in ProcessorRegistry
2628
@Suppress("unused")
2729
object AxisPreProcessor : PropertyPreProcessor {
2830
override fun acceptsState(targetState: BlockState) =
2931
Properties.AXIS in targetState
3032

31-
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState) {
33+
context(safeContext: SafeContext)
34+
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState, pos: BlockPos) {
3235
val axis = targetState.get(Properties.AXIS)
3336
retainSides { side -> side.axis == axis }
3437
}

src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/property/placement/pre/BlockFacePreProcessor.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
package com.lambda.interaction.construction.simulation.processing.preprocessors.property.placement.pre
1919

20+
import com.lambda.context.SafeContext
2021
import com.lambda.interaction.construction.simulation.processing.PreProcessingInfoAccumulator
2122
import com.lambda.interaction.construction.simulation.processing.PropertyPreProcessor
2223
import net.minecraft.block.BlockState
2324
import net.minecraft.block.enums.BlockFace
2425
import net.minecraft.state.property.Properties
26+
import net.minecraft.util.math.BlockPos
2527
import net.minecraft.util.math.Direction
2628

2729
// Collected using reflections and then accessed from a collection in ProcessorRegistry
@@ -30,7 +32,8 @@ object BlockFacePreProcessor : PropertyPreProcessor {
3032
override fun acceptsState(targetState: BlockState) =
3133
Properties.BLOCK_FACE in targetState
3234

33-
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState) {
35+
context(safeContext: SafeContext)
36+
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState, pos: BlockPos) {
3437
val property = targetState.get(Properties.BLOCK_FACE) ?: return
3538
when (property) {
3639
BlockFace.FLOOR -> retainSides(Direction.DOWN)

src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/property/placement/pre/BlockHalfPreProcessor.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717

1818
package com.lambda.interaction.construction.simulation.processing.preprocessors.property.placement.pre
1919

20+
import com.lambda.context.SafeContext
2021
import com.lambda.interaction.construction.simulation.processing.PreProcessingInfoAccumulator
2122
import com.lambda.interaction.construction.simulation.processing.PropertyPreProcessor
2223
import com.lambda.interaction.construction.verify.ScanMode
2324
import com.lambda.interaction.construction.verify.SurfaceScan
2425
import net.minecraft.block.BlockState
2526
import net.minecraft.block.enums.BlockHalf
2627
import net.minecraft.state.property.Properties
28+
import net.minecraft.util.math.BlockPos
2729
import net.minecraft.util.math.Direction
2830

2931
// Collected using reflections and then accessed from a collection in ProcessorRegistry
@@ -32,7 +34,8 @@ object BlockHalfPreProcessor : PropertyPreProcessor {
3234
override fun acceptsState(targetState: BlockState) =
3335
Properties.BLOCK_HALF in targetState
3436

35-
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState) {
37+
context(safeContext: SafeContext)
38+
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState, pos: BlockPos) {
3639
val slab = targetState.get(Properties.BLOCK_HALF) ?: return
3740

3841
val surfaceScan = when (slab) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2026 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.simulation.processing.preprocessors.property.placement.pre
19+
20+
import com.lambda.context.SafeContext
21+
import com.lambda.interaction.construction.simulation.processing.PreProcessingInfoAccumulator
22+
import com.lambda.interaction.construction.simulation.processing.PropertyPreProcessor
23+
import com.lambda.threading.runSafe
24+
import net.minecraft.block.BlockState
25+
import net.minecraft.block.ChestBlock
26+
import net.minecraft.block.enums.ChestType
27+
import net.minecraft.state.property.Properties
28+
import net.minecraft.util.math.BlockPos
29+
30+
// Collected using reflections and then accessed from a collection in ProcessorRegistry
31+
@Suppress("unused")
32+
object ChestPreProcessor : PropertyPreProcessor {
33+
override fun acceptsState(targetState: BlockState) =
34+
targetState.block is ChestBlock && Properties.CHEST_TYPE in targetState && Properties.HORIZONTAL_FACING in targetState
35+
36+
context(safeContext: SafeContext)
37+
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState, pos: BlockPos) {
38+
noCaching()
39+
runSafe {
40+
val chestBlock = targetState.block as? ChestBlock ?: return
41+
val targetType = targetState.get(Properties.CHEST_TYPE)
42+
val targetFacing = targetState.get(Properties.HORIZONTAL_FACING)
43+
val placeType = chestBlock.getChestType(world, pos, targetFacing)
44+
if (placeType == targetType) return
45+
if (targetType != ChestType.SINGLE) {
46+
if (placeType == ChestType.SINGLE) addIgnores(Properties.CHEST_TYPE)
47+
else {
48+
val canPlaceWithTypeRight = targetFacing == chestBlock.getNeighborChestDirection(world, pos, targetFacing.rotateYCounterclockwise())
49+
if (targetType != ChestType.RIGHT || !canPlaceWithTypeRight) {
50+
setExpectedState(targetState.with(Properties.CHEST_TYPE, ChestType.SINGLE))
51+
setSneak(true)
52+
}
53+
}
54+
} else setSneak(true)
55+
}
56+
}
57+
}

src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/property/placement/pre/DoorHingePreProcessor.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717

1818
package com.lambda.interaction.construction.simulation.processing.preprocessors.property.placement.pre
1919

20+
import com.lambda.context.SafeContext
2021
import com.lambda.interaction.construction.simulation.processing.PreProcessingInfoAccumulator
2122
import com.lambda.interaction.construction.simulation.processing.PropertyPreProcessor
2223
import com.lambda.interaction.construction.verify.ScanMode
2324
import com.lambda.interaction.construction.verify.SurfaceScan
2425
import net.minecraft.block.BlockState
2526
import net.minecraft.block.enums.DoorHinge
2627
import net.minecraft.state.property.Properties
28+
import net.minecraft.util.math.BlockPos
2729
import net.minecraft.util.math.Direction
2830

2931
// Collected using reflections and then accessed from a collection in ProcessorRegistry
@@ -32,7 +34,8 @@ object DoorHingePreProcessor : PropertyPreProcessor {
3234
override fun acceptsState(targetState: BlockState) =
3335
Properties.DOOR_HINGE in targetState
3436

35-
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState) {
37+
context(safeContext: SafeContext)
38+
override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState, pos: BlockPos) {
3639
val side = targetState.get(Properties.DOOR_HINGE) ?: return
3740
val scanner = when (targetState.get(Properties.HORIZONTAL_FACING) ?: return) {
3841
Direction.NORTH ->

0 commit comments

Comments
 (0)