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!

 

Joined Nov 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@Timson what do you mean …
Tue, 08/19/2025 - 14:22

@Timson what do you mean "model code"? What is that and how do you edit it?

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I think it refers to the…
Tue, 08/19/2025 - 14:55

I think it refers to the model's file that you export from blockbench. Using various tools such as notepad, you can open and edit it.

Joined Jul 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@ktosiowy ktos It`s a .java…
Sat, 09/06/2025 - 00:51

@ktosiowy ktos It`s a .java model file. @Catnip is absolutely right. You can edit it with any text editor. Just make sure you do it BEFORE importing this model file in MCreator

Joined Jul 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@Timson can you make a…
Sat, 09/06/2025 - 05:43

@Timson can you make a proper guide for mcreator 2024.x i cant understand the guild on page 1

Joined Jul 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@idkwhattoput what can`t you…
Sat, 09/06/2025 - 13:24

@idkwhattoput what can`t you understand exactly?

Joined Jul 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@Timson Honestly, I don't…
Sun, 09/28/2025 - 09:36

@Timson Honestly, I don't understand anything either. The Java model code doesn't throw an error, let alone render the mob. Is this method compatible with version 1.20.1? Could you make a video tutorial?

Joined Mar 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm afraid that you (Timson)…
Fri, 01/02/2026 - 03:40

I'm afraid that you (Timson) did not explain this tutorial thoroughly. You seem to have just thrown random lines of code, without telling me specifically where to place them, as well as what lines of code to replace. I'm afraid I'm going to need a better explanation for this (preferably through a video tutorial).