### Custom Entity Definition with GeckoLib Source: https://github.com/goodbird-git/geckolib-unofficial-1.7.10/wiki/Dev:-Creating-a-custom-modeled-entity Defines a custom entity inheriting from EntityCreature and implementing GeckoLib's animation interfaces. Includes AI tasks and animation controller setup. ```Java package software.bernie.example.entity; //The package our class is located in //Imports of the classes used in this class description import net.minecraft.entity.EntityCreature; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import software.bernie.geckolib3.core.IAnimatable; import software.bernie.geckolib3.core.IAnimationTickable; import software.bernie.geckolib3.core.PlayState; import software.bernie.geckolib3.core.builder.AnimationBuilder; import software.bernie.geckolib3.core.controller.AnimationController; import software.bernie.geckolib3.core.event.predicate.AnimationEvent; import software.bernie.geckolib3.core.manager.AnimationData; import software.bernie.geckolib3.core.manager.AnimationFactory; //Our entity will be derived from the EntityCreature class, meaning that it will be a peaceful creature with some simple AI //It will also implement IAnimatable and IAnimationTickable interfaces, which are required for something to have a geckolib animated model public class GeoExampleEntity extends EntityCreature implements IAnimatable, IAnimationTickable { //We create a field for an animation factory - a special storage for all of the animation states for our entity private final AnimationFactory factory = new AnimationFactory(this); //The constructor of our class, requires a World instance and uses it for the call of super-constructor public GeoExampleEntity(World worldIn) { super(worldIn); this.ignoreFrustumCheck = true; //The entity will be rendered even if it's hitbox is not visible //Here we add an AI task for our entity to watch the closest player in the range of 8 blocks this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.setSize(5F, 5F); //the size of the entity hitbox } //This function is called a predicate. It is used to determine what animation should be played and whether it should play at all // based on the entity state, which is provided in the event argument private PlayState predicate(AnimationEvent event) { //We set the controller to play the looping "animation.bat.fly" animation event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.bat.fly", true)); return PlayState.CONTINUE; //And we say that the animation should be played } //This function is used to register the animation controllers, which will play animations determined by the predicate given @Override public void registerControllers(AnimationData data) { //Here we register a controller with name "controller", with predicate referenced as this::predicate //And we set transition length to 50 ticks, meaning that when one animation ends, the model will transition //To the beginning of the next animation smoothly during those 50 ticks. It can be set to 0 for immediate switch between animations data.addAnimationController(new AnimationController<>(this, "controller", 50, this::predicate)); } //Here we add a getter-function so that geckolib could get the reference to the animation factory @Override public AnimationFactory getFactory() { return this.factory; } //This function should return the value of a timer which will increase every tick - the ticksExisted field fits very well for that @Override public int tickTimer() { return ticksExisted; } } ``` -------------------------------- ### ExampleGeoRenderer Class Source: https://github.com/goodbird-git/geckolib-unofficial-1.7.10/wiki/Dev:-Creating-a-custom-modeled-entity Defines how a custom entity model is rendered in the game. It allows for customization of rendering, such as applying color modifiers based on the entity's state. ```java package software.bernie.example.client.renderer.entity; import software.bernie.example.client.model.entity.ExampleEntityModel; import software.bernie.example.entity.GeoExampleEntity; import software.bernie.geckolib3.core.util.Color; import software.bernie.geckolib3.renderers.geo.GeoEntityRenderer; public class ExampleGeoRenderer extends GeoEntityRenderer { public ExampleGeoRenderer() { super(new ExampleEntityModel()); } public Color getRenderColor(GeoExampleEntity animatable, float partialTicks) { if(animatable.hurtTime>0 || animatable.deathTime > 0) { return Color.ofRGBA(255, 153, 153, 255); } return Color.ofRGBA(255,255,255,255); } } ``` -------------------------------- ### ExampleEntityModel Class Source: https://github.com/goodbird-git/geckolib-unofficial-1.7.10/wiki/Dev:-Creating-a-custom-modeled-entity Defines the model for a custom entity, specifying animation, model, and texture file locations. It also allows for dynamic animation adjustments based on entity state. ```java package software.bernie.example.client.model.entity; import net.minecraft.util.ResourceLocation; import software.bernie.example.entity.GeoExampleEntity; import software.bernie.geckolib3.GeckoLib; import software.bernie.geckolib3.core.event.predicate.AnimationEvent; import software.bernie.geckolib3.core.processor.IBone; import software.bernie.geckolib3.model.AnimatedTickingGeoModel; import software.bernie.geckolib3.model.provider.data.EntityModelData; public class ExampleEntityModel extends AnimatedTickingGeoModel { @Override public ResourceLocation getAnimationFileLocation(GeoExampleEntity entity) { return new ResourceLocation(GeckoLib.ModID, "animations/bat.animation.json"); } @Override public ResourceLocation getModelLocation(GeoExampleEntity entity) { return new ResourceLocation(GeckoLib.ModID, "geo/bat.geo.json"); } @Override public ResourceLocation getTextureLocation(GeoExampleEntity entity) { return new ResourceLocation(GeckoLib.ModID, "textures/model/entity/bat.png"); } @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void setLivingAnimations(GeoExampleEntity entity, Integer uniqueID, AnimationEvent animationEvent) { super.setLivingAnimations(entity, uniqueID, animationEvent); IBone head = this.getAnimationProcessor().getBone("head"); EntityModelData extraData = (EntityModelData) animationEvent.getExtraDataOfType(EntityModelData.class).get(0); head.setRotationX(extraData.headPitch * ((float) Math.PI / 180F)); head.setRotationY(extraData.netHeadYaw * ((float) Math.PI / 180F)); } } ``` -------------------------------- ### Registering a Custom Entity Renderer Source: https://github.com/goodbird-git/geckolib-unofficial-1.7.10/wiki/Dev:-Creating-a-custom-modeled-entity Link your custom entity class to its specific renderer. This registration is client-only and should be performed during the initialization stage after the entity has been registered. ```java //We tell that we want to link our renderer to our entity class RenderingRegistry.registerEntityRenderingHandler(GeoExampleEntity.class, new ExampleGeoRenderer()); ``` -------------------------------- ### Registering a Custom Entity Source: https://github.com/goodbird-git/geckolib-unofficial-1.7.10/wiki/Dev:-Creating-a-custom-modeled-entity Register your custom entity class with a unique name, ID, and tracking parameters. This should be done on the server and client side during the pre-initialization stage. ```java //We register our entity class, GeoExampleEntity, we call the new entity "example", we set it's id to 0, //We tell that this entity belongs to the geckolib mod, and tell some information about the tracking range and velocity updates (not that important in our case) EntityRegistry.registerModEntity(GeoExampleEntity.class, "example", 0, GeckoLibMod.instance, 160, 2, false); ``` -------------------------------- ### Gradle Dependencies for GeckoLib Source: https://github.com/goodbird-git/geckolib-unofficial-1.7.10/wiki/Dev:-Adding-to-the-project Configure your build.gradle file to include the GeckoLib-Unofficial library from your local 'lib' directory. Ensure the dependency name matches the GeckoLib JAR file name (without the .jar extension). ```gradle repositories { flatDir { dirs 'lib' } } dependencies { compile name: "geckolib-unofficial-1.7.10-1.x.x-dev" //The name of the geckolib file in the lib folder without ".jar" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.