77 lines
3.1 KiB
Java
77 lines
3.1 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import java.util.Random;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.grower.AbstractTreeGrower;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
|
|
public class SaplingBlock extends BushBlock implements BonemealableBlock {
|
|
public static final IntegerProperty STAGE;
|
|
protected static final VoxelShape SHAPE;
|
|
private final AbstractTreeGrower treeGrower;
|
|
|
|
protected SaplingBlock(final AbstractTreeGrower bxp, final Properties c) {
|
|
super(c);
|
|
this.treeGrower = bxp;
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Integer>setValue((Property<Comparable>)SaplingBlock.STAGE, 0));
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return SaplingBlock.SHAPE;
|
|
}
|
|
|
|
@Override
|
|
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
|
|
super.tick(byg, xd, fk, random);
|
|
if (xd.getMaxLocalRawBrightness(fk.above()) >= 9 && random.nextInt(7) == 0) {
|
|
this.advanceTree(xd, fk, byg, random);
|
|
}
|
|
}
|
|
|
|
public void advanceTree(final ServerLevel xd, final BlockPos fk, final BlockState byg, final Random random) {
|
|
if (byg.<Integer>getValue((Property<Integer>)SaplingBlock.STAGE) == 0) {
|
|
xd.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable>cycle((Property<Comparable>)SaplingBlock.STAGE), 4);
|
|
}
|
|
else {
|
|
this.treeGrower.growTree(xd, xd.getChunkSource().getGenerator(), fk, byg, random);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidBonemealTarget(final BlockGetter bjd, final BlockPos fk, final BlockState byg, final boolean boolean4) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isBonemealSuccess(final Level bjt, final Random random, final BlockPos fk, final BlockState byg) {
|
|
return bjt.random.nextFloat() < 0.45;
|
|
}
|
|
|
|
@Override
|
|
public void performBonemeal(final ServerLevel xd, final Random random, final BlockPos fk, final BlockState byg) {
|
|
this.advanceTree(xd, fk, byg, random);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(SaplingBlock.STAGE);
|
|
}
|
|
|
|
static {
|
|
STAGE = BlockStateProperties.STAGE;
|
|
SHAPE = Block.box(2.0, 0.0, 2.0, 14.0, 12.0, 14.0);
|
|
}
|
|
}
|