Skip to content

Commit 97bb079

Browse files
authored
Feature: Click redstone wire into a dot or cross (#358)
1 parent 9d05a26 commit 97bb079

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
}

‎src/main/resources/lambda.accesswidener‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ transitive-accessible field net/minecraft/entity/Entity GLIDING_FLAG_INDEX I
3131
transitive-accessible method net/minecraft/entity/Entity getFlag (I)Z
3232
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;
3333
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;
34+
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;
3435
transitive-accessible field net/minecraft/block/TrapdoorBlock blockSetType Lnet/minecraft/block/BlockSetType;
3536
transitive-accessible field net/minecraft/block/AbstractBlock collidable Z
3637

0 commit comments

Comments
 (0)