From e86ea25b60ba2e15d45900a966688074505170c5 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 23 Jul 2023 09:40:17 +0200 Subject: [PATCH] Revert "[Change] Adopting FAPI 0.86, which makes this incompatible with any previous version of FAPI." This reverts commit ad13bcac92b0420885e3896ffdf7c3b1bb5d4c27. --- bclib.gradle | 4 +- gradle.properties | 8 +-- .../org/betterx/bclib/client/BCLibClient.java | 54 ++++++++----------- .../client/models/CustomModelBakery.java | 33 ++---------- src/main/resources/fabric.mod.json | 7 +-- 5 files changed, 35 insertions(+), 71 deletions(-) diff --git a/bclib.gradle b/bclib.gradle index 8256e79f..d949fbc9 100644 --- a/bclib.gradle +++ b/bclib.gradle @@ -62,9 +62,7 @@ dependencies { modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}" modCompileOnly "dev.emi:emi-fabric:${emi_version}:api" - modLocalRuntime("dev.emi:emi-fabric:${emi_version}") { - transitive = false; - } + modLocalRuntime "dev.emi:emi-fabric:${emi_version}" println "Using local WunderLib: ${local_wunderlib}" if (local_wunderlib) { diff --git a/gradle.properties b/gradle.properties index a68fcee3..c60f2c5c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,12 +10,12 @@ loom_version=1.0-SNAPSHOT # check these on https://fabricmc.net/versions.html minecraft_version=1.20.1 loader_version=0.14.21 -fabric_version=0.86.0+1.20.1 +fabric_version=0.85.0+1.20.1 # Mod Properties mod_version=3.0.12 maven_group=org.betterx.bclib archives_base_name=bclib # Dependencies -modmenu_version=7.2.1 -emi_version=1.0.12+1.20.1 -wunderlib_version=1.1.6 \ No newline at end of file +modmenu_version=7.0.0 +emi_version=1.0.3+1.20 +wunderlib_version=1.1.5 \ No newline at end of file diff --git a/src/main/java/org/betterx/bclib/client/BCLibClient.java b/src/main/java/org/betterx/bclib/client/BCLibClient.java index 95b16a0a..5fab2eb2 100644 --- a/src/main/java/org/betterx/bclib/client/BCLibClient.java +++ b/src/main/java/org/betterx/bclib/client/BCLibClient.java @@ -14,13 +14,14 @@ import org.betterx.worlds.together.client.WorldsTogetherClient; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.client.resources.model.UnbakedModel; +import net.minecraft.resources.ResourceLocation; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; -import net.fabricmc.fabric.api.client.model.loading.v1.ModelModifier; -import net.fabricmc.fabric.api.client.model.loading.v1.ModelResolver; +import net.fabricmc.fabric.api.client.model.*; -public class BCLibClient implements ClientModInitializer { +import org.jetbrains.annotations.Nullable; + +public class BCLibClient implements ClientModInitializer, ModelResourceProvider, ModelVariantProvider { private static CustomModelBakery modelBakery; public static CustomModelBakery lazyModelbakery() { @@ -32,15 +33,15 @@ public class BCLibClient implements ClientModInitializer { @Override public void onInitializeClient() { - modelBakery = lazyModelbakery(); + modelBakery = new CustomModelBakery(); WorldsTogetherClient.onInitializeClient(); ModIntegrationAPI.registerAll(); BaseBlockEntityRenders.register(); DataExchangeAPI.prepareClientside(); PostInitAPI.postInit(true); - - ModelLoadingPlugin.register(BCLibClient::onInitializeModelLoader); + ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> this); + ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> this); PresetsRegistryClient.onLoad(); WorldsTogether.SURPRESS_EXPERIMENTAL_DIALOG = Configs.CLIENT_CONFIG.suppressExperimentalDialog(); @@ -49,33 +50,22 @@ public class BCLibClient implements ClientModInitializer { AtlasSetManager.addSource(AtlasSetManager.VANILLA_BLOCKS, new SpriteLister("blocks")); } - private static void onInitializeModelLoader(ModelLoadingPlugin.Context pluginContext) { - modelBakery.registerBlockStateResolvers(pluginContext); - - pluginContext.resolveModel().register(BCLibClient::resolveModel); - pluginContext.modifyModelOnLoad().register(BCLibClient::modifyModelOnLoad); + @Override + public @Nullable UnbakedModel loadModelResource( + ResourceLocation resourceId, + ModelProviderContext context + ) throws ModelProviderException { + return modelBakery.getBlockModel(resourceId); } - private static UnbakedModel resolveModel(ModelResolver.Context ctx) { - boolean isItem = ctx.id().getPath().startsWith("item/"); - if (ctx.id() instanceof ModelResourceLocation modelId && modelId.getVariant().equals("inventory")) { - isItem = true; - } - - return isItem ? modelBakery.getItemModel(ctx.id()) : modelBakery.getBlockModel(ctx.id()); - } - - private static UnbakedModel modifyModelOnLoad(UnbakedModel model, ModelModifier.OnLoad.Context ctx) { - UnbakedModel res = null; - if (ctx.id() instanceof ModelResourceLocation modelId) { - res = modelId.getVariant().equals("inventory") - ? modelBakery.getItemModel(modelId) - : modelBakery.getBlockModel(modelId); - } - - if (res == null) - return model; - return res; + @Override + public @Nullable UnbakedModel loadModelVariant( + ModelResourceLocation modelId, + ModelProviderContext context + ) throws ModelProviderException { + return modelId.getVariant().equals("inventory") + ? modelBakery.getItemModel(modelId) + : modelBakery.getBlockModel(modelId); } diff --git a/src/main/java/org/betterx/bclib/client/models/CustomModelBakery.java b/src/main/java/org/betterx/bclib/client/models/CustomModelBakery.java index ad5843b2..f75dba28 100644 --- a/src/main/java/org/betterx/bclib/client/models/CustomModelBakery.java +++ b/src/main/java/org/betterx/bclib/client/models/CustomModelBakery.java @@ -15,21 +15,13 @@ import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; - import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; -import java.util.ArrayList; -import java.util.List; import java.util.Map; public class CustomModelBakery { - private record StateModelPair(BlockState state, UnbakedModel model) { - } - private final Map models = Maps.newConcurrentMap(); - private final Map> blockModels = Maps.newConcurrentMap(); public UnbakedModel getBlockModel(ResourceLocation location) { return models.get(location); @@ -39,17 +31,6 @@ public class CustomModelBakery { return models.get(location); } - public void registerBlockStateResolvers(ModelLoadingPlugin.Context pluginContext) { - for (Map.Entry> e : this.blockModels.entrySet()) { - pluginContext.registerBlockStateResolver( - e.getKey(), - context -> { - e.getValue().forEach(p -> context.setModel(p.state, p.model)); - } - ); - } - } - public void loadCustomModels(ResourceManager resourceManager) { BuiltInRegistries.BLOCK.stream() .parallel() @@ -99,12 +80,10 @@ public class CustomModelBakery { ResourceLocation defaultStateID = BlockModelShaper.stateToModelLocation(blockID, defaultState); UnbakedModel defaultModel = provider.getModelVariant(defaultStateID, defaultState, models); - List stateModels = new ArrayList<>(states.size()); if (defaultModel instanceof MultiPart) { states.forEach(blockState -> { ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, blockState); models.put(stateID, defaultModel); - stateModels.add(new StateModelPair(blockState, defaultModel)); }); } else { states.forEach(blockState -> { @@ -113,10 +92,8 @@ public class CustomModelBakery { ? defaultModel : provider.getModelVariant(stateID, blockState, models); models.put(stateID, model); - stateModels.add(new StateModelPair(blockState, model)); }); } - blockModels.put(block, stateModels); } private void addItemModel(ResourceLocation itemID, ItemModelProvider provider) { @@ -125,12 +102,10 @@ public class CustomModelBakery { itemID.getPath(), "inventory" ); - - if (!models.containsKey(modelLocation)) { - ResourceLocation itemModelLocation = itemID.withPrefix("item/"); - BlockModel model = provider.getItemModel(modelLocation); - models.put(modelLocation, model); - models.put(itemModelLocation, model); + if (models.containsKey(modelLocation)) { + return; } + BlockModel model = provider.getItemModel(modelLocation); + models.put(modelLocation, model); } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8bdd4078..bbbcb5aa 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -47,7 +47,7 @@ ], "depends": { "fabricloader": ">=0.14.21", - "fabric": ">=0.86.0", + "fabric": ">=0.83.0", "minecraft": [ "1.20", "1.20.1" @@ -55,8 +55,9 @@ "wunderlib": "1.1.x" }, "breaks": { - "wunderlib": "<1.1.6", - "emi": "<1.0.0" + "wunderlib": "<1.1.2", + "emi": "<1.0.0", + "fabric": ">=0.86" }, "custom": { "bclib": {