BannerBlock .java

net.minecraft.world.level.block.BannerBlock (class, 94 lines): members: AttachmentType, ROTATION, canSurvive, SHAPE, mirror, rotate, neighbourState, ticks.

net.minecraft.world.level.blockclass94 linescommonextends AbstractBannerBlock3.3 KB

API Surface (8)

boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos)
VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
BlockState getStateForPlacement(final BlockPlaceContext context)
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)
BlockState rotate(final BlockState state, final Rotation rotation)
BlockState mirror(final BlockState state, final Mirror mirror)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
String getSerializedName()

Fields & Constants (9)

ROTATION
SHAPE
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

String literals (2)

"wall"
"ground"

Full Source

BannerBlock.java94 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import com.mojang.serialization.Codec;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.util.RandomSource;
7
import net.minecraft.util.StringRepresentable;
8
import net.minecraft.world.item.DyeColor;
9
import net.minecraft.world.item.context.BlockPlaceContext;
10
import net.minecraft.world.level.BlockGetter;
11
import net.minecraft.world.level.LevelReader;
12
import net.minecraft.world.level.ScheduledTickAccess;
13
import net.minecraft.world.level.block.state.BlockBehaviour;
14
import net.minecraft.world.level.block.state.BlockState;
15
import net.minecraft.world.level.block.state.StateDefinition;
16
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
17
import net.minecraft.world.level.block.state.properties.IntegerProperty;
18
import net.minecraft.world.level.block.state.properties.RotationSegment;
19
import net.minecraft.world.phys.shapes.CollisionContext;
20
import net.minecraft.world.phys.shapes.VoxelShape;
21
22
public class BannerBlock extends AbstractBannerBlock {
23
	public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
24
	private static final VoxelShape SHAPE = Block.column(8.0, 0.0, 16.0);
25
26
	public BannerBlock(final DyeColor color, final BlockBehaviour.Properties properties) {
27
		super(color, properties);
28
		this.registerDefaultState(this.stateDefinition.any().setValue(ROTATION, 8));
29
	}
30
31
	@Override
32
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
33
		return level.getBlockState(pos.below()).isSolid();
34
	}
35
36
	@Override
37
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
38
		return SHAPE;
39
	}
40
41
	@Override
42
	public BlockState getStateForPlacement(final BlockPlaceContext context) {
43
		return this.defaultBlockState().setValue(ROTATION, RotationSegment.convertToSegment(context.getRotation() + 180.0F));
44
	}
45
46
	@Override
47
	protected BlockState updateShape(
48
		final BlockState state,
49
		final LevelReader level,
50
		final ScheduledTickAccess ticks,
51
		final BlockPos pos,
52
		final Direction directionToNeighbour,
53
		final BlockPos neighbourPos,
54
		final BlockState neighbourState,
55
		final RandomSource random
56
	) {
57
		return directionToNeighbour == Direction.DOWN && !state.canSurvive(level, pos)
58
			? Blocks.AIR.defaultBlockState()
59
			: super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
60
	}
61
62
	@Override
63
	protected BlockState rotate(final BlockState state, final Rotation rotation) {
64
		return state.setValue(ROTATION, rotation.rotate(state.getValue(ROTATION), 16));
65
	}
66
67
	@Override
68
	protected BlockState mirror(final BlockState state, final Mirror mirror) {
69
		return state.setValue(ROTATION, mirror.mirror(state.getValue(ROTATION), 16));
70
	}
71
72
	@Override
73
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
74
		builder.add(ROTATION);
75
	}
76
77
	public enum AttachmentType implements StringRepresentable {
78
		WALL("wall"),
79
		GROUND("ground");
80
81
		public static final Codec<BannerBlock.AttachmentType> CODEC = StringRepresentable.fromEnum(BannerBlock.AttachmentType::values);
82
		private final String name;
83
84
		AttachmentType(final String name) {
85
			this.name = name;
86
		}
87
88
		@Override
89
		public String getSerializedName() {
90
			return this.name;
91
		}
92
	}
93
}
94

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