Revert "[Change] Adopting FAPI 0.86, which makes this incompatible with any previous version of FAPI."

This reverts commit ad13bcac92.
This commit is contained in:
Frank 2023-07-23 09:40:17 +02:00
parent a42ed2a414
commit e86ea25b60
5 changed files with 35 additions and 71 deletions

View file

@ -62,9 +62,7 @@ dependencies {
modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}" modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
modCompileOnly "dev.emi:emi-fabric:${emi_version}:api" modCompileOnly "dev.emi:emi-fabric:${emi_version}:api"
modLocalRuntime("dev.emi:emi-fabric:${emi_version}") { modLocalRuntime "dev.emi:emi-fabric:${emi_version}"
transitive = false;
}
println "Using local WunderLib: ${local_wunderlib}" println "Using local WunderLib: ${local_wunderlib}"
if (local_wunderlib) { if (local_wunderlib) {

View file

@ -10,12 +10,12 @@ loom_version=1.0-SNAPSHOT
# check these on https://fabricmc.net/versions.html # check these on https://fabricmc.net/versions.html
minecraft_version=1.20.1 minecraft_version=1.20.1
loader_version=0.14.21 loader_version=0.14.21
fabric_version=0.86.0+1.20.1 fabric_version=0.85.0+1.20.1
# Mod Properties # Mod Properties
mod_version=3.0.12 mod_version=3.0.12
maven_group=org.betterx.bclib maven_group=org.betterx.bclib
archives_base_name=bclib archives_base_name=bclib
# Dependencies # Dependencies
modmenu_version=7.2.1 modmenu_version=7.0.0
emi_version=1.0.12+1.20.1 emi_version=1.0.3+1.20
wunderlib_version=1.1.6 wunderlib_version=1.1.5

View file

@ -14,13 +14,14 @@ import org.betterx.worlds.together.client.WorldsTogetherClient;
import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; import net.fabricmc.fabric.api.client.model.*;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelModifier;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelResolver;
public class BCLibClient implements ClientModInitializer { import org.jetbrains.annotations.Nullable;
public class BCLibClient implements ClientModInitializer, ModelResourceProvider, ModelVariantProvider {
private static CustomModelBakery modelBakery; private static CustomModelBakery modelBakery;
public static CustomModelBakery lazyModelbakery() { public static CustomModelBakery lazyModelbakery() {
@ -32,15 +33,15 @@ public class BCLibClient implements ClientModInitializer {
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
modelBakery = lazyModelbakery(); modelBakery = new CustomModelBakery();
WorldsTogetherClient.onInitializeClient(); WorldsTogetherClient.onInitializeClient();
ModIntegrationAPI.registerAll(); ModIntegrationAPI.registerAll();
BaseBlockEntityRenders.register(); BaseBlockEntityRenders.register();
DataExchangeAPI.prepareClientside(); DataExchangeAPI.prepareClientside();
PostInitAPI.postInit(true); PostInitAPI.postInit(true);
ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> this);
ModelLoadingPlugin.register(BCLibClient::onInitializeModelLoader); ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> this);
PresetsRegistryClient.onLoad(); PresetsRegistryClient.onLoad();
WorldsTogether.SURPRESS_EXPERIMENTAL_DIALOG = Configs.CLIENT_CONFIG.suppressExperimentalDialog(); 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")); AtlasSetManager.addSource(AtlasSetManager.VANILLA_BLOCKS, new SpriteLister("blocks"));
} }
private static void onInitializeModelLoader(ModelLoadingPlugin.Context pluginContext) { @Override
modelBakery.registerBlockStateResolvers(pluginContext); public @Nullable UnbakedModel loadModelResource(
ResourceLocation resourceId,
pluginContext.resolveModel().register(BCLibClient::resolveModel); ModelProviderContext context
pluginContext.modifyModelOnLoad().register(BCLibClient::modifyModelOnLoad); ) throws ModelProviderException {
return modelBakery.getBlockModel(resourceId);
} }
private static UnbakedModel resolveModel(ModelResolver.Context ctx) { @Override
boolean isItem = ctx.id().getPath().startsWith("item/"); public @Nullable UnbakedModel loadModelVariant(
if (ctx.id() instanceof ModelResourceLocation modelId && modelId.getVariant().equals("inventory")) { ModelResourceLocation modelId,
isItem = true; ModelProviderContext context
} ) throws ModelProviderException {
return modelId.getVariant().equals("inventory")
return isItem ? modelBakery.getItemModel(ctx.id()) : modelBakery.getBlockModel(ctx.id()); ? modelBakery.getItemModel(modelId)
} : modelBakery.getBlockModel(modelId);
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;
} }

View file

@ -15,21 +15,13 @@ import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; 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.ImmutableList;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
public class CustomModelBakery { public class CustomModelBakery {
private record StateModelPair(BlockState state, UnbakedModel model) {
}
private final Map<ResourceLocation, UnbakedModel> models = Maps.newConcurrentMap(); private final Map<ResourceLocation, UnbakedModel> models = Maps.newConcurrentMap();
private final Map<Block, List<StateModelPair>> blockModels = Maps.newConcurrentMap();
public UnbakedModel getBlockModel(ResourceLocation location) { public UnbakedModel getBlockModel(ResourceLocation location) {
return models.get(location); return models.get(location);
@ -39,17 +31,6 @@ public class CustomModelBakery {
return models.get(location); return models.get(location);
} }
public void registerBlockStateResolvers(ModelLoadingPlugin.Context pluginContext) {
for (Map.Entry<Block, List<StateModelPair>> e : this.blockModels.entrySet()) {
pluginContext.registerBlockStateResolver(
e.getKey(),
context -> {
e.getValue().forEach(p -> context.setModel(p.state, p.model));
}
);
}
}
public void loadCustomModels(ResourceManager resourceManager) { public void loadCustomModels(ResourceManager resourceManager) {
BuiltInRegistries.BLOCK.stream() BuiltInRegistries.BLOCK.stream()
.parallel() .parallel()
@ -99,12 +80,10 @@ public class CustomModelBakery {
ResourceLocation defaultStateID = BlockModelShaper.stateToModelLocation(blockID, defaultState); ResourceLocation defaultStateID = BlockModelShaper.stateToModelLocation(blockID, defaultState);
UnbakedModel defaultModel = provider.getModelVariant(defaultStateID, defaultState, models); UnbakedModel defaultModel = provider.getModelVariant(defaultStateID, defaultState, models);
List<StateModelPair> stateModels = new ArrayList<>(states.size());
if (defaultModel instanceof MultiPart) { if (defaultModel instanceof MultiPart) {
states.forEach(blockState -> { states.forEach(blockState -> {
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, blockState); ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, blockState);
models.put(stateID, defaultModel); models.put(stateID, defaultModel);
stateModels.add(new StateModelPair(blockState, defaultModel));
}); });
} else { } else {
states.forEach(blockState -> { states.forEach(blockState -> {
@ -113,10 +92,8 @@ public class CustomModelBakery {
? defaultModel ? defaultModel
: provider.getModelVariant(stateID, blockState, models); : provider.getModelVariant(stateID, blockState, models);
models.put(stateID, model); models.put(stateID, model);
stateModels.add(new StateModelPair(blockState, model));
}); });
} }
blockModels.put(block, stateModels);
} }
private void addItemModel(ResourceLocation itemID, ItemModelProvider provider) { private void addItemModel(ResourceLocation itemID, ItemModelProvider provider) {
@ -125,12 +102,10 @@ public class CustomModelBakery {
itemID.getPath(), itemID.getPath(),
"inventory" "inventory"
); );
if (models.containsKey(modelLocation)) {
if (!models.containsKey(modelLocation)) { return;
ResourceLocation itemModelLocation = itemID.withPrefix("item/");
BlockModel model = provider.getItemModel(modelLocation);
models.put(modelLocation, model);
models.put(itemModelLocation, model);
} }
BlockModel model = provider.getItemModel(modelLocation);
models.put(modelLocation, model);
} }
} }

View file

@ -47,7 +47,7 @@
], ],
"depends": { "depends": {
"fabricloader": ">=0.14.21", "fabricloader": ">=0.14.21",
"fabric": ">=0.86.0", "fabric": ">=0.83.0",
"minecraft": [ "minecraft": [
"1.20", "1.20",
"1.20.1" "1.20.1"
@ -55,8 +55,9 @@
"wunderlib": "1.1.x" "wunderlib": "1.1.x"
}, },
"breaks": { "breaks": {
"wunderlib": "<1.1.6", "wunderlib": "<1.1.2",
"emi": "<1.0.0" "emi": "<1.0.0",
"fabric": ">=0.86"
}, },
"custom": { "custom": {
"bclib": { "bclib": {