FANDOM


To begin making our animations, we first have to create the actual entity that will handle the animations. Creating the basic entity consists of making the actual entity and connecting it to some animation terms. You should already have prior knowledge of how to make a normal entity.

Starting Off

The first thing you need to do is to make the entity. Let's start by creating an entity called EntityTest. For now, we're focusing on the entity implementation portion, as you should know how to register your entity's id to the mod and all that. Here's an example of the code:

public class EntityTest extends EntityCreature implements IAnimals {
	
	public EntityTest(World world) {
		super(world);
		texture = "nothing";
		//add some typical ai; remember not to use ai priority 2
		//this will be explained why later
		tasks.addTask(1, new EntityAISwimming(this));
		tasks.addTask(3, new EntityAIAttackOnCollide(this, 1F, false));
		tasks.addTask(4, new EntityAIWander(this, 0.8F));
		tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 8F));
		tasks.addTask(5, new EntityAILookIdle(this));
		targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
	}
	
	@Override
	protected void applyEntityAttributes() {
		super.applyEntityAttributes();
		getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(16D); //max health
		getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(0.24D); //move speed
	}
	
	public boolean isAIEnabled() {
		return true;
	}
}

As you can see, this is just a typical entity with AI. Note that an animated entity must at least extend EntityCreature and will NOT work for by only extending Entity or EntityLiving. Also, for the sake of this example, the texture is set to "nothing", which just creates a null texture ingame. You can set it to whatever you want. Remember that the entity must have AI enabled, which plays a very important role later on in linking the animations to actual behaviors.

Implementing IAnimatedEntity

After doing this, the first link you need to make is to make your entity into an animated entity. To do this, you have to implement the interface, IAnimatedEntity. First, let's take a look at how the actual interface is defined:

public interface IAnimatedEntity {
	
	void setAnimID(int id);
	void setAnimTick(int tick);
	int getAnimID();
	int getAnimTick();
}

As you can see, the interface has four methods that you will have to implement. Basically, what you will have to do is you will have to create two fields that can be changed or returned through these methods, so the AnimationAPI classes can access the fields. So let's add these few things to our entity:

public class EntityTest extends EntityCreature implements IAnimals, IAnimatedEntity {
	private int animID;
	private int animTick;
	/*
	 * Implemented method from IAnimatedEntity.
	 * Set the animID field to the id in the parameter.
	 */
	public void setAnimID(int id) {
		animID = id;
	}
	
	/*
	 * Implemented method from IAnimatedEntity.
	 * Set the animTick field to the tick in the parameter.
	 */
	public void setAnimTick(int tick) {
		animTick = tick;
	}
	
	/*
	 * Implemented method from IAnimatedEntity.
	 * Return the animID.
	 */
	public int getAnimID() {
		return animID;
	}
	
	/*
	 * Implemented method from IAnimatedEntity.
	 * Return the animTick.
	 */
	public int getAnimTick() {
		return animTick;
	}

Remember to implement the IAnimatedEntity class, create the fields animID and animTick, and implement the methods. Basically, only one animation can be running at a time, and this is represented with animID. If animID is equal to 0, then no animation is being played. The animTick field is an incrementing tick that helps the animation progress through time. However, this doesn't naturally increase. Instead, you need to add a line of code into the onUpdate method like so:

public void onUpdate() {
	super.onUpdate();
	//increment the animTick if there is an animation playing
	if(animID != 0) animTick++;
}

Finishing Up

That's all you need for your entity (for now)! If you've done everything correctly, your file should look something like this:

public class EntityTest extends EntityCreature implements IAnimals, IAnimatedEntity {
	
	private int animID;
	private int animTick;
	
	public EntityTest(World world) {
		super(world);
		texture = "nothing";
		animID = 0;
		animTick = 0;
		tasks.addTask(1, new EntityAISwimming(this));
		tasks.addTask(3, new EntityAIAttackOnCollide(this, 1F, false));
		tasks.addTask(4, new EntityAIWander(this, 0.8F));
		tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 8F));
		tasks.addTask(5, new EntityAILookIdle(this));
		targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
	}
	
	@Override
	protected void applyEntityAttributes() {
		super.applyEntityAttributes();
		getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(16D); //max health
		getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(0.24D); //move speed
	}
	
	public boolean isAIEnabled() {
		return true;
	}
	
	/*
	 * Implemented method from IAnimatedEntity.
	 * Set the animID field to the id in the parameter.
	 */
	public void setAnimID(int id) {
		animID = id;
	}
	
	/*
	 * Implemented method from IAnimatedEntity.
	 * Set the animTick field to the tick in the parameter.
	 */
	public void setAnimTick(int tick) {
		animTick = tick;
	}
	
	/*
	 * Implemented method from IAnimatedEntity.
	 * Return the animID.
	 */
	public int getAnimID() {
		return animID;
	}
	
	/*
	 * Implemented method from IAnimatedEntity.
	 * Return the animTick.
	 */
	public int getAnimTick() {
		return animTick;
	}
	
	public void onUpdate() {
		super.onUpdate();
		//increment the animTick if there is an animation playing
		if(animID != 0) animTick++;
	}

}

Congratulations, you finished Step 1! Head on to Step 2: Creating an Automatic Animation AI.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.