115 lines
4.8 KiB
Java
115 lines
4.8 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.pathfinder.PathComputationType;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.level.material.Material;
|
|
import java.util.Iterator;
|
|
import net.minecraft.tags.FluidTags;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import java.util.Random;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
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 CactusBlock extends Block {
|
|
public static final IntegerProperty AGE;
|
|
protected static final VoxelShape COLLISION_SHAPE;
|
|
protected static final VoxelShape OUTLINE_SHAPE;
|
|
|
|
protected CactusBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Integer>setValue((Property<Comparable>)CactusBlock.AGE, 0));
|
|
}
|
|
|
|
@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;
|
|
}
|
|
final BlockPos fk2 = fk.above();
|
|
if (!xd.isEmptyBlock(fk2)) {
|
|
return;
|
|
}
|
|
int integer7;
|
|
for (integer7 = 1; xd.getBlockState(fk.below(integer7)).getBlock() == this; ++integer7) {}
|
|
if (integer7 >= 3) {
|
|
return;
|
|
}
|
|
final int integer8 = byg.<Integer>getValue((Property<Integer>)CactusBlock.AGE);
|
|
if (integer8 == 15) {
|
|
xd.setBlockAndUpdate(fk2, this.defaultBlockState());
|
|
final BlockState byg2 = ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Integer>setValue((Property<Comparable>)CactusBlock.AGE, 0);
|
|
xd.setBlock(fk, byg2, 4);
|
|
byg2.neighborChanged(xd, fk2, this, fk, false);
|
|
}
|
|
else {
|
|
xd.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Integer>setValue((Property<Comparable>)CactusBlock.AGE, integer8 + 1), 4);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getCollisionShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return CactusBlock.COLLISION_SHAPE;
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return CactusBlock.OUTLINE_SHAPE;
|
|
}
|
|
|
|
@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) {
|
|
for (final Direction fp6 : Direction.Plane.HORIZONTAL) {
|
|
final BlockState byg2 = bjw.getBlockState(fk.relative(fp6));
|
|
final Material cok8 = byg2.getMaterial();
|
|
if (cok8.isSolid() || bjw.getFluidState(fk.relative(fp6)).is(FluidTags.LAVA)) {
|
|
return false;
|
|
}
|
|
}
|
|
final Block bpe5 = bjw.getBlockState(fk.below()).getBlock();
|
|
return (bpe5 == Blocks.CACTUS || bpe5 == Blocks.SAND || bpe5 == Blocks.RED_SAND) && !bjw.getBlockState(fk.above()).getMaterial().isLiquid();
|
|
}
|
|
|
|
@Override
|
|
public void entityInside(final BlockState byg, final Level bjt, final BlockPos fk, final Entity akn) {
|
|
akn.hurt(DamageSource.CACTUS, 1.0f);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(CactusBlock.AGE);
|
|
}
|
|
|
|
@Override
|
|
public boolean isPathfindable(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final PathComputationType cqo) {
|
|
return false;
|
|
}
|
|
|
|
static {
|
|
AGE = BlockStateProperties.AGE_15;
|
|
COLLISION_SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 15.0, 15.0);
|
|
OUTLINE_SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 16.0, 15.0);
|
|
}
|
|
}
|