Topic category: Help with modding (Java Edition)
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:
- The movementPredicate , which adds the idle, walk, attack, and death animations
- The tickDeath , which will keep the dead entity for 80 ticks (4 seconds - it can be changed) after death/killed
- The registerControllers , for the movementPredicate
- 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!
Do you need Gecklib API be added to the workspace?
how i can get the api or setup it using build.gradle
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
but ShadowsAPIs for 2022.1 + can i setup Geckolib using the normal way i mean using build.gradle
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.
Build.gradle for Forge 1.18.x
Example: https://github.com/AzureDoom/MCDoom/blob/forge1.18/build.gradle
thanks alot
Nice tutorial, pinning the topic ;)
Thanks!
I think you can lock base mod files to stop mcreator from overwriting the initialize thing, but that can cause problems.
Very nice tutorial (even if Minecraft 1.19 added a new animation system).
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?
Will be there a Tutorial for Blocks, Items and Armor?
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