Skip to content

[1.21.5] Add model loading plugins to replace ModelEvent.ModifyBakingResult #1884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: 1.21.x
Choose a base branch
from

Conversation

XFactHD
Copy link
Member

@XFactHD XFactHD commented Jan 21, 2025

This PR adds model loading plugins which are intended to replace ModelEvent.ModifyBakingResult. These allow more precise model wrapping, including wrapping unbaked models. Another benefit of this API design is that it allows mods which implement on-demand model loading/baking a lot more control and improves compatibility between those mods and ones using the model wrapping APIs.
As is probably very obvious, this PR is very heavily inspired by Fabric API's model loading APIs and therefor has an almost 100% overlap in terms of API surface and injection points.

The model loading plugins provide seven entrypoints into the model loading and baking process:

  • On-load/on-load-block modifiers: on-load modifiers are registered globally and allow wrapping unbaked models and unbaked blockstate models as they are loaded and therefor affect all further uses of the model in question
  • Pre-bake-block/pre-bake-item modifiers: pre-bake modifiers are registered globally and allow wrapping unbaked blockstate models and unbaked item models respectively right before baking and therefor only affect the specific baking process following their execution
  • Post-bake-block/post-bake-item modifiers: post-bake modifiers are registered globally and allow wrapping baked blockstate models and baked item models respectively right after baking (effectively equivalent to wrapping models in ModelEvent.ModifyBakingResult)

Apart from the missing documentation, there are still a few questions open:

  • Should we try to aggressively re-use context objects?
  • What would be the preferred way of exposing the plugins to mods implementing on-demand loading/baking?

@XFactHD XFactHD added enhancement New (or improvement to existing) feature or request rendering Related to rendering 1.21.4 Targeted at Minecraft 1.21.4 labels Jan 21, 2025
@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Jan 21, 2025

  • Publish PR to GitHub Packages

Last commit published: 7947f32e41a0a9fc23a37f15c2b8c71fdf51eaf6.

PR Publishing

The artifacts published by this PR:

Repository Declaration

In order to use the artifacts published by the PR, add the following repository to your buildscript:

repositories {
    maven {
        name 'Maven for PR #1884' // https://github.com/neoforged/NeoForge/pull/1884
        url 'https://prmaven.neoforged.net/NeoForge/pr1884'
        content {
            includeModule('net.neoforged', 'neoforge')
            includeModule('net.neoforged', 'testframework')
        }
    }
}

MDK installation

In order to setup a MDK using the latest PR version, run the following commands in a terminal.
The script works on both *nix and Windows as long as you have the JDK bin folder on the path.
The script will clone the MDK in a folder named NeoForge-pr1884.
On Powershell you will need to remove the -L flag from the curl invocation.

mkdir NeoForge-pr1884
cd NeoForge-pr1884
curl -L https://prmaven.neoforged.net/NeoForge/pr1884/net/neoforged/neoforge/21.5.29-beta-pr-1884-model_loading_plugins/mdk-pr1884.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip

To test a production environment, you can download the installer from here.

@XFactHD XFactHD force-pushed the model_loading_plugins branch from 3c4627c to 4b1c988 Compare January 21, 2025 03:13
@XFactHD XFactHD force-pushed the model_loading_plugins branch from 4b1c988 to 6135c07 Compare January 21, 2025 21:38
@XFactHD XFactHD requested a review from embeddedt January 21, 2025 22:25
@neoforged-compatibility-checks
Copy link

neoforged-compatibility-checks bot commented Feb 2, 2025

@XFactHD, this PR introduces breaking changes.
Fortunately, this project is currently accepting breaking changes, but if they are not intentional, please revert them.
Last checked commit: 7947f32e41a0a9fc23a37f15c2b8c71fdf51eaf6.

neoforge (:neoforge)

  • net/minecraft/client/resources/model/ModelBakery
    • <init>(Lnet/minecraft/client/model/geom/EntityModelSet;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Lnet/minecraft/client/resources/model/ResolvedModel;Lnet/neoforged/neoforge/client/model/standalone/StandaloneModelLoader$LoadedModels;)V: ❗ API method was removed

@XFactHD XFactHD marked this pull request as ready for review February 14, 2025 09:15
@Fuzss
Copy link

Fuzss commented Mar 16, 2025

Any update on merging this?

@embeddedt
Copy link
Member

This is probably not going to be merged in the current state because of the drastic vanilla changes to model handling in 1.21.5, which is right around the corner.

@XFactHD XFactHD force-pushed the model_loading_plugins branch from fcbc5bb to 49ee251 Compare March 26, 2025 19:25
@XFactHD XFactHD marked this pull request as draft March 26, 2025 19:25
@XFactHD XFactHD added 1.21.5 Targeted at Minecraft 1.21.5 and removed 1.21.4 Targeted at Minecraft 1.21.4 labels Mar 26, 2025
@XFactHD XFactHD changed the title [1.21.4] Add model loading plugins to replace ModelEvent.ModifyBakingResult [1.21.5] Add model loading plugins to replace ModelEvent.ModifyBakingResult Mar 28, 2025
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;

public sealed interface ModelModifier {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure that each of these has a clear use case.


package net.neoforged.neoforge.client.model.loadingplugin;

public interface ModelLoadingPlugin {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also fold standalone models into the plugin system. (Possibly just deprecating the current API, or rewriting it as a wrapper on top of a plugin).


package net.neoforged.neoforge.client.model.loadingplugin;

public interface ModelLoadingPlugin {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course javadoc is still missing everywhere.

@XFactHD XFactHD requested a review from Technici4n April 2, 2025 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.5 Targeted at Minecraft 1.21.5 enhancement New (or improvement to existing) feature or request rendering Related to rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants