minecraft-source/src/net/minecraft/world/level/block/SpreadingSnowyDirtBlock.java

52 lines
2.4 KiB
Java

package net.minecraft.world.level.block;
import net.minecraft.world.level.block.state.AbstractStateHolder;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.level.lighting.LayerLightEngine;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.state.BlockState;
public abstract class SpreadingSnowyDirtBlock extends SnowyDirtBlock {
protected SpreadingSnowyDirtBlock(final Properties c) {
super(c);
}
private static boolean canBeGrass(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
final BlockPos fk2 = fk.above();
final BlockState byg2 = bjw.getBlockState(fk2);
if (byg2.getBlock() == Blocks.SNOW && byg2.<Integer>getValue((Property<Integer>)SnowLayerBlock.LAYERS) == 1) {
return true;
}
final int integer6 = LayerLightEngine.getLightBlockInto(bjw, byg, fk, byg2, fk2, Direction.UP, byg2.getLightBlock(bjw, fk2));
return integer6 < bjw.getMaxLightLevel();
}
private static boolean canPropagate(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
final BlockPos fk2 = fk.above();
return canBeGrass(byg, bjw, fk) && !bjw.getFluidState(fk2).is(FluidTags.WATER);
}
@Override
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
if (!canBeGrass(byg, xd, fk)) {
xd.setBlockAndUpdate(fk, Blocks.DIRT.defaultBlockState());
return;
}
if (xd.getMaxLocalRawBrightness(fk.above()) >= 9) {
final BlockState byg2 = this.defaultBlockState();
for (int integer7 = 0; integer7 < 4; ++integer7) {
final BlockPos fk2 = fk.offset(random.nextInt(3) - 1, random.nextInt(5) - 3, random.nextInt(3) - 1);
if (xd.getBlockState(fk2).getBlock() == Blocks.DIRT && canPropagate(byg2, xd, fk2)) {
xd.setBlockAndUpdate(fk2, ((AbstractStateHolder<O, BlockState>)byg2).<Comparable, Boolean>setValue((Property<Comparable>)SpreadingSnowyDirtBlock.SNOWY, xd.getBlockState(fk2.above()).getBlock() == Blocks.SNOW));
}
}
}
}
}