WallSignBlock .java

net.minecraft.world.level.block.WallSignBlock (class): members: getSignHitboxCenterPosition, getYRotationDegrees, attachmentPoint, SHAPES, FACING, mirror.

net.minecraft.world.level.blockclass110 linescommonextends SignBlock4.0 KB

Implements

API Surface (9)

VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos)
BlockState updateShape(final BlockState state, final LevelReader level, final ScheduledTickAccess ticks, final BlockPos pos, final Direction directionToNeighbour, final BlockPos neighbourPos, final BlockState neighbourState, final RandomSource random)
float getYRotationDegrees(final BlockState state)
Vec3 getSignHitboxCenterPosition(final BlockState state)
BlockState rotate(final BlockState state, final Rotation rotation)
BlockState mirror(final BlockState state, final Mirror mirror)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
PlainSignBlock.Attachment attachmentPoint(final BlockState state)

Fields & Constants (9)

FACING
SHAPES
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

WallSignBlock.java110 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.util.RandomSource;
7
import net.minecraft.world.item.context.BlockPlaceContext;
8
import net.minecraft.world.level.BlockGetter;
9
import net.minecraft.world.level.LevelReader;
10
import net.minecraft.world.level.ScheduledTickAccess;
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.EnumProperty;
15
import net.minecraft.world.level.block.state.properties.WoodType;
16
import net.minecraft.world.level.material.FluidState;
17
import net.minecraft.world.level.material.Fluids;
18
import net.minecraft.world.phys.Vec3;
19
import net.minecraft.world.phys.shapes.CollisionContext;
20
import net.minecraft.world.phys.shapes.Shapes;
21
import net.minecraft.world.phys.shapes.VoxelShape;
22
import org.jspecify.annotations.Nullable;
23
24
public class WallSignBlock extends SignBlock implements PlainSignBlock {
25
	public static final EnumProperty<Direction> FACING = HorizontalDirectionalBlock.FACING;
26
	private static final Map<Direction, VoxelShape> SHAPES = Shapes.rotateHorizontal(Block.boxZ(16.0, 4.5, 12.5, 14.0, 16.0));
27
28
	public WallSignBlock(final WoodType type, final BlockBehaviour.Properties properties) {
29
		super(type, properties.sound(type.soundType()));
30
		this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false));
31
	}
32
33
	@Override
34
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
35
		return SHAPES.get(state.getValue(FACING));
36
	}
37
38
	@Override
39
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
40
		return level.getBlockState(pos.relative(state.getValue(FACING).getOpposite())).isSolid();
41
	}
42
43
	@Override
44
	public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
45
		BlockState state = this.defaultBlockState();
46
		FluidState replacedFluidState = context.getLevel().getFluidState(context.getClickedPos());
47
		LevelReader level = context.getLevel();
48
		BlockPos pos = context.getClickedPos();
49
		Direction[] directions = context.getNearestLookingDirections();
50
51
		for (Direction direction : directions) {
52
			if (direction.getAxis().isHorizontal()) {
53
				Direction facing = direction.getOpposite();
54
				state = state.setValue(FACING, facing);
55
				if (state.canSurvive(level, pos)) {
56
					return state.setValue(WATERLOGGED, replacedFluidState.is(Fluids.WATER));
57
				}
58
			}
59
		}
60
61
		return null;
62
	}
63
64
	@Override
65
	protected BlockState updateShape(
66
		final BlockState state,
67
		final LevelReader level,
68
		final ScheduledTickAccess ticks,
69
		final BlockPos pos,
70
		final Direction directionToNeighbour,
71
		final BlockPos neighbourPos,
72
		final BlockState neighbourState,
73
		final RandomSource random
74
	) {
75
		return directionToNeighbour.getOpposite() == state.getValue(FACING) && !state.canSurvive(level, pos)
76
			? Blocks.AIR.defaultBlockState()
77
			: super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
78
	}
79
80
	@Override
81
	public float getYRotationDegrees(final BlockState state) {
82
		return state.getValue(FACING).toYRot();
83
	}
84
85
	@Override
86
	public Vec3 getSignHitboxCenterPosition(final BlockState state) {
87
		return SHAPES.get(state.getValue(FACING)).bounds().getCenter();
88
	}
89
90
	@Override
91
	protected BlockState rotate(final BlockState state, final Rotation rotation) {
92
		return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
93
	}
94
95
	@Override
96
	protected BlockState mirror(final BlockState state, final Mirror mirror) {
97
		return state.rotate(mirror.getRotation(state.getValue(FACING)));
98
	}
99
100
	@Override
101
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
102
		builder.add(FACING, WATERLOGGED);
103
	}
104
105
	@Override
106
	public PlainSignBlock.Attachment attachmentPoint(final BlockState state) {
107
		return PlainSignBlock.Attachment.WALL;
108
	}
109
}
110

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