Skip to content

Commit

Permalink
fix: Move biome modifier registration to a more stable place
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Sep 16, 2023
1 parent c828415 commit 60cbc5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalm.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.blay09.mods.balm.config.ExampleConfig;
import net.blay09.mods.balm.forge.client.ForgeBalmClient;
import net.blay09.mods.balm.forge.provider.ForgeBalmProviders;
import net.blay09.mods.balm.forge.world.ForgeBalmWorldGen;
import net.minecraft.world.Container;
import net.minecraftforge.common.capabilities.CapabilityToken;
import net.minecraftforge.energy.IEnergyStorage;
Expand All @@ -23,6 +24,7 @@ public ForgeBalm() {
((AbstractBalmConfig) Balm.getConfig()).initialize();
ExampleConfig.initialize();

FMLJavaModLoadingContext.get().getModEventBus().addListener(ForgeBalmWorldGen::initializeBalmBiomeModifiers);
FMLJavaModLoadingContext.get().getModEventBus().addListener(ForgeBalmClient::onInitializeClient);

ForgeBalmProviders providers = (ForgeBalmProviders) Balm.getProviders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ public void commonSetup(FMLCommonSetupEvent event) {
private final Map<String, Registrations> registrations = new ConcurrentHashMap<>();

public ForgeBalmWorldGen() {
// Mod loading context may be null if something in load process errored before // TODO can we move this to FMLCommonLoadEvent to avoid this null check?
if (FMLJavaModLoadingContext.get() != null) {
var registry = DeferredRegister.create(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, "balm");
registry.register("balm", () -> BALM_BIOME_MODIFIER_CODEC);
registry.register(FMLJavaModLoadingContext.get().getModEventBus());
}

MinecraftForge.EVENT_BUS.register(this);
}

Expand Down Expand Up @@ -113,4 +106,12 @@ public void register() {
private Registrations getActiveRegistrations() {
return registrations.computeIfAbsent(ModLoadingContext.get().getActiveNamespace(), it -> new Registrations());
}

public static void initializeBalmBiomeModifiers(FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
var registry = DeferredRegister.create(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, "balm");
registry.register("balm", () -> BALM_BIOME_MODIFIER_CODEC);
registry.register(FMLJavaModLoadingContext.get().getModEventBus());
});
}
}

0 comments on commit 60cbc5c

Please sign in to comment.