AbstractSkullBlock .java

net.minecraft.world.level.block.AbstractSkullBlock (class, 81 lines): members: POWERED, neighborChanged, getTicker, orientation, newBlockEntity, getType.

net.minecraft.world.level.blockclass81 linescommonextends BaseEntityBlock3.0 KB

API Surface (6)

BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState)
SkullBlock.Type getType()
boolean isPathfindable(final BlockState state, final PathComputationType type)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
BlockState getStateForPlacement(final BlockPlaceContext context)
void neighborChanged(final BlockState state, final Level level, final BlockPos pos, final Block block, final @Nullable Orientation orientation, final boolean movedByPiston)

Fields & Constants (3)

POWERED
type
orientation

Full Source

AbstractSkullBlock.java81 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.world.item.context.BlockPlaceContext;
5
import net.minecraft.world.level.Level;
6
import net.minecraft.world.level.block.entity.BlockEntity;
7
import net.minecraft.world.level.block.entity.BlockEntityTicker;
8
import net.minecraft.world.level.block.entity.BlockEntityType;
9
import net.minecraft.world.level.block.entity.BlockEntityTypes;
10
import net.minecraft.world.level.block.entity.SkullBlockEntity;
11
import net.minecraft.world.level.block.state.BlockBehaviour;
12
import net.minecraft.world.level.block.state.BlockState;
13
import net.minecraft.world.level.block.state.StateDefinition;
14
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
15
import net.minecraft.world.level.block.state.properties.BooleanProperty;
16
import net.minecraft.world.level.pathfinder.PathComputationType;
17
import net.minecraft.world.level.redstone.Orientation;
18
import org.jspecify.annotations.Nullable;
19
20
public abstract class AbstractSkullBlock extends BaseEntityBlock {
21
	public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
22
	private final SkullBlock.Type type;
23
24
	public AbstractSkullBlock(final SkullBlock.Type type, final BlockBehaviour.Properties properties) {
25
		super(properties);
26
		this.type = type;
27
		this.registerDefaultState(this.stateDefinition.any().setValue(POWERED, false));
28
	}
29
30
	@Override
31
	public BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
32
		return new SkullBlockEntity(worldPosition, blockState);
33
	}
34
35
	@Override
36
	public <T extends BlockEntity> @Nullable BlockEntityTicker<T> getTicker(final Level level, final BlockState blockState, final BlockEntityType<T> type) {
37
		if (level.isClientSide()) {
38
			boolean isAnimated = blockState.is(Blocks.DRAGON_HEAD)
39
				|| blockState.is(Blocks.DRAGON_WALL_HEAD)
40
				|| blockState.is(Blocks.PIGLIN_HEAD)
41
				|| blockState.is(Blocks.PIGLIN_WALL_HEAD);
42
			if (isAnimated) {
43
				return createTickerHelper(type, BlockEntityTypes.SKULL, SkullBlockEntity::animation);
44
			}
45
		}
46
47
		return null;
48
	}
49
50
	public SkullBlock.Type getType() {
51
		return this.type;
52
	}
53
54
	@Override
55
	protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
56
		return false;
57
	}
58
59
	@Override
60
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
61
		builder.add(POWERED);
62
	}
63
64
	@Override
65
	public BlockState getStateForPlacement(final BlockPlaceContext context) {
66
		return this.defaultBlockState().setValue(POWERED, context.getLevel().hasNeighborSignal(context.getClickedPos()));
67
	}
68
69
	@Override
70
	protected void neighborChanged(
71
		final BlockState state, final Level level, final BlockPos pos, final Block block, final @Nullable Orientation orientation, final boolean movedByPiston
72
	) {
73
		if (!level.isClientSide()) {
74
			boolean signal = level.hasNeighborSignal(pos);
75
			if (signal != state.getValue(POWERED)) {
76
				level.setBlock(pos, state.setValue(POWERED, signal), 2);
77
			}
78
		}
79
	}
80
}
81

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