From 8e684ec7959f966ab04b6a90a6c55c8cdd710ad6 Mon Sep 17 00:00:00 2001 From: Mal Larsson-Reyes <139512944+maloryware@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:24:54 +0000 Subject: [PATCH] feat: Add PoiType registration (#103) * Added PoiType Registering to WorldGen * Update forge/src/main/java/net/blay09/mods/balm/forge/world/ForgeBalmWorldGen.java Co-authored-by: Mal Larsson-Reyes <139512944+maloryware@users.noreply.github.com> --------- Co-authored-by: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> --- .../balm/fabric/world/FabricBalmWorldGen.java | 17 ++++++++++------- .../balm/forge/world/ForgeBalmWorldGen.java | 9 ++++++++- .../mods/balm/api/world/BalmWorldGen.java | 3 +++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/fabric/src/main/java/net/blay09/mods/balm/fabric/world/FabricBalmWorldGen.java b/fabric/src/main/java/net/blay09/mods/balm/fabric/world/FabricBalmWorldGen.java index 322a7e7c..043c5e71 100644 --- a/fabric/src/main/java/net/blay09/mods/balm/fabric/world/FabricBalmWorldGen.java +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/world/FabricBalmWorldGen.java @@ -4,20 +4,14 @@ import net.blay09.mods.balm.api.world.BalmWorldGen; import net.blay09.mods.balm.api.world.BiomePredicate; import net.fabricmc.fabric.api.biome.v1.BiomeModifications; -import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; -import net.minecraft.data.worldgen.features.FeatureUtils; -import net.minecraft.data.worldgen.placement.PlacementUtils; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.ai.village.poi.PoiType; import net.minecraft.world.level.levelgen.GenerationStep; -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.placement.PlacedFeature; -import net.minecraft.world.level.levelgen.placement.PlacementModifier; import net.minecraft.world.level.levelgen.placement.PlacementModifierType; import java.util.function.Supplier; @@ -41,6 +35,15 @@ public > DeferredObject registerPlacementM }).resolveImmediately(); } + @Override + public DeferredObject registerPoiType(ResourceLocation identifier, Supplier supplier) { + return new DeferredObject<>(identifier, () -> { + T poiType = supplier.get(); + Registry.register(BuiltInRegistries.POINT_OF_INTEREST_TYPE, identifier, poiType); + return poiType; + }).resolveImmediately(); + } + @Override public void addFeatureToBiomes(BiomePredicate biomePredicate, GenerationStep.Decoration step, ResourceLocation placedFeatureIdentifier) { BiomeModifications.addFeature(it -> biomePredicate.test(it.getBiomeKey().location(), it.getBiomeRegistryEntry()), diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/world/ForgeBalmWorldGen.java b/forge/src/main/java/net/blay09/mods/balm/forge/world/ForgeBalmWorldGen.java index 787ed26e..6d353b22 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/world/ForgeBalmWorldGen.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/world/ForgeBalmWorldGen.java @@ -11,6 +11,7 @@ import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.ai.village.poi.PoiType; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.feature.Feature; @@ -50,7 +51,6 @@ public void commonSetup(FMLCommonSetupEvent event) { }); } } - public static final Codec BALM_BIOME_MODIFIER_CODEC = Codec.unit(BalmBiomeModifier.INSTANCE); private final Map registrations = new ConcurrentHashMap<>(); @@ -76,6 +76,13 @@ public > DeferredObject registerPlacementM return deferredObject; } + @Override + public DeferredObject registerPoiType(ResourceLocation identifier, Supplier supplier) { + DeferredRegister register = DeferredRegisters.get(ForgeRegistries.POI_TYPES, identifier.getNamespace()); + RegistryObject registryObject = register.register(identifier.getPath(), supplier); + return new DeferredObject<>(identifier,registryObject, registryObject::isPresent); + } + private static final List biomeModifications = new ArrayList<>(); @Override diff --git a/shared/src/main/java/net/blay09/mods/balm/api/world/BalmWorldGen.java b/shared/src/main/java/net/blay09/mods/balm/api/world/BalmWorldGen.java index 4cc4ca34..fd41845c 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/world/BalmWorldGen.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/world/BalmWorldGen.java @@ -2,6 +2,7 @@ import net.blay09.mods.balm.api.DeferredObject; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.ai.village.poi.PoiType; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; @@ -17,5 +18,7 @@ public interface BalmWorldGen { > DeferredObject registerPlacementModifier(ResourceLocation identifier, Supplier supplier); + DeferredObject registerPoiType(ResourceLocation identifier, Supplier supplier); + void addFeatureToBiomes(BiomePredicate biomePredicate, GenerationStep.Decoration step, ResourceLocation configuredFeatureIdentifier); }