WallBannerBlock .java

net.minecraft.world.level.block.WallBannerBlock (class, 90 lines): members: SHAPES, FACING, canSurvive, mirror, rotate, neighbourState, updateShape, ticks.

net.minecraft.world.level.blockclass90 linescommonextends AbstractBannerBlock3.2 KB

API Surface (7)

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)
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 (9)

FACING
SHAPES
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

WallBannerBlock.java90 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.DyeColor;
8
import net.minecraft.world.item.context.BlockPlaceContext;
9
import net.minecraft.world.level.BlockGetter;
10
import net.minecraft.world.level.LevelReader;
11
import net.minecraft.world.level.ScheduledTickAccess;
12
import net.minecraft.world.level.block.state.BlockBehaviour;
13
import net.minecraft.world.level.block.state.BlockState;
14
import net.minecraft.world.level.block.state.StateDefinition;
15
import net.minecraft.world.level.block.state.properties.EnumProperty;
16
import net.minecraft.world.phys.shapes.CollisionContext;
17
import net.minecraft.world.phys.shapes.Shapes;
18
import net.minecraft.world.phys.shapes.VoxelShape;
19
20
public class WallBannerBlock extends AbstractBannerBlock {
21
	public static final EnumProperty<Direction> FACING = HorizontalDirectionalBlock.FACING;
22
	private static final Map<Direction, VoxelShape> SHAPES = Shapes.rotateHorizontal(Block.boxZ(16.0, 0.0, 12.5, 14.0, 16.0));
23
24
	public WallBannerBlock(final DyeColor color, final BlockBehaviour.Properties properties) {
25
		super(color, properties);
26
		this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
27
	}
28
29
	@Override
30
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
31
		return level.getBlockState(pos.relative(state.getValue(FACING).getOpposite())).isSolid();
32
	}
33
34
	@Override
35
	protected BlockState updateShape(
36
		final BlockState state,
37
		final LevelReader level,
38
		final ScheduledTickAccess ticks,
39
		final BlockPos pos,
40
		final Direction directionToNeighbour,
41
		final BlockPos neighbourPos,
42
		final BlockState neighbourState,
43
		final RandomSource random
44
	) {
45
		return directionToNeighbour == state.getValue(FACING).getOpposite() && !state.canSurvive(level, pos)
46
			? Blocks.AIR.defaultBlockState()
47
			: super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
48
	}
49
50
	@Override
51
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
52
		return SHAPES.get(state.getValue(FACING));
53
	}
54
55
	@Override
56
	public BlockState getStateForPlacement(final BlockPlaceContext context) {
57
		BlockState state = this.defaultBlockState();
58
		LevelReader level = context.getLevel();
59
		BlockPos pos = context.getClickedPos();
60
		Direction[] directions = context.getNearestLookingDirections();
61
62
		for (Direction direction : directions) {
63
			if (direction.getAxis().isHorizontal()) {
64
				Direction facing = direction.getOpposite();
65
				state = state.setValue(FACING, facing);
66
				if (state.canSurvive(level, pos)) {
67
					return state;
68
				}
69
			}
70
		}
71
72
		return null;
73
	}
74
75
	@Override
76
	protected BlockState rotate(final BlockState state, final Rotation rotation) {
77
		return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
78
	}
79
80
	@Override
81
	protected BlockState mirror(final BlockState state, final Mirror mirror) {
82
		return state.rotate(mirror.getRotation(state.getValue(FACING)));
83
	}
84
85
	@Override
86
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
87
		builder.add(FACING);
88
	}
89
}
90

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