| 1 | package net.minecraft.data.worldgen.features;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import java.util.Optional;
|
| 5 | import java.util.stream.Stream;
|
| 6 | import net.minecraft.core.Direction;
|
| 7 | import net.minecraft.core.Holder;
|
| 8 | import net.minecraft.core.HolderGetter;
|
| 9 | import net.minecraft.core.HolderSet;
|
| 10 | import net.minecraft.core.registries.Registries;
|
| 11 | import net.minecraft.data.worldgen.BootstrapContext;
|
| 12 | import net.minecraft.data.worldgen.placement.PlacementUtils;
|
| 13 | import net.minecraft.references.BlockItemIds;
|
| 14 | import net.minecraft.resources.ResourceKey;
|
| 15 | import net.minecraft.tags.BlockTags;
|
| 16 | import net.minecraft.util.random.Weighted;
|
| 17 | import net.minecraft.util.random.WeightedList;
|
| 18 | import net.minecraft.util.valueproviders.ConstantInt;
|
| 19 | import net.minecraft.util.valueproviders.UniformInt;
|
| 20 | import net.minecraft.world.level.block.Block;
|
| 21 | import net.minecraft.world.level.block.Blocks;
|
| 22 | import net.minecraft.world.level.block.KelpBlock;
|
| 23 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 24 | import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate;
|
| 25 | import net.minecraft.world.level.levelgen.feature.BlockColumnFeature;
|
| 26 | import net.minecraft.world.level.levelgen.feature.CoralClawFeature;
|
| 27 | import net.minecraft.world.level.levelgen.feature.CoralTreeFeature;
|
| 28 | import net.minecraft.world.level.levelgen.feature.CuboidPlacement;
|
| 29 | import net.minecraft.world.level.levelgen.feature.Feature;
|
| 30 | import net.minecraft.world.level.levelgen.feature.NoOpFeature;
|
| 31 | import net.minecraft.world.level.levelgen.feature.OverlayFeature;
|
| 32 | import net.minecraft.world.level.levelgen.feature.SimpleBlockFeature;
|
| 33 | import net.minecraft.world.level.levelgen.feature.SimpleRandomSelectorFeature;
|
| 34 | import net.minecraft.world.level.levelgen.feature.WeightedRandomSelectorFeature;
|
| 35 | import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
|
| 36 | import net.minecraft.world.level.levelgen.feature.stateproviders.RandomBlockProvider;
|
| 37 | import net.minecraft.world.level.levelgen.feature.stateproviders.RandomizedIntStateProvider;
|
| 38 | import net.minecraft.world.level.levelgen.feature.stateproviders.RotatedBlockProvider;
|
| 39 | import net.minecraft.world.level.levelgen.placement.BlockPredicateFilter;
|
| 40 | import net.minecraft.world.level.levelgen.placement.OffsetPlacement;
|
| 41 | import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
| 42 | import net.minecraft.world.level.levelgen.placement.RandomChancePlacement;
|
| 43 |
|
| 44 | public class AquaticFeatures {
|
| 45 | public static final ResourceKey<Feature> SEAGRASS_SHORT = FeatureUtils.createKey("seagrass_short");
|
| 46 | public static final ResourceKey<Feature> SEAGRASS_SLIGHTLY_LESS_SHORT = FeatureUtils.createKey("seagrass_slightly_less_short");
|
| 47 | public static final ResourceKey<Feature> SEAGRASS_MID = FeatureUtils.createKey("seagrass_mid");
|
| 48 | public static final ResourceKey<Feature> SEAGRASS_TALL = FeatureUtils.createKey("seagrass_tall");
|
| 49 | public static final ResourceKey<Feature> SEA_PICKLE = FeatureUtils.createKey("sea_pickle");
|
| 50 | public static final ResourceKey<Feature> KELP = FeatureUtils.createKey("kelp");
|
| 51 | public static final ResourceKey<Feature> CORAL_BLOCK_DECORATION = FeatureUtils.createKey("coral/block_decoration");
|
| 52 | public static final ResourceKey<Feature> TUBE_CORAL_BLOCK = FeatureUtils.createKey("coral/tube_block");
|
| 53 | public static final ResourceKey<Feature> BRAIN_CORAL_BLOCK = FeatureUtils.createKey("coral/brain_block");
|
| 54 | public static final ResourceKey<Feature> BUBBLE_CORAL_BLOCK = FeatureUtils.createKey("coral/bubble_block");
|
| 55 | public static final ResourceKey<Feature> FIRE_CORAL_BLOCK = FeatureUtils.createKey("coral/fire_block");
|
| 56 | public static final ResourceKey<Feature> HORN_CORAL_BLOCK = FeatureUtils.createKey("coral/horn_block");
|
| 57 | public static final ResourceKey<Feature> WARM_OCEAN_VEGETATION = FeatureUtils.createKey("warm_ocean_vegetation");
|
| 58 |
|
| 59 | public static void bootstrap(final BootstrapContext<Feature> context) {
|
| 60 | HolderGetter<Block> blocks = context.lookup(Registries.BLOCK);
|
| 61 | HolderGetter<Feature> features = context.lookup(Registries.FEATURE);
|
| 62 | context.register(SEAGRASS_SHORT, seagrass(30));
|
| 63 | context.register(SEAGRASS_SLIGHTLY_LESS_SHORT, seagrass(40));
|
| 64 | context.register(SEAGRASS_MID, seagrass(60));
|
| 65 | context.register(SEAGRASS_TALL, seagrass(80));
|
| 66 | context.register(
|
| 67 | SEA_PICKLE,
|
| 68 | new SimpleBlockFeature(new RandomizedIntStateProvider(BlockStateProvider.of(Blocks.SEA_PICKLE), BlockStateProperties.PICKLES, UniformInt.of(1, 4)))
|
| 69 | );
|
| 70 | context.register(
|
| 71 | KELP,
|
| 72 | new BlockColumnFeature(
|
| 73 | List.of(
|
| 74 | BlockColumnFeature.layer(UniformInt.of(0, 9), BlockStateProvider.of(Blocks.KELP_PLANT)),
|
| 75 | BlockColumnFeature.layer(ConstantInt.of(1), new RandomizedIntStateProvider(BlockStateProvider.of(Blocks.KELP), KelpBlock.AGE, UniformInt.of(20, 23)))
|
| 76 | ),
|
| 77 | Direction.UP,
|
| 78 | BlockPredicate.allOf(BlockPredicate.matchesBlocks(Blocks.WATER), BlockPredicate.matchesBlocks(Direction.UP, Blocks.WATER)),
|
| 79 | true
|
| 80 | )
|
| 81 | );
|
| 82 | BlockPredicateFilter coralAllowed = BlockPredicateFilter.forPredicate(
|
| 83 | BlockPredicate.allOf(
|
| 84 | BlockPredicate.anyOf(BlockPredicate.matchesBlocks(Blocks.WATER), BlockPredicate.matchesTag(BlockTags.CORALS)),
|
| 85 | BlockPredicate.matchesBlocks(Direction.UP, Blocks.WATER)
|
| 86 | )
|
| 87 | );
|
| 88 | context.register(
|
| 89 | CORAL_BLOCK_DECORATION,
|
| 90 | new OverlayFeature(
|
| 91 | HolderSet.direct(
|
| 92 | PlacementUtils.inlinePlaced(
|
| 93 | new WeightedRandomSelectorFeature(
|
| 94 | WeightedList.of(
|
| 95 | new Weighted<>(PlacementUtils.inlinePlaced(new SimpleBlockFeature(new RandomBlockProvider(blocks.getOrThrow(BlockTags.CORALS)))), 20),
|
| 96 | new Weighted<>(PlacementUtils.inlinePlaced(features.getOrThrow(SEA_PICKLE)), 3),
|
| 97 | new Weighted<>(PlacementUtils.inlinePlaced(new NoOpFeature()), 57)
|
| 98 | )
|
| 99 | ),
|
| 100 | OffsetPlacement.above()
|
| 101 | ),
|
| 102 | wallCoral(blocks, Direction.NORTH),
|
| 103 | wallCoral(blocks, Direction.EAST),
|
| 104 | wallCoral(blocks, Direction.SOUTH),
|
| 105 | wallCoral(blocks, Direction.WEST)
|
| 106 | )
|
| 107 | )
|
| 108 | );
|
| 109 | Holder.Reference<Feature> tubeCoralBlock = context.register(TUBE_CORAL_BLOCK, coralBlock(features, blocks.getOrThrow(BlockItemIds.TUBE_CORAL_BLOCK.block())));
|
| 110 | Holder.Reference<Feature> brainCoralBlock = context.register(
|
| 111 | BRAIN_CORAL_BLOCK, coralBlock(features, blocks.getOrThrow(BlockItemIds.BRAIN_CORAL_BLOCK.block()))
|
| 112 | );
|
| 113 | Holder.Reference<Feature> bubbleCoralBlock = context.register(
|
| 114 | BUBBLE_CORAL_BLOCK, coralBlock(features, blocks.getOrThrow(BlockItemIds.BUBBLE_CORAL_BLOCK.block()))
|
| 115 | );
|
| 116 | Holder.Reference<Feature> fireCoralBlock = context.register(FIRE_CORAL_BLOCK, coralBlock(features, blocks.getOrThrow(BlockItemIds.FIRE_CORAL_BLOCK.block())));
|
| 117 | Holder.Reference<Feature> hornCoralBlock = context.register(HORN_CORAL_BLOCK, coralBlock(features, blocks.getOrThrow(BlockItemIds.HORN_CORAL_BLOCK.block())));
|
| 118 | context.register(
|
| 119 | WARM_OCEAN_VEGETATION,
|
| 120 | new SimpleRandomSelectorFeature(
|
| 121 | HolderSet.direct(
|
| 122 | Stream.of(tubeCoralBlock, brainCoralBlock, bubbleCoralBlock, fireCoralBlock, hornCoralBlock)
|
| 123 | .flatMap(
|
| 124 | blockFeature -> Stream.of(
|
| 125 | PlacementUtils.inlinePlaced(new CoralTreeFeature(PlacementUtils.inlinePlaced(blockFeature, coralAllowed))),
|
| 126 | PlacementUtils.inlinePlaced(new CoralClawFeature(PlacementUtils.inlinePlaced(blockFeature, coralAllowed))),
|
| 127 | PlacementUtils.inlinePlaced(
|
| 128 | blockFeature,
|
| 129 | OffsetPlacement.vertical(UniformInt.of(-3, -1)),
|
| 130 | new CuboidPlacement(UniformInt.of(3, 5), UniformInt.of(3, 5), false, false),
|
| 131 | new RandomChancePlacement(0.9F),
|
| 132 | coralAllowed
|
| 133 | )
|
| 134 | )
|
| 135 | )
|
| 136 | .toList()
|
| 137 | )
|
| 138 | )
|
| 139 | );
|
| 140 | }
|
| 141 |
|
| 142 | private static Feature coralBlock(final HolderGetter<Feature> features, final Holder<Block> block) {
|
| 143 | return new OverlayFeature(
|
| 144 | HolderSet.direct(
|
| 145 | PlacementUtils.inlinePlaced(new SimpleBlockFeature(BlockStateProvider.of(block.value()))),
|
| 146 | PlacementUtils.inlinePlaced(features.getOrThrow(CORAL_BLOCK_DECORATION))
|
| 147 | )
|
| 148 | );
|
| 149 | }
|
| 150 |
|
| 151 | private static Holder<PlacedFeature> wallCoral(final HolderGetter<Block> blocks, final Direction direction) {
|
| 152 | return PlacementUtils.inlinePlaced(
|
| 153 | new SimpleBlockFeature(new RotatedBlockProvider(Holder.direct(new RandomBlockProvider(blocks.getOrThrow(BlockTags.WALL_CORALS))), Optional.of(direction))),
|
| 154 | new RandomChancePlacement(0.2F),
|
| 155 | OffsetPlacement.of(direction),
|
| 156 | BlockPredicateFilter.forPredicate(BlockPredicate.matchesBlocks(Blocks.WATER))
|
| 157 | );
|
| 158 | }
|
| 159 |
|
| 160 | private static Feature seagrass(final int tallPercentage) {
|
| 161 | return new WeightedRandomSelectorFeature(
|
| 162 | WeightedList.of(
|
| 163 | new Weighted<>(
|
| 164 | PlacementUtils.inlinePlaced(
|
| 165 | new SimpleBlockFeature(BlockStateProvider.of(Blocks.TALL_SEAGRASS)),
|
| 166 | BlockPredicateFilter.forPredicate(BlockPredicate.matchesBlocks(Direction.UP, Blocks.WATER))
|
| 167 | ),
|
| 168 | tallPercentage
|
| 169 | ),
|
| 170 | new Weighted<>(PlacementUtils.inlinePlaced(new SimpleBlockFeature(BlockStateProvider.of(Blocks.SEAGRASS))), 100 - tallPercentage)
|
| 171 | )
|
| 172 | );
|
| 173 | }
|
| 174 | }
|
| 175 |
|