RedstoneWireEvaluator .java

net.minecraft.world.level.redstone.RedstoneWireEvaluator (class): members: getIncomingWireSignal, wireBlock, getBlockSignal, getWireSignal, orientation.

net.minecraft.world.level.redstoneclass49 linescommon1.9 KB

API Surface (3)

int getBlockSignal(final Level level, final BlockPos pos)
int getWireSignal(final BlockPos pos, final BlockState state)
int getIncomingWireSignal(final Level level, final BlockPos pos)

Fields & Constants (2)

wireBlock
orientation

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

RedstoneWireEvaluator.java49 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.redstone;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.Direction;
5
import net.minecraft.world.level.Level;
6
import net.minecraft.world.level.block.RedstoneWireBlock;
7
import net.minecraft.world.level.block.state.BlockState;
8
import org.jspecify.annotations.Nullable;
9
10
public abstract class RedstoneWireEvaluator {
11
	protected final RedstoneWireBlock wireBlock;
12
13
	protected RedstoneWireEvaluator(final RedstoneWireBlock wireBlock) {
14
		this.wireBlock = wireBlock;
15
	}
16
17
	public abstract void updatePowerStrength(
18
		final Level level, final BlockPos pos, final BlockState state, final @Nullable Orientation orientation, final boolean skipShapeUpdates
19
	);
20
21
	protected int getBlockSignal(final Level level, final BlockPos pos) {
22
		return this.wireBlock.getBlockSignal(level, pos);
23
	}
24
25
	protected int getWireSignal(final BlockPos pos, final BlockState state) {
26
		return state.is(this.wireBlock) ? state.getValue(RedstoneWireBlock.POWER) : 0;
27
	}
28
29
	protected int getIncomingWireSignal(final Level level, final BlockPos pos) {
30
		int wireSignal = 0;
31
32
		for (Direction direction : Direction.Plane.HORIZONTAL) {
33
			BlockPos neighborPos = pos.relative(direction);
34
			BlockState neighborState = level.getBlockState(neighborPos);
35
			wireSignal = Math.max(wireSignal, this.getWireSignal(neighborPos, neighborState));
36
			BlockPos abovePos = pos.above();
37
			if (neighborState.isRedstoneConductor(level, neighborPos) && !level.getBlockState(abovePos).isRedstoneConductor(level, abovePos)) {
38
				BlockPos aboveNeighborPos = neighborPos.above();
39
				wireSignal = Math.max(wireSignal, this.getWireSignal(aboveNeighborPos, level.getBlockState(aboveNeighborPos)));
40
			} else if (!neighborState.isRedstoneConductor(level, neighborPos)) {
41
				BlockPos belowNeighborPos = neighborPos.below();
42
				wireSignal = Math.max(wireSignal, this.getWireSignal(belowNeighborPos, level.getBlockState(belowNeighborPos)));
43
			}
44
		}
45
46
		return Math.max(0, wireSignal - 1);
47
	}
48
}
49

Decompiled Minecraft 26.3 source of RedstoneWireEvaluator (net/minecraft/world/level/redstone/RedstoneWireEvaluator.java) with Mojang official mappings, stored verbatim on the site.