2025-11-24 22:52:51 +03:00

122 lines
4.3 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.serialization.MapCodec
*/
package net.minecraft.world.level.block;
import com.mojang.serialization.MapCodec;
import java.util.function.Function;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SegmentableBlock;
import net.minecraft.world.level.block.VegetationBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
public class FlowerBedBlock
extends VegetationBlock
implements BonemealableBlock,
SegmentableBlock {
public static final MapCodec<FlowerBedBlock> CODEC = FlowerBedBlock.simpleCodec(FlowerBedBlock::new);
public static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final IntegerProperty AMOUNT = BlockStateProperties.FLOWER_AMOUNT;
private final Function<BlockState, VoxelShape> shapes;
public MapCodec<FlowerBedBlock> codec() {
return CODEC;
}
protected FlowerBedBlock(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState((BlockState)((BlockState)((BlockState)this.stateDefinition.any()).setValue(FACING, Direction.NORTH)).setValue(AMOUNT, 1));
this.shapes = this.makeShapes();
}
private Function<BlockState, VoxelShape> makeShapes() {
return this.getShapeForEachState(this.getShapeCalculator(FACING, AMOUNT));
}
@Override
public BlockState rotate(BlockState state, Rotation rotation) {
return (BlockState)state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
}
@Override
public BlockState mirror(BlockState state, Mirror mirror) {
return state.rotate(mirror.getRotation(state.getValue(FACING)));
}
@Override
public boolean canBeReplaced(BlockState state, BlockPlaceContext context) {
if (this.canBeReplaced(state, context, AMOUNT)) {
return true;
}
return super.canBeReplaced(state, context);
}
@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return this.shapes.apply(state);
}
@Override
public double getShapeHeight() {
return 3.0;
}
@Override
public IntegerProperty getSegmentAmountProperty() {
return AMOUNT;
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.getStateForPlacement(context, this, AMOUNT, FACING);
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, AMOUNT);
}
@Override
public boolean isValidBonemealTarget(LevelReader level, BlockPos pos, BlockState state) {
return true;
}
@Override
public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state) {
return true;
}
@Override
public void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, BlockState state) {
int currentAmount = state.getValue(AMOUNT);
if (currentAmount < 4) {
level.setBlock(pos, (BlockState)state.setValue(AMOUNT, currentAmount + 1), 2);
} else {
FlowerBedBlock.popResource((Level)level, pos, new ItemStack(this));
}
}
}