From fccdd97f87b2c7edb42afeaccfda7ed005428dbf Mon Sep 17 00:00:00 2001 From: CallMeEchoCodes Date: Sun, 24 Nov 2024 17:29:32 +1100 Subject: [PATCH] feat(worldgen): move more to datagen --- .../configured_feature/birch_bees_0002.json | 27 ++- .../configured_feature/birch_tall.json | 0 .../worldgen/configured_feature/cattails.json | 0 .../configured_feature/patch_waterlily.json | 18 +- .../super_birch_bees_0002.json | 27 ++- .../configured_feature/swamp_oak.json | 15 +- .../placed_feature/birch_bees_0002.json | 0 .../worldgen/placed_feature/birch_tall.json | 22 +- .../worldgen/placed_feature/cattails.json | 12 +- .../placed_feature/patch_campion.json | 8 +- .../worldgen/placed_feature/patch_twig.json | 6 +- .../placed_feature/patch_waterlily.json | 6 +- .../placed_feature/super_birch_bees_0002.json | 0 .../hollow/block/CattailBlock.java | 11 + .../datagen/ConfiguredFeatureProvider.java | 60 +----- .../hollow/datagen/HollowDatagen.java | 14 +- .../hollow/datagen/PlacedFeatureProvider.java | 32 +++ .../worldgen/feature/CattailFeature.java | 3 +- .../feature/HollowConfiguredFeatures.java | 188 +++++++++++++++++- .../feature/HollowPlacedFeatures.java | 118 +++++++++++ .../worldgen/placed_feature/trees_birch.json | 12 +- 21 files changed, 464 insertions(+), 115 deletions(-) rename src/main/{resources => generated}/data/hollow/worldgen/configured_feature/birch_bees_0002.json (81%) rename src/main/{resources => generated}/data/hollow/worldgen/configured_feature/birch_tall.json (100%) rename src/main/{resources => generated}/data/hollow/worldgen/configured_feature/cattails.json (100%) rename src/main/{resources => generated}/data/hollow/worldgen/configured_feature/patch_waterlily.json (86%) rename src/main/{resources => generated}/data/hollow/worldgen/configured_feature/super_birch_bees_0002.json (81%) rename src/main/{resources => generated}/data/hollow/worldgen/configured_feature/swamp_oak.json (87%) rename src/main/{resources => generated}/data/hollow/worldgen/placed_feature/birch_bees_0002.json (100%) rename src/main/{resources => generated}/data/hollow/worldgen/placed_feature/birch_tall.json (64%) rename src/main/{resources => generated}/data/hollow/worldgen/placed_feature/cattails.json (75%) rename src/main/{resources => generated}/data/hollow/worldgen/placed_feature/patch_campion.json (95%) rename src/main/{resources => generated}/data/hollow/worldgen/placed_feature/patch_twig.json (100%) rename src/main/{resources => generated}/data/hollow/worldgen/placed_feature/patch_waterlily.json (100%) rename src/main/{resources => generated}/data/hollow/worldgen/placed_feature/super_birch_bees_0002.json (100%) create mode 100644 src/main/java/dev/spiritstudios/hollow/datagen/PlacedFeatureProvider.java create mode 100644 src/main/java/dev/spiritstudios/hollow/worldgen/feature/HollowPlacedFeatures.java diff --git a/src/main/resources/data/hollow/worldgen/configured_feature/birch_bees_0002.json b/src/main/generated/data/hollow/worldgen/configured_feature/birch_bees_0002.json similarity index 81% rename from src/main/resources/data/hollow/worldgen/configured_feature/birch_bees_0002.json rename to src/main/generated/data/hollow/worldgen/configured_feature/birch_bees_0002.json index b262e0e..7a9f24c 100644 --- a/src/main/resources/data/hollow/worldgen/configured_feature/birch_bees_0002.json +++ b/src/main/generated/data/hollow/worldgen/configured_feature/birch_bees_0002.json @@ -3,22 +3,29 @@ "config": { "decorators": [ { - "type": "hollow:branch_tree_decorator", + "type": "hollow:polypore_tree_decorator", "provider": { "type": "minecraft:simple_state_provider", "state": { - "Name": "minecraft:birch_log" + "Name": "hollow:polypore", + "Properties": { + "amount": "1", + "facing": "north" + } } - }, - "max_amount": 2, - "probability": 0.5 + } }, { - "type": "hollow:polypore_tree_decorator", + "type": "hollow:branch_tree_decorator", + "max_amount": 2, + "probability": 0.5, "provider": { "type": "minecraft:simple_state_provider", "state": { - "Name": "hollow:polypore" + "Name": "minecraft:birch_log", + "Properties": { + "axis": "y" + } } } } @@ -31,11 +38,11 @@ }, "foliage_placer": { "type": "hollow:blob_with_hanging", + "hanging_leaves_chance": 0.25, + "hanging_leaves_extension_chance": 0.4, "height": 3, "offset": 0, - "radius": 2, - "hanging_leaves_chance": 0.25, - "hanging_leaves_extension_chance": 0.4 + "radius": 2 }, "foliage_provider": { "type": "minecraft:simple_state_provider", diff --git a/src/main/resources/data/hollow/worldgen/configured_feature/birch_tall.json b/src/main/generated/data/hollow/worldgen/configured_feature/birch_tall.json similarity index 100% rename from src/main/resources/data/hollow/worldgen/configured_feature/birch_tall.json rename to src/main/generated/data/hollow/worldgen/configured_feature/birch_tall.json diff --git a/src/main/resources/data/hollow/worldgen/configured_feature/cattails.json b/src/main/generated/data/hollow/worldgen/configured_feature/cattails.json similarity index 100% rename from src/main/resources/data/hollow/worldgen/configured_feature/cattails.json rename to src/main/generated/data/hollow/worldgen/configured_feature/cattails.json diff --git a/src/main/resources/data/hollow/worldgen/configured_feature/patch_waterlily.json b/src/main/generated/data/hollow/worldgen/configured_feature/patch_waterlily.json similarity index 86% rename from src/main/resources/data/hollow/worldgen/configured_feature/patch_waterlily.json rename to src/main/generated/data/hollow/worldgen/configured_feature/patch_waterlily.json index df73e78..e4862b9 100644 --- a/src/main/resources/data/hollow/worldgen/configured_feature/patch_waterlily.json +++ b/src/main/generated/data/hollow/worldgen/configured_feature/patch_waterlily.json @@ -1,9 +1,6 @@ { "type": "minecraft:random_patch", "config": { - "tries": 10, - "xz_spread": 7, - "y_spread": 3, "feature": { "feature": { "type": "minecraft:simple_block", @@ -12,16 +9,16 @@ "type": "minecraft:weighted_state_provider", "entries": [ { - "weight": 4, "data": { "Name": "minecraft:lily_pad" - } + }, + "weight": 4 }, { - "weight": 1, "data": { "Name": "hollow:lotus_lilypad" - } + }, + "weight": 1 } ] } @@ -36,6 +33,9 @@ } } ] - } + }, + "tries": 10, + "xz_spread": 7, + "y_spread": 3 } -} +} \ No newline at end of file diff --git a/src/main/resources/data/hollow/worldgen/configured_feature/super_birch_bees_0002.json b/src/main/generated/data/hollow/worldgen/configured_feature/super_birch_bees_0002.json similarity index 81% rename from src/main/resources/data/hollow/worldgen/configured_feature/super_birch_bees_0002.json rename to src/main/generated/data/hollow/worldgen/configured_feature/super_birch_bees_0002.json index 0f36aee..f2f9c3a 100644 --- a/src/main/resources/data/hollow/worldgen/configured_feature/super_birch_bees_0002.json +++ b/src/main/generated/data/hollow/worldgen/configured_feature/super_birch_bees_0002.json @@ -3,22 +3,29 @@ "config": { "decorators": [ { - "type": "hollow:branch_tree_decorator", + "type": "hollow:polypore_tree_decorator", "provider": { "type": "minecraft:simple_state_provider", "state": { - "Name": "minecraft:birch_log" + "Name": "hollow:polypore", + "Properties": { + "amount": "1", + "facing": "north" + } } - }, - "max_amount": 5, - "probability": 0.5 + } }, { - "type": "hollow:polypore_tree_decorator", + "type": "hollow:branch_tree_decorator", + "max_amount": 5, + "probability": 0.5, "provider": { "type": "minecraft:simple_state_provider", "state": { - "Name": "hollow:polypore" + "Name": "minecraft:birch_log", + "Properties": { + "axis": "y" + } } } } @@ -31,11 +38,11 @@ }, "foliage_placer": { "type": "hollow:blob_with_hanging", + "hanging_leaves_chance": 0.25, + "hanging_leaves_extension_chance": 0.4, "height": 3, "offset": 0, - "radius": 2, - "hanging_leaves_chance": 0.25, - "hanging_leaves_extension_chance": 0.4 + "radius": 2 }, "foliage_provider": { "type": "minecraft:simple_state_provider", diff --git a/src/main/resources/data/hollow/worldgen/configured_feature/swamp_oak.json b/src/main/generated/data/hollow/worldgen/configured_feature/swamp_oak.json similarity index 87% rename from src/main/resources/data/hollow/worldgen/configured_feature/swamp_oak.json rename to src/main/generated/data/hollow/worldgen/configured_feature/swamp_oak.json index a78ecb6..016a713 100644 --- a/src/main/resources/data/hollow/worldgen/configured_feature/swamp_oak.json +++ b/src/main/generated/data/hollow/worldgen/configured_feature/swamp_oak.json @@ -8,13 +8,16 @@ }, { "type": "hollow:big_branch_tree_decorator", + "probability": 0.5, "provider": { "type": "minecraft:simple_state_provider", "state": { - "Name": "minecraft:oak_log" + "Name": "minecraft:oak_log", + "Properties": { + "axis": "y" + } } - }, - "probability": 0.5 + } } ], "dirt_provider": { @@ -25,11 +28,11 @@ }, "foliage_placer": { "type": "hollow:blob_with_hanging", + "hanging_leaves_chance": 1.0, + "hanging_leaves_extension_chance": 0.5, "height": 3, "offset": 0, - "radius": 3, - "hanging_leaves_chance": 1.0, - "hanging_leaves_extension_chance": 0.5 + "radius": 3 }, "foliage_provider": { "type": "minecraft:simple_state_provider", diff --git a/src/main/resources/data/hollow/worldgen/placed_feature/birch_bees_0002.json b/src/main/generated/data/hollow/worldgen/placed_feature/birch_bees_0002.json similarity index 100% rename from src/main/resources/data/hollow/worldgen/placed_feature/birch_bees_0002.json rename to src/main/generated/data/hollow/worldgen/placed_feature/birch_bees_0002.json diff --git a/src/main/resources/data/hollow/worldgen/placed_feature/birch_tall.json b/src/main/generated/data/hollow/worldgen/placed_feature/birch_tall.json similarity index 64% rename from src/main/resources/data/hollow/worldgen/placed_feature/birch_tall.json rename to src/main/generated/data/hollow/worldgen/placed_feature/birch_tall.json index 2b7dbf0..e714246 100644 --- a/src/main/resources/data/hollow/worldgen/placed_feature/birch_tall.json +++ b/src/main/generated/data/hollow/worldgen/placed_feature/birch_tall.json @@ -1,17 +1,21 @@ { "feature": "hollow:birch_tall", "placement": [ + { + "type": "minecraft:heightmap", + "heightmap": "OCEAN_FLOOR" + }, { "type": "minecraft:count", "count": { "type": "minecraft:weighted_list", "distribution": [ { - "data": 3, + "data": 10, "weight": 9 }, { - "data": 4, + "data": 11, "weight": 1 } ] @@ -25,11 +29,19 @@ "max_water_depth": 0 }, { - "type": "minecraft:heightmap", - "heightmap": "OCEAN_FLOOR" + "type": "minecraft:biome" }, { - "type": "minecraft:biome" + "type": "minecraft:block_predicate_filter", + "predicate": { + "type": "minecraft:would_survive", + "state": { + "Name": "minecraft:birch_sapling", + "Properties": { + "stage": "0" + } + } + } } ] } \ No newline at end of file diff --git a/src/main/resources/data/hollow/worldgen/placed_feature/cattails.json b/src/main/generated/data/hollow/worldgen/placed_feature/cattails.json similarity index 75% rename from src/main/resources/data/hollow/worldgen/placed_feature/cattails.json rename to src/main/generated/data/hollow/worldgen/placed_feature/cattails.json index ba0cfec..aa354ee 100644 --- a/src/main/resources/data/hollow/worldgen/placed_feature/cattails.json +++ b/src/main/generated/data/hollow/worldgen/placed_feature/cattails.json @@ -2,18 +2,22 @@ "feature": "hollow:cattails", "placement": [ { - "type": "minecraft:in_square" + "type": "minecraft:count", + "count": 2 + }, + { + "type": "minecraft:rarity_filter", + "chance": 2 }, { "type": "minecraft:heightmap", "heightmap": "OCEAN_FLOOR_WG" }, { - "type": "minecraft:count", - "count": 32 + "type": "minecraft:biome" }, { - "type": "minecraft:biome" + "type": "minecraft:in_square" } ] } \ No newline at end of file diff --git a/src/main/resources/data/hollow/worldgen/placed_feature/patch_campion.json b/src/main/generated/data/hollow/worldgen/placed_feature/patch_campion.json similarity index 95% rename from src/main/resources/data/hollow/worldgen/placed_feature/patch_campion.json rename to src/main/generated/data/hollow/worldgen/placed_feature/patch_campion.json index df626c0..a7caf82 100644 --- a/src/main/resources/data/hollow/worldgen/placed_feature/patch_campion.json +++ b/src/main/generated/data/hollow/worldgen/placed_feature/patch_campion.json @@ -3,21 +3,21 @@ "placement": [ { "type": "minecraft:count", - "count": 4 + "count": 1 }, { "type": "minecraft:rarity_filter", "chance": 2 }, - { - "type": "minecraft:in_square" - }, { "type": "minecraft:heightmap", "heightmap": "MOTION_BLOCKING" }, { "type": "minecraft:biome" + }, + { + "type": "minecraft:in_square" } ] } \ No newline at end of file diff --git a/src/main/resources/data/hollow/worldgen/placed_feature/patch_twig.json b/src/main/generated/data/hollow/worldgen/placed_feature/patch_twig.json similarity index 100% rename from src/main/resources/data/hollow/worldgen/placed_feature/patch_twig.json rename to src/main/generated/data/hollow/worldgen/placed_feature/patch_twig.json index 9abd960..883caaf 100644 --- a/src/main/resources/data/hollow/worldgen/placed_feature/patch_twig.json +++ b/src/main/generated/data/hollow/worldgen/placed_feature/patch_twig.json @@ -9,15 +9,15 @@ "type": "minecraft:rarity_filter", "chance": 2 }, - { - "type": "minecraft:in_square" - }, { "type": "minecraft:heightmap", "heightmap": "MOTION_BLOCKING" }, { "type": "minecraft:biome" + }, + { + "type": "minecraft:in_square" } ] } \ No newline at end of file diff --git a/src/main/resources/data/hollow/worldgen/placed_feature/patch_waterlily.json b/src/main/generated/data/hollow/worldgen/placed_feature/patch_waterlily.json similarity index 100% rename from src/main/resources/data/hollow/worldgen/placed_feature/patch_waterlily.json rename to src/main/generated/data/hollow/worldgen/placed_feature/patch_waterlily.json index ecc7a9a..8439bf0 100644 --- a/src/main/resources/data/hollow/worldgen/placed_feature/patch_waterlily.json +++ b/src/main/generated/data/hollow/worldgen/placed_feature/patch_waterlily.json @@ -5,15 +5,15 @@ "type": "minecraft:count", "count": 4 }, - { - "type": "minecraft:in_square" - }, { "type": "minecraft:heightmap", "heightmap": "WORLD_SURFACE_WG" }, { "type": "minecraft:biome" + }, + { + "type": "minecraft:in_square" } ] } \ No newline at end of file diff --git a/src/main/resources/data/hollow/worldgen/placed_feature/super_birch_bees_0002.json b/src/main/generated/data/hollow/worldgen/placed_feature/super_birch_bees_0002.json similarity index 100% rename from src/main/resources/data/hollow/worldgen/placed_feature/super_birch_bees_0002.json rename to src/main/generated/data/hollow/worldgen/placed_feature/super_birch_bees_0002.json diff --git a/src/main/java/dev/spiritstudios/hollow/block/CattailBlock.java b/src/main/java/dev/spiritstudios/hollow/block/CattailBlock.java index f2892f5..6c4c6c6 100644 --- a/src/main/java/dev/spiritstudios/hollow/block/CattailBlock.java +++ b/src/main/java/dev/spiritstudios/hollow/block/CattailBlock.java @@ -77,6 +77,17 @@ public BlockState getPlacementState(ItemPlacementContext ctx) { return null; } + @Override + protected boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + boolean canPlace = true; + if (state.get(PIECE) == Piece.BASE) { + FluidState fluidState = world.getFluidState(pos); + if (!fluidState.isIn(FluidTags.WATER) || fluidState.getLevel() != 8) canPlace = false; + + } + return super.canPlaceAt(state, world, pos) && canPlace; + } + @Override protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { return SHAPE; diff --git a/src/main/java/dev/spiritstudios/hollow/datagen/ConfiguredFeatureProvider.java b/src/main/java/dev/spiritstudios/hollow/datagen/ConfiguredFeatureProvider.java index ee00033..8c01304 100644 --- a/src/main/java/dev/spiritstudios/hollow/datagen/ConfiguredFeatureProvider.java +++ b/src/main/java/dev/spiritstudios/hollow/datagen/ConfiguredFeatureProvider.java @@ -1,16 +1,11 @@ package dev.spiritstudios.hollow.datagen; -import dev.spiritstudios.hollow.registry.HollowBlockRegistrar; -import dev.spiritstudios.hollow.registry.HollowFeatureRegistrar; -import dev.spiritstudios.hollow.worldgen.feature.FallenTreeFeatureConfig; -import dev.spiritstudios.hollow.worldgen.feature.HollowConfiguredFeatures; +import dev.spiritstudios.hollow.Hollow; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider; -import net.minecraft.block.Block; +import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryWrapper; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.world.gen.feature.*; -import net.minecraft.world.gen.stateprovider.BlockStateProvider; +import net.minecraft.world.gen.feature.ConfiguredFeature; import java.util.concurrent.CompletableFuture; @@ -21,54 +16,17 @@ public ConfiguredFeatureProvider(FabricDataOutput output, CompletableFuture> lookup = registries.getWrapperOrThrow(RegistryKeys.CONFIGURED_FEATURE); - entries.add(HollowConfiguredFeatures.PATCH_TWIG, createRandomPatch(HollowBlockRegistrar.TWIG, 10)); - entries.add(HollowConfiguredFeatures.PATCH_CAMPION, createRandomPatch(HollowBlockRegistrar.CAMPION, 10)); - entries.add( - HollowConfiguredFeatures.PATCH_GIANT_LILYPAD, - createRandomPatch( - PlacedFeatures.createEntry(HollowFeatureRegistrar.GIANT_LILYPAD, new DefaultFeatureConfig()), - 10 - ) - ); + lookup.streamKeys() + .filter(key -> + key.getValue().getNamespace().equals(Hollow.MODID)) + .forEach(key -> + entries.add(key, lookup.getOrThrow(key).value())); } @Override public String getName() { return "Hollow/Configured Features"; } - - public static ConfiguredFeature fallenTree(Block block, boolean polypore, boolean mossy) { - return new ConfiguredFeature<>( - HollowFeatureRegistrar.FALLEN_TREE, - new FallenTreeFeatureConfig(BlockStateProvider.of(block), polypore, mossy) - ); - } - - public static ConfiguredFeature createRandomPatch(RegistryEntry feature, int tries) { - return new ConfiguredFeature<>( - Feature.RANDOM_PATCH, - ConfiguredFeatures.createRandomPatchFeatureConfig( - tries, - feature - ) - ); - } - - public static ConfiguredFeature createRandomPatch(BlockStateProvider block, int tries) { - return createRandomPatch( - PlacedFeatures.createEntry( - Feature.SIMPLE_BLOCK, - new SimpleBlockFeatureConfig(block) - ), - tries - ); - - } - - private static ConfiguredFeature createRandomPatch(Block block, int tries) { - return createRandomPatch(BlockStateProvider.of(block), tries); - } } diff --git a/src/main/java/dev/spiritstudios/hollow/datagen/HollowDatagen.java b/src/main/java/dev/spiritstudios/hollow/datagen/HollowDatagen.java index 872986b..5cb1e1d 100644 --- a/src/main/java/dev/spiritstudios/hollow/datagen/HollowDatagen.java +++ b/src/main/java/dev/spiritstudios/hollow/datagen/HollowDatagen.java @@ -1,17 +1,29 @@ package dev.spiritstudios.hollow.datagen; +import dev.spiritstudios.hollow.worldgen.feature.HollowConfiguredFeatures; +import dev.spiritstudios.hollow.worldgen.feature.HollowPlacedFeatures; import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; +import net.minecraft.registry.RegistryBuilder; +import net.minecraft.registry.RegistryKeys; public class HollowDatagen implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { FabricDataGenerator.Pack pack = fabricDataGenerator.createPack(); - + pack.addProvider(ModelProvider::new); pack.addProvider(LootTableProvider::new); pack.addProvider(RecipeProvider::new); pack.addProvider(ItemGroupProvider::new); pack.addProvider(ConfiguredFeatureProvider::new); + pack.addProvider(PlacedFeatureProvider::new); + } + + @Override + public void buildRegistry(RegistryBuilder registryBuilder) { + registryBuilder + .addRegistry(RegistryKeys.CONFIGURED_FEATURE, HollowConfiguredFeatures::bootstrap) + .addRegistry(RegistryKeys.PLACED_FEATURE, HollowPlacedFeatures::bootstrap); } } diff --git a/src/main/java/dev/spiritstudios/hollow/datagen/PlacedFeatureProvider.java b/src/main/java/dev/spiritstudios/hollow/datagen/PlacedFeatureProvider.java new file mode 100644 index 0000000..2b545be --- /dev/null +++ b/src/main/java/dev/spiritstudios/hollow/datagen/PlacedFeatureProvider.java @@ -0,0 +1,32 @@ +package dev.spiritstudios.hollow.datagen; + +import dev.spiritstudios.hollow.Hollow; +import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.RegistryWrapper; +import net.minecraft.world.gen.feature.PlacedFeature; + +import java.util.concurrent.CompletableFuture; + +public class PlacedFeatureProvider extends FabricDynamicRegistryProvider { + public PlacedFeatureProvider(FabricDataOutput output, CompletableFuture registriesFuture) { + super(output, registriesFuture); + } + + @Override + protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) { + RegistryWrapper lookup = registries.getWrapperOrThrow(RegistryKeys.PLACED_FEATURE); + + lookup.streamKeys() + .filter(key -> + key.getValue().getNamespace().equals(Hollow.MODID)) + .forEach(key -> + entries.add(key, lookup.getOrThrow(key).value())); + } + + @Override + public String getName() { + return "Hollow/Placed Features"; + } +} diff --git a/src/main/java/dev/spiritstudios/hollow/worldgen/feature/CattailFeature.java b/src/main/java/dev/spiritstudios/hollow/worldgen/feature/CattailFeature.java index 04a0106..87d2d8a 100644 --- a/src/main/java/dev/spiritstudios/hollow/worldgen/feature/CattailFeature.java +++ b/src/main/java/dev/spiritstudios/hollow/worldgen/feature/CattailFeature.java @@ -4,7 +4,6 @@ import dev.spiritstudios.hollow.block.CattailBlock; import dev.spiritstudios.hollow.registry.HollowBlockRegistrar; import net.minecraft.block.Block; -import net.minecraft.block.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.random.Random; import net.minecraft.world.Heightmap; @@ -25,7 +24,7 @@ public boolean generate(FeatureContext context) { StructureWorldAccess world = context.getWorld(); BlockPos pos = origin.withY(world.getTopY(Heightmap.Type.OCEAN_FLOOR, origin.getX(), origin.getZ())); - if (!world.getBlockState(pos).isOf(Blocks.WATER)) return false; + if (!HollowBlockRegistrar.CATTAIL.getDefaultState().canPlaceAt(world, pos)) return false; world.setBlockState(pos, HollowBlockRegistrar.CATTAIL.getDefaultState(), Block.NOTIFY_LISTENERS); pos = pos.up(); diff --git a/src/main/java/dev/spiritstudios/hollow/worldgen/feature/HollowConfiguredFeatures.java b/src/main/java/dev/spiritstudios/hollow/worldgen/feature/HollowConfiguredFeatures.java index 4045eb3..474c036 100644 --- a/src/main/java/dev/spiritstudios/hollow/worldgen/feature/HollowConfiguredFeatures.java +++ b/src/main/java/dev/spiritstudios/hollow/worldgen/feature/HollowConfiguredFeatures.java @@ -1,10 +1,32 @@ package dev.spiritstudios.hollow.worldgen.feature; import dev.spiritstudios.hollow.Hollow; +import dev.spiritstudios.hollow.registry.HollowBlockRegistrar; +import dev.spiritstudios.hollow.registry.HollowFeatureRegistrar; +import dev.spiritstudios.hollow.worldgen.decorator.BigBranchTreeDecorator; +import dev.spiritstudios.hollow.worldgen.decorator.BranchTreeDecorator; +import dev.spiritstudios.hollow.worldgen.decorator.PolyporeTreeDecorator; +import dev.spiritstudios.hollow.worldgen.foliage.BlobWithHangingFoliagePlacer; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.registry.Registerable; +import net.minecraft.registry.RegistryEntryLookup; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.Identifier; -import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.util.collection.DataPool; +import net.minecraft.util.math.intprovider.ConstantIntProvider; +import net.minecraft.world.gen.feature.*; +import net.minecraft.world.gen.feature.size.TwoLayersFeatureSize; +import net.minecraft.world.gen.foliage.BlobFoliagePlacer; +import net.minecraft.world.gen.stateprovider.BlockStateProvider; +import net.minecraft.world.gen.stateprovider.WeightedBlockStateProvider; +import net.minecraft.world.gen.treedecorator.LeavesVineTreeDecorator; +import net.minecraft.world.gen.trunk.StraightTrunkPlacer; + +import java.util.List; public final class HollowConfiguredFeatures { public static final RegistryKey> FALLEN_OAK = of("fallen_oak"); @@ -13,8 +35,172 @@ public final class HollowConfiguredFeatures { public static final RegistryKey> PATCH_TWIG = of("patch_twig"); public static final RegistryKey> PATCH_CAMPION = of("patch_campion"); public static final RegistryKey> PATCH_GIANT_LILYPAD = of("patch_giant_lilypad"); + public static final RegistryKey> PATCH_WATERLILY = of("patch_waterlily"); + + + public static final RegistryKey> SWAMP_OAK = of("swamp_oak"); + + public static final RegistryKey> BIRCH_BEES_0002 = of("birch_bees_0002"); + public static final RegistryKey> SUPER_BIRCH_BEES_0002 = of("super_birch_bees_0002"); + public static final RegistryKey> BIRCH_TALL = of("birch_tall"); + + + public static final RegistryKey> CATTAILS = of("cattails"); + + + public static void bootstrap(Registerable> featureRegisterable) { + RegistryEntryLookup placedLookup = featureRegisterable.getRegistryLookup(RegistryKeys.PLACED_FEATURE); + + featureRegisterable.register(FALLEN_OAK, fallenTree(HollowBlockRegistrar.OAK_HOLLOW_LOG, false, true)); + featureRegisterable.register(FALLEN_BIRCH, fallenTree(HollowBlockRegistrar.BIRCH_HOLLOW_LOG, true, true)); + + featureRegisterable.register(PATCH_TWIG, createRandomPatch(HollowBlockRegistrar.TWIG, 10)); + featureRegisterable.register(PATCH_CAMPION, createRandomPatch(HollowBlockRegistrar.CAMPION, 10)); + featureRegisterable.register( + PATCH_GIANT_LILYPAD, + createRandomPatch( + PlacedFeatures.createEntry(HollowFeatureRegistrar.GIANT_LILYPAD, new DefaultFeatureConfig()), + 10 + ) + ); + + // region Trees + featureRegisterable.register( + SWAMP_OAK, + new ConfiguredFeature<>( + Feature.TREE, + hangingLeavestreeBuilder( + Blocks.OAK_LOG, Blocks.OAK_LEAVES, + 8, 2, 0, + 3, 1.0F, 0.5F + ).decorators(List.of( + new LeavesVineTreeDecorator(0.05F), + new BigBranchTreeDecorator(BlockStateProvider.of(Blocks.OAK_LOG), 0.5F) + )).build() + ) + ); + + featureRegisterable.register( + BIRCH_BEES_0002, + new ConfiguredFeature<>( + Feature.TREE, + hangingLeavestreeBuilder( + Blocks.BIRCH_LOG, Blocks.BIRCH_LEAVES, + 8, 5, 0, + 2, 0.25F, 0.4F + ).decorators(List.of( + new PolyporeTreeDecorator(BlockStateProvider.of(HollowBlockRegistrar.POLYPORE)), + new BranchTreeDecorator(BlockStateProvider.of(Blocks.BIRCH_LOG), 0.5F, 2) + )).ignoreVines().build() + ) + ); + + featureRegisterable.register( + SUPER_BIRCH_BEES_0002, + new ConfiguredFeature<>( + Feature.TREE, + hangingLeavestreeBuilder( + Blocks.BIRCH_LOG, Blocks.BIRCH_LEAVES, + 8, 5, 6, + 2, 0.25F, 0.4F + ).decorators(List.of( + new PolyporeTreeDecorator(BlockStateProvider.of(HollowBlockRegistrar.POLYPORE)), + new BranchTreeDecorator(BlockStateProvider.of(Blocks.BIRCH_LOG), 0.5F, 5) + )).ignoreVines().build() + ) + ); + + featureRegisterable.register( + BIRCH_TALL, + new ConfiguredFeature<>( + Feature.RANDOM_SELECTOR, + new RandomFeatureConfig( + List.of( + new RandomFeatureEntry( + placedLookup.getOrThrow(HollowPlacedFeatures.SUPER_BIRCH_BEES_0002), + 0.5F + ) + ), + placedLookup.getOrThrow(HollowPlacedFeatures.BIRCH_BEES_0002) + ) + ) + ); + // endregion + + featureRegisterable.register( + CATTAILS, + new ConfiguredFeature<>( + HollowFeatureRegistrar.CATTAILS, + new DefaultFeatureConfig() + ) + ); + + featureRegisterable.register( + PATCH_WATERLILY, + createRandomPatch( + new WeightedBlockStateProvider(DataPool.builder() + .add(Blocks.LILY_PAD.getDefaultState(), 4) + .add(HollowBlockRegistrar.LOTUS_LILYPAD.getDefaultState(), 1) + .build()), + 10 + ) + ); + } public static RegistryKey> of(String id) { return RegistryKey.of(RegistryKeys.CONFIGURED_FEATURE, Identifier.of(Hollow.MODID, id)); } + + + public static ConfiguredFeature fallenTree(Block block, boolean polypore, boolean mossy) { + return new ConfiguredFeature<>( + HollowFeatureRegistrar.FALLEN_TREE, + new FallenTreeFeatureConfig(BlockStateProvider.of(block), polypore, mossy) + ); + } + + public static ConfiguredFeature createRandomPatch(RegistryEntry feature, int tries) { + return new ConfiguredFeature<>( + Feature.RANDOM_PATCH, + ConfiguredFeatures.createRandomPatchFeatureConfig( + tries, + feature + ) + ); + } + + public static ConfiguredFeature createRandomPatch(BlockStateProvider block, int tries) { + return createRandomPatch( + PlacedFeatures.createEntry( + Feature.SIMPLE_BLOCK, + new SimpleBlockFeatureConfig(block) + ), + tries + ); + + } + + private static ConfiguredFeature createRandomPatch(Block block, int tries) { + return createRandomPatch(BlockStateProvider.of(block), tries); + } + + private static TreeFeatureConfig.Builder treeBuilder(Block log, Block leaves, int baseHeight, int firstRandomHeight, int secondRandomHeight, int radius) { + return new TreeFeatureConfig.Builder( + BlockStateProvider.of(log), + new StraightTrunkPlacer(baseHeight, firstRandomHeight, secondRandomHeight), + BlockStateProvider.of(leaves), + new BlobFoliagePlacer(ConstantIntProvider.create(radius), ConstantIntProvider.create(0), 3), + new TwoLayersFeatureSize(1, 0, 1) + ); + } + + private static TreeFeatureConfig.Builder hangingLeavestreeBuilder(Block log, Block leaves, int baseHeight, int firstRandomHeight, int secondRandomHeight, int radius, float hangingLeavesChance, float hangingLeavesExtensionChance) { + return new TreeFeatureConfig.Builder( + BlockStateProvider.of(log), + new StraightTrunkPlacer(baseHeight, firstRandomHeight, secondRandomHeight), + BlockStateProvider.of(leaves), + new BlobWithHangingFoliagePlacer(ConstantIntProvider.create(radius), ConstantIntProvider.create(0), 3, hangingLeavesChance, hangingLeavesExtensionChance), + new TwoLayersFeatureSize(1, 0, 1) + ); + } } \ No newline at end of file diff --git a/src/main/java/dev/spiritstudios/hollow/worldgen/feature/HollowPlacedFeatures.java b/src/main/java/dev/spiritstudios/hollow/worldgen/feature/HollowPlacedFeatures.java new file mode 100644 index 0000000..1dc1d51 --- /dev/null +++ b/src/main/java/dev/spiritstudios/hollow/worldgen/feature/HollowPlacedFeatures.java @@ -0,0 +1,118 @@ +package dev.spiritstudios.hollow.worldgen.feature; + +import dev.spiritstudios.hollow.Hollow; +import dev.spiritstudios.hollow.registry.HollowBlockRegistrar; +import net.minecraft.block.Blocks; +import net.minecraft.registry.*; +import net.minecraft.util.Identifier; +import net.minecraft.util.collection.DataPool; +import net.minecraft.util.math.intprovider.ConstantIntProvider; +import net.minecraft.util.math.intprovider.IntProvider; +import net.minecraft.util.math.intprovider.WeightedListIntProvider; +import net.minecraft.world.Heightmap; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.feature.PlacedFeature; +import net.minecraft.world.gen.feature.PlacedFeatures; +import net.minecraft.world.gen.placementmodifier.*; + +import java.util.List; + +public final class HollowPlacedFeatures { + public static final RegistryKey BIRCH_BEES_0002 = of("birch_bees_0002"); + public static final RegistryKey SUPER_BIRCH_BEES_0002 = of("super_birch_bees_0002"); + + public static final RegistryKey BIRCH_TALL = of("birch_tall"); + + public static final RegistryKey CATTAILS = of("cattails"); + + public static final RegistryKey PATCH_TWIG = of("patch_twig"); + public static final RegistryKey PATCH_WATERLILY = of("patch_waterlily"); + public static final RegistryKey PATCH_CAMPION = of("patch_campion"); + + public static void bootstrap(Registerable featureRegisterable) { + PlacedFeatureHelper helper = new PlacedFeatureHelper(featureRegisterable.getRegistryLookup(RegistryKeys.CONFIGURED_FEATURE), featureRegisterable); + + helper.add( + BIRCH_BEES_0002, + HollowConfiguredFeatures.BIRCH_BEES_0002, + PlacedFeatures.wouldSurvive(Blocks.BIRCH_SAPLING) + ); + + helper.add( + SUPER_BIRCH_BEES_0002, + HollowConfiguredFeatures.SUPER_BIRCH_BEES_0002, + PlacedFeatures.wouldSurvive(Blocks.BIRCH_SAPLING) + ); + + helper.add( + BIRCH_TALL, + HollowConfiguredFeatures.BIRCH_TALL, + PlacedFeatures.OCEAN_FLOOR_HEIGHTMAP, + CountPlacementModifier.of(new WeightedListIntProvider(DataPool.builder() + .add(ConstantIntProvider.create(10), 9) + .add(ConstantIntProvider.create(11), 1) + .build())), + SquarePlacementModifier.of(), + SurfaceWaterDepthFilterPlacementModifier.of(0), + BiomePlacementModifier.of(), + PlacedFeatures.wouldSurvive(Blocks.BIRCH_SAPLING) + ); + + helper.add( + CATTAILS, + HollowConfiguredFeatures.CATTAILS, + CountPlacementModifier.of(2), + RarityFilterPlacementModifier.of(2), + PlacedFeatures.OCEAN_FLOOR_WG_HEIGHTMAP, + BiomePlacementModifier.of(), + SquarePlacementModifier.of() + ); + + helper.add( + PATCH_TWIG, + HollowConfiguredFeatures.PATCH_TWIG, + CountPlacementModifier.of(2), + RarityFilterPlacementModifier.of(2), + HeightmapPlacementModifier.of(Heightmap.Type.MOTION_BLOCKING), + BiomePlacementModifier.of(), + SquarePlacementModifier.of() + ); + + helper.add( + PATCH_WATERLILY, + HollowConfiguredFeatures.PATCH_WATERLILY, + CountPlacementModifier.of(4), + HeightmapPlacementModifier.of(Heightmap.Type.WORLD_SURFACE_WG), + BiomePlacementModifier.of(), + SquarePlacementModifier.of() + ); + + helper.add( + PATCH_CAMPION, + HollowConfiguredFeatures.PATCH_CAMPION, + CountPlacementModifier.of(1), + RarityFilterPlacementModifier.of(2), + HeightmapPlacementModifier.of(Heightmap.Type.MOTION_BLOCKING), + BiomePlacementModifier.of(), + SquarePlacementModifier.of() + ); + } + + public static RegistryKey of(String id) { + return RegistryKey.of(RegistryKeys.PLACED_FEATURE, Identifier.of(Hollow.MODID, id)); + } + + + private record PlacedFeatureHelper(RegistryEntryLookup> lookup, + Registerable featureRegisterable) { + public void add(RegistryKey key, RegistryKey> configuredKey, PlacementModifier... modifiers) { + featureRegisterable.register( + key, + new PlacedFeature( + lookup.getOrThrow(configuredKey), + List.of(modifiers) + ) + ); + } + } +} \ No newline at end of file diff --git a/src/main/resources/data/hollow/worldgen/placed_feature/trees_birch.json b/src/main/resources/data/hollow/worldgen/placed_feature/trees_birch.json index 7ec0805..86a0a5b 100644 --- a/src/main/resources/data/hollow/worldgen/placed_feature/trees_birch.json +++ b/src/main/resources/data/hollow/worldgen/placed_feature/trees_birch.json @@ -1,17 +1,21 @@ { "feature": "hollow:birch_bees_0002", "placement": [ + { + "type": "minecraft:heightmap", + "heightmap": "OCEAN_FLOOR" + }, { "type": "minecraft:count", "count": { "type": "minecraft:weighted_list", "distribution": [ { - "data": 3, + "data": 10, "weight": 9 }, { - "data": 4, + "data": 11, "weight": 1 } ] @@ -24,10 +28,6 @@ "type": "minecraft:surface_water_depth_filter", "max_water_depth": 0 }, - { - "type": "minecraft:heightmap", - "heightmap": "OCEAN_FLOOR" - }, { "type": "minecraft:biome" },