Skip to content

[1.21.4] Dynamic resources breaks Fabric Api's PreparableModelLoadingPlugin #522

@Fuzss

Description

@Fuzss

Bug Description

Fabric Api: 0.115.1+1.21.4
ModernFix: 5.20.2+mc1.21.4

Enabling ModernFix's Dynamic Resource option prevents Fabric Api's PreparableModelLoadingPlugin from applying any changes. The plugin does execute along with all the hooks and events, but none have any effect. Like placing a breakpoint at BlockStateResolver.Context::setModel in ModelLoadingPlugin.Context::registerBlockStateResolver shows that the method is indeed called, but no effect is noticeable in-game.

A simple test was conducted where the stone block and item model is supposed to be replaced by the missing model. For replacing the block model both registerBlockStateResolver and modifyBlockModelOnLoad have been tried, everything without success.
This code snipped was used for testing:

        PreparableModelLoadingPlugin.register((resourceManager, executor) -> {
            return CompletableFuture.completedFuture(null);
        }, (Void data, ModelLoadingPlugin.Context pluginContext) -> {
            pluginContext.registerBlockStateResolver(Blocks.STONE, context -> {
                for (BlockState blockState : context.block().getStateDefinition().getPossibleStates()) {
                    context.setModel(blockState, ModelLoadingHelper.missingModel());
                }
            });
            ResourceLocation resourceLocation = BuiltInRegistries.BLOCK.getKey(Blocks.STONE).withPrefix("block/");
            ModelResourceLocation modelResourceLocation = BlockModelShaper.stateToModelLocation(Blocks.STONE.defaultBlockState());
            pluginContext.modifyModelOnLoad().register((model, context) -> {
                return context.id().equals(resourceLocation) ? MissingBlockModel.missingModel() : model;
            });
            pluginContext.modifyBlockModelOnLoad().register((model, context) -> {
                return context.id().equals(modelResourceLocation) ? ModelLoadingHelper.missingModel() : model;
            });
        });

However running the exact same code as a ModelLoadingPlugin works perfectly fine without any issues:

        ModelLoadingPlugin.register(pluginContext -> {
            pluginContext.registerBlockStateResolver(Blocks.STONE, context -> {
                for (BlockState blockState : context.block().getStateDefinition().getPossibleStates()) {
                    context.setModel(blockState, ModelLoadingHelper.missingModel());
                }
            });
            ResourceLocation resourceLocation = BuiltInRegistries.BLOCK.getKey(Blocks.STONE).withPrefix("block/");
            ModelResourceLocation modelResourceLocation = BlockModelShaper.stateToModelLocation(Blocks.STONE.defaultBlockState());
            pluginContext.modifyModelOnLoad().register((model, context) -> {
                return context.id().equals(resourceLocation) ? MissingBlockModel.missingModel() : model;
            });
            pluginContext.modifyBlockModelOnLoad().register((model, context) -> {
                return context.id().equals(modelResourceLocation) ? ModelLoadingHelper.missingModel() : model;
            });
        });

Finally, here is the code used for creating the unbaked block state missing model:

    public static UnbakedBlockStateModel missingModel() {
        return new UnbakedBlockStateModel() {

            @Override
            public BakedModel bake(ModelBaker baker) {
                return UnbakedModel.bakeWithTopModelValues(MissingBlockModel.missingModel(),
                        baker,
                        BlockModelRotation.X0_Y0);
            }

            @Override
            public Object visualEqualityGroup(BlockState state) {
                return this;
            }

            @Override
            public void resolveDependencies(Resolver resolver) {
                // NO-OP
            }
        };
    }

Reproduction Steps

See above.

Log File

latest.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed in betaDevelopment builds are available with the fix

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions