[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 Minecraft modding (Java Edition)

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
Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Do you need Gecklib API be…
Mon, 09/26/2022 - 13:14

Do you need Gecklib API be added to the workspace?

Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how i can get the api or …
Mon, 09/26/2022 - 13:20

how i can get the api or  setup it using build.gradle

Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yes, Geckolib is required…
Mon, 09/26/2022 - 14:56

Yes, 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

Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
but ShadowsAPIs for 2022.1 +…
Mon, 09/26/2022 - 16:30

but ShadowsAPIs for 2022.1 + can i setup Geckolib using the normal way i mean using build.gradle

 

 

 

 

 

 

 

 

 

Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Shadow API works on 2022.2,…
Mon, 09/26/2022 - 16:50

Shadow API works on 2022.2, it will add Geckolib repository and dependency to MCreator automatically. MCreator does things a little bit different, but it works as intended. Geckolib repository and dependency from ShadowAPIs will be added in mcreator.gradle. When the mod is exported, it will be included in the build.

 

This tutorial is mostly for users that don't understand a lot about coding. In your case, the repository and dependency can be added as usual (when coded manually). Just remember, Geckolib mod is required. You can also include/integrate it in your mod ... but that is a more advanced process. Here I am using the most MCreator can provide.

Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Build.gradle for Forge 1.18…
Mon, 09/26/2022 - 16:54

Build.gradle for Forge 1.18.x

 

repositories{
        maven { url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/' }
}
dependencies{
        implementation fg.deobf('software.bernie.geckolib:geckolib-forge-1.18:3.0.39')
}

Example: https://github.com/AzureDoom/MCDoom/blob/forge1.18/build.gradle

Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
thanks alot
Mon, 09/26/2022 - 17:24

thanks alot

Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I think you can lock base…
Mon, 09/26/2022 - 20:22

I think you can lock base mod files to stop mcreator from overwriting the initialize thing, but that can cause problems.

Joined Aug 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Very nice tutorial (even if…
Tue, 09/27/2022 - 00:49

Very nice tutorial (even if Minecraft 1.19 added a new animation system).

Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks, I have been using…
Tue, 09/27/2022 - 02:37

Thanks, I have been using Geckolib for 1.19.2 and have ready a tutorial for MCreator when it gets the update ... but have not heard about a new animation system. Where can I find documentation about it?

Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Will be there a Tutorial for…
Tue, 09/27/2022 - 12:28

Will be there a Tutorial for Blocks, Items and Armor?

Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i think you just need to…
Tue, 09/27/2022 - 14:24

i think you just need to watch  Modding by Kaupenjoe  videos   about model animation 

And comparing it with this tutorial, you will be able to do it