#1.21 Using Mixins to render item as 3d in hand and 2d in inventory

2 messages · Page 1 of 1 (latest)

hallow mural
#

Hi I'm trying to create an item that shows a 3d render when in a players hand and is 2d in the inventory. However when the game loads one of the mixins is crashes.

This is the code for the mixin in question, not including the imports:

public abstract class ModelLoaderMixin {

    @Shadow
    protected abstract void addModel(ModelIdentifier modelIdentifier);

    @Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/ModelLoader;addModel(Lnet/minecraft/client/util/ModelIdentifier;)V", ordinal = 3, shift = At.Shift.AFTER))
    public void addEmptyJar(Map<Identifier, JsonUnbakedModel> jsonUnbakedModels, Map<Identifier, List<ModelLoader.SpriteGetter>> blockStates, CallbackInfo ci) {
        this.addModel(new ModelIdentifier(Identifier.of(BoozinMod.MOD_ID, "empty_jar_3d"), "inventory"));
    }
}```

This mixin is loaded along side ItemRendererMixin and ItemRendererAccessor, both of which seem to load correctly
hallow mural
#

Updated the code a bit:

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

    @Shadow
    protected abstract void loadItemModel(ModelIdentifier id);

    @Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/ModelLoader;loadItemModel(Lnet/minecraft/client/util/ModelIdentifier;)V", ordinal = 1, shift = At.Shift.AFTER))
    public void addItemModel(BlockColors blockColors, Profiler profiler, Map<Identifier, JsonUnbakedModel> jsonUnbakedModels, Map<Identifier, List<BlockStatesLoader.SourceTrackedData>> blockStates, CallbackInfo ci) {
        this.loadItemModel(ModelIdentifier.ofInventoryVariant(Identifier.of(BoozinMod.MOD_ID, "empty_jar_3d")));
    }
}

It seems to specifically be

As removing that line allows to game to load with no errors but makes it so the held item is untextured (however the item in the inventory is the correct 2d sprite)

Has something changed in the inject method that im missing?