From 20fcfface5d1d6061b6a3e9f66370dd517b38998 Mon Sep 17 00:00:00 2001 From: blocksimus <336769374+blocksimus@users.noreply.github.com> Date: Fri, 6 Nov 2026 17:04:52 +1100 Subject: [PATCH] feat: click redstone wire into a dot or cross --- .../post/RedstoneWirePostProcessor.kt | 55 +++++++++++++++++++ src/main/resources/lambda.accesswidener | 1 + 2 files changed, 56 insertions(+) create mode 100644 src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/property/placement/post/RedstoneWirePostProcessor.kt diff --git a/src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/property/placement/post/RedstoneWirePostProcessor.kt b/src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/property/placement/post/RedstoneWirePostProcessor.kt new file mode 100644 index 000000000..94bda84fa --- /dev/null +++ b/src/main/kotlin/com/lambda/interaction/construction/simulation/processing/preprocessors/property/placement/post/RedstoneWirePostProcessor.kt @@ -0,0 +1,55 @@ +/* + * Copyright 2026 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.interaction.construction.simulation.processing.preprocessors.property.placement.post + +import com.lambda.context.SafeContext +import com.lambda.interaction.construction.simulation.processing.PreProcessingInfoAccumulator +import com.lambda.interaction.construction.simulation.processing.PropertyPostProcessor +import net.minecraft.block.BlockState +import net.minecraft.block.RedstoneWireBlock +import net.minecraft.state.property.Properties +import net.minecraft.util.math.BlockPos + +/** + * Clicking redstone wire turns a cross into a dot and back, when nothing around it connects. + */ +@Suppress("unused") +object RedstoneWirePostProcessor : PropertyPostProcessor { + private val connections = listOf( + Properties.NORTH_WIRE_CONNECTION, + Properties.EAST_WIRE_CONNECTION, + Properties.SOUTH_WIRE_CONNECTION, + Properties.WEST_WIRE_CONNECTION + ) + + override fun acceptsState(state: BlockState, targetState: BlockState) = + state.block is RedstoneWireBlock && state.block == targetState.block && + (state.isCross() && targetState.isDot() || state.isDot() && targetState.isCross()) + + context(safeContext: SafeContext) + override fun PreProcessingInfoAccumulator.preProcess(state: BlockState, targetState: BlockState, pos: BlockPos) { + noCaching() + val clicked = (state.block as RedstoneWireBlock).getPlacementState(safeContext.world, targetState, pos) + if (connections.any { clicked.get(it) != targetState.get(it) }) return + with(StandardInteractPostProcessor) { preProcess(state, targetState, pos) } + } + + private fun BlockState.isCross() = connections.all { get(it).isConnected } + + private fun BlockState.isDot() = connections.none { get(it).isConnected } +} diff --git a/src/main/resources/lambda.accesswidener b/src/main/resources/lambda.accesswidener index c446edbb0..f2b24cb9f 100644 --- a/src/main/resources/lambda.accesswidener +++ b/src/main/resources/lambda.accesswidener @@ -31,6 +31,7 @@ transitive-accessible field net/minecraft/entity/Entity GLIDING_FLAG_INDEX I transitive-accessible method net/minecraft/entity/Entity getFlag (I)Z transitive-accessible method net/minecraft/block/ChestBlock getChestType (Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)Lnet/minecraft/block/enums/ChestType; transitive-accessible method net/minecraft/block/ChestBlock getNeighborChestDirection (Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)Lnet/minecraft/util/math/Direction; +transitive-accessible method net/minecraft/block/RedstoneWireBlock getPlacementState (Lnet/minecraft/world/BlockView;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState; transitive-accessible field net/minecraft/block/TrapdoorBlock blockSetType Lnet/minecraft/block/BlockSetType; transitive-accessible field net/minecraft/block/AbstractBlock collidable Z