package net.minecraft.world.level.block; import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.tags.BlockTags; import net.minecraft.util.RandomSource; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; public class DryVegetationBlock extends VegetationBlock { public static final MapCodec CODEC = simpleCodec(DryVegetationBlock::new); private static final VoxelShape SHAPE = Block.column(12.0, 0.0, 13.0); private static final int IDLE_SOUND_CHANCE = 150; private static final int IDLE_SOUND_BADLANDS_DECREASED_CHANCE = 5; @Override public MapCodec codec() { return CODEC; } protected DryVegetationBlock(BlockBehaviour.Properties properties) { super(properties); } @Override protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { return SHAPE; } @Override protected boolean mayPlaceOn(BlockState state, BlockGetter level, BlockPos pos) { return state.is(BlockTags.DRY_VEGETATION_MAY_PLACE_ON); } @Override public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) { if (random.nextInt(150) == 0) { BlockState blockState = level.getBlockState(pos.below()); if ((blockState.is(Blocks.RED_SAND) || blockState.is(BlockTags.TERRACOTTA)) && random.nextInt(5) != 0) { return; } BlockState blockState2 = level.getBlockState(pos.below(2)); if (blockState.is(BlockTags.PLAYS_AMBIENT_DESERT_BLOCK_SOUNDS) && blockState2.is(BlockTags.PLAYS_AMBIENT_DESERT_BLOCK_SOUNDS)) { level.playLocalSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.DEAD_BUSH_IDLE, SoundSource.AMBIENT, 1.0F, 1.0F, false); } } } }