Topic category: Help with Minecraft 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!
dident work xd i think i go back to custom code xd
@noobBrolY
Can you share the log in order to understand what did not work for you?
@GamesofFreak
Blocks, and Items are more tricky ... will try them later. I will be first trying animated Armors.
Why does the game crash when my custom entity is generated? This is my error report
https://github.com/scpendless/error/files/9741546/debug.log
https://github.com/scpendless/error/files/9741547/latest.log
Your model, Mgc.geo.json could not be found. make sure the location and name are correct.
Okay, because I capitalized
can i have geckolib for 2022.2 ?
@SaYZoX 93 - Get ShadowsAPI or Nerdy's GeckoLib Plugin
thanks I finaly understand.