package net.minecraft.world.level.block; import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.RandomSource; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.ScheduledTickAccess; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; /** * Access widened by fabric-transitive-access-wideners-v1 to accessible */ public class DirtPathBlock extends Block { public static final MapCodec CODEC = simpleCodec(DirtPathBlock::new); private static final VoxelShape SHAPE = Block.column(16.0, 0.0, 15.0); @Override public MapCodec codec() { return CODEC; } /** * Access widened by fabric-transitive-access-wideners-v1 to accessible */ public DirtPathBlock(final BlockBehaviour.Properties properties) { super(properties); } @Override protected boolean useShapeForLightOcclusion(final BlockState state) { return true; } @Override public BlockState getStateForPlacement(final BlockPlaceContext context) { return !this.defaultBlockState().canSurvive(context.getLevel(), context.getClickedPos()) ? Block.pushEntitiesUp(this.defaultBlockState(), Blocks.DIRT.defaultBlockState(), context.getLevel(), context.getClickedPos()) : super.getStateForPlacement(context); } @Override protected BlockState updateShape( final BlockState state, final LevelReader level, final ScheduledTickAccess ticks, final BlockPos pos, final Direction directionToNeighbour, final BlockPos neighbourPos, final BlockState neighbourState, final RandomSource random ) { if (directionToNeighbour == Direction.UP && !state.canSurvive(level, pos)) { ticks.scheduleTick(pos, this, 1); } return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random); } @Override protected void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) { FarmlandBlock.turnToDirt(null, state, level, pos); } @Override protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) { BlockState aboveState = level.getBlockState(pos.above()); return !aboveState.isSolid() || aboveState.getBlock() instanceof FenceGateBlock; } @Override protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) { return SHAPE; } @Override protected boolean isPathfindable(final BlockState state, final PathComputationType type) { return false; } }