| 1 | package net.minecraft.world.level.levelgen.feature;
|
| 2 |
|
| 3 | import com.mojang.serialization.Codec;
|
| 4 | import com.mojang.serialization.MapCodec;
|
| 5 | import java.util.function.Predicate;
|
| 6 | import java.util.stream.Stream;
|
| 7 | import net.minecraft.core.BlockPos;
|
| 8 | import net.minecraft.core.Direction;
|
| 9 | import net.minecraft.core.Holder;
|
| 10 | import net.minecraft.core.HolderSet;
|
| 11 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 12 | import net.minecraft.core.registries.Registries;
|
| 13 | import net.minecraft.core.registries.codec.RegistryCodecs;
|
| 14 | import net.minecraft.util.RandomSource;
|
| 15 | import net.minecraft.world.level.LevelWriter;
|
| 16 | import net.minecraft.world.level.WorldGenLevel;
|
| 17 | import net.minecraft.world.level.block.state.BlockState;
|
| 18 | import net.minecraft.world.level.chunk.ChunkGenerator;
|
| 19 |
|
| 20 | public interface Feature {
|
| 21 | Codec<Feature> DIRECT_CODEC = BuiltInRegistries.FEATURE_TYPE.byNameCodec().dispatch(Feature::codec, t -> t);
|
| 22 | Codec<Holder<Feature>> CODEC = RegistryCodecs.holder(Registries.FEATURE, DIRECT_CODEC);
|
| 23 | Codec<HolderSet<Feature>> LIST_CODEC = RegistryCodecs.holderSet(Registries.FEATURE, DIRECT_CODEC);
|
| 24 |
|
| 25 | MapCodec<? extends Feature> codec();
|
| 26 |
|
| 27 | boolean place(final WorldGenLevel level, final ChunkGenerator chunkGenerator, final RandomSource random, final BlockPos origin);
|
| 28 |
|
| 29 | default Stream<Holder<Feature>> getSubFeatures() {
|
| 30 | return Stream.empty();
|
| 31 | }
|
| 32 |
|
| 33 | default void setBlock(final LevelWriter level, final BlockPos pos, final BlockState blockState) {
|
| 34 | level.setBlockAndUpdate(pos, blockState);
|
| 35 | }
|
| 36 |
|
| 37 | default void safeSetBlock(final WorldGenLevel level, final BlockPos pos, final BlockState state, final Predicate<BlockState> canReplace) {
|
| 38 | if (canReplace.test(level.getBlockState(pos))) {
|
| 39 | level.setBlock(pos, state, 2);
|
| 40 | }
|
| 41 | }
|
| 42 |
|
| 43 | default void markAboveForPostProcessing(final WorldGenLevel level, final BlockPos placePos) {
|
| 44 | BlockPos.MutableBlockPos pos = placePos.mutable();
|
| 45 |
|
| 46 | for (int i = 0; i < 2; i++) {
|
| 47 | pos.move(Direction.UP);
|
| 48 | if (level.getBlockState(pos).isAir()) {
|
| 49 | return;
|
| 50 | }
|
| 51 |
|
| 52 | level.getChunk(pos).markPosForPostProcessing(pos);
|
| 53 | }
|
| 54 | }
|
| 55 | }
|
| 56 |
|