diff --git a/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water.json b/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water.json new file mode 100644 index 0000000..06ebf67 --- /dev/null +++ b/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water.json @@ -0,0 +1,6 @@ +{ + "type": "forge:add_features", + "biomes": "#minecraft:is_overworld", + "features": "firefly_bush_backport:patch_firefly_bush_near_water", + "step": "vegetal_decoration" +} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water_swamp.json b/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water_swamp.json new file mode 100644 index 0000000..fe5ccb4 --- /dev/null +++ b/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_near_water_swamp.json @@ -0,0 +1,6 @@ +{ + "type": "forge:add_features", + "biomes": "#forge:is_swamp", + "features": "firefly_bush_backport:patch_firefly_bush_near_water_swamp", + "step": "vegetal_decoration" +} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_swamp.json b/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_swamp.json new file mode 100644 index 0000000..6591b04 --- /dev/null +++ b/src/generated/resources/data/firefly_bush_backport/forge/biome_modifier/add_patch_firefly_bush_swamp.json @@ -0,0 +1,6 @@ +{ + "type": "forge:add_features", + "biomes": "#forge:is_swamp", + "features": "firefly_bush_backport:patch_firefly_bush_swamp", + "step": "vegetal_decoration" +} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/worldgen/configured_feature/patch_firefly_bush.json b/src/generated/resources/data/firefly_bush_backport/worldgen/configured_feature/patch_firefly_bush.json new file mode 100644 index 0000000..38e328d --- /dev/null +++ b/src/generated/resources/data/firefly_bush_backport/worldgen/configured_feature/patch_firefly_bush.json @@ -0,0 +1,30 @@ +{ + "type": "minecraft:random_patch", + "config": { + "feature": { + "feature": { + "type": "minecraft:simple_block", + "config": { + "to_place": { + "type": "minecraft:simple_state_provider", + "state": { + "Name": "firefly_bush_backport:firefly_bush" + } + } + } + }, + "placement": [ + { + "type": "minecraft:block_predicate_filter", + "predicate": { + "type": "minecraft:matching_blocks", + "blocks": "minecraft:air" + } + } + ] + }, + "tries": 20, + "xz_spread": 4, + "y_spread": 3 + } +} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water.json b/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water.json new file mode 100644 index 0000000..abc3586 --- /dev/null +++ b/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water.json @@ -0,0 +1,90 @@ +{ + "feature": "firefly_bush_backport:patch_firefly_bush", + "placement": [ + { + "type": "minecraft:count", + "count": 2 + }, + { + "type": "minecraft:in_square" + }, + { + "type": "minecraft:heightmap", + "heightmap": "MOTION_BLOCKING_NO_LEAVES" + }, + { + "type": "minecraft:biome" + }, + { + "type": "minecraft:block_predicate_filter", + "predicate": { + "type": "minecraft:all_of", + "predicates": [ + { + "type": "minecraft:matching_blocks", + "blocks": "minecraft:air" + }, + { + "type": "minecraft:would_survive", + "state": { + "Name": "firefly_bush_backport:firefly_bush" + } + }, + { + "type": "minecraft:any_of", + "predicates": [ + { + "type": "minecraft:matching_fluids", + "fluids": [ + "minecraft:water", + "minecraft:flowing_water" + ], + "offset": [ + 1, + -1, + 0 + ] + }, + { + "type": "minecraft:matching_fluids", + "fluids": [ + "minecraft:water", + "minecraft:flowing_water" + ], + "offset": [ + -1, + -1, + 0 + ] + }, + { + "type": "minecraft:matching_fluids", + "fluids": [ + "minecraft:water", + "minecraft:flowing_water" + ], + "offset": [ + 0, + -1, + 1 + ] + }, + { + "type": "minecraft:matching_fluids", + "fluids": [ + "minecraft:water", + "minecraft:flowing_water" + ], + "offset": [ + 0, + -1, + -1 + ] + } + ] + } + ] + } + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water_swamp.json b/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water_swamp.json new file mode 100644 index 0000000..905cc61 --- /dev/null +++ b/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_near_water_swamp.json @@ -0,0 +1,90 @@ +{ + "feature": "firefly_bush_backport:patch_firefly_bush", + "placement": [ + { + "type": "minecraft:count", + "count": 3 + }, + { + "type": "minecraft:in_square" + }, + { + "type": "minecraft:heightmap", + "heightmap": "MOTION_BLOCKING" + }, + { + "type": "minecraft:biome" + }, + { + "type": "minecraft:block_predicate_filter", + "predicate": { + "type": "minecraft:all_of", + "predicates": [ + { + "type": "minecraft:matching_blocks", + "blocks": "minecraft:air" + }, + { + "type": "minecraft:would_survive", + "state": { + "Name": "firefly_bush_backport:firefly_bush" + } + }, + { + "type": "minecraft:any_of", + "predicates": [ + { + "type": "minecraft:matching_fluids", + "fluids": [ + "minecraft:water", + "minecraft:flowing_water" + ], + "offset": [ + 1, + -1, + 0 + ] + }, + { + "type": "minecraft:matching_fluids", + "fluids": [ + "minecraft:water", + "minecraft:flowing_water" + ], + "offset": [ + -1, + -1, + 0 + ] + }, + { + "type": "minecraft:matching_fluids", + "fluids": [ + "minecraft:water", + "minecraft:flowing_water" + ], + "offset": [ + 0, + -1, + 1 + ] + }, + { + "type": "minecraft:matching_fluids", + "fluids": [ + "minecraft:water", + "minecraft:flowing_water" + ], + "offset": [ + 0, + -1, + -1 + ] + } + ] + } + ] + } + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_swamp.json b/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_swamp.json new file mode 100644 index 0000000..8e849e5 --- /dev/null +++ b/src/generated/resources/data/firefly_bush_backport/worldgen/placed_feature/patch_firefly_bush_swamp.json @@ -0,0 +1,19 @@ +{ + "feature": "firefly_bush_backport:patch_firefly_bush", + "placement": [ + { + "type": "minecraft:rarity_filter", + "chance": 8 + }, + { + "type": "minecraft:in_square" + }, + { + "type": "minecraft:heightmap", + "heightmap": "MOTION_BLOCKING" + }, + { + "type": "minecraft:biome" + } + ] +} \ No newline at end of file diff --git a/src/main/java/dev/micle/firefly_bush_backport/data/DataGenerators.java b/src/main/java/dev/micle/firefly_bush_backport/data/DataGenerators.java index 3e682b4..e31fdc1 100644 --- a/src/main/java/dev/micle/firefly_bush_backport/data/DataGenerators.java +++ b/src/main/java/dev/micle/firefly_bush_backport/data/DataGenerators.java @@ -4,21 +4,27 @@ import dev.micle.firefly_bush_backport.FireflyBushBackport; import dev.micle.firefly_bush_backport.data.client.ModBlockStateProvider; import dev.micle.firefly_bush_backport.data.client.ModItemModelProvider; import dev.micle.firefly_bush_backport.data.client.ModSoundDefinitionsProvider; +import dev.micle.firefly_bush_backport.data.server.ModWorldGenProvider; +import net.minecraft.core.HolderLookup; import net.minecraft.data.DataGenerator; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.data.event.GatherDataEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import java.util.concurrent.CompletableFuture; + @Mod.EventBusSubscriber(modid = FireflyBushBackport.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class DataGenerators { @SubscribeEvent public static void gatherData(GatherDataEvent event) { DataGenerator generator = event.getGenerator(); ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); + CompletableFuture lookupProvider = event.getLookupProvider(); generator.addProvider(event.includeClient(), new ModBlockStateProvider(generator, existingFileHelper)); generator.addProvider(event.includeClient(), new ModItemModelProvider(generator, existingFileHelper)); generator.addProvider(event.includeClient(), new ModSoundDefinitionsProvider(generator, existingFileHelper)); + generator.addProvider(event.includeServer(), new ModWorldGenProvider(generator, lookupProvider)); } } diff --git a/src/main/java/dev/micle/firefly_bush_backport/data/server/ModWorldGenProvider.java b/src/main/java/dev/micle/firefly_bush_backport/data/server/ModWorldGenProvider.java new file mode 100644 index 0000000..3c9edc6 --- /dev/null +++ b/src/main/java/dev/micle/firefly_bush_backport/data/server/ModWorldGenProvider.java @@ -0,0 +1,26 @@ +package dev.micle.firefly_bush_backport.data.server; + +import dev.micle.firefly_bush_backport.FireflyBushBackport; +import dev.micle.firefly_bush_backport.worldgen.ModBiomeModifiers; +import dev.micle.firefly_bush_backport.worldgen.ModConfiguredFeatures; +import dev.micle.firefly_bush_backport.worldgen.ModPlacedFeatures; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.RegistrySetBuilder; +import net.minecraft.core.registries.Registries; +import net.minecraft.data.DataGenerator; +import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.Set; +import java.util.concurrent.CompletableFuture; + +public class ModWorldGenProvider extends DatapackBuiltinEntriesProvider { + public static final RegistrySetBuilder BUILDER = new RegistrySetBuilder() + .add(Registries.CONFIGURED_FEATURE, ModConfiguredFeatures::bootstrap) + .add(Registries.PLACED_FEATURE, ModPlacedFeatures::bootstrap) + .add(ForgeRegistries.Keys.BIOME_MODIFIERS, ModBiomeModifiers::bootstrap); + + public ModWorldGenProvider(DataGenerator generator, CompletableFuture registries) { + super(generator.getPackOutput(), registries, BUILDER, Set.of(FireflyBushBackport.MOD_ID)); + } +} diff --git a/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModBiomeModifiers.java b/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModBiomeModifiers.java new file mode 100644 index 0000000..d9e18ae --- /dev/null +++ b/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModBiomeModifiers.java @@ -0,0 +1,50 @@ +package dev.micle.firefly_bush_backport.worldgen; + +import dev.micle.firefly_bush_backport.FireflyBushBackport; +import net.minecraft.core.HolderGetter; +import net.minecraft.core.HolderSet; +import net.minecraft.core.registries.Registries; +import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.BiomeTags; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.minecraftforge.common.Tags; +import net.minecraftforge.common.world.BiomeModifier; +import net.minecraftforge.common.world.ForgeBiomeModifiers; +import net.minecraftforge.registries.ForgeRegistries; + +public class ModBiomeModifiers { + public static final ResourceKey ADD_PATCH_FIREFLY_BUSH_SWAMP = registerKey("add_patch_firefly_bush_swamp"); + public static final ResourceKey ADD_PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP = registerKey("add_patch_firefly_bush_near_water_swamp"); + public static final ResourceKey ADD_PATCH_FIREFLY_BUSH_NEAR_WATER = registerKey("add_patch_firefly_bush_near_water"); + + public static void bootstrap(BootstapContext context) { + HolderGetter placedFeatures = context.lookup(Registries.PLACED_FEATURE); + HolderGetter biomes = context.lookup(Registries.BIOME); + + context.register(ADD_PATCH_FIREFLY_BUSH_SWAMP, new ForgeBiomeModifiers.AddFeaturesBiomeModifier( + biomes.getOrThrow(Tags.Biomes.IS_SWAMP), + HolderSet.direct(placedFeatures.getOrThrow(ModPlacedFeatures.PATCH_FIREFLY_BUSH_SWAMP_PLACED_KEY)), + GenerationStep.Decoration.VEGETAL_DECORATION + )); + + context.register(ADD_PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP, new ForgeBiomeModifiers.AddFeaturesBiomeModifier( + biomes.getOrThrow(Tags.Biomes.IS_SWAMP), + HolderSet.direct(placedFeatures.getOrThrow(ModPlacedFeatures.PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP_PLACED_KEY)), + GenerationStep.Decoration.VEGETAL_DECORATION + )); + + context.register(ADD_PATCH_FIREFLY_BUSH_NEAR_WATER, new ForgeBiomeModifiers.AddFeaturesBiomeModifier( + biomes.getOrThrow(BiomeTags.IS_OVERWORLD), + HolderSet.direct(placedFeatures.getOrThrow(ModPlacedFeatures.PATCH_FIREFLY_BUSH_NEAR_WATER_PLACED_KEY)), + GenerationStep.Decoration.VEGETAL_DECORATION + )); + } + + private static ResourceKey registerKey(String name) { + return ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, name)); + } +} diff --git a/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModConfiguredFeatures.java b/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModConfiguredFeatures.java new file mode 100644 index 0000000..66849da --- /dev/null +++ b/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModConfiguredFeatures.java @@ -0,0 +1,44 @@ +package dev.micle.firefly_bush_backport.worldgen; + +import dev.micle.firefly_bush_backport.FireflyBushBackport; +import dev.micle.firefly_bush_backport.block.ModBlocks; +import net.minecraft.core.registries.Registries; +import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.data.worldgen.placement.PlacementUtils; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; +import net.minecraft.world.level.levelgen.feature.configurations.RandomPatchConfiguration; +import net.minecraft.world.level.levelgen.feature.configurations.SimpleBlockConfiguration; +import net.minecraft.world.level.levelgen.feature.stateproviders.SimpleStateProvider; + +public class ModConfiguredFeatures { + public static final ResourceKey> PATCH_FIREFLY_BUSH_KEY = registerKey("patch_firefly_bush"); + + public static void bootstrap(BootstapContext> context) { + register(context, PATCH_FIREFLY_BUSH_KEY, Feature.RANDOM_PATCH, new RandomPatchConfiguration( + 20, + 4, + 3, + PlacementUtils.onlyWhenEmpty( + Feature.SIMPLE_BLOCK, + new SimpleBlockConfiguration( + SimpleStateProvider.simple(ModBlocks.FIREFLY_BUSH.get()) + ) + ) + )); + } + + public static ResourceKey> registerKey(String name) { + return ResourceKey.create(Registries.CONFIGURED_FEATURE, ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, name)); + } + + private static > void register( + BootstapContext> context, + ResourceKey> key, F feature, FC configuration + ) { + context.register(key, new ConfiguredFeature<>(feature, configuration)); + } +} diff --git a/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModPlacedFeatures.java b/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModPlacedFeatures.java new file mode 100644 index 0000000..c7a3094 --- /dev/null +++ b/src/main/java/dev/micle/firefly_bush_backport/worldgen/ModPlacedFeatures.java @@ -0,0 +1,79 @@ +package dev.micle.firefly_bush_backport.worldgen; + +import dev.micle.firefly_bush_backport.FireflyBushBackport; +import dev.micle.firefly_bush_backport.block.ModBlocks; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderGetter; +import net.minecraft.core.Vec3i; +import net.minecraft.core.registries.Registries; +import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.data.worldgen.placement.PlacementUtils; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.placement.*; +import net.minecraft.world.level.material.Fluids; + +import java.util.List; + +public class ModPlacedFeatures { + public static final ResourceKey PATCH_FIREFLY_BUSH_SWAMP_PLACED_KEY = registerKey("patch_firefly_bush_swamp"); + public static final ResourceKey PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP_PLACED_KEY = registerKey("patch_firefly_bush_near_water_swamp"); + public static final ResourceKey PATCH_FIREFLY_BUSH_NEAR_WATER_PLACED_KEY = registerKey("patch_firefly_bush_near_water"); + + public static void bootstrap(BootstapContext context) { + HolderGetter> configuredFeatures = context.lookup(Registries.CONFIGURED_FEATURE); + + register(context, PATCH_FIREFLY_BUSH_SWAMP_PLACED_KEY, configuredFeatures.getOrThrow(ModConfiguredFeatures.PATCH_FIREFLY_BUSH_KEY), List.of( + RarityFilter.onAverageOnceEvery(8), + InSquarePlacement.spread(), + PlacementUtils.HEIGHTMAP, + BiomeFilter.biome() + )); + + register(context, PATCH_FIREFLY_BUSH_NEAR_WATER_SWAMP_PLACED_KEY, configuredFeatures.getOrThrow(ModConfiguredFeatures.PATCH_FIREFLY_BUSH_KEY), List.of( + CountPlacement.of(3), + InSquarePlacement.spread(), + PlacementUtils.HEIGHTMAP, + BiomeFilter.biome(), + BlockPredicateFilter.forPredicate(BlockPredicate.allOf( + BlockPredicate.matchesBlocks(Blocks.AIR), + BlockPredicate.wouldSurvive(ModBlocks.FIREFLY_BUSH.get().defaultBlockState(), Vec3i.ZERO), + BlockPredicate.anyOf( + BlockPredicate.matchesFluids(new Vec3i(1, -1, 0), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), + BlockPredicate.matchesFluids(new Vec3i(-1, -1, 0), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), + BlockPredicate.matchesFluids(new Vec3i(0, -1, 1), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), + BlockPredicate.matchesFluids(new Vec3i(0, -1, -1), List.of(Fluids.WATER, Fluids.FLOWING_WATER)) + ) + )) + )); + + register(context, PATCH_FIREFLY_BUSH_NEAR_WATER_PLACED_KEY, configuredFeatures.getOrThrow(ModConfiguredFeatures.PATCH_FIREFLY_BUSH_KEY), List.of( + CountPlacement.of(2), + InSquarePlacement.spread(), + HeightmapPlacement.onHeightmap(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES), + BiomeFilter.biome(), + BlockPredicateFilter.forPredicate(BlockPredicate.allOf( + BlockPredicate.matchesBlocks(Blocks.AIR), + BlockPredicate.wouldSurvive(ModBlocks.FIREFLY_BUSH.get().defaultBlockState(), Vec3i.ZERO), + BlockPredicate.anyOf( + BlockPredicate.matchesFluids(new Vec3i(1, -1, 0), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), + BlockPredicate.matchesFluids(new Vec3i(-1, -1, 0), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), + BlockPredicate.matchesFluids(new Vec3i(0, -1, 1), List.of(Fluids.WATER, Fluids.FLOWING_WATER)), + BlockPredicate.matchesFluids(new Vec3i(0, -1, -1), List.of(Fluids.WATER, Fluids.FLOWING_WATER)) + ) + )) + )); + } + + private static ResourceKey registerKey(String name) { + return ResourceKey.create(Registries.PLACED_FEATURE, ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, name)); + } + + private static void register(BootstapContext context, ResourceKey key, Holder> configuration, List modifiers) { + context.register(key, new PlacedFeature(configuration, List.copyOf(modifiers))); + } +}