CopperBulbBlock .java

net.minecraft.world.level.block.CopperBulbBlock (class): members: checkAndFlip, LIT, POWERED, hasAnalogOutputSignal, getAnalogOutputSignal, onPlace.

net.minecraft.world.level.blockclass70 linescommonextends Block2.6 KB

API Surface (6)

void onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston)
void neighborChanged(final BlockState state, final Level level, final BlockPos pos, final Block block, final @Nullable Orientation orientation, final boolean movedByPiston)
void checkAndFlip(final BlockState state, final ServerLevel level, final BlockPos pos)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
boolean hasAnalogOutputSignal(final BlockState state)
int getAnalogOutputSignal(final BlockState state, final Level level, final BlockPos pos, final Direction direction)

Fields & Constants (3)

POWERED
LIT
orientation

Full Source

CopperBulbBlock.java70 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.Direction;
5
import net.minecraft.server.level.ServerLevel;
6
import net.minecraft.sounds.SoundEvents;
7
import net.minecraft.sounds.SoundSource;
8
import net.minecraft.world.level.Level;
9
import net.minecraft.world.level.block.state.BlockBehaviour;
10
import net.minecraft.world.level.block.state.BlockState;
11
import net.minecraft.world.level.block.state.StateDefinition;
12
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
13
import net.minecraft.world.level.block.state.properties.BooleanProperty;
14
import net.minecraft.world.level.redstone.Orientation;
15
import org.jspecify.annotations.Nullable;
16
17
public class CopperBulbBlock extends Block {
18
	public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
19
	public static final BooleanProperty LIT = BlockStateProperties.LIT;
20
21
	public CopperBulbBlock(final BlockBehaviour.Properties properties) {
22
		super(properties);
23
		this.registerDefaultState(this.defaultBlockState().setValue(LIT, false).setValue(POWERED, false));
24
	}
25
26
	@Override
27
	protected void onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston) {
28
		if (oldState.getBlock() != state.getBlock() && level instanceof ServerLevel serverLevel) {
29
			this.checkAndFlip(state, serverLevel, pos);
30
		}
31
	}
32
33
	@Override
34
	protected void neighborChanged(
35
		final BlockState state, final Level level, final BlockPos pos, final Block block, final @Nullable Orientation orientation, final boolean movedByPiston
36
	) {
37
		if (level instanceof ServerLevel serverLevel) {
38
			this.checkAndFlip(state, serverLevel, pos);
39
		}
40
	}
41
42
	public void checkAndFlip(final BlockState state, final ServerLevel level, final BlockPos pos) {
43
		boolean signal = level.hasNeighborSignal(pos);
44
		if (signal != state.getValue(POWERED)) {
45
			BlockState newState = state;
46
			if (!state.getValue(POWERED)) {
47
				newState = newState.cycle(LIT);
48
				level.playSound(null, pos, newState.getValue(LIT) ? SoundEvents.COPPER_BULB_TURN_ON : SoundEvents.COPPER_BULB_TURN_OFF, SoundSource.BLOCKS);
49
			}
50
51
			level.setBlockAndUpdate(pos, newState.setValue(POWERED, signal));
52
		}
53
	}
54
55
	@Override
56
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
57
		builder.add(LIT, POWERED);
58
	}
59
60
	@Override
61
	protected boolean hasAnalogOutputSignal(final BlockState state) {
62
		return true;
63
	}
64
65
	@Override
66
	protected int getAnalogOutputSignal(final BlockState state, final Level level, final BlockPos pos, final Direction direction) {
67
		return level.getBlockState(pos).getValue(LIT) ? 15 : 0;
68
	}
69
}
70

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