diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmRuntime.java b/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmRuntime.java index b11dde83..0630957e 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmRuntime.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmRuntime.java @@ -178,7 +178,6 @@ public String getModName(String modId) { public void initialize(String modId, ForgeLoadContext context, Runnable initializer) { ((ForgeBalmItems) items).register(modId, context.modEventBus()); ((ForgeBalmEntities) entities).register(modId, context.modEventBus()); - ((ForgeBalmWorldGen) worldGen).register(modId, context.modEventBus()); ((ForgeBalmStats) stats).register(modId, context.modEventBus()); initializer.run(); diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/client/keymappings/ForgeBalmKeyMappings.java b/forge/src/main/java/net/blay09/mods/balm/forge/client/keymappings/ForgeBalmKeyMappings.java index e75b6d6a..fa4c9ab4 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/client/keymappings/ForgeBalmKeyMappings.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/client/keymappings/ForgeBalmKeyMappings.java @@ -5,14 +5,12 @@ import net.blay09.mods.balm.api.client.keymappings.KeyModifier; import net.blay09.mods.balm.api.client.keymappings.KeyModifiers; import net.blay09.mods.balm.common.client.keymappings.CommonBalmKeyMappings; -import net.blay09.mods.balm.forge.client.rendering.ForgeBalmModels; import net.minecraft.client.KeyMapping; import net.minecraftforge.client.event.RegisterKeyMappingsEvent; import net.minecraftforge.client.settings.IKeyConflictContext; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import java.util.*; import java.util.concurrent.ConcurrentHashMap; diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/client/rendering/ForgeBalmModels.java b/forge/src/main/java/net/blay09/mods/balm/forge/client/rendering/ForgeBalmModels.java index 4c1093db..96738d21 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/client/rendering/ForgeBalmModels.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/client/rendering/ForgeBalmModels.java @@ -11,7 +11,6 @@ import net.minecraftforge.client.event.ModelEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ModLoadingContext; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -52,7 +51,7 @@ public boolean canResolve() { return getRegistrations(identifier.getNamespace()).bakedStandaloneModels.containsKey(identifier); } }; - getActiveRegistrations().additionalModels.add(identifier); + getRegistrations(identifier.getNamespace()).additionalModels.add(identifier); return deferredModel; } @@ -60,10 +59,6 @@ public void register(String modId, IEventBus eventBus) { eventBus.register(getRegistrations(modId)); } - private Registrations getActiveRegistrations() { - return getRegistrations(ModLoadingContext.get().getActiveNamespace()); - } - private Registrations getRegistrations(String modId) { return registrations.computeIfAbsent(modId, it -> new Registrations()); } diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/entity/ForgeBalmEntities.java b/forge/src/main/java/net/blay09/mods/balm/forge/entity/ForgeBalmEntities.java index 19f336b7..ceee00d1 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/entity/ForgeBalmEntities.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/entity/ForgeBalmEntities.java @@ -3,7 +3,6 @@ import net.blay09.mods.balm.api.DeferredObject; import net.blay09.mods.balm.api.entity.BalmEntities; import net.blay09.mods.balm.forge.DeferredRegisters; -import net.blay09.mods.balm.forge.world.ForgeBalmWorldGen; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; @@ -14,8 +13,6 @@ import net.minecraftforge.event.entity.EntityAttributeCreationEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import java.util.HashMap; import java.util.Map; @@ -48,7 +45,7 @@ public DeferredObject> registerEntity(ResourceL @Override public DeferredObject> registerEntity(ResourceLocation identifier, EntityType.Builder typeBuilder, Supplier attributeBuilder) { final var register = DeferredRegisters.get(Registries.ENTITY_TYPE, identifier.getNamespace()); - final var registrations = getActiveRegistrations(); + final var registrations = getRegistrations(identifier.getNamespace()); final var registryObject = register.register(identifier.getPath(), () -> { EntityType entityType = typeBuilder.build(ResourceKey.create(Registries.ENTITY_TYPE, identifier)); registrations.attributeSuppliers.put(entityType, attributeBuilder.get().build()); @@ -61,10 +58,6 @@ public void register(String modId, IEventBus eventBus) { eventBus.register(getRegistrations(modId)); } - private Registrations getActiveRegistrations() { - return getRegistrations(ModLoadingContext.get().getActiveNamespace()); - } - private Registrations getRegistrations(String modId) { return registrations.computeIfAbsent(modId, it -> new Registrations()); } diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/event/ForgeBalmClientEvents.java b/forge/src/main/java/net/blay09/mods/balm/forge/event/ForgeBalmClientEvents.java index 877182be..8a90d02f 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/event/ForgeBalmClientEvents.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/event/ForgeBalmClientEvents.java @@ -1,19 +1,16 @@ package net.blay09.mods.balm.forge.event; -import net.blay09.mods.balm.api.event.client.RecipesUpdatedEvent; import net.blay09.mods.balm.api.event.TickPhase; import net.blay09.mods.balm.api.event.TickType; import net.blay09.mods.balm.api.event.client.*; import net.blay09.mods.balm.api.event.client.RenderHandEvent; import net.blay09.mods.balm.api.event.client.screen.*; import net.minecraft.client.Minecraft; -import net.minecraft.core.RegistryAccess; import net.minecraftforge.client.event.*; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.TickEvent; import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import org.jetbrains.annotations.Nullable; public class ForgeBalmClientEvents { diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/item/ForgeBalmItems.java b/forge/src/main/java/net/blay09/mods/balm/forge/item/ForgeBalmItems.java index 042e80fb..0908d66a 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/item/ForgeBalmItems.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/item/ForgeBalmItems.java @@ -4,7 +4,6 @@ import net.blay09.mods.balm.api.DeferredObject; import net.blay09.mods.balm.api.item.BalmItems; import net.blay09.mods.balm.forge.DeferredRegisters; -import net.blay09.mods.balm.forge.client.rendering.ForgeBalmModels; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -13,10 +12,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.DeferredRegister; -import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; import org.jetbrains.annotations.Nullable; @@ -53,7 +49,7 @@ public DeferredObject registerItem(Function suppli final var register = DeferredRegisters.get(Registries.ITEM, identifier.getNamespace()); final var registryObject = register.register(identifier.getPath(), () -> supplier.apply(identifier)); if (creativeTab != null) { - getActiveRegistrations().creativeTabContents.put(creativeTab, () -> new ItemLike[]{registryObject.get()}); + getRegistrations(identifier.getNamespace()).creativeTabContents.put(creativeTab, () -> new ItemLike[]{registryObject.get()}); } return new DeferredObject<>(identifier, registryObject, registryObject::isPresent); } @@ -63,7 +59,7 @@ public DeferredObject registerCreativeModeTab(Supplier register = DeferredRegisters.get(Registries.CREATIVE_MODE_TAB, identifier.getNamespace()); RegistryObject registryObject = register.register(identifier.getPath(), () -> { Component displayName = Component.translatable("itemGroup." + identifier.toString().replace(':', '.')); - final var registrations = getActiveRegistrations(); + final var registrations = getRegistrations(identifier.getNamespace()); return CreativeModeTab.builder() .title(displayName) .icon(iconSupplier) @@ -75,22 +71,18 @@ public DeferredObject registerCreativeModeTab(Supplier itemsSupplier) { - getActiveRegistrations().creativeTabContents.put(tabIdentifier, itemsSupplier); + getRegistrations(tabIdentifier.getNamespace()).creativeTabContents.put(tabIdentifier, itemsSupplier); } @Override public void setCreativeModeTabSorting(ResourceLocation tabIdentifier, Comparator comparator) { - getActiveRegistrations().creativeTabSorting.put(tabIdentifier, comparator); + getRegistrations(tabIdentifier.getNamespace()).creativeTabSorting.put(tabIdentifier, comparator); } public void register(String modId, IEventBus eventBus) { eventBus.register(getRegistrations(modId)); } - private Registrations getActiveRegistrations() { - return getRegistrations(ModLoadingContext.get().getActiveNamespace()); - } - private Registrations getRegistrations(String modId) { return registrations.computeIfAbsent(modId, it -> new Registrations()); } diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/stats/ForgeBalmStats.java b/forge/src/main/java/net/blay09/mods/balm/forge/stats/ForgeBalmStats.java index 27d82ce7..d860821b 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/stats/ForgeBalmStats.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/stats/ForgeBalmStats.java @@ -37,17 +37,13 @@ public void commonSetup(FMLCommonSetupEvent event) { @Override public void registerCustomStat(ResourceLocation identifier) { - getActiveRegistrations().customStats.add(identifier); + getRegistrations(identifier.getNamespace()).customStats.add(identifier); } public void register(String modId, IEventBus eventBus) { eventBus.register(getRegistrations(modId)); } - private Registrations getActiveRegistrations() { - return getRegistrations(ModLoadingContext.get().getActiveNamespace()); - } - private Registrations getRegistrations(String modId) { return registrations.computeIfAbsent(modId, it -> new Registrations()); } 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 276ad360..a3cd5a9b 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 @@ -7,7 +7,6 @@ import net.blay09.mods.balm.forge.DeferredRegisters; 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.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; @@ -21,10 +20,6 @@ import net.minecraftforge.common.world.BiomeModifier; import net.minecraftforge.common.world.ModifiableBiomeInfo; import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; @@ -32,29 +27,11 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; public class ForgeBalmWorldGen implements BalmWorldGen { - private static class Registrations { - public final List> configuredFeatures = new ArrayList<>(); - public final List> placedFeatures = new ArrayList<>(); - public final List> placementModifiers = new ArrayList<>(); - - @SubscribeEvent - public void commonSetup(FMLCommonSetupEvent event) { - event.enqueueWork(() -> { - placementModifiers.forEach(DeferredObject::resolve); - configuredFeatures.forEach(DeferredObject::resolve); - placedFeatures.forEach(DeferredObject::resolve); - }); - } - } - public static final MapCodec BALM_BIOME_MODIFIER_CODEC = MapCodec.unit(BalmBiomeModifier.INSTANCE); - private final Map registrations = new ConcurrentHashMap<>(); public ForgeBalmWorldGen() { MinecraftForge.EVENT_BUS.register(this); @@ -69,13 +46,9 @@ public > DeferredObject registerFeature(ResourceLocation @Override public > DeferredObject registerPlacementModifier(ResourceLocation identifier, Supplier supplier) { - DeferredObject deferredObject = new DeferredObject<>(identifier, () -> { - T placementModifierType = supplier.get(); - Registry.register(BuiltInRegistries.PLACEMENT_MODIFIER_TYPE, identifier, placementModifierType); - return placementModifierType; - }); - getActiveRegistrations().placementModifiers.add(deferredObject); - return deferredObject; + final var register = DeferredRegisters.get(Registries.PLACEMENT_MODIFIER_TYPE, identifier.getNamespace()); + RegistryObject registryObject = register.register(identifier.getPath(), supplier); + return new DeferredObject<>(identifier, registryObject, registryObject::isPresent); } @Override @@ -108,18 +81,6 @@ public void modifyBiome(Holder biome, BiomeModifier.Phase phase, Modifiab } } - public void register(String modId, IEventBus eventBus) { - eventBus.register(getRegistrations(modId)); - } - - private Registrations getActiveRegistrations() { - return getRegistrations(ModLoadingContext.get().getActiveNamespace()); - } - - private Registrations getRegistrations(String modId) { - return registrations.computeIfAbsent(modId, it -> new Registrations()); - } - public static void initializeBalmBiomeModifiers(IEventBus modEventBus) { var registry = DeferredRegister.create(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, "balm"); registry.register("balm", () -> BALM_BIOME_MODIFIER_CODEC);