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 4f885c25..06496b1c 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 @@ -180,7 +180,6 @@ public void initialize(String modId, EmptyLoadContext context, Runnable initiali ((ForgeBalmItems) items).register(); ((ForgeBalmEntities) entities).register(); ((ForgeBalmWorldGen) worldGen).register(); - ((ForgeBalmComponents) components).register(); ((ForgeBalmStats) stats).register(); initializer.run(); diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/component/ForgeBalmComponents.java b/forge/src/main/java/net/blay09/mods/balm/forge/component/ForgeBalmComponents.java index 9c5d3258..4eb20635 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/component/ForgeBalmComponents.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/component/ForgeBalmComponents.java @@ -2,50 +2,20 @@ import net.blay09.mods.balm.api.DeferredObject; import net.blay09.mods.balm.api.component.BalmComponents; -import net.minecraft.core.Registry; +import net.blay09.mods.balm.forge.DeferredRegisters; import net.minecraft.core.component.DataComponentType; -import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; -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 java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; public class ForgeBalmComponents implements BalmComponents { - private static class Registrations { - public final List> dataComponentTypes = new ArrayList<>(); - - @SubscribeEvent - public void commonSetup(FMLCommonSetupEvent event) { - event.enqueueWork(() -> dataComponentTypes.forEach(DeferredObject::resolve)); - } - } - - private final Map registrations = new ConcurrentHashMap<>(); - @Override public DeferredObject> registerComponent(Supplier> supplier, ResourceLocation identifier) { - DeferredObject> deferredObject = new DeferredObject<>(identifier, () -> { - DataComponentType dataComponentType = supplier.get(); - Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, identifier, dataComponentType); - return dataComponentType; - }); - getActiveRegistrations().dataComponentTypes.add(deferredObject); - return deferredObject; + final var register = DeferredRegisters.get(Registries.DATA_COMPONENT_TYPE, identifier.getNamespace()); + final var registryObject = register.register(identifier.getPath(), supplier); + return new DeferredObject<>(identifier, registryObject, registryObject::isPresent); } - public void register() { - FMLJavaModLoadingContext.get().getModEventBus().register(getActiveRegistrations()); - } - - private ForgeBalmComponents.Registrations getActiveRegistrations() { - return registrations.computeIfAbsent(ModLoadingContext.get().getActiveNamespace(), it -> new ForgeBalmComponents.Registrations()); - } } diff --git a/gradle.properties b/gradle.properties index 32eae9ec..13572838 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,7 +32,7 @@ parchment_minecraft=1.21 parchment_version=2024.06.23 # Forge -forge_version = 52.0.2 +forge_version = 52.0.18 forge_version_range = [51,) forge_loader_version_range = [51,)