LeafLitterBlock .java

net.minecraft.world.level.block.LeafLitterBlock (class, 67 lines): members: canBeReplaced, shapes, FACING, canSurvive, mirror, rotate, getShape.

net.minecraft.world.level.blockclass67 linescommonextends VegetationBlock2.7 KB

Implements

API Surface (7)

BlockState rotate(final BlockState state, final Rotation rotation)
BlockState mirror(final BlockState state, final Mirror mirror)
boolean canBeReplaced(final BlockState state, final BlockPlaceContext context)
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)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)

Fields & Constants (2)

FACING
shapes

Full Source

LeafLitterBlock.java67 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import java.util.function.Function;
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.LevelReader;
9
import net.minecraft.world.level.block.state.BlockBehaviour;
10
import net.minecraft.world.level.block.state.BlockState;
11
import net.minecraft.world.level.block.state.StateDefinition;
12
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
13
import net.minecraft.world.level.block.state.properties.EnumProperty;
14
import net.minecraft.world.phys.shapes.CollisionContext;
15
import net.minecraft.world.phys.shapes.VoxelShape;
16
17
public class LeafLitterBlock extends VegetationBlock implements SegmentableBlock {
18
	public static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;
19
	private final Function<BlockState, VoxelShape> shapes;
20
21
	public LeafLitterBlock(final BlockBehaviour.Properties properties) {
22
		super(properties);
23
		this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(this.getSegmentAmountProperty(), 1));
24
		this.shapes = this.makeShapes();
25
	}
26
27
	private Function<BlockState, VoxelShape> makeShapes() {
28
		return this.getShapeForEachState(this.getShapeCalculator(FACING, this.getSegmentAmountProperty()));
29
	}
30
31
	@Override
32
	public BlockState rotate(final BlockState state, final Rotation rotation) {
33
		return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
34
	}
35
36
	@Override
37
	public BlockState mirror(final BlockState state, final Mirror mirror) {
38
		return state.rotate(mirror.getRotation(state.getValue(FACING)));
39
	}
40
41
	@Override
42
	public boolean canBeReplaced(final BlockState state, final BlockPlaceContext context) {
43
		return this.canBeReplaced(state, context, this.getSegmentAmountProperty()) ? true : super.canBeReplaced(state, context);
44
	}
45
46
	@Override
47
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
48
		BlockPos belowPos = pos.below();
49
		return level.getBlockState(belowPos).isFaceSturdy(level, belowPos, Direction.UP);
50
	}
51
52
	@Override
53
	public VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
54
		return this.shapes.apply(state);
55
	}
56
57
	@Override
58
	public BlockState getStateForPlacement(final BlockPlaceContext context) {
59
		return this.getStateForPlacement(context, this, this.getSegmentAmountProperty(), FACING);
60
	}
61
62
	@Override
63
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
64
		builder.add(FACING, this.getSegmentAmountProperty());
65
	}
66
}
67

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