Skip to content

Commit fe14b56

Browse files
committed
omit top half DOUBLE_BLOCK_HALF property holders
1 parent 165de50 commit fe14b56

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import net.minecraft.util.math.BlockPos
2828

2929
object ProcessorRegistry : Loadable {
3030
private val processors = getInstances<PlacementProcessor>()
31-
private val processorCache = mutableMapOf<BlockState, PreProcessingInfo>()
31+
private val processorCache = mutableMapOf<BlockState, PreProcessingInfo?>()
3232

3333
val postProcessedProperties = setOf(
3434
Properties.EXTENDED,
@@ -107,22 +107,26 @@ object ProcessorRegistry : Loadable {
107107

108108
override fun load() = "Loaded ${processors.size} pre processors"
109109

110-
fun TargetState.getProcessingInfo(pos: BlockPos): PreProcessingInfo =
111-
(this as? TargetState.State)?.let { state ->
112-
val get: () -> PreProcessingInfo = {
113-
110+
fun TargetState.getProcessingInfo(pos: BlockPos): PreProcessingInfo? {
111+
return if (this is TargetState.State) {
112+
val targetState = this as? TargetState.State ?: return null
113+
val get: () -> PreProcessingInfo? = get@ {
114114
val infoAccumulator = PreProcessingInfoAccumulator()
115115

116116
processors.forEach {
117-
if (!it.acceptsState(state.blockState)) return@forEach
118-
it.preProcess(state.blockState, pos, infoAccumulator)
117+
if (!it.acceptsState(targetState.blockState)) return@forEach
118+
it.preProcess(targetState.blockState, pos, infoAccumulator)
119+
if (infoAccumulator.shouldBeOmitted) {
120+
return@get null
121+
}
119122
}
120123

121124
infoAccumulator.complete()
122125
}
123-
if (isExemptFromCache(state)) get()
124-
else processorCache.getOrPut(state.blockState, get)
125-
} ?: PreProcessingInfo.DEFAULT
126+
if (isExemptFromCache(targetState)) get()
127+
else processorCache.getOrPut(targetState.blockState, get)
128+
} else PreProcessingInfo.DEFAULT
129+
}
126130

127131
private fun isExemptFromCache(state: TargetState.State) =
128132
state.blockState.block is SlabBlock && state.blockState.get(Properties.SLAB_TYPE) == SlabType.DOUBLE
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 net.minecraft.block.BlockState
23+
import net.minecraft.block.enums.DoubleBlockHalf
24+
import net.minecraft.state.property.Properties
25+
import net.minecraft.util.math.BlockPos
26+
27+
// Collected using reflections and then accessed from a collection in ProcessorRegistry
28+
@Suppress("unused")
29+
object OmitPreProcessor : PlacementProcessor() {
30+
override fun acceptsState(state: BlockState) = true
31+
32+
override fun preProcess(state: BlockState, pos: BlockPos, accumulator: PreProcessingInfoAccumulator) {
33+
if (Properties.DOUBLE_BLOCK_HALF in state.properties) {
34+
if (state.get(Properties.DOUBLE_BLOCK_HALF) == DoubleBlockHalf.UPPER) {
35+
accumulator.omitPlacement()
36+
}
37+
}
38+
}
39+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ object BuildSimulator {
9797
build: BuildConfig = TaskFlowModule.build,
9898
) = runSafe {
9999
structure.entries.flatMap { (pos, target) ->
100-
val preProcessing = target.getProcessingInfo(pos)
100+
val preProcessing = target.getProcessingInfo(pos) ?: return@flatMap emptySet()
101101
checkRequirements(pos, target, build).let {
102102
if (it.isEmpty()) return@let
103103
return@flatMap it

0 commit comments

Comments
 (0)