[TUTORIAL] How to add a Geckolib animated entity to MCreator 2022.2 (only for 1.18.2)

Started by __SK__ on

Topic category: Help with modding (Java Edition)

Last seen on 21:00, 23. Apr 2024
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[TUTORIAL] How to add a Geckolib animated entity to MCreator 2022.2 (only for 1.18.2)
Mon, 09/26/2022 - 17:42 (edited)

First create a custom entity in Blockbench using Geckolib Animation Utils (3.0.5) plugin. A good tutorial for it ... https://www.youtube.com/watch?v=VlUwLXkwb2c

Once your custom entity, texture and animation(s) are ready/saved/exported, go to MCreator and start your entity as usual. No need to import the model to Mcreator since Geckolib uses a different process to add your model, animation(s) and texture.

A little tip about Geckolib ... models have no size limit, but as usual it depends on your system's performance. Their wiki site has everything you could need (if you understand coding), but don't go to their discord to ask about implementing it to MCreator ... They will ban you.

Geckolib is required. How to add it? 

In order to work as intended, it will require ShadowAPIs and Geckolib enabled.

https://mcreator.net/plugin/84967/shadowsapis

Template workspace is included here ...

https://mcreator.net/modification/91118/unexpected-animations

 

Now let's continue with the tutorial ... Add your living entity using MCreators template. When done, lock the code.

Note ... The entire presentation was recorded/copied at the highest resolution possible, right click it/them and save for future reference.

Now use you favorite code editor. I will be using IntelliJ 2022.2. Load the workspace to it and open your entity's file. The example will be named 

CrazyMobEntity

Paste the following portion which will implement IAnimatable. You will get an error ... No problem, it is normal.

implements IAnimatable {
   private AnimationFactory factory = new AnimationFactory(this);

Where does it go? 

Now go to the 

AttributeSupplier

Right before the last "}" and add the following


   private <E extends IAnimatable> PlayState movementPredicate(AnimationEvent<E> event) {

      if (event.isMoving()) {
         event.getController().setAnimation(new AnimationBuilder().addAnimation("walk", true));
         return PlayState.CONTINUE;
      }
      if (!event.isMoving()) {
         event.getController().setAnimation(new AnimationBuilder().addAnimation("idle", true));
         return PlayState.CONTINUE;
      }
      if (this.isDeadOrDying()) {
         event.getController().setAnimation(new AnimationBuilder().addAnimation("death", false));
         return PlayState.CONTINUE;
      }
      if (this.isAggressive()) {
         event.getController().setAnimation(new AnimationBuilder().addAnimation("attack", false));
         return PlayState.CONTINUE;
      }
      return PlayState.CONTINUE;
   }

   @Override
   protected void tickDeath() {
      ++this.deathTime;
      if (this.deathTime == 80) {
         this.remove(Entity.RemovalReason.KILLED);
      }
   }

   @Override
   public void registerControllers(AnimationData data) {
      data.addAnimationController(new AnimationController<>(this, "movement", 4, this::movementPredicate));
   }

   @Override
   public AnimationFactory getFactory() {
      return this.factory;
   }
}

This part adds:

  1. The movementPredicate , which adds the idle, walk, attack, and death animations
  2. The tickDeath , which will keep the dead entity for 80 ticks (4 seconds - it can be changed) after death/killed
  3. The registerControllers , for the movementPredicate
  4. Finally, the AnimationFactory , which closes this portion of the class

Where does it go? 

All errors in this class are now cleared. Now we need to go to the renderer

CrazyMobRenderer

Almost everything needs to be replaced, but the advantage is that here we will gain access to the 

stack.scale

Yes ... now we can scale the models anyway we like. Make sure to pre-plan the model's bounding box vs the new size you will give to your entity.

The required code ...

extends GeoEntityRenderer<CrazyMobEntity> {
   public CrazyMobRenderer(EntityRendererProvider.Context renderManager) {
      super(renderManager, new CrazyMobModel());
      this.shadowRadius = 0.3f;
   }

   @Override
   public RenderType getRenderType(CrazyMobEntity animatable, float partialTicks, PoseStack stack,
                           MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn,
                           ResourceLocation textureLocation) {
      stack.scale(0.8F, 0.8F, 0.8F);
      return super.getRenderType(animatable, partialTicks, stack, renderTypeBuffer, vertexBuilder, packedLightIn, textureLocation);
   }
}

How it's done?

You will have an error with

CrazyMobModel

No worries, that file/class has not been created. 

How to add package and class? 

Now, with this step your entity is almost ready. The class you need to add is 

CrazyMobModel

This class basically takes care of mapping the animation file, the model and the texture. All the errors will require the class to be imported. Also, your MODID is not ( UnexpectedAnimationsMod ), it will be different. Change it to yours. 

This is the code ...

public class CrazyMobModel extends AnimatedGeoModel<CrazyMobEntity> {
    @Override
    public ResourceLocation getAnimationFileLocation(CrazyMobEntity entity) {
        return new ResourceLocation(UnexpectedAnimationsMod.MODID, "animations/test_zombie.animation.json");
    }

    @Override
    public ResourceLocation getModelLocation(CrazyMobEntity entity) {
        return new ResourceLocation(UnexpectedAnimationsMod.MODID, "geo/test_zombie.geo.json");
    }

    @Override
    public ResourceLocation getTextureLocation(CrazyMobEntity entity) {
        return new ResourceLocation(UnexpectedAnimationsMod.MODID, "textures/model/entity/test_zombie02.png");
    }
}

Finally, go back to MCreator and test your mod. Now ... before exporting you will need to make sure Geckolib is initializes in your mod. For this you will be required to add ...

GeckoLib.initialize();

Where does it go?

Make sure you don't regenerate the code, it will get rid of most of Geckolib's code.

End result ...

Congratulations, you just added an animated entity to MCreator using Geckolib and hopefully learning and understanding a little bit of coding.

 

Happy modding!

 

Edited by __SK__ on Mon, 09/26/2022 - 17:42
Last seen on 15:49, 18. Apr 2023
Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
 dident work  xd i think i…
Tue, 09/27/2022 - 15:23

 dident work  xd i think i go back to custom code xd

Last seen on 21:00, 23. Apr 2024
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@noobBrolY    Can you share…
Tue, 09/27/2022 - 18:58

@noobBrolY 

 

Can you share the log in order to understand what did not work for you?

Last seen on 21:00, 23. Apr 2024
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@GamesofFreak   Blocks, and…
Tue, 09/27/2022 - 19:01

@GamesofFreak

 

Blocks, and Items are more tricky ... will try them later. I will be first trying animated Armors.

Last seen on 21:32, 23. Apr 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Your model, Mgc.geo.json…
Sun, 10/09/2022 - 14:12

Your model, Mgc.geo.json could not be found. make sure the location and name are correct.

Last seen on 17:49, 31. Dec 2023
Joined Aug 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay, because I capitalized
Sun, 10/09/2022 - 16:31

Okay, because I capitalized

Last seen on 22:32, 20. Apr 2024
Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
can i have geckolib for 2022…
Tue, 04/25/2023 - 08:56

can i have geckolib for 2022.2 ?

Last seen on 21:00, 23. Apr 2024
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@SaYZoX 93 - Get ShadowsAPI…
Tue, 05/09/2023 - 07:57

@SaYZoX 93 - Get ShadowsAPI or Nerdy's GeckoLib Plugin