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:
parent
a42ed2a414
commit
e86ea25b60
5 changed files with 35 additions and 71 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<ResourceLocation, UnbakedModel> models = Maps.newConcurrentMap();
|
||||
private final Map<Block, List<StateModelPair>> 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<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()
|
||||
|
@ -99,12 +80,10 @@ 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 -> {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue