Allowing an entity with custom model to hold an item

Started by _Ness on

Topic category: Advanced modding

Joined Oct 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Allowing an entity with custom model to hold an item

Hi, I'm trying to allow my custom model mob to display the item in its hand, I know this was possible in previous versions, but I can't figure out what lines of the code I need to mess with in order for this to work, can anyone help me please ? Thanks in advance.

Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Definitely the version…
Sun, 03/23/2025 - 05:11

Definitely the version/modloader difference, iirc minecraft's rendering system as a whole was nearly completely rewritten in 1.21

Joined Aug 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The solution I posted does…
Sat, 07/12/2025 - 00:52

The solution I posted does not work anymore for 1.21.4. :/

 

Currently I am trying to get it working again

Joined Jul 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Here`s a solution for…
Sun, 07/20/2025 - 17:32

Here`s a solution for MCreator 2025.2, 1.21.4: 

  • Your custom model must extend ArmedEntityRenderState and implement ArmedModel. You should put this in your model`s code directly BEFORE importing it in MCreator, or else it will rewrite your changes. Here`s the example from my Java model code: 
public class Kefir extends EntityModel<ArmedEntityRenderState> implements ArmedModel
  • As mentioned earlier, your model code also must have getArm and translateToHand functions.
  • In your custom entity renderer code, you need to replace EVERY LivingEntityRenderState with ArmedEntityRenderState
import net.minecraft.client.renderer.entity.state.ArmedEntityRenderState;
public class KefirRenderer extends MobRenderer<KefirEntity, ArmedEntityRenderState, ModelKefir>
  • As mentioned earlier, you need to add ItemInHandLayer(don`t forget about imports): 
    import net.minecraft.client.renderer.entity.layers.ItemInHandLayer;
    .
    .
    .
    public KefirRenderer(EntityRendererProvider.Context context) {
        super(context, new AnimatedModel(context.bakeLayer(ModelKefir.LAYER_LOCATION)), 0.5f);
               this.addLayer(new ItemInHandLayer<>(this));
    }
  • And for the final step, you will need to add extractArmedEntityRenderState to the extractRenderState method, as in this example:
    @Override
    public void extractRenderState(KefirEntity entity, ArmedEntityRenderState state, float partialTicks) {
        super.extractRenderState(entity, state, partialTicks);
        ArmedEntityRenderState.extractArmedEntityRenderState(entity, state, this.itemModelResolver); //important
        this.entity = entity;
        if (this.model instanceof AnimatedModel) {
            ((AnimatedModel) this.model).setEntity(entity);
        }
    }
  • IMPORTANT NOTE: If you are using keyframe-based Java animations, you also better change setupAnim part at the end of your entity renderer code, or else your animations won`t work at all. Here`s what I did: 
        @Override
        public void setupAnim(ArmedEntityRenderState state) {
            //this.root().getAllParts().forEach(ModelPart::resetPose); -I believe this line breaks all animations, so I commented it
            super.setupAnim(state);
            this.animate(entity.animationState0, KefirAnimation.idle, state.ageInTicks, 0.35f);
            this.animateWalk(KefirAnimation.walk, state.walkAnimationPos, state.walkAnimationSpeed, 2f, 2.5f);
            this.animate(entity.animationState2, KefirAnimation.attack, state.ageInTicks, 1f);
        }

Hope this helps!