211 lines
10 KiB
Java
211 lines
10 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.item.SwordItem;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import java.util.Random;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.tags.BlockTags;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.level.pathfinder.PathComputationType;
|
|
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.StateDefinition;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.properties.BambooLeaves;
|
|
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
public class BambooBlock extends Block implements BonemealableBlock {
|
|
protected static final VoxelShape SMALL_SHAPE;
|
|
protected static final VoxelShape LARGE_SHAPE;
|
|
protected static final VoxelShape COLLISION_SHAPE;
|
|
public static final IntegerProperty AGE;
|
|
public static final EnumProperty<BambooLeaves> LEAVES;
|
|
public static final IntegerProperty STAGE;
|
|
|
|
public BambooBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)BambooBlock.AGE, 0)).setValue(BambooBlock.LEAVES, BambooLeaves.NONE)).<Comparable, Integer>setValue((Property<Comparable>)BambooBlock.STAGE, 0));
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(BambooBlock.AGE, BambooBlock.LEAVES, BambooBlock.STAGE);
|
|
}
|
|
|
|
@Override
|
|
public OffsetType getOffsetType() {
|
|
return OffsetType.XZ;
|
|
}
|
|
|
|
@Override
|
|
public boolean propagatesSkylightDown(final BlockState byg, final BlockGetter bjd, final BlockPos fk) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
final VoxelShape cwc6 = (byg.<BambooLeaves>getValue(BambooBlock.LEAVES) == BambooLeaves.LARGE) ? BambooBlock.LARGE_SHAPE : BambooBlock.SMALL_SHAPE;
|
|
final Vec3 cvi7 = byg.getOffset(bjd, fk);
|
|
return cwc6.move(cvi7.x, cvi7.y, cvi7.z);
|
|
}
|
|
|
|
@Override
|
|
public boolean isPathfindable(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final PathComputationType cqo) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getCollisionShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
final Vec3 cvi6 = byg.getOffset(bjd, fk);
|
|
return BambooBlock.COLLISION_SHAPE.move(cvi6.x, cvi6.y, cvi6.z);
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
final FluidState cog3 = bcn.getLevel().getFluidState(bcn.getClickedPos());
|
|
if (!cog3.isEmpty()) {
|
|
return null;
|
|
}
|
|
final BlockState byg4 = bcn.getLevel().getBlockState(bcn.getClickedPos().below());
|
|
if (!byg4.is(BlockTags.BAMBOO_PLANTABLE_ON)) {
|
|
return null;
|
|
}
|
|
final Block bpe5 = byg4.getBlock();
|
|
if (bpe5 == Blocks.BAMBOO_SAPLING) {
|
|
return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Integer>setValue((Property<Comparable>)BambooBlock.AGE, 0);
|
|
}
|
|
if (bpe5 == Blocks.BAMBOO) {
|
|
final int integer6 = (byg4.<Integer>getValue((Property<Integer>)BambooBlock.AGE) > 0) ? 1 : 0;
|
|
return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Integer>setValue((Property<Comparable>)BambooBlock.AGE, integer6);
|
|
}
|
|
return Blocks.BAMBOO_SAPLING.defaultBlockState();
|
|
}
|
|
|
|
@Override
|
|
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
|
|
if (!byg.canSurvive(xd, fk)) {
|
|
xd.destroyBlock(fk, true);
|
|
return;
|
|
}
|
|
if (byg.<Integer>getValue((Property<Integer>)BambooBlock.STAGE) != 0) {
|
|
return;
|
|
}
|
|
if (random.nextInt(3) == 0 && xd.isEmptyBlock(fk.above()) && xd.getRawBrightness(fk.above(), 0) >= 9) {
|
|
final int integer6 = this.getHeightBelowUpToMax(xd, fk) + 1;
|
|
if (integer6 < 16) {
|
|
this.growBamboo(byg, xd, fk, random, integer6);
|
|
}
|
|
}
|
|
}
|
|
|
|
@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)) {
|
|
bju.getBlockTicks().scheduleTick(fk5, this, 1);
|
|
}
|
|
if (fp == Direction.UP && byg3.getBlock() == Blocks.BAMBOO && byg3.<Integer>getValue((Property<Integer>)BambooBlock.AGE) > byg1.<Integer>getValue((Property<Integer>)BambooBlock.AGE)) {
|
|
bju.setBlock(fk5, ((AbstractStateHolder<O, BlockState>)byg1).<Comparable>cycle((Property<Comparable>)BambooBlock.AGE), 2);
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidBonemealTarget(final BlockGetter bjd, final BlockPos fk, final BlockState byg, final boolean boolean4) {
|
|
final int integer6 = this.getHeightAboveUpToMax(bjd, fk);
|
|
final int integer7 = this.getHeightBelowUpToMax(bjd, fk);
|
|
return integer6 + integer7 + 1 < 16 && bjd.getBlockState(fk.above(integer6)).<Integer>getValue((Property<Integer>)BambooBlock.STAGE) != 1;
|
|
}
|
|
|
|
@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) {
|
|
int integer6 = this.getHeightAboveUpToMax(xd, fk);
|
|
final int integer7 = this.getHeightBelowUpToMax(xd, fk);
|
|
int integer8 = integer6 + integer7 + 1;
|
|
for (int integer9 = 1 + random.nextInt(2), integer10 = 0; integer10 < integer9; ++integer10) {
|
|
final BlockPos fk2 = fk.above(integer6);
|
|
final BlockState byg2 = xd.getBlockState(fk2);
|
|
if (integer8 >= 16 || byg2.<Integer>getValue((Property<Integer>)BambooBlock.STAGE) == 1 || !xd.isEmptyBlock(fk2.above())) {
|
|
return;
|
|
}
|
|
this.growBamboo(byg2, xd, fk2, random, integer8);
|
|
++integer6;
|
|
++integer8;
|
|
}
|
|
}
|
|
|
|
@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 BlockState byg, final Level bjt, final BlockPos fk, final Random random, final int integer) {
|
|
final BlockState byg2 = bjt.getBlockState(fk.below());
|
|
final BlockPos fk2 = fk.below(2);
|
|
final BlockState byg3 = bjt.getBlockState(fk2);
|
|
BambooLeaves byu10 = BambooLeaves.NONE;
|
|
if (integer >= 1) {
|
|
if (byg2.getBlock() != Blocks.BAMBOO || byg2.<BambooLeaves>getValue(BambooBlock.LEAVES) == BambooLeaves.NONE) {
|
|
byu10 = BambooLeaves.SMALL;
|
|
}
|
|
else if (byg2.getBlock() == Blocks.BAMBOO && byg2.<BambooLeaves>getValue(BambooBlock.LEAVES) != BambooLeaves.NONE) {
|
|
byu10 = BambooLeaves.LARGE;
|
|
if (byg3.getBlock() == Blocks.BAMBOO) {
|
|
bjt.setBlock(fk.below(), ((AbstractStateHolder<O, BlockState>)byg2).<BambooLeaves, BambooLeaves>setValue(BambooBlock.LEAVES, BambooLeaves.SMALL), 3);
|
|
bjt.setBlock(fk2, ((AbstractStateHolder<O, BlockState>)byg3).<BambooLeaves, BambooLeaves>setValue(BambooBlock.LEAVES, BambooLeaves.NONE), 3);
|
|
}
|
|
}
|
|
}
|
|
final int integer2 = (byg.<Integer>getValue((Property<Integer>)BambooBlock.AGE) == 1 || byg3.getBlock() == Blocks.BAMBOO) ? 1 : 0;
|
|
final int integer3 = ((integer >= 11 && random.nextFloat() < 0.25f) || integer == 15) ? 1 : 0;
|
|
bjt.setBlock(fk.above(), ((((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue((Property<Comparable>)BambooBlock.AGE, integer2)).setValue(BambooBlock.LEAVES, byu10)).<Comparable, Integer>setValue((Property<Comparable>)BambooBlock.STAGE, integer3), 3);
|
|
}
|
|
|
|
protected int getHeightAboveUpToMax(final BlockGetter bjd, final BlockPos fk) {
|
|
int integer4;
|
|
for (integer4 = 0; integer4 < 16 && bjd.getBlockState(fk.above(integer4 + 1)).getBlock() == Blocks.BAMBOO; ++integer4) {}
|
|
return integer4;
|
|
}
|
|
|
|
protected int getHeightBelowUpToMax(final BlockGetter bjd, final BlockPos fk) {
|
|
int integer4;
|
|
for (integer4 = 0; integer4 < 16 && bjd.getBlockState(fk.below(integer4 + 1)).getBlock() == Blocks.BAMBOO; ++integer4) {}
|
|
return integer4;
|
|
}
|
|
|
|
static {
|
|
SMALL_SHAPE = Block.box(5.0, 0.0, 5.0, 11.0, 16.0, 11.0);
|
|
LARGE_SHAPE = Block.box(3.0, 0.0, 3.0, 13.0, 16.0, 13.0);
|
|
COLLISION_SHAPE = Block.box(6.5, 0.0, 6.5, 9.5, 16.0, 9.5);
|
|
AGE = BlockStateProperties.AGE_1;
|
|
LEAVES = BlockStateProperties.BAMBOO_LEAVES;
|
|
STAGE = BlockStateProperties.STAGE;
|
|
}
|
|
}
|