| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Direction;
|
| 5 | import net.minecraft.core.Registry;
|
| 6 | import net.minecraft.core.registries.Registries;
|
| 7 | import net.minecraft.data.worldgen.features.NetherFeatures;
|
| 8 | import net.minecraft.resources.ResourceKey;
|
| 9 | import net.minecraft.server.level.ServerLevel;
|
| 10 | import net.minecraft.util.RandomSource;
|
| 11 | import net.minecraft.world.level.Level;
|
| 12 | import net.minecraft.world.level.LevelReader;
|
| 13 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 14 | import net.minecraft.world.level.block.state.BlockState;
|
| 15 | import net.minecraft.world.level.chunk.ChunkGenerator;
|
| 16 | import net.minecraft.world.level.levelgen.feature.Feature;
|
| 17 | import net.minecraft.world.level.lighting.LightEngine;
|
| 18 |
|
| 19 | /**
|
| 20 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 21 | */
|
| 22 | public class NyliumBlock extends Block implements BonemealableBlock {
|
| 23 | /**
|
| 24 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 25 | */
|
| 26 | public NyliumBlock(final BlockBehaviour.Properties properties) {
|
| 27 | super(properties);
|
| 28 | }
|
| 29 |
|
| 30 | private static boolean canBeNylium(final BlockState state, final LevelReader level, final BlockPos pos) {
|
| 31 | BlockPos above = pos.above();
|
| 32 | BlockState aboveState = level.getBlockState(above);
|
| 33 | int lightDampeningTopFace = LightEngine.getLightDampeningInto(state, aboveState, Direction.UP, aboveState.getLightDampening());
|
| 34 | return lightDampeningTopFace < 15;
|
| 35 | }
|
| 36 |
|
| 37 | @Override
|
| 38 | protected void randomTick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
|
| 39 | if (!canBeNylium(state, level, pos)) {
|
| 40 | level.setBlockAndUpdate(pos, Blocks.NETHERRACK.defaultBlockState());
|
| 41 | }
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | public boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source) {
|
| 46 | return level.getBlockState(pos.above()).isAir() && level.isInsideBuildHeight(pos.above());
|
| 47 | }
|
| 48 |
|
| 49 | @Override
|
| 50 | public boolean isBonemealSuccess(final Level level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
|
| 51 | return true;
|
| 52 | }
|
| 53 |
|
| 54 | @Override
|
| 55 | public void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
|
| 56 | BlockPos abovePos = pos.above();
|
| 57 | ChunkGenerator generator = level.getChunkSource().getGenerator();
|
| 58 | Registry<Feature> configuredFeatures = level.registryAccess().lookupOrThrow(Registries.FEATURE);
|
| 59 | this.place(configuredFeatures, NetherFeatures.NYLIUM_BONEMEAL, level, generator, random, abovePos);
|
| 60 | }
|
| 61 |
|
| 62 | private void place(
|
| 63 | final Registry<Feature> configuredFeatures,
|
| 64 | final ResourceKey<Feature> id,
|
| 65 | final ServerLevel level,
|
| 66 | final ChunkGenerator generator,
|
| 67 | final RandomSource random,
|
| 68 | final BlockPos pos
|
| 69 | ) {
|
| 70 | if (level.isInsideBuildHeight(pos)) {
|
| 71 | configuredFeatures.get(id).ifPresent(h -> h.value().place(level, generator, random, pos));
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | @Override
|
| 76 | public BonemealableBlock.Type getType() {
|
| 77 | return BonemealableBlock.Type.NEIGHBOR_SPREADER;
|
| 78 | }
|
| 79 | }
|
| 80 |
|