WallSkullBlock .java

net.minecraft.world.level.block.WallSkullBlock (class, 72 lines): members: SHAPES, FACING, mirror, rotate, getStateForPlacement, getShape. imports: Shapes.

net.minecraft.world.level.blockclass72 linescommonextends AbstractSkullBlock2.5 KB

API Surface (5)

VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
BlockState getStateForPlacement(final BlockPlaceContext context)
BlockState rotate(final BlockState state, final Rotation rotation)
BlockState mirror(final BlockState state, final Mirror mirror)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)

Fields & Constants (2)

FACING
SHAPES

Full Source

WallSkullBlock.java72 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import java.util.Map;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.world.item.context.BlockPlaceContext;
7
import net.minecraft.world.level.BlockGetter;
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.EnumProperty;
12
import net.minecraft.world.phys.shapes.CollisionContext;
13
import net.minecraft.world.phys.shapes.Shapes;
14
import net.minecraft.world.phys.shapes.VoxelShape;
15
16
/**
17
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
18
 */
19
public class WallSkullBlock extends AbstractSkullBlock {
20
	public static final EnumProperty<Direction> FACING = HorizontalDirectionalBlock.FACING;
21
	private static final Map<Direction, VoxelShape> SHAPES = Shapes.rotateHorizontal(Block.boxZ(8.0, 8.0, 16.0));
22
23
	/**
24
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
25
	 */
26
	public WallSkullBlock(final SkullBlock.Type type, final BlockBehaviour.Properties properties) {
27
		super(type, properties);
28
		this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH));
29
	}
30
31
	@Override
32
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
33
		return SHAPES.get(state.getValue(FACING));
34
	}
35
36
	@Override
37
	public BlockState getStateForPlacement(final BlockPlaceContext context) {
38
		BlockState state = super.getStateForPlacement(context);
39
		BlockGetter level = context.getLevel();
40
		BlockPos pos = context.getClickedPos();
41
		Direction[] directions = context.getNearestLookingDirections();
42
43
		for (Direction direction : directions) {
44
			if (direction.getAxis().isHorizontal()) {
45
				Direction facing = direction.getOpposite();
46
				state = state.setValue(FACING, facing);
47
				if (!level.getBlockState(pos.relative(direction)).canBeReplaced(context)) {
48
					return state;
49
				}
50
			}
51
		}
52
53
		return null;
54
	}
55
56
	@Override
57
	protected BlockState rotate(final BlockState state, final Rotation rotation) {
58
		return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
59
	}
60
61
	@Override
62
	protected BlockState mirror(final BlockState state, final Mirror mirror) {
63
		return state.rotate(mirror.getRotation(state.getValue(FACING)));
64
	}
65
66
	@Override
67
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
68
		super.createBlockStateDefinition(builder);
69
		builder.add(FACING);
70
	}
71
}
72

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