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

Started by __SK__ on Sun, 10/02/2022 - 21:04

Topic category: Help with modding (Java Edition)

Last seen on 07:06, 29. Nov 2022
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
[TUTORIAL] How to add a Geckolib animated swords/items to MCreator 2022.2 (only for 1.18.2)
Mon, 10/03/2022 - 04:22 (edited)

First create a custom sword/item in Blockbench using Geckolib Animation Utils (3.0.5) plugin. A good tutorial for it ... https://www.youtube.com/watch?v=E_M_wRHATdY&t=339s (you will only need to watch from 0:35 - 3:30, it explains the most important parts there ... everything else is non-MCreator related)

Once your custom sword/item, texture and animation(s) are ready/saved/exported, go to MCreator and start your sword/item 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 (as in sword/item) have no size/voxel 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

Now let's continue with the tutorial ...

Add your custom sword/item using MCreators, you can use a blank/transparent texture. 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 sword/item's file. The example will be named 

UnexpectedSword

Paste the following portion which will implement IAnimatable (this example gives wither effect for 60 tick when attacing verify the notes "//"). You will get an error with UnexpectedSwordItemRender ... No problem, it has not been created.

implements IAnimatable {
   //////////////////////////SWORDITEM  ^^^^^^^^^  OR  TOOL OR ITEM
   public AnimationFactory factory = new AnimationFactory(this);

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

   //when entity is hit with sword
   @Override
   public boolean hurtEnemy(ItemStack p_43278_, LivingEntity p_43279_, LivingEntity p_43280_) {
      p_43279_.addEffect(new MobEffectInstance(MobEffects.WITHER, 60), p_43280_);
      ////////////////////////////////////////////EFFECT ^^^^^^^ //TICKS  ^^^
      return super.hurtEnemy(p_43278_, p_43279_, p_43280_);
   }

   @Override
   public void initializeClient(Consumer<IItemRenderProperties> consumer) {
      super.initializeClient(consumer);
      consumer.accept(new IItemRenderProperties() {
         private final BlockEntityWithoutLevelRenderer renderer = new UnexpectedSwordItemRender();


         public BlockEntityWithoutLevelRenderer getItemStackRenderer() {
            return renderer;
         }
      });
   }

   @Override
   public void registerControllers(AnimationData data) {
      data.addAnimationController(new AnimationController(this, "controller",
            0, this::predicate));
   }

   private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
      event.getController().setAnimation(new AnimationBuilder().addAnimation("idle", true));

      return PlayState.CONTINUE;
   }

Where does it go? 

Now create one package named 

  • client     

inside it create two packages named

  • model
  • renderer

 

How?

Now inside the model package, you will need to add a class named 

UnexpectedSwordItemModel

Inside this class paste the following

extends AnimatedGeoModel<UnexpectedSwordItem> {
    @Override
    public ResourceLocation getModelLocation(UnexpectedSwordItem object) {
        return new ResourceLocation(AnimatedSwordsMod.MODID, "geo/unexpected_sword.geo.json");
    }

    @Override
    public ResourceLocation getTextureLocation(UnexpectedSwordItem object) {
        return new ResourceLocation(AnimatedSwordsMod.MODID, "textures/item/unexpected_sword.png");
    }

    @Override
    public ResourceLocation getAnimationFileLocation(UnexpectedSwordItem animatable) {
        return new ResourceLocation(AnimatedSwordsMod.MODID, "animations/unexpected_sword.animation.json");
    }
}

Your MODID might be different, change it to yours. For the errors, just import the respective class.

How?

 

Now we move to the renderer package, and create a new class named

UnexpectedSwordItemRender

Inside this class paste the following

extends GeoItemRenderer<UnexpectedSwordItem> {
    public UnexpectedSwordItemRender() {
        super(new UnexpectedSwordItemModel());
    }
}

If you get errors, just import the respective class.

How it's done?

Now we are done with the coding, you just need to add all the assets.

Inside the resources/assets  you will need to create three new folders

  • animations
  • geo
  • textures/item  (why item? this is how geckolib uses it, you could change it if you like)

Finally add your required files in the respective folders.

They should look like the following ...

Remember  ... 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 have added an animated sword/item into MCreator using Geckolib.

 

Have fun!

Edited by __SK__ on Mon, 10/03/2022 - 04:22
Last seen on 01:13, 25. Nov 2022
Joined Jul 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
That's great. Such tutorials…
Mon, 10/03/2022 - 05:14

That's great. Such tutorials are very interesting and easy to understand. Thank you.

Last seen on 08:54, 29. Nov 2022
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Great tutorial!
Mon, 10/03/2022 - 08:32

Great tutorial!

Last seen on 07:06, 29. Nov 2022
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Glad you like it.
Mon, 10/03/2022 - 11:57

Glad you like it.