diff --git a/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/api/client/model/loading/v1/ModelLoadingPlugin.java b/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/api/client/model/loading/v1/ModelLoadingPlugin.java index 615c69712c..30bc4ea274 100644 --- a/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/api/client/model/loading/v1/ModelLoadingPlugin.java +++ b/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/api/client/model/loading/v1/ModelLoadingPlugin.java @@ -17,8 +17,10 @@ package net.fabricmc.fabric.api.client.model.loading.v1; import java.util.Collection; +import java.util.List; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.UnmodifiableView; import net.minecraft.block.Block; import net.minecraft.resource.ResourceManager; @@ -42,6 +44,14 @@ static void register(ModelLoadingPlugin plugin) { ModelLoadingPluginManager.registerPlugin(plugin); } + /** + * Gets a list of all registered model loading plugins. + */ + @UnmodifiableView + static List getAll() { + return ModelLoadingPluginManager.PLUGINS_VIEW; + } + /** * Called towards the beginning of the model loading process, every time resource are (re)loaded. * Use the context object to extend model loading as desired. diff --git a/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/api/client/model/loading/v1/PreparableModelLoadingPlugin.java b/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/api/client/model/loading/v1/PreparableModelLoadingPlugin.java index b0a3eb526a..983c59a626 100644 --- a/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/api/client/model/loading/v1/PreparableModelLoadingPlugin.java +++ b/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/api/client/model/loading/v1/PreparableModelLoadingPlugin.java @@ -16,10 +16,14 @@ package net.fabricmc.fabric.api.client.model.loading.v1; +import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.function.Supplier; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.UnmodifiableView; + import net.minecraft.resource.ResourceManager; import net.fabricmc.fabric.impl.client.model.loading.ModelLoadingPluginManager; @@ -41,6 +45,14 @@ static void register(DataLoader loader, PreparableModelLoadingPlugin p ModelLoadingPluginManager.registerPlugin(loader, plugin); } + /** + * Gets a list of all registered preparable model loading plugins. + */ + @UnmodifiableView + static List> getAll() { + return ModelLoadingPluginManager.PREPARABLE_PLUGINS_VIEW; + } + /** * Called towards the beginning of the model loading process, every time resource are (re)loaded. * Use the context object to extend model loading as desired. @@ -63,4 +75,15 @@ interface DataLoader { */ CompletableFuture load(ResourceManager resourceManager, Executor executor); } + + /** + * Bundles a {@link PreparableModelLoadingPlugin} with its corresponding {@link DataLoader} + * for retrieval through {@link #getAll()}. + */ + @ApiStatus.NonExtendable + interface Holder { + DataLoader loader(); + + PreparableModelLoadingPlugin plugin(); + } } diff --git a/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/impl/client/model/loading/ModelLoadingPluginManager.java b/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/impl/client/model/loading/ModelLoadingPluginManager.java index 21f43bd2a4..99da93de39 100644 --- a/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/impl/client/model/loading/ModelLoadingPluginManager.java +++ b/fabric-model-loading-api-v1/src/client/java/net/fabricmc/fabric/impl/client/model/loading/ModelLoadingPluginManager.java @@ -17,11 +17,14 @@ package net.fabricmc.fabric.impl.client.model.loading; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; +import org.jetbrains.annotations.UnmodifiableView; + import net.minecraft.resource.ResourceManager; import net.minecraft.util.Util; @@ -30,9 +33,12 @@ public final class ModelLoadingPluginManager { private static final List PLUGINS = new ArrayList<>(); - private static final List> PREPARABLE_PLUGINS = new ArrayList<>(); + private static final List> PREPARABLE_PLUGINS = new ArrayList<>(); - public static final ThreadLocal> CURRENT_PLUGINS = new ThreadLocal<>(); + @UnmodifiableView + public static final List PLUGINS_VIEW = Collections.unmodifiableList(PLUGINS); + @UnmodifiableView + public static final List> PREPARABLE_PLUGINS_VIEW = Collections.unmodifiableList(PREPARABLE_PLUGINS); public static void registerPlugin(ModelLoadingPlugin plugin) { Objects.requireNonNull(plugin, "plugin must not be null"); @@ -44,7 +50,7 @@ public static void registerPlugin(PreparableModelLoadingPlugin.DataLoader Objects.requireNonNull(loader, "data loader must not be null"); Objects.requireNonNull(plugin, "plugin must not be null"); - PREPARABLE_PLUGINS.add(new PreparablePluginHolder<>(loader, plugin)); + PREPARABLE_PLUGINS.add(new HolderImpl<>(loader, plugin)); } public static CompletableFuture> preparePlugins(ResourceManager resourceManager, Executor executor) { @@ -54,19 +60,20 @@ public static CompletableFuture> preparePlugins(Resourc futures.add(CompletableFuture.completedFuture(plugin)); } - for (PreparablePluginHolder holder : PREPARABLE_PLUGINS) { + for (HolderImpl holder : PREPARABLE_PLUGINS) { futures.add(preparePlugin(holder, resourceManager, executor)); } return Util.combineSafe(futures); } - private static CompletableFuture preparePlugin(PreparablePluginHolder holder, ResourceManager resourceManager, Executor executor) { + private static CompletableFuture preparePlugin(HolderImpl holder, ResourceManager resourceManager, Executor executor) { CompletableFuture dataFuture = holder.loader.load(resourceManager, executor); return dataFuture.thenApply(data -> pluginContext -> holder.plugin.initialize(data, pluginContext)); } private ModelLoadingPluginManager() { } - private record PreparablePluginHolder(PreparableModelLoadingPlugin.DataLoader loader, PreparableModelLoadingPlugin plugin) { } + private record HolderImpl(PreparableModelLoadingPlugin.DataLoader loader, PreparableModelLoadingPlugin plugin) implements PreparableModelLoadingPlugin.Holder { + } }