57 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| 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.tags.FluidTags;
 | |
| import net.minecraft.util.RandomSource;
 | |
| import net.minecraft.world.level.LevelReader;
 | |
| import net.minecraft.world.level.block.state.BlockBehaviour;
 | |
| import net.minecraft.world.level.block.state.BlockState;
 | |
| import net.minecraft.world.level.lighting.LightEngine;
 | |
| 
 | |
| public abstract class SpreadingSnowyDirtBlock extends SnowyDirtBlock {
 | |
| 	protected SpreadingSnowyDirtBlock(BlockBehaviour.Properties properties) {
 | |
| 		super(properties);
 | |
| 	}
 | |
| 
 | |
| 	private static boolean canBeGrass(BlockState state, LevelReader levelReader, BlockPos pos) {
 | |
| 		BlockPos blockPos = pos.above();
 | |
| 		BlockState blockState = levelReader.getBlockState(blockPos);
 | |
| 		if (blockState.is(Blocks.SNOW) && (Integer)blockState.getValue(SnowLayerBlock.LAYERS) == 1) {
 | |
| 			return true;
 | |
| 		} else if (blockState.getFluidState().getAmount() == 8) {
 | |
| 			return false;
 | |
| 		} else {
 | |
| 			int i = LightEngine.getLightBlockInto(state, blockState, Direction.UP, blockState.getLightBlock());
 | |
| 			return i < 15;
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	protected abstract MapCodec<? extends SpreadingSnowyDirtBlock> codec();
 | |
| 
 | |
| 	private static boolean canPropagate(BlockState state, LevelReader level, BlockPos pos) {
 | |
| 		BlockPos blockPos = pos.above();
 | |
| 		return canBeGrass(state, level, pos) && !level.getFluidState(blockPos).is(FluidTags.WATER);
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
 | |
| 		if (!canBeGrass(state, level, pos)) {
 | |
| 			level.setBlockAndUpdate(pos, Blocks.DIRT.defaultBlockState());
 | |
| 		} else {
 | |
| 			if (level.getMaxLocalRawBrightness(pos.above()) >= 9) {
 | |
| 				BlockState blockState = this.defaultBlockState();
 | |
| 
 | |
| 				for (int i = 0; i < 4; i++) {
 | |
| 					BlockPos blockPos = pos.offset(random.nextInt(3) - 1, random.nextInt(5) - 3, random.nextInt(3) - 1);
 | |
| 					if (level.getBlockState(blockPos).is(Blocks.DIRT) && canPropagate(blockState, level, blockPos)) {
 | |
| 						level.setBlockAndUpdate(blockPos, blockState.setValue(SNOWY, isSnowySetting(level.getBlockState(blockPos.above()))));
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| }
 |