79 lines
3.3 KiB
Java
79 lines
3.3 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import java.util.List;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
|
import net.minecraft.world.level.levelgen.feature.AbstractFlowerFeature;
|
|
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
|
import net.minecraft.world.level.levelgen.feature.configurations.DecoratedFeatureConfiguration;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import java.util.Random;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
|
|
public class GrassBlock extends SpreadingSnowyDirtBlock implements BonemealableBlock {
|
|
public GrassBlock(final Properties c) {
|
|
super(c);
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidBonemealTarget(final BlockGetter bjd, final BlockPos fk, final BlockState byg, final boolean boolean4) {
|
|
return bjd.getBlockState(fk.above()).isAir();
|
|
}
|
|
|
|
@Override
|
|
public boolean isBonemealSuccess(final Level bjt, final Random random, final BlockPos fk, final BlockState byg) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void performBonemeal(final ServerLevel xd, final Random random, final BlockPos fk, final BlockState byg) {
|
|
final BlockPos fk2 = fk.above();
|
|
final BlockState byg2 = Blocks.GRASS.defaultBlockState();
|
|
int integer8 = 0;
|
|
Label_0282_Outer:
|
|
while (integer8 < 128) {
|
|
BlockPos fk3 = fk2;
|
|
int integer9 = 0;
|
|
while (true) {
|
|
while (integer9 < integer8 / 16) {
|
|
fk3 = fk3.offset(random.nextInt(3) - 1, (random.nextInt(3) - 1) * random.nextInt(3) / 2, random.nextInt(3) - 1);
|
|
if (xd.getBlockState(fk3.below()).getBlock() == this) {
|
|
if (!xd.getBlockState(fk3).isCollisionShapeFullBlock(xd, fk3)) {
|
|
++integer9;
|
|
continue Label_0282_Outer;
|
|
}
|
|
}
|
|
++integer8;
|
|
continue Label_0282_Outer;
|
|
}
|
|
final BlockState byg3 = xd.getBlockState(fk3);
|
|
if (byg3.getBlock() == byg2.getBlock() && random.nextInt(10) == 0) {
|
|
((BonemealableBlock)byg2.getBlock()).performBonemeal(xd, random, fk3, byg3);
|
|
}
|
|
if (!byg3.isAir()) {
|
|
continue;
|
|
}
|
|
BlockState byg4;
|
|
if (random.nextInt(8) == 0) {
|
|
final List<ConfiguredFeature<?, ?>> list12 = xd.getBiome(fk3).getFlowerFeatures();
|
|
if (list12.isEmpty()) {
|
|
continue;
|
|
}
|
|
final ConfiguredFeature<?, ?> ccz13 = ((DecoratedFeatureConfiguration)list12.get(0).config).feature;
|
|
byg4 = ((AbstractFlowerFeature)ccz13.feature).getRandomFlower(random, fk3, (FeatureConfiguration)ccz13.config);
|
|
}
|
|
else {
|
|
byg4 = byg2;
|
|
}
|
|
if (byg4.canSurvive(xd, fk3)) {
|
|
xd.setBlock(fk3, byg4, 3);
|
|
}
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|