From c494beaf7f1cdd23caf857871f112e64cb33f795 Mon Sep 17 00:00:00 2001 From: "Joseph T. McQuigg" Date: Mon, 30 Sep 2024 15:21:32 -0400 Subject: [PATCH] Move TemplatePools to Factories Model Signed-off-by: Joseph T. McQuigg --- .../GenerationsStructureSettings.java | 13 - .../village/VanillaVillages.java | 8 +- .../GenerationsTemplatePools.java | 256 ++++++++---------- .../forge/datagen/ForgeDatagen.java | 2 +- 4 files changed, 125 insertions(+), 154 deletions(-) diff --git a/common/src/main/java/generations/gg/generations/structures/generationsstructures/structures/GenerationsStructureSettings.java b/common/src/main/java/generations/gg/generations/structures/generationsstructures/structures/GenerationsStructureSettings.java index e0a9a76..7c75328 100644 --- a/common/src/main/java/generations/gg/generations/structures/generationsstructures/structures/GenerationsStructureSettings.java +++ b/common/src/main/java/generations/gg/generations/structures/generationsstructures/structures/GenerationsStructureSettings.java @@ -114,19 +114,6 @@ public static void bootstrap(BootstapContext context) { Heightmap.Types.WORLD_SURFACE_WG )); - registerStructure(context, GenerationsStructuresKeys.LUGIA_SHRINE, createJigsaw( - new Structure.StructureSettings( - biomeHolderGetter.getOrThrow(GenerationsBiomeTags.HAS_LUGIA_SHRINE), - Map.of(), - GenerationStep.Decoration.SURFACE_STRUCTURES, - TerrainAdjustment.BEARD_THIN - ), - poolHolderGetter.getOrThrow(GenerationsTemplatePools.LUGIA_SHRINE), - 1, - ConstantHeight.of(VerticalAnchor.absolute(1)), - Heightmap.Types.WORLD_SURFACE_WG - )); - registerStructure(context, GenerationsStructuresKeys.ISLANDS, createJigsaw( new Structure.StructureSettings( biomeHolderGetter.getOrThrow(GenerationsBiomeTags.HAS_ISLANDS), diff --git a/common/src/main/java/generations/gg/generations/structures/generationsstructures/village/VanillaVillages.java b/common/src/main/java/generations/gg/generations/structures/generationsstructures/village/VanillaVillages.java index be64eaf..f753720 100644 --- a/common/src/main/java/generations/gg/generations/structures/generationsstructures/village/VanillaVillages.java +++ b/common/src/main/java/generations/gg/generations/structures/generationsstructures/village/VanillaVillages.java @@ -13,10 +13,10 @@ public enum VanillaVillages { PLAINS("plains", GenerationsTemplatePools.PLAINS_VILLAGE_POKECENTER, GenerationsTemplatePools.PLAINS_VILLAGE_POKEMART, GenerationsTemplatePools.PLAINS_VILLAGE_POKECENTER_STREETS, GenerationsTemplatePools.PLAINS_VILLAGE_POKEMART_STREETS, BiomeTags.HAS_VILLAGE_PLAINS), - DESERT("desert", GenerationsTemplatePools.DESERT_VILLAGE_POKECENTER, GenerationsTemplatePools.DESERT_VILLAGE_POKEMART, GenerationsTemplatePools.DESERT_VILLAGE_POKECENTER_STREETS, GenerationsTemplatePools.DESERT_VILLAGE_POKEMART_STREETS, BiomeTags.HAS_VILLAGE_DESERT), - SAVANNA("savanna", GenerationsTemplatePools.SAVANNA_VILLAGE_POKECENTER, GenerationsTemplatePools.SAVANNA_VILLAGE_POKEMART, GenerationsTemplatePools.SAVANNA_VILLAGE_POKECENTER_STREETS, GenerationsTemplatePools.SAVANNA_VILLAGE_POKEMART_STREETS, BiomeTags.HAS_VILLAGE_SAVANNA), - SNOWY("snowy", GenerationsTemplatePools.SNOWY_VILLAGE_POKECENTER, GenerationsTemplatePools.SNOWY_VILLAGE_POKEMART, GenerationsTemplatePools.SNOWY_VILLAGE_POKECENTER_STREETS, GenerationsTemplatePools.SNOWY_VILLAGE_POKEMART_STREETS, BiomeTags.HAS_VILLAGE_SNOWY), - TAIGA("taiga", GenerationsTemplatePools.TAIGA_VILLAGE_POKECENTER, GenerationsTemplatePools.TAIGA_VILLAGE_POKEMART, GenerationsTemplatePools.TAIGA_VILLAGE_POKECENTER_STREETS, GenerationsTemplatePools.TAIGA_VILLAGE_POKEMART_STREETS, BiomeTags.HAS_VILLAGE_TAIGA); + DESERT("desert", GenerationsTemplatePools.DESERT_VILLAGE_POKECENTER, GenerationsTemplatePools.DESERT_VILLAGE_POKEMART, GenerationsTemplatePools.DESERT_VILLAGE_POKECENTER_STREETS, GenerationsTemplatePools.DESERT_VILLAGE_POKEMART_STREETS, BiomeTags.HAS_VILLAGE_DESERT); + //SAVANNA("savanna", GenerationsTemplatePools.SAVANNA_VILLAGE_POKECENTER, GenerationsTemplatePools.SAVANNA_VILLAGE_POKEMART, GenerationsTemplatePools.SAVANNA_VILLAGE_POKECENTER_STREETS, GenerationsTemplatePools.SAVANNA_VILLAGE_POKEMART_STREETS, BiomeTags.HAS_VILLAGE_SAVANNA), + //SNOWY("snowy", GenerationsTemplatePools.SNOWY_VILLAGE_POKECENTER, GenerationsTemplatePools.SNOWY_VILLAGE_POKEMART, GenerationsTemplatePools.SNOWY_VILLAGE_POKECENTER_STREETS, GenerationsTemplatePools.SNOWY_VILLAGE_POKEMART_STREETS, BiomeTags.HAS_VILLAGE_SNOWY), + //TAIGA("taiga", GenerationsTemplatePools.TAIGA_VILLAGE_POKECENTER, GenerationsTemplatePools.TAIGA_VILLAGE_POKEMART, GenerationsTemplatePools.TAIGA_VILLAGE_POKECENTER_STREETS, GenerationsTemplatePools.TAIGA_VILLAGE_POKEMART_STREETS, BiomeTags.HAS_VILLAGE_TAIGA); private final String name; private final ResourceKey pokecenter; diff --git a/common/src/main/java/generations/gg/generations/structures/generationsstructures/worldgen/template_pool/GenerationsTemplatePools.java b/common/src/main/java/generations/gg/generations/structures/generationsstructures/worldgen/template_pool/GenerationsTemplatePools.java index 24a1805..4029b1d 100644 --- a/common/src/main/java/generations/gg/generations/structures/generationsstructures/worldgen/template_pool/GenerationsTemplatePools.java +++ b/common/src/main/java/generations/gg/generations/structures/generationsstructures/worldgen/template_pool/GenerationsTemplatePools.java @@ -6,46 +6,80 @@ import generations.gg.generations.structures.generationsstructures.processors.GenerationsProcessorLists; import generations.gg.generations.structures.generationsstructures.structures.GenerationsStructuresKeys; import generations.gg.generations.structures.generationsstructures.village.VanillaVillages; +import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BootstapContext; import net.minecraft.data.worldgen.Pools; import net.minecraft.data.worldgen.ProcessorLists; import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement; import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList; import java.util.List; +import java.util.Map; import java.util.function.Function; public class GenerationsTemplatePools { - public static final ResourceKey BEAST_BALLOON = create("loot_balloon/beast_balloon"); - public static final ResourceKey GREAT_BALLOON = create("loot_balloon/great_balloon"); - public static final ResourceKey MASTER_BALLOON = create("loot_balloon/master_balloon"); - public static final ResourceKey MEOWTH_BALLOON = create("loot_balloon/meowth_balloon"); - public static final ResourceKey POKE_BALLOON = create("loot_balloon/poke_balloon"); - public static final ResourceKey ULTRA_BALLOON = create("loot_balloon/ultra_balloon"); - - public static final ResourceKey COMET = create("comet"); - public static final ResourceKey SCARLET_POKECENTER = create("scarlet_pokecenter"); - public static final ResourceKey SCARLET_POKECENTER_ANTENNA = create("scarlet_pokecenter_antenna"); - public static final ResourceKey LARGE_POKECENTER = create("large_pokecenter"); - public static final ResourceKey ISLANDS = create("islands"); - public static final ResourceKey FROZEN_SHRINE = create("shrines/frozen_shrine"); - public static final ResourceKey FIERY_SHRINE = create("shrines/fiery_shrine"); - public static final ResourceKey STATIC_SHRINE = create("shrines/static_shrine"); - public static final ResourceKey LUGIA_SHRINE = create("shrines/lugia_shrine"); - - public static final ResourceKey PLAINS_VILLAGE_POKECENTER_STREETS = create("village/plains/streets/pokecenter"); - public static final ResourceKey PLAINS_VILLAGE_POKECENTER = create("village/plains/pokecenter"); - public static final ResourceKey PLAINS_VILLAGE_POKEMART_STREETS = create("village/plains/streets/pokemart"); - public static final ResourceKey PLAINS_VILLAGE_POKEMART = create("village/plains/pokemart"); - public static final ResourceKey DESERT_VILLAGE_POKECENTER_STREETS = create("village/desert/streets/pokecenter"); - public static final ResourceKey DESERT_VILLAGE_POKECENTER = create("village/desert/pokecenter"); - public static final ResourceKey DESERT_VILLAGE_POKEMART_STREETS = create("village/desert/streets/pokemart"); - public static final ResourceKey DESERT_VILLAGE_POKEMART = create("village/desert/pokemart"); + public static final Map, TemplatePoolFactory> TEMPLATE_POOL_FACTORIES = new Reference2ObjectOpenHashMap<>(); + + public static final ResourceKey BEAST_BALLOON = registerSimple("loot_balloon/beast_balloon", GenerationsStructuresKeys.BEAST_BALLOON); + public static final ResourceKey GREAT_BALLOON = registerSimple("loot_balloon/great_balloon", GenerationsStructuresKeys.GREAT_BALLOON); + public static final ResourceKey MASTER_BALLOON = registerSimple("loot_balloon/master_balloon", GenerationsStructuresKeys.MASTER_BALLOON); + public static final ResourceKey MEOWTH_BALLOON = registerSimple("loot_balloon/meowth_balloon", GenerationsStructuresKeys.MEOWTH_BALLOON); + public static final ResourceKey POKE_BALLOON = registerSimple("loot_balloon/poke_balloon", GenerationsStructuresKeys.POKE_BALLOON); + public static final ResourceKey ULTRA_BALLOON = registerSimple("loot_balloon/ultra_balloon", GenerationsStructuresKeys.ULTRA_BALLOON); + + public static final ResourceKey COMET = registerSimple("comet", GenerationsStructuresKeys.COMET); + public static final ResourceKey SCARLET_POKECENTER = registerSimple("scarlet_pokecenter", GenerationsStructuresKeys.SCARLET_POKECENTER, GenerationsProcessorLists.SCARLET_POKECENTER_PROCESSOR_LIST); + public static final ResourceKey SCARLET_POKECENTER_ANTENNA = registerSimple("scarlet_pokecenter_antenna", GenerationsStructuresKeys.SCARLET_POKECENTER_ANTENNA); + public static final ResourceKey LARGE_POKECENTER = registerSimple("large_pokecenter", GenerationsStructuresKeys.LARGE_POKECENTER, GenerationsProcessorLists.POKECENTER_PROCESSOR_LIST); + public static final ResourceKey ISLANDS = registerSimple("islands", GenerationsStructuresKeys.ISLANDS); + public static final ResourceKey FROZEN_SHRINE = registerSimple("shrines/frozen_shrine", GenerationsStructuresKeys.FROZEN_SHRINE, GenerationsProcessorLists.FROZEN_SHRINE_PROCESSOR_LIST); + public static final ResourceKey FIERY_SHRINE = registerSimple("shrines/fiery_shrine", GenerationsStructuresKeys.FIERY_SHRINE, GenerationsProcessorLists.FIERY_SHRINE_PROCESSOR_LIST); + public static final ResourceKey STATIC_SHRINE = registerSimple("shrines/static_shrine", GenerationsStructuresKeys.STATIC_SHRINE, GenerationsProcessorLists.STATIC_SHRINE_PROCESSOR_LIST); + + public static final ResourceKey PLAINS_VILLAGE_POKECENTER_STREETS = register("village/plains/streets/pokecenter", context -> createTemplatePool(getPool(context, VanillaVillages.PLAINS.getVillagePool("streets")), ImmutableList.of( + createPoolElement(context, GenerationsStructuresKeys.PLAINS_POKECENTER_STREET_CORNER_01, ProcessorLists.STREET_PLAINS, 1), + createPoolElement(context, GenerationsStructuresKeys.PLAINS_POKECENTER_STREET_STRAIGHT_05, ProcessorLists.STREET_PLAINS, 1) + ), StructureTemplatePool.Projection.TERRAIN_MATCHING)); + public static final ResourceKey PLAINS_VILLAGE_POKECENTER = register("village/plains/pokecenter", context -> createTemplatePool(context, ImmutableList.of( + createPoolElement(context, GenerationsStructuresKeys.PLAINS_POKECENTER_1, 1), + createPoolElement(context, GenerationsStructuresKeys.PLAINS_POKECENTER_2, 1), + createPoolElement(context, GenerationsStructuresKeys.PLAINS_POKECENTER_3, 1) + ))); + public static final ResourceKey PLAINS_VILLAGE_POKEMART_STREETS = register("village/plains/streets/pokemart", context -> createTemplatePool(getPool(context, VanillaVillages.PLAINS.getVillagePool("streets")), ImmutableList.of( + createPoolElement(context, GenerationsStructuresKeys.PLAINS_POKEMART_STREET_CORNER_01, ProcessorLists.STREET_PLAINS, 1), + createPoolElement(context, GenerationsStructuresKeys.PLAINS_POKEMART_STREET_STRAIGHT_05, ProcessorLists.STREET_PLAINS, 1) + ), StructureTemplatePool.Projection.TERRAIN_MATCHING)); + + public static final ResourceKey PLAINS_VILLAGE_POKEMART = register("village/plains/pokemart", context -> createTemplatePool(context, ImmutableList.of( + createPoolElement(context, GenerationsStructuresKeys.PLAINS_POKEMART_1, 1), + createPoolElement(context, GenerationsStructuresKeys.PLAINS_POKEMART_2, 1), + createPoolElement(context, GenerationsStructuresKeys.PLAINS_POKEMART_3, 1) + ))); + public static final ResourceKey DESERT_VILLAGE_POKECENTER_STREETS = register("village/desert/streets/pokecenter", context -> createTemplatePool(getPool(context, VanillaVillages.DESERT.getVillagePool("streets")), ImmutableList.of( + createPoolElement(context, GenerationsStructuresKeys.DESERT_POKECENTER_STREET_CORNER_01, ProcessorLists.EMPTY, 1), + createPoolElement(context, GenerationsStructuresKeys.DESERT_POKECENTER_STREET_STRAIGHT_05, ProcessorLists.EMPTY, 1) + ), StructureTemplatePool.Projection.TERRAIN_MATCHING)); + public static final ResourceKey DESERT_VILLAGE_POKECENTER = register("village/desert/pokecenter", context -> createTemplatePool(context, ImmutableList.of( + createPoolElement(context, GenerationsStructuresKeys.DESERT_POKECENTER_1, 1), + createPoolElement(context, GenerationsStructuresKeys.DESERT_POKECENTER_2, 1), + createPoolElement(context, GenerationsStructuresKeys.DESERT_POKECENTER_3, 1) + ))); + public static final ResourceKey DESERT_VILLAGE_POKEMART_STREETS = register("village/desert/streets/pokemart", context -> createTemplatePool(getPool(context, VanillaVillages.DESERT.getVillagePool("streets")), ImmutableList.of( + createPoolElement(context, GenerationsStructuresKeys.DESERT_POKEMART_STREET_CORNER_01, ProcessorLists.EMPTY, 1), + createPoolElement(context, GenerationsStructuresKeys.DESERT_POKEMART_STREET_STRAIGHT_05, ProcessorLists.EMPTY, 1) + ), StructureTemplatePool.Projection.TERRAIN_MATCHING)); + public static final ResourceKey DESERT_VILLAGE_POKEMART = register("village/desert/pokemart", context -> createTemplatePool(context, ImmutableList.of( + createPoolElement(context, GenerationsStructuresKeys.DESERT_POKEMART_1, 1), + createPoolElement(context, GenerationsStructuresKeys.DESERT_POKEMART_2, 1), + createPoolElement(context, GenerationsStructuresKeys.DESERT_POKEMART_3, 1) + ))); + /* public static final ResourceKey SAVANNA_VILLAGE_POKECENTER_STREETS = create("village/savanna/streets/pokecenter"); public static final ResourceKey SAVANNA_VILLAGE_POKECENTER = create("village/savanna/pokecenter"); public static final ResourceKey SAVANNA_VILLAGE_POKEMART_STREETS = create("village/savanna/streets/pokemart"); @@ -57,124 +91,74 @@ public class GenerationsTemplatePools { public static final ResourceKey TAIGA_VILLAGE_POKECENTER_STREETS = create("village/taiga/streets/pokecenter"); public static final ResourceKey TAIGA_VILLAGE_POKECENTER = create("village/taiga/pokecenter"); public static final ResourceKey TAIGA_VILLAGE_POKEMART_STREETS = create("village/taiga/streets/pokemart"); - public static final ResourceKey TAIGA_VILLAGE_POKEMART = create("village/taiga/pokemart"); - - - public static void bootstrap(BootstapContext context) { - register(context, BEAST_BALLOON, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.BEAST_BALLOON.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, GREAT_BALLOON, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.GREAT_BALLOON.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, MASTER_BALLOON, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.MASTER_BALLOON.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, MEOWTH_BALLOON, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.MEOWTH_BALLOON.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, POKE_BALLOON, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.POKE_BALLOON.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, ULTRA_BALLOON, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.ULTRA_BALLOON.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, COMET, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.COMET.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, SCARLET_POKECENTER, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.SCARLET_POKECENTER.location().toString(), getProcessor(context, GenerationsProcessorLists.SCARLET_POKECENTER_PROCESSOR_LIST)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, SCARLET_POKECENTER_ANTENNA, SCARLET_POKECENTER_ANTENNA, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.SCARLET_POKECENTER_ANTENNA.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, LARGE_POKECENTER, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.LARGE_POKECENTER.location().toString(), getProcessor(context, GenerationsProcessorLists.POKECENTER_PROCESSOR_LIST)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, ISLANDS, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.ISLANDS.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, FROZEN_SHRINE, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.FROZEN_SHRINE.location().toString(), getProcessor(context, GenerationsProcessorLists.FROZEN_SHRINE_PROCESSOR_LIST)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, FIERY_SHRINE, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.FIERY_SHRINE.location().toString(), getProcessor(context, GenerationsProcessorLists.FIERY_SHRINE_PROCESSOR_LIST)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, STATIC_SHRINE, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.STATIC_SHRINE.location().toString(), getProcessor(context, GenerationsProcessorLists.STATIC_SHRINE_PROCESSOR_LIST)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, LUGIA_SHRINE, Pools.EMPTY, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.LUGIA_SHRINE.location().toString(), getProcessor(context, GenerationsProcessorLists.LUGIA_SHRINE_PROCESSOR_LIST)), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, PLAINS_VILLAGE_POKECENTER_STREETS, VanillaVillages.PLAINS.getVillagePool("streets"), ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.PLAINS_POKECENTER_STREET_CORNER_01.location().toString(), getProcessor(context, ProcessorLists.STREET_PLAINS)), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.PLAINS_POKECENTER_STREET_STRAIGHT_05.location().toString(), getProcessor(context, ProcessorLists.STREET_PLAINS)), 1) - ), StructureTemplatePool.Projection.TERRAIN_MATCHING); - - register(context, PLAINS_VILLAGE_POKECENTER, PLAINS_VILLAGE_POKECENTER, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.PLAINS_POKECENTER_1.location().toString()), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.PLAINS_POKECENTER_2.location().toString()), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.PLAINS_POKECENTER_3.location().toString()), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, PLAINS_VILLAGE_POKEMART_STREETS, VanillaVillages.PLAINS.getVillagePool("streets"), ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.PLAINS_POKEMART_STREET_CORNER_01.location().toString(), getProcessor(context, ProcessorLists.STREET_PLAINS)), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.PLAINS_POKEMART_STREET_STRAIGHT_05.location().toString(), getProcessor(context, ProcessorLists.STREET_PLAINS)), 1) - ), StructureTemplatePool.Projection.TERRAIN_MATCHING); - - register(context, PLAINS_VILLAGE_POKEMART, PLAINS_VILLAGE_POKEMART, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.PLAINS_POKEMART_1.location().toString()), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.PLAINS_POKEMART_2.location().toString()), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.PLAINS_POKEMART_3.location().toString()), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, DESERT_VILLAGE_POKEMART_STREETS, VanillaVillages.DESERT.getVillagePool("streets"), ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.DESERT_POKEMART_STREET_CORNER_01.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.DESERT_POKEMART_STREET_STRAIGHT_05.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1) - ), StructureTemplatePool.Projection.TERRAIN_MATCHING); - - register(context, DESERT_VILLAGE_POKECENTER_STREETS, VanillaVillages.DESERT.getVillagePool("streets"), ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.DESERT_POKECENTER_STREET_CORNER_01.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.DESERT_POKECENTER_STREET_STRAIGHT_05.location().toString(), getProcessor(context, ProcessorLists.EMPTY)), 1) - ), StructureTemplatePool.Projection.TERRAIN_MATCHING); - - register(context, DESERT_VILLAGE_POKEMART, DESERT_VILLAGE_POKEMART, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.DESERT_POKEMART_1.location().toString()), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.DESERT_POKEMART_2.location().toString()), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.DESERT_POKEMART_3.location().toString()), 1) - ), StructureTemplatePool.Projection.RIGID); - - register(context, DESERT_VILLAGE_POKECENTER, DESERT_VILLAGE_POKECENTER, ImmutableList.of( - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.DESERT_POKECENTER_1.location().toString()), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.DESERT_POKECENTER_2.location().toString()), 1), - Pair.of(StructurePoolElement.single(GenerationsStructuresKeys.DESERT_POKECENTER_3.location().toString()), 1) - ), StructureTemplatePool.Projection.RIGID); + public static final ResourceKey TAIGA_VILLAGE_POKEMART = create("village/taiga/pokemart"); */ + + + private static Pair, Integer> createPoolElement(BootstapContext context, ResourceKey structure) { + return createPoolElement(context, structure, 1); } - private static ResourceKey create(String name) { - return ResourceKey.create(Registries.TEMPLATE_POOL, GenerationsStructures.id(name)); + private static Pair, Integer> createPoolElement(BootstapContext context, ResourceKey structure, int weight) { + return Pair.of(StructurePoolElement.single(structure.location().toString(), getEmptyProcessor(context)), weight); + } + + private static Pair, Integer> createPoolElement(BootstapContext context, ResourceKey structure, ResourceKey processor) { + return createPoolElement(context, structure, processor, 1); + } + + private static Pair, Integer> createPoolElement(BootstapContext context, ResourceKey structure, ResourceKey processor, int weight) { + return Pair.of(StructurePoolElement.single(structure.location().toString(), getProcessor(context, processor)), weight); } - private static void register(BootstapContext context, ResourceKey key, ResourceKey fallback, List, Integer>> rawTemplateFactories, StructureTemplatePool.Projection projection) { - context.register(key, new StructureTemplatePool(context.lookup(Registries.TEMPLATE_POOL).getOrThrow(fallback), rawTemplateFactories, projection)); + private static StructureTemplatePool createTemplatePool(Holder fallback, List, Integer>> rawTemplateFactories, StructureTemplatePool.Projection projection) { + return new StructureTemplatePool(fallback, rawTemplateFactories, projection); + } + + private static StructureTemplatePool createTemplatePool(BootstapContext context, List, Integer>> rawTemplateFactories) { + return new StructureTemplatePool(getPool(context, Pools.EMPTY), rawTemplateFactories, StructureTemplatePool.Projection.RIGID); + } + + private static StructureTemplatePool createTemplatePool(Holder fallback, List, Integer>> rawTemplateFactories) { + return new StructureTemplatePool(fallback, rawTemplateFactories, StructureTemplatePool.Projection.RIGID); + } + + private static ResourceKey registerSimple(String id, ResourceKey structure, ResourceKey processor) { + ResourceKey templatePoolResourceKey = create(id); + TEMPLATE_POOL_FACTORIES.put(templatePoolResourceKey, context -> createTemplatePool(context, ImmutableList.of(createPoolElement(context, structure, processor)))); + return templatePoolResourceKey; + } + + private static ResourceKey registerSimple(String id, ResourceKey structure) { + ResourceKey templatePoolResourceKey = create(id); + TEMPLATE_POOL_FACTORIES.put(templatePoolResourceKey, context -> createTemplatePool(context, ImmutableList.of(createPoolElement(context, structure)))); + return templatePoolResourceKey; + } + + private static ResourceKey register(String id, TemplatePoolFactory factory) { + ResourceKey templatePoolResourceKey = create(id); + TEMPLATE_POOL_FACTORIES.put(templatePoolResourceKey, factory); + return templatePoolResourceKey; + } + + private static ResourceKey create(String name) { + return ResourceKey.create(Registries.TEMPLATE_POOL, GenerationsStructures.id(name)); } private static Holder.Reference getProcessor(BootstapContext context, ResourceKey processorList) { return context.lookup(Registries.PROCESSOR_LIST).getOrThrow(processorList); } + + private static Holder.Reference getPool(BootstapContext context, ResourceKey poolResourceKey) { + return context.lookup(Registries.TEMPLATE_POOL).getOrThrow(poolResourceKey); + } + + private static Holder.Reference getEmptyProcessor(BootstapContext context) { + return context.lookup(Registries.PROCESSOR_LIST).getOrThrow(ProcessorLists.EMPTY); + } + + + @FunctionalInterface + public interface TemplatePoolFactory { + StructureTemplatePool generate(BootstapContext templatePoolFactoryContext); + } } diff --git a/forge/src/main/java/generations/gg/generations/structures/generationsstructures/forge/datagen/ForgeDatagen.java b/forge/src/main/java/generations/gg/generations/structures/generationsstructures/forge/datagen/ForgeDatagen.java index 5e8dd15..e5bbec4 100644 --- a/forge/src/main/java/generations/gg/generations/structures/generationsstructures/forge/datagen/ForgeDatagen.java +++ b/forge/src/main/java/generations/gg/generations/structures/generationsstructures/forge/datagen/ForgeDatagen.java @@ -50,7 +50,7 @@ public static void gatherData(GatherDataEvent event) { } private static final RegistrySetBuilder BUILDER = new RegistrySetBuilder() - .add(Registries.TEMPLATE_POOL, GenerationsTemplatePools::bootstrap) + .add(Registries.TEMPLATE_POOL, context -> GenerationsTemplatePools.TEMPLATE_POOL_FACTORIES.forEach((key, factory) -> context.register(key, factory.generate(context)))) .add(Registries.STRUCTURE, GenerationsStructureSettings::bootstrap) .add(Registries.STRUCTURE_SET, context -> GenerationsStructureSets.STRUCTURE_SET_FACTORIES.forEach((key, factory) -> context.register(key, factory.generate(context.lookup(Registries.STRUCTURE))))) .add(Registries.PROCESSOR_LIST, GenerationsProcessorLists::bootstrap);