RedstoneLampBlock .java

net.minecraft.world.level.block.RedstoneLampBlock (class): members: LIT, neighborChanged, orientation, getStateForPlacement, tick. imports: Orientation.

net.minecraft.world.level.blockclass56 linescommonextends Block1.9 KB

API Surface (3)

void neighborChanged(final BlockState state, final Level level, final BlockPos pos, final Block block, final @Nullable Orientation orientation, final boolean movedByPiston)
void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)

Fields & Constants (2)

LIT
orientation

Full Source

RedstoneLampBlock.java56 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.util.RandomSource;
6
import net.minecraft.world.item.context.BlockPlaceContext;
7
import net.minecraft.world.level.Level;
8
import net.minecraft.world.level.block.state.BlockBehaviour;
9
import net.minecraft.world.level.block.state.BlockState;
10
import net.minecraft.world.level.block.state.StateDefinition;
11
import net.minecraft.world.level.block.state.properties.BooleanProperty;
12
import net.minecraft.world.level.redstone.Orientation;
13
import org.jspecify.annotations.Nullable;
14
15
public class RedstoneLampBlock extends Block {
16
	public static final BooleanProperty LIT = RedstoneTorchBlock.LIT;
17
18
	public RedstoneLampBlock(final BlockBehaviour.Properties properties) {
19
		super(properties);
20
		this.registerDefaultState(this.defaultBlockState().setValue(LIT, false));
21
	}
22
23
	@Override
24
	public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
25
		return this.defaultBlockState().setValue(LIT, context.getLevel().hasNeighborSignal(context.getClickedPos()));
26
	}
27
28
	@Override
29
	protected void neighborChanged(
30
		final BlockState state, final Level level, final BlockPos pos, final Block block, final @Nullable Orientation orientation, final boolean movedByPiston
31
	) {
32
		if (!level.isClientSide()) {
33
			boolean isLit = state.getValue(LIT);
34
			if (isLit != level.hasNeighborSignal(pos)) {
35
				if (isLit) {
36
					level.scheduleTick(pos, this, 4);
37
				} else {
38
					level.setBlock(pos, state.cycle(LIT), 2);
39
				}
40
			}
41
		}
42
	}
43
44
	@Override
45
	protected void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
46
		if (state.getValue(LIT) && !level.hasNeighborSignal(pos)) {
47
			level.setBlock(pos, state.cycle(LIT), 2);
48
		}
49
	}
50
51
	@Override
52
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
53
		builder.add(LIT);
54
	}
55
}
56

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