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

113 lines
4.4 KiB
Java

package net.minecraft.world.level.block;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.levelgen.feature.configurations.HugeMushroomFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.ChunkGeneratorSettings;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.biome.BiomeDefaultFeatures;
import net.minecraft.world.level.levelgen.feature.Feature;
import java.util.Iterator;
import net.minecraft.world.level.LevelReader;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;
public class MushroomBlock extends BushBlock implements BonemealableBlock {
protected static final VoxelShape SHAPE;
public MushroomBlock(final Properties c) {
super(c);
}
@Override
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
return MushroomBlock.SHAPE;
}
@Override
public void tick(final BlockState byg, final ServerLevel xd, BlockPos fk, final Random random) {
if (random.nextInt(25) == 0) {
int integer6 = 5;
final int integer7 = 4;
for (final BlockPos fk2 : BlockPos.betweenClosed(fk.offset(-4, -1, -4), fk.offset(4, 1, 4))) {
if (xd.getBlockState(fk2).getBlock() == this && --integer6 <= 0) {
return;
}
}
BlockPos fk3 = fk.offset(random.nextInt(3) - 1, random.nextInt(2) - random.nextInt(2), random.nextInt(3) - 1);
for (int integer8 = 0; integer8 < 4; ++integer8) {
if (xd.isEmptyBlock(fk3) && byg.canSurvive(xd, fk3)) {
fk = fk3;
}
fk3 = fk.offset(random.nextInt(3) - 1, random.nextInt(2) - random.nextInt(2), random.nextInt(3) - 1);
}
if (xd.isEmptyBlock(fk3) && byg.canSurvive(xd, fk3)) {
xd.setBlock(fk3, byg, 2);
}
}
}
@Override
protected boolean mayPlaceOn(final BlockState byg, final BlockGetter bjd, final BlockPos fk) {
return byg.isSolidRender(bjd, fk);
}
@Override
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
final BlockPos fk2 = fk.below();
final BlockState byg2 = bjw.getBlockState(fk2);
final Block bpe7 = byg2.getBlock();
return bpe7 == Blocks.MYCELIUM || bpe7 == Blocks.PODZOL || (bjw.getRawBrightness(fk, 0) < 13 && this.mayPlaceOn(byg2, bjw, fk2));
}
public boolean growMushroom(final ServerLevel xd, final BlockPos fk, final BlockState byg, final Random random) {
xd.removeBlock(fk, false);
ConfiguredFeature<HugeMushroomFeatureConfiguration, ?> ccz6;
if (this == Blocks.BROWN_MUSHROOM) {
ccz6 = Feature.HUGE_BROWN_MUSHROOM.configured(BiomeDefaultFeatures.HUGE_BROWN_MUSHROOM_CONFIG);
}
else {
if (this != Blocks.RED_MUSHROOM) {
xd.setBlock(fk, byg, 3);
return false;
}
ccz6 = Feature.HUGE_RED_MUSHROOM.configured(BiomeDefaultFeatures.HUGE_RED_MUSHROOM_CONFIG);
}
if (ccz6.place(xd, xd.getChunkSource().getGenerator(), random, fk)) {
return true;
}
xd.setBlock(fk, byg, 3);
return false;
}
@Override
public boolean isValidBonemealTarget(final BlockGetter bjd, final BlockPos fk, final BlockState byg, final boolean boolean4) {
return true;
}
@Override
public boolean isBonemealSuccess(final Level bjt, final Random random, final BlockPos fk, final BlockState byg) {
return random.nextFloat() < 0.4;
}
@Override
public void performBonemeal(final ServerLevel xd, final Random random, final BlockPos fk, final BlockState byg) {
this.growMushroom(xd, fk, byg, random);
}
@Override
public boolean hasPostProcess(final BlockState byg, final BlockGetter bjd, final BlockPos fk) {
return true;
}
static {
SHAPE = Block.box(5.0, 0.0, 5.0, 11.0, 6.0, 11.0);
}
}