[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 "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) {
|
||||||
|
|
|
@ -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.85.0+1.20.1
|
fabric_version=0.86.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.0.0
|
modmenu_version=7.2.1
|
||||||
emi_version=1.0.3+1.20
|
emi_version=1.0.12+1.20.1
|
||||||
wunderlib_version=1.1.5
|
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.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.*;
|
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 {
|
||||||
|
|
||||||
public class BCLibClient implements ClientModInitializer, ModelResourceProvider, ModelVariantProvider {
|
|
||||||
private static CustomModelBakery modelBakery;
|
private static CustomModelBakery modelBakery;
|
||||||
|
|
||||||
public static CustomModelBakery lazyModelbakery() {
|
public static CustomModelBakery lazyModelbakery() {
|
||||||
|
@ -33,15 +32,15 @@ public class BCLibClient implements ClientModInitializer, ModelResourceProvider,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
modelBakery = new CustomModelBakery();
|
modelBakery = lazyModelbakery();
|
||||||
|
|
||||||
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);
|
|
||||||
ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> this);
|
ModelLoadingPlugin.register(BCLibClient::onInitializeModelLoader);
|
||||||
|
|
||||||
PresetsRegistryClient.onLoad();
|
PresetsRegistryClient.onLoad();
|
||||||
WorldsTogether.SURPRESS_EXPERIMENTAL_DIALOG = Configs.CLIENT_CONFIG.suppressExperimentalDialog();
|
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"));
|
AtlasSetManager.addSource(AtlasSetManager.VANILLA_BLOCKS, new SpriteLister("blocks"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static void onInitializeModelLoader(ModelLoadingPlugin.Context pluginContext) {
|
||||||
public @Nullable UnbakedModel loadModelResource(
|
modelBakery.registerBlockStateResolvers(pluginContext);
|
||||||
ResourceLocation resourceId,
|
|
||||||
ModelProviderContext context
|
pluginContext.resolveModel().register(BCLibClient::resolveModel);
|
||||||
) throws ModelProviderException {
|
pluginContext.modifyModelOnLoad().register(BCLibClient::modifyModelOnLoad);
|
||||||
return modelBakery.getBlockModel(resourceId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static UnbakedModel resolveModel(ModelResolver.Context ctx) {
|
||||||
public @Nullable UnbakedModel loadModelVariant(
|
boolean isItem = ctx.id().getPath().startsWith("item/");
|
||||||
ModelResourceLocation modelId,
|
if (ctx.id() instanceof ModelResourceLocation modelId && modelId.getVariant().equals("inventory")) {
|
||||||
ModelProviderContext context
|
isItem = true;
|
||||||
) throws ModelProviderException {
|
}
|
||||||
return modelId.getVariant().equals("inventory")
|
|
||||||
? modelBakery.getItemModel(modelId)
|
return isItem ? modelBakery.getItemModel(ctx.id()) : modelBakery.getBlockModel(ctx.id());
|
||||||
: 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,21 @@ 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);
|
||||||
|
@ -31,6 +39,17 @@ 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()
|
||||||
|
@ -80,10 +99,12 @@ 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 -> {
|
||||||
|
@ -92,8 +113,10 @@ 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) {
|
||||||
|
@ -102,10 +125,12 @@ public class CustomModelBakery {
|
||||||
itemID.getPath(),
|
itemID.getPath(),
|
||||||
"inventory"
|
"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": {
|
"depends": {
|
||||||
"fabricloader": ">=0.14.21",
|
"fabricloader": ">=0.14.21",
|
||||||
"fabric": ">=0.83.0",
|
"fabric": ">=0.86.0",
|
||||||
"minecraft": [
|
"minecraft": [
|
||||||
"1.20",
|
"1.20",
|
||||||
"1.20.1"
|
"1.20.1"
|
||||||
|
@ -55,9 +55,8 @@
|
||||||
"wunderlib": "1.1.x"
|
"wunderlib": "1.1.x"
|
||||||
},
|
},
|
||||||
"breaks": {
|
"breaks": {
|
||||||
"wunderlib": "<1.1.2",
|
"wunderlib": "<1.1.6",
|
||||||
"emi": "<1.0.0",
|
"emi": "<1.0.0"
|
||||||
"fabric": ">=0.86"
|
|
||||||
},
|
},
|
||||||
"custom": {
|
"custom": {
|
||||||
"bclib": {
|
"bclib": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue