#Load a model from json

1 messages · Page 1 of 1 (latest)

torn sand
#

Hello! I was wondering if someone can help me figure out how to load a model from json. I've been looking through the source code and I managed to track down UnbakedJsonModel and the BakedModelManager but I'm not how to get actually get the model. Would really appreciate some help.

molten radish
#

Easist way would be to make a mixin to ModelLoader.class
and use the addModel method

@Mixin(ModelLoader.class)
public abstract class ModelLoaderMixin {

    @Shadow
    protected abstract void addModel(ModelIdentifier modelId);

    @Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/ModelLoader;addModel(Lnet/minecraft/client/util/ModelIdentifier;)V", ordinal = 2, shift = At.Shift.BEFORE))
    public void addModels(BlockColors blockColors, Profiler profiler, Map<Identifier, JsonUnbakedModel> jsonUnbakedModels, Map<Identifier, List<ModelLoader.SourceTrackedData>> blockStates, CallbackInfo ci) {;
            this.addModel(new ModelIdentifier(NAMESPACE (modID), PATH (path to your model (assets/modid/), VARIANT (use "inventory" for general gui stuff));
        }
    }

}

With this, Minecraft will do your model loading.
Then you can just use one of the model managesr to get your model

MinecraftClient.getInstance().getBakedModelManager().getModel(ModelIdentifier);
bitter coral
#

I remember seeing a model loader fapi module? Maybe that might help?

torn sand
fierce pewter
#

Wait are you trying to make a 3D renderer for a item when it is held in the hand just like a spyglass or something?

#

@torn sand

torn sand
fierce pewter
#

Oh

torn sand
#

Thank you for asking, tough