94 lines
4.0 KiB
Java
94 lines
4.0 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.material.FluidState;
|
|
import java.util.Iterator;
|
|
import net.minecraft.tags.FluidTags;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.LevelReader;
|
|
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.phys.shapes.VoxelShape;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
|
|
public class SugarCaneBlock extends Block {
|
|
public static final IntegerProperty AGE;
|
|
protected static final VoxelShape SHAPE;
|
|
|
|
protected SugarCaneBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Integer>setValue((Property<Comparable>)SugarCaneBlock.AGE, 0));
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return SugarCaneBlock.SHAPE;
|
|
}
|
|
|
|
@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);
|
|
}
|
|
else if (xd.isEmptyBlock(fk.above())) {
|
|
int integer6;
|
|
for (integer6 = 1; xd.getBlockState(fk.below(integer6)).getBlock() == this; ++integer6) {}
|
|
if (integer6 < 3) {
|
|
final int integer7 = byg.<Integer>getValue((Property<Integer>)SugarCaneBlock.AGE);
|
|
if (integer7 == 15) {
|
|
xd.setBlockAndUpdate(fk.above(), this.defaultBlockState());
|
|
xd.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Integer>setValue((Property<Comparable>)SugarCaneBlock.AGE, 0), 4);
|
|
}
|
|
else {
|
|
xd.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Integer>setValue((Property<Comparable>)SugarCaneBlock.AGE, integer7 + 1), 4);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@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);
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
|
|
final Block bpe5 = bjw.getBlockState(fk.below()).getBlock();
|
|
if (bpe5 == this) {
|
|
return true;
|
|
}
|
|
if (bpe5 == Blocks.GRASS_BLOCK || bpe5 == Blocks.DIRT || bpe5 == Blocks.COARSE_DIRT || bpe5 == Blocks.PODZOL || bpe5 == Blocks.SAND || bpe5 == Blocks.RED_SAND) {
|
|
final BlockPos fk2 = fk.below();
|
|
for (final Direction fp8 : Direction.Plane.HORIZONTAL) {
|
|
final BlockState byg2 = bjw.getBlockState(fk2.relative(fp8));
|
|
final FluidState cog10 = bjw.getFluidState(fk2.relative(fp8));
|
|
if (cog10.is(FluidTags.WATER) || byg2.getBlock() == Blocks.FROSTED_ICE) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(SugarCaneBlock.AGE);
|
|
}
|
|
|
|
static {
|
|
AGE = BlockStateProperties.AGE_15;
|
|
SHAPE = Block.box(2.0, 0.0, 2.0, 14.0, 16.0, 14.0);
|
|
}
|
|
}
|