FlowerBedBlock .java

net.minecraft.world.level.block.FlowerBedBlock (class): members: getSegmentAmountProperty, getShapeHeight, shapeHeight, AMOUNT, canBeReplaced, shapes.

net.minecraft.world.level.blockclass105 linescommonextends VegetationBlock3.8 KB

Implements

API Surface (11)

BlockState rotate(final BlockState state, final Rotation rotation)
BlockState mirror(final BlockState state, final Mirror mirror)
boolean canBeReplaced(final BlockState state, final BlockPlaceContext context)
VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
double getShapeHeight()
IntegerProperty getSegmentAmountProperty()
BlockState getStateForPlacement(final BlockPlaceContext context)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source)
boolean isBonemealSuccess(final Level level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source)
void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source)

Fields & Constants (4)

FACING
AMOUNT
shapeHeight
shapes

Full Source

FlowerBedBlock.java105 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.server.level.ServerLevel;
7
import net.minecraft.util.RandomSource;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.item.context.BlockPlaceContext;
10
import net.minecraft.world.level.BlockGetter;
11
import net.minecraft.world.level.Level;
12
import net.minecraft.world.level.LevelReader;
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.EnumProperty;
18
import net.minecraft.world.level.block.state.properties.IntegerProperty;
19
import net.minecraft.world.phys.shapes.CollisionContext;
20
import net.minecraft.world.phys.shapes.VoxelShape;
21
22
/**
23
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
24
 */
25
public class FlowerBedBlock extends VegetationBlock implements BonemealableBlock, SegmentableBlock {
26
	public static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;
27
	public static final IntegerProperty AMOUNT = BlockStateProperties.FLOWER_AMOUNT;
28
	private final int shapeHeight;
29
	private final Function<BlockState, VoxelShape> shapes;
30
31
	/**
32
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
33
	 */
34
	public FlowerBedBlock(final BlockBehaviour.Properties properties, final int shapeHeight) {
35
		super(properties);
36
		this.shapeHeight = shapeHeight;
37
		this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(AMOUNT, 1));
38
		this.shapes = this.makeShapes();
39
	}
40
41
	private Function<BlockState, VoxelShape> makeShapes() {
42
		return this.getShapeForEachState(this.getShapeCalculator(FACING, AMOUNT));
43
	}
44
45
	@Override
46
	public BlockState rotate(final BlockState state, final Rotation rotation) {
47
		return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
48
	}
49
50
	@Override
51
	public BlockState mirror(final BlockState state, final Mirror mirror) {
52
		return state.rotate(mirror.getRotation(state.getValue(FACING)));
53
	}
54
55
	@Override
56
	public boolean canBeReplaced(final BlockState state, final BlockPlaceContext context) {
57
		return this.canBeReplaced(state, context, AMOUNT) ? true : super.canBeReplaced(state, context);
58
	}
59
60
	@Override
61
	public VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
62
		return this.shapes.apply(state);
63
	}
64
65
	@Override
66
	public double getShapeHeight() {
67
		return this.shapeHeight;
68
	}
69
70
	@Override
71
	public IntegerProperty getSegmentAmountProperty() {
72
		return AMOUNT;
73
	}
74
75
	@Override
76
	public BlockState getStateForPlacement(final BlockPlaceContext context) {
77
		return this.getStateForPlacement(context, this, AMOUNT, FACING);
78
	}
79
80
	@Override
81
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
82
		builder.add(FACING, AMOUNT);
83
	}
84
85
	@Override
86
	public boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source) {
87
		return true;
88
	}
89
90
	@Override
91
	public boolean isBonemealSuccess(final Level level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
92
		return true;
93
	}
94
95
	@Override
96
	public void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
97
		int currentAmount = state.getValue(AMOUNT);
98
		if (currentAmount < 4) {
99
			level.setBlock(pos, state.setValue(AMOUNT, currentAmount + 1), 2);
100
		} else {
101
			popResource(level, pos, new ItemStack(this));
102
		}
103
	}
104
}
105

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