Skip to content

Commit

Permalink
feat: Add PoiType registration (#103)
Browse files Browse the repository at this point in the history
* Added PoiType Registering to WorldGen

* Update forge/src/main/java/net/blay09/mods/balm/forge/world/ForgeBalmWorldGen.java

Co-authored-by: Mal Larsson-Reyes <[email protected]>

---------

Co-authored-by: BlayTheNinth <[email protected]>
  • Loading branch information
maloryware and BlayTheNinth authored Dec 4, 2024
1 parent ea41392 commit 8e684ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,6 +35,15 @@ public <T extends PlacementModifierType<?>> DeferredObject<T> registerPlacementM
}).resolveImmediately();
}

@Override
public <T extends PoiType> DeferredObject<T> registerPoiType(ResourceLocation identifier, Supplier<T> 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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,7 +51,6 @@ public void commonSetup(FMLCommonSetupEvent event) {
});
}
}

public static final Codec<BalmBiomeModifier> BALM_BIOME_MODIFIER_CODEC = Codec.unit(BalmBiomeModifier.INSTANCE);
private final Map<String, Registrations> registrations = new ConcurrentHashMap<>();

Expand All @@ -76,6 +76,13 @@ public <T extends PlacementModifierType<?>> DeferredObject<T> registerPlacementM
return deferredObject;
}

@Override
public <T extends PoiType> DeferredObject<T> registerPoiType(ResourceLocation identifier, Supplier<T> supplier) {
DeferredRegister<PoiType> register = DeferredRegisters.get(ForgeRegistries.POI_TYPES, identifier.getNamespace());
RegistryObject<T> registryObject = register.register(identifier.getPath(), supplier);
return new DeferredObject<>(identifier,registryObject, registryObject::isPresent);
}

private static final List<BiomeModification> biomeModifications = new ArrayList<>();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,5 +18,7 @@ public interface BalmWorldGen {

<T extends PlacementModifierType<?>> DeferredObject<T> registerPlacementModifier(ResourceLocation identifier, Supplier<T> supplier);

<T extends PoiType> DeferredObject<T> registerPoiType(ResourceLocation identifier, Supplier<T> supplier);

void addFeatureToBiomes(BiomePredicate biomePredicate, GenerationStep.Decoration step, ResourceLocation configuredFeatureIdentifier);
}

0 comments on commit 8e684ec

Please sign in to comment.