| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import java.util.Optional;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.core.Holder;
|
| 6 | import net.minecraft.core.registries.Registries;
|
| 7 | import net.minecraft.resources.ResourceKey;
|
| 8 | import net.minecraft.server.level.ServerLevel;
|
| 9 | import net.minecraft.tags.TagKey;
|
| 10 | import net.minecraft.util.RandomSource;
|
| 11 | import net.minecraft.world.level.BlockGetter;
|
| 12 | import net.minecraft.world.level.Level;
|
| 13 | import net.minecraft.world.level.LevelReader;
|
| 14 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 15 | import net.minecraft.world.level.block.state.BlockState;
|
| 16 | import net.minecraft.world.level.levelgen.feature.Feature;
|
| 17 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 18 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 19 |
|
| 20 | /**
|
| 21 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 22 | */
|
| 23 | public class NetherFungusBlock extends VegetationBlock implements BonemealableBlock {
|
| 24 | private static final double BONEMEAL_SUCCESS_PROBABILITY = 0.4;
|
| 25 | private static final VoxelShape SHAPE = Block.column(8.0, 0.0, 9.0);
|
| 26 | private final Block requiredBlock;
|
| 27 | private final ResourceKey<Feature> feature;
|
| 28 | private final TagKey<Block> supportBlocks;
|
| 29 |
|
| 30 | /**
|
| 31 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 32 | */
|
| 33 | public NetherFungusBlock(
|
| 34 | final ResourceKey<Feature> feature, final Block requiredBlock, final TagKey<Block> supportBlocks, final BlockBehaviour.Properties properties
|
| 35 | ) {
|
| 36 | super(properties);
|
| 37 | this.feature = feature;
|
| 38 | this.requiredBlock = requiredBlock;
|
| 39 | this.supportBlocks = supportBlocks;
|
| 40 | }
|
| 41 |
|
| 42 | @Override
|
| 43 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 44 | return SHAPE;
|
| 45 | }
|
| 46 |
|
| 47 | @Override
|
| 48 | protected boolean mayPlaceOn(final BlockState state, final BlockGetter level, final BlockPos pos) {
|
| 49 | return state.is(this.supportBlocks);
|
| 50 | }
|
| 51 |
|
| 52 | private Optional<? extends Holder<Feature>> getFeature(final LevelReader level) {
|
| 53 | return level.registryAccess().lookupOrThrow(Registries.FEATURE).get(this.feature);
|
| 54 | }
|
| 55 |
|
| 56 | @Override
|
| 57 | public boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source) {
|
| 58 | BlockState belowState = level.getBlockState(pos.below());
|
| 59 | return belowState.is(this.requiredBlock) && level.isInsideBuildHeight(pos.above());
|
| 60 | }
|
| 61 |
|
| 62 | @Override
|
| 63 | public boolean isBonemealSuccess(final Level level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
|
| 64 | return random.nextFloat() < 0.4;
|
| 65 | }
|
| 66 |
|
| 67 | @Override
|
| 68 | public void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
|
| 69 | this.getFeature(level).ifPresent(feature -> feature.value().place(level, level.getChunkSource().getGenerator(), random, pos));
|
| 70 | }
|
| 71 | }
|
| 72 |
|