[Change] Adopting FAPI 0.86, which makes this incompatible with any previous version of FAPI.
This commit is contained in:
parent
9b1d336533
commit
ad13bcac92
5 changed files with 71 additions and 35 deletions
|
@ -62,7 +62,9 @@ dependencies {
|
|||
modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||
|
||||
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}"
|
||||
if (local_wunderlib) {
|
||||
|
|
|
@ -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.85.0+1.20.1
|
||||
fabric_version=0.86.0+1.20.1
|
||||
# Mod Properties
|
||||
mod_version=3.0.12
|
||||
maven_group=org.betterx.bclib
|
||||
archives_base_name=bclib
|
||||
# Dependencies
|
||||
modmenu_version=7.0.0
|
||||
emi_version=1.0.3+1.20
|
||||
wunderlib_version=1.1.5
|
||||
modmenu_version=7.2.1
|
||||
emi_version=1.0.12+1.20.1
|
||||
wunderlib_version=1.1.6
|
|
@ -14,14 +14,13 @@ 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.*;
|
||||
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 org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BCLibClient implements ClientModInitializer, ModelResourceProvider, ModelVariantProvider {
|
||||
public class BCLibClient implements ClientModInitializer {
|
||||
private static CustomModelBakery modelBakery;
|
||||
|
||||
public static CustomModelBakery lazyModelbakery() {
|
||||
|
@ -33,15 +32,15 @@ public class BCLibClient implements ClientModInitializer, ModelResourceProvider,
|
|||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
modelBakery = new CustomModelBakery();
|
||||
modelBakery = lazyModelbakery();
|
||||
|
||||
WorldsTogetherClient.onInitializeClient();
|
||||
ModIntegrationAPI.registerAll();
|
||||
BaseBlockEntityRenders.register();
|
||||
DataExchangeAPI.prepareClientside();
|
||||
PostInitAPI.postInit(true);
|
||||
ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> this);
|
||||
ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> this);
|
||||
|
||||
ModelLoadingPlugin.register(BCLibClient::onInitializeModelLoader);
|
||||
|
||||
PresetsRegistryClient.onLoad();
|
||||
WorldsTogether.SURPRESS_EXPERIMENTAL_DIALOG = Configs.CLIENT_CONFIG.suppressExperimentalDialog();
|
||||
|
@ -50,22 +49,33 @@ public class BCLibClient implements ClientModInitializer, ModelResourceProvider,
|
|||
AtlasSetManager.addSource(AtlasSetManager.VANILLA_BLOCKS, new SpriteLister("blocks"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UnbakedModel loadModelResource(
|
||||
ResourceLocation resourceId,
|
||||
ModelProviderContext context
|
||||
) throws ModelProviderException {
|
||||
return modelBakery.getBlockModel(resourceId);
|
||||
private static void onInitializeModelLoader(ModelLoadingPlugin.Context pluginContext) {
|
||||
modelBakery.registerBlockStateResolvers(pluginContext);
|
||||
|
||||
pluginContext.resolveModel().register(BCLibClient::resolveModel);
|
||||
pluginContext.modifyModelOnLoad().register(BCLibClient::modifyModelOnLoad);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UnbakedModel loadModelVariant(
|
||||
ModelResourceLocation modelId,
|
||||
ModelProviderContext context
|
||||
) throws ModelProviderException {
|
||||
return modelId.getVariant().equals("inventory")
|
||||
? modelBakery.getItemModel(modelId)
|
||||
: modelBakery.getBlockModel(modelId);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,13 +15,21 @@ 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<ResourceLocation, UnbakedModel> models = Maps.newConcurrentMap();
|
||||
private final Map<Block, List<StateModelPair>> blockModels = Maps.newConcurrentMap();
|
||||
|
||||
public UnbakedModel getBlockModel(ResourceLocation location) {
|
||||
return models.get(location);
|
||||
|
@ -31,6 +39,17 @@ public class CustomModelBakery {
|
|||
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) {
|
||||
BuiltInRegistries.BLOCK.stream()
|
||||
.parallel()
|
||||
|
@ -80,10 +99,12 @@ public class CustomModelBakery {
|
|||
ResourceLocation defaultStateID = BlockModelShaper.stateToModelLocation(blockID, defaultState);
|
||||
UnbakedModel defaultModel = provider.getModelVariant(defaultStateID, defaultState, models);
|
||||
|
||||
List<StateModelPair> 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 -> {
|
||||
|
@ -92,8 +113,10 @@ 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) {
|
||||
|
@ -102,10 +125,12 @@ public class CustomModelBakery {
|
|||
itemID.getPath(),
|
||||
"inventory"
|
||||
);
|
||||
if (models.containsKey(modelLocation)) {
|
||||
return;
|
||||
|
||||
if (!models.containsKey(modelLocation)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.21",
|
||||
"fabric": ">=0.83.0",
|
||||
"fabric": ">=0.86.0",
|
||||
"minecraft": [
|
||||
"1.20",
|
||||
"1.20.1"
|
||||
|
@ -55,9 +55,8 @@
|
|||
"wunderlib": "1.1.x"
|
||||
},
|
||||
"breaks": {
|
||||
"wunderlib": "<1.1.2",
|
||||
"emi": "<1.0.0",
|
||||
"fabric": ">=0.86"
|
||||
"wunderlib": "<1.1.6",
|
||||
"emi": "<1.0.0"
|
||||
},
|
||||
"custom": {
|
||||
"bclib": {
|
||||
|
|
Loading…
Reference in a new issue