|
| 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.post |
| 19 | + |
| 20 | +import com.lambda.context.SafeContext |
| 21 | +import com.lambda.interaction.construction.simulation.processing.PreProcessingInfoAccumulator |
| 22 | +import com.lambda.interaction.construction.simulation.processing.PropertyPostProcessor |
| 23 | +import net.minecraft.block.BlockState |
| 24 | +import net.minecraft.block.RedstoneWireBlock |
| 25 | +import net.minecraft.state.property.Properties |
| 26 | +import net.minecraft.util.math.BlockPos |
| 27 | + |
| 28 | +/** |
| 29 | + * Clicking redstone wire turns a cross into a dot and back, when nothing around it connects. |
| 30 | + */ |
| 31 | +@Suppress("unused") |
| 32 | +object RedstoneWirePostProcessor : PropertyPostProcessor { |
| 33 | + private val connections = listOf( |
| 34 | + Properties.NORTH_WIRE_CONNECTION, |
| 35 | + Properties.EAST_WIRE_CONNECTION, |
| 36 | + Properties.SOUTH_WIRE_CONNECTION, |
| 37 | + Properties.WEST_WIRE_CONNECTION |
| 38 | + ) |
| 39 | + |
| 40 | + override fun acceptsState(state: BlockState, targetState: BlockState) = |
| 41 | + state.block is RedstoneWireBlock && state.block == targetState.block && |
| 42 | + (state.isCross() && targetState.isDot() || state.isDot() && targetState.isCross()) |
| 43 | + |
| 44 | + context(safeContext: SafeContext) |
| 45 | + override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState, pos: BlockPos) { |
| 46 | + noCaching() |
| 47 | + val clicked = (state.block as RedstoneWireBlock).getPlacementState(safeContext.world, targetState, pos) |
| 48 | + if (connections.any { clicked.get(it) != targetState.get(it) }) return |
| 49 | + with(StandardInteractPostProcessor) { preProcess(state, targetState, pos) } |
| 50 | + } |
| 51 | + |
| 52 | + private fun BlockState.isCross() = connections.all { get(it).isConnected } |
| 53 | + |
| 54 | + private fun BlockState.isDot() = connections.none { get(it).isConnected } |
| 55 | +} |
0 commit comments