102 lines
3.9 KiB
Java
102 lines
3.9 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.block.state.properties.BambooLeaves;
|
|
import net.minecraft.world.item.SwordItem;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.level.ItemLike;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.tags.BlockTags;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.Level;
|
|
import java.util.Random;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.world.phys.Vec3;
|
|
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.BlockState;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
public class BambooSaplingBlock extends Block implements BonemealableBlock {
|
|
protected static final VoxelShape SAPLING_SHAPE;
|
|
|
|
public BambooSaplingBlock(final Properties c) {
|
|
super(c);
|
|
}
|
|
|
|
@Override
|
|
public OffsetType getOffsetType() {
|
|
return OffsetType.XZ;
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
final Vec3 cvi6 = byg.getOffset(bjd, fk);
|
|
return BambooSaplingBlock.SAPLING_SHAPE.move(cvi6.x, cvi6.y, cvi6.z);
|
|
}
|
|
|
|
@Override
|
|
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
|
|
if (random.nextInt(3) == 0 && xd.isEmptyBlock(fk.above()) && xd.getRawBrightness(fk.above(), 0) >= 9) {
|
|
this.growBamboo(xd, fk);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
|
|
return bjw.getBlockState(fk.below()).is(BlockTags.BAMBOO_PLANTABLE_ON);
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (!byg1.canSurvive(bju, fk5)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
if (fp == Direction.UP && byg3.getBlock() == Blocks.BAMBOO) {
|
|
bju.setBlock(fk5, Blocks.BAMBOO.defaultBlockState(), 2);
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getCloneItemStack(final BlockGetter bjd, final BlockPos fk, final BlockState byg) {
|
|
return new ItemStack(Items.BAMBOO);
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidBonemealTarget(final BlockGetter bjd, final BlockPos fk, final BlockState byg, final boolean boolean4) {
|
|
return bjd.getBlockState(fk.above()).isAir();
|
|
}
|
|
|
|
@Override
|
|
public boolean isBonemealSuccess(final Level bjt, final Random random, final BlockPos fk, final BlockState byg) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void performBonemeal(final ServerLevel xd, final Random random, final BlockPos fk, final BlockState byg) {
|
|
this.growBamboo(xd, fk);
|
|
}
|
|
|
|
@Override
|
|
public float getDestroyProgress(final BlockState byg, final Player ayg, final BlockGetter bjd, final BlockPos fk) {
|
|
if (ayg.getMainHandItem().getItem() instanceof SwordItem) {
|
|
return 1.0f;
|
|
}
|
|
return super.getDestroyProgress(byg, ayg, bjd, fk);
|
|
}
|
|
|
|
protected void growBamboo(final Level bjt, final BlockPos fk) {
|
|
bjt.setBlock(fk.above(), ((AbstractStateHolder<O, BlockState>)Blocks.BAMBOO.defaultBlockState()).<BambooLeaves, BambooLeaves>setValue(BambooBlock.LEAVES, BambooLeaves.SMALL), 3);
|
|
}
|
|
|
|
static {
|
|
SAPLING_SHAPE = Block.box(4.0, 0.0, 4.0, 12.0, 12.0, 12.0);
|
|
}
|
|
}
|