Sodium

Sodium

49M Downloads

Non `isVanillaAdapter` item models cause a crash

SuperMartijn642 opened this issue ยท 4 comments

commented

Bug Description

This concerns the Fabric version of Sodium for Minecraft 1.21.3 and is specifically related to the Fabric Rendering API.

Returning false for FabricBakedModel#isVanillaAdapter for an item model results in a crash when that model is rendered. Even when overriding FabricBakedModel#emitItemQuads to do nothing, it still results in a crash, hence it seems it is caused purely by the FabricBakedModel#isVanillaAdapter result.

Reproduction Steps

Add the following snippet to the client initialization entry point:

ModelLoadingPluginManager.registerPlugin(pluginContext -> {
    pluginContext.modifyModelAfterBake().register((bakedModel, modelContext) ->{
        if(modelContext.sourceModel() instanceof ItemModel itemModel && itemModel.id.equals(ResourceLocation.parse("minecraft:item/cobblestone"))){
            var forwardingBakedModel = new ForwardingBakedModel() {
                @Override
                public boolean isVanillaAdapter(){
                    return false;
                }

                public void setModel(BakedModel model){
                    this.wrapped = model;
                }
            };
            forwardingBakedModel.setModel(bakedModel);
            return forwardingBakedModel;
        }
        return bakedModel;
    });
});

The snippet replaces the cobblestone item model with a ForwardingBakedModel wrapping the original item model, but which returns false for FabricBakedModel#isVanillaAdapter. The ForwardingBakedModel returns the same as the original model for any other methods in BakedModel.

The snippet also requires an access widener entry for the ItemModel#id field:
accessible field net/minecraft/client/resources/model/ItemModel id Lnet/minecraft/resources/ResourceLocation;

With the snippet added, simply try to look at a cobblestone item and it will cause a crash.

Log File

latest.log
The log shows Moving Elevators as a mod as that is what I used for testing, but it is stripped down to include nothing but the snippet given.

Crash Report

crash-2024-10-29_13.16.50-client.txt

commented

Removed that. Seems to have been a leftover from 1.21.1.

commented

Fixed with 7401075. The latest nightly build contains the fix but we haven't packaged it into a release yet.

commented

@IMS212 This random PoseStack#popStack() in the code for FRAPI item model integration seems highly suspect...

commented

Sodium 0.6.0-beta.5 is published and resolves this issue.