List of all EntityAI classes

This page
contains all EntityAI classes, and an interpretation of their code.

These
classes contain information about the behaviour of certain entities. The reason
these behaviours get their own page separately from the entities using them is,
that many behaviours are used by many different entities. For example the class
EntityAIWander is used by Blazes, Creepers, Endermen, Endermites, Guardians,
Iron Golems, Silverfish, Skeletons, Snowmans, Spiders (including Cave Spiders),
Witches, Zombies (including Pigman Zombies and Giants), Chickens, Cows (including
Mooshroms), Horses, Ocelots, Pigs, Rabbits, Sheep, Villagers, Wolves and
Withers. Therefore it would be redundant to explain each behaviour in detail on
each of the page about the affected entities and instead you can find here, how
exactly mobs wander around randomly, and other stuff.

## Classes used by multiple entities

### **ArrowAttack**

This class
is used by Skeletons that hold a bow, Snowmans, Witches and Withers.

This class is
 only active, if the entity using it has a target. If the entity can see
 its target for a full 20 game ticks, the entity checks whether the
target is within its maximum attack distance in a straight line. Then,
if the target is within its attack range, the entity stops pathfinding. If the target is
 not within its attack range, the entity continues pathfinding. When it has
finished pathfinding, the entity starts looking at its target. If
the entity is able to shoot its target, and the cooldown between each
shot is finished, the entity fires a ranged attack towards its target and resets the cooldown timer.

The different types of entities using this class, use it with the following values:

 Snowman | 10
 Witch
 Wither

For snowmans, witches and withers, the cooldown time equals the maxRangedAttackTime value, because maxRangedAttackTime - field\_96561\_g is 0 and the first part of the formula disappears.

For skeletons, the cooldown time also depends on the distance to the target. Generally the cooldown time can be calculated using the following formula (click for full zoom):

### **AttackOnCollide**

This class
is used by Creepers, Endermen, Endermite, Iron Golems, Silverfish, Skeletons, Zombies (including
Giants and PigZombies) and Wolves.

This class remains inactive for Skeletons that have a bow.

If the entity E, that uses this class, has a target, that is not dead, and if there is a path from E to the target, then E will tell its Pathfinding AI, that it wants to walk towards the target with the a speed of speedTowardsTarget (see table below). If E has a classTarget (see table below) it will additionally check, whether the target belongs to that classTarget. If the target should not belong to the classTarget, E will not activate AttackOnCollide. If E has no classTarget, E will use AttackOnCollide on any entity it happens to target.

While AttackOnCollide is active, E will do the following things every tick:

First E will check, whether it wants to stop using AttackOnCollide. This happens if the target is dead or not existent. If E has no longMemory (see table below) and there is no path to the target, E will also stop using AttackOnCollide. If E has a longMemory, then it will check whether it has a home. Because if E has a home, and the distance between the target and the homePosition is greater than the maximumHomeDistance, then E will discontinue using AttackOnCollide. If E however has a longMemory and no home, then it will hunt down its target until the target is dead.

After checking all that stuff, E will actually do something every tick. First it will look at its target. Then it will do some fairly obscure checks, to give some unnamed completely unused variables some meaningless values. After that it will check whether the square of the distance between E and the target is less than (E.width^2 \*4 + target.width). If that should be the case and the attack cooldown is over, then E will get an attack cooldown of 20 ticks. Now if E holds an item in its hand, it will swing that item. E will also attack the target.

The different types of entities using this class, use it with the following values:

### **AvoidEntity**

This class
is used by Creepers, Skeletons and Villagers. Rabbits use a modified version of
this class.

**(More information needs to be added.)**

The different types of entities using this class, use it with the following values:

 Skeleton
 Villager
 Rabbit

The field value is probably used for how close the avoided Entity needs to be, once the avoided entity is in this field, the other entity (Creeper in this example) will move at a speed of 1.2, once the avoided entity is out of the field, the creeper will move at a speed of 1 away from the entity!

### **FindEntityNearestPlayer**

This class
is used by Ghasts and Slimes (including Magma Cubes)..

(More
information needs to be added.)

### **FollowOwner**

This class
is used by Ocelots and Wolves.

**(More information needs to be added.)**

 Wolf

Note: The meaning of minDist and maxDist is apparently not intuitive.

### **FollowParent**

This class
is used by Chickens, Cows (including Mooshrooms), Horses, Pigs and Sheep.

If the growing
age of the user is smaller than 0, it will constantly search for entities with
the same type as the user in a 8x4x8 box centered around the user. Out of the
found entities, it will determine the closest entity, whose growing age is 0 or
greater. If there is such an entity, and that entity is more than 3 blocks
away, it will be stored in a variable called parentAnimal, and this AI-class
will activate. It will continue executing until the growing age of the user
gets 0 or greater, or the parentAnimal stops being alive, or the parentAnimal
is more than 16 or less than 3 blocks away.

Whenever
this task is updated, a variable called field\_75345\_d will be decreased by 1.
If it gets below 0, it will be reset to 10 and the user will use its path
navigator to go towards the parentAnimal, with a speed of field\_75347\_c (see
table below).

 Cow
 Horse
 Pig
 Sheep

### **HurtByTarget**

This class is used by Blazes, Creepers, Endermen, Endermite, Iron Golems, Silverfish, Skeletons, Spiders (including Cave Spiders), Witches, Zombies (including Giants), Withers, Killer Bunnies (which are a special kind of Rabbit) and Wolves. PigZombies also use a modified version of this class.

**(More information needs to be added)**

### **LeapAtTarget**

This class
is used by Spiders, Ocelots and Wolves.

This class will only activate, if the entity using it has a target. If the distance between the entity and the target is more than 2, but less than 4 and the entity is on the ground, then the entity has every tick a 25% chance of doing the following things:

The x-motion and z-motion will be increased by 20%. The entity will also get some x and z motion added, so that it gains in total a 0.4 blocks/tick motion directed at the target.

The y-motion will be set to a variable called leapMotionY.

The different types of entities using this class, use it with the following values:

 Ocelot
 Wolf

### **LookIdle**

This class
is used by Blazes, Creepers, Endermen, Endermites, Guardians, Iron Golems,
Silverfish, Skeletons, Snowmans, Spiders (including Cave Spiders), Witches,
Zombies (including Pigman Zombies and Giants), Chickens, Cows (including Mooshroms),
Horses, Pigs, Sheep, Wolves and Withers.

Every 3
ticks a Mob M, that uses the LookIdle class, has a 2% chance of starting to
look idle.

In that
case, it will start looking in a random x and z direction for 20-40 ticks. After that, it will stop looking idle.

### **Mate**

This class
is used by Chickens, Cows (including Mooshrooms), Horses, Ocelots, Pigs,
Rabbits, Sheep and Wolves.

If the inLove
variable of the user is true, it will constantly search for entities with the
same type as the user in a 8x8x8 box centered around the user. For each found entity it will check, whether it can mate with the entity, and whether the
entity is less than (2-2-52)·21023 blocks away. The user
can mate with another entity, if the other entity is not the user, has the same
class as the user, and if both the user and the other entity are inLove. The
last entity suitable for mating is saved in the targetMate variable, and if
there is now a targetMate, this AIclass will actually activate. It will continue
executing as long as the targetMate is alive, in love, and the variable
spawnBabyDelay is smaller than 60.

The user
will constantly look at the targetMate and try to move towards it with a speed
of moveSpeed (see table below). Additionally the spawnBabyDelay will be
increased by 1. If the spawnBabyDelay is greater or equal to 60 and the user is
less than 3 blocks away from the targetMate, a baby will be spawned. The
createChild() method is different for different types of entities, and will be
discussed below in more detail. After creating the child, the user will check
whether it had a playerInLove, and if not, whether the targetMate had a
playerInLove, and it found a player during those checks, it will store something in the statistics of
the player, and if the user was a cow, it will trigger something achievement
related (I didn´t bother looking to deep into this part). Additionally the age
of the user and the targetMate will be set to 6000, the inLove variable of the
user and the targetMate will be reset to false, the growingAge of the created
Child will be set to -24000, and the position will be set to the position of
the user. Also some 7 heart particles will be created. If the gamerule
doMobLoot ist ture, then 1-7 xp will be spawned.

The
createChild() method for the different classes:

Chickens,
Cows, Mooshrooms and Pigs will just return a new member of their own class.

Horses: (More
information needs to be added)

Ocelot: (More information needs to be added)

Rabbit:
(More information needs to be added)

Sheep:
(More information needs to be added)

Wolf: (More
information needs to be added)

 Cow
 Horse
 Ocelot
 Pig
 Rabbit
 Sheep
 Wolf

### **MoveThroughVillage**

This class
is used by Iron Golems and Zombies (including Giants) . This class is
not used by PigZombies.

**(More**
information needs to be added.)

 Zombie

### **MoveTowardsRestriction**

This class
is used by Iron Golems, Zombies (including Giants and PigZombies (this needs to
be verified)) and Villagers.

(More
information needs to be added.)

### **NearestAttackableTarget**

This class
is used by Withers, Blazes, Creepers, Endermite, Guardians,
Silverfish, Skeletons, Snowmen, Witches, Zombies (including Giants), Killer
Bunnies (which are a special kind of Rabbit) and Wolves. This class is not used
by PigZombies. Spiders (including Cave Spiders) and Iron Golems use a modified
version of this class. Endermen use both the normal and a modified version of this class.

(More
information needs to be added.)

### Iron Golem: NearestAttackableTargetNonCreeper

This AI class is implemented as a static class in the EntityIronGolem
class file. This AI class inherits from EntityAINearestAttackableTarget,
 and has only the difference, that the method boolean
apply(EntityLivingBase e), returns always false, if e is a Creeper.

### **Panic**

This class
is used by Chickens, Cows (including Mooshrooms), Horses, Pigs and Sheep.
Rabbits use a modified version of this class.

(More
information needs to be added.)

### **Sit**

This class
is used by Ocelots and Wolves.

(More
information needs to be added.)

### **Swimming**

This class
is used by Creepers, Endermen, Endermites, Silverfish, Skeletons, Spiders
(including Cave Spiders), Witches, Zombies (including Pigman Zombies and
Giants), Chickens, Cows (including Mooshroms), Horses, Ocelots, Pigs, Rabbits,
Sheep, Villagers, Wolves and Withers.

(More
information needs to be added.)

### **TargetNonTamed**

This class
is used by Ocelots and Wolves.

(More
information needs to be added.)

### **Tempt**

This class
is used by Chickens, Cows (including Mooshrooms), Horses, Ocelots, Pigs,
Rabbits and Sheep

(More
information needs to be added.)

### **Wander**

This class
is used by Blazes, Creepers, Endermen, Endermites, Guardians, Iron Golems, Skeletons,
Snowmans, Spiders (including Cave Spiders), Witches, Zombies (including Pigman
Zombies and Giants), Chickens, Cows (including Mooshroms), Horses, Ocelots,
Pigs, Rabbits, Sheep, Villagers, Wolves and Withers. Silverfish use a modified
version of this class.

(More
information needs to be added.)

### **WatchClosest**

This class
is used by Blazes, Creepers, Endermen, Endermites, Guardians, Iron Golems, Skeletons,
Snowmans, Spiders (including Cave Spiders), Witches, Zombies (including Pigman
Zombies and Giants), Chickens, Cows (including Mooshroms), Horses, Ocelots,
Pigs, Rabbits, Sheep, Villagers, Wolves and Withers.

(More
information needs to be added.)

## Classes used by only 1 entity

Each of these classes is only used by one single entity. These classes can also be found on the pages of the entities using them.

### **Beg**

This class
is used exclusively by Wolves.

This class will only activate, if the player closest to the wolf is less than 8 blocks away and holds a bone in his hand. In that occasion, the wolf will look at the player for 40-80 ticks. This will be interrupted, if the player selects a different item, or moves more than 8 blocks away.

### **BreakDoor**

This class
is used exclusively by Zombies (including Giants). This class is not used by
PigZombies. (this needs to be verified)

(More
information needs to be added.)

### **ControlledByPlayer**

This class
is used exclusively by Pigs.

(More
information needs to be added.)

### **CreeperSwell**

This class
is used exclusively by Creepers.

(More
information needs to be added.)

### **DefendVillage**

This class
is used exclusively by Iron Golems.

If the iron golem I has a home village V, and village V has at least one
 agressor A, that is a suitable target for I, I will target A. If there
is no suitable village aggressor, I will target the first player in the
playerlist of V, that has -15 or less village popularity in V and is a
suitable target for I. *(What counts as an agressor, and what is a*
suitable target is implemented in the classes Village and
EntityAITarget. They might get their own page at some point.)

### **DoorInteract**

This class
is used exclusively by Villagers.

(More
information needs to be added.)

### **EatGrass**

This class
is used exclusively by Sheep.

(More
information needs to be added.)

### **FindEntityNearest**

This class
is used exclusively by Slimes (including Magma Cubes).

(More
information needs to be added.)

### **FleeSun**

This class
is used exclusively by Skeletons.

(More
information needs to be added.)

### **FollowGolem**

This class
is used exclusively by Villagers.

(More
information needs to be added.)

### **HarvestFarmland**

This class
is used exclusively by Farmer Villagers (which are a special kind of Villager).

(More
information needs to be added.)

### **LookAtTradePlayer**

This class
is used exclusively by Villagers.

(More
information needs to be added.)

### **LookAtVillager**

This class
is used exclusively by Iron Golems.

If it´s day, an iron golem has every 3 ticks a 1 in 8000 chance to look for
 villagers in 6x2x6 box around the iron golem. If there is a villager,
he will hold a rose for 1200 ticks, while looking at the villager he
found.

### **MoveIndoors**

This class
is used exclusively by Villagers.

(More
information needs to be added.)

### **MoveTowardsTarget**

This class is used exclusively by Iron Golems. However other EntityAI classes inherit from this class, so that modified version of this class also used by other mobs (This needs to be more exact.)

(More
information needs to be added.)

### **OcelotAttack**

This class
is used exclusively by Ocelots.

(More
information needs to be added.)

### **OcelotSit**

This class
is used exclusively by Ocelots.

(More
information needs to be added.)

### **OpenDoor**

This class
is used exclusively by Villagers.

(More
information needs to be added.)

### **OwnerHurtByTarget**

This class
is used exclusively by Wolves.

(More
information needs to be added.)

### **Play**

This class
is used exclusively by Villager Childs (which are a special kind of Villager)

(More
information needs to be added.)

### **RestrictOpenDoor**

This class
is used exclusively by Villagers.

(More
information needs to be added.)

### **RestrictSun**

This class
is used exclusively by Skeletons.

(More
information needs to be added.)

### **RunAroundLikeCrazy**

This class
is used exclusively by Horses.

(More
information needs to be added.)

### **TradePlayer**

This class
is used exclusively by Villagers.

(More
information needs to be added.)

### **VillagerInteract**

This class is
used exclusively by Villagers.

(More
information needs to be added.)

### **VillagerMate**

This class
is used exclusively by Villagers.

(More
information needs to be added.)

### **WatchClosest2**

This class
is used exclusively by Villagers.

(More
information needs to be added.)

## Nested Classes

Nestes classes are only used by their parent class.

### **Enderman - FindPlayer**

This class inherits from NearestAttackableTarget.

(More information needs to be added.)

### **IronGolem - NearestAttackableTargetNonCreeper**

This class inherits from NearestAttackableTarget.

(More information needs to be added.)

### **Silverfish - HideInStone**

This class inherits from Wander.

(More information needs to be added.)

### **Spider - SpiderAttack**

This class inherits from AttackOnCollide.

(More information needs to be added.)

### **Spider - SpiderTarget**

This class inherits from NearestAttackableTarget.

(More information needs to be added.)

### **PigZombie - HurtByAggressor**

This class inherits from HurtByTarget.

(More information needs to be added.)

### **PigZombie - TargetAggressor**

This class inherits from NearestAttackableTarget.

(More information needs to be added.)

### **Rabbit - Panic**

This class inherits from Panic

(More information needs to be added.)

### **Rabbit - RaidFarm**

This class inherits from MoveToBlock.

(More information needs to be added.)

### **Rabbit - AvoidEntity**

This class inherits from AvoidEntity.

This class behaves exactly like AvoidEntity.

### **Rabbit - EvilAttack**

This class inherits from AttackOnCollide.

(More information needs to be added.)

## Abstract EntityAI classes

### **EntityAIBase**

All EntityAI classes inherit from this class.

(More
information needs to be added.)

### **EntityAIMoveToBlock**

(More
information needs to be added.)

### **EntityAITarget**

(More
information needs to be added.)

## Which mobs use what?

### **Wither:**

Swimming

ArrowAttack

Wander

WatchClosest

LookIdle

HurtByTarget

NearestAttackableTarget

### **Blaze:**

Blaze - FireballAttack

MoveTowardsRestriction

Wander

WatchClosest

LookIdle

HurtByTarget

NearestAttackableTarget

### **Creeper:**

Swimming

CreeperSwell

AvoidEntity
(Ocelot)

AttackOnCollide

Wander

WatchClosest

LookIdle

NearestAttackableTarget

HurtByTarget

### **Enderman:**

Swimming

AttackOnCollide

Wander

WatchClosest

LookIdle

Enderman
- PlaceBlock

Enderman
- TakeBlock

HurtByTarget

Enderman
- FindPlayer

NearestAttackableTarget

### **Endermite:**

Swimming

AttackOnCollide

Wander

WatchClosest

LookIdle

HurtByTarget

NearestAttackableTarget

### **Ghast:**

Ghast - RandomFly

Ghast - LookAround

Ghast - FireballAttack

FindEntityNearestPlayer

### **Guardian:**

GuardianAttack

MoveTowardsRestriction

Wander

WatchClosest

LookIdle

NearestAttackableTarget

### **IronGolem:**

AttackOnCollide

MoveTowardsTarget

MoveThroughVillage

MoveTowardsRestriction

LookAtVillager

Wander

WatchClosest

LookIdle

DefendVillage

HurtByTarget

IronGolem
- NearestAttackableTargetNonCreeper

### **Silverfish:**

Swimming

Silverfish
- SummonSilverfish

AttackOnCollide

Silverfish
- HideInStone

HurtByTarget

NearestAttackableTarget

### **Skeleton:**

Swimming

RestrictSun

FleeSun

AvoidEntity

Wander

WatchClosest

LookIdle

HurtByTarget

NearestAttackableTarget

The combat AI classes are added to the EntityAITasks depending on whether the Skeleton holds a bow:

EntityAIArrowAttack (with bow)

EntityAIAttackOnCollide (without bow)

### **Slime and Magma Cubes:**

Slime - SlimeFloat

Slime - SlimeAttack

Slime - SlimeFaceRandom

Slime - SlimeHop

FindEntityNearestPlayer

FindEntityNearest

### **Snowman:**

ArrowAttack

Wander

WatchClosest

LookIdle

NearestAttackableTarget

### **Spider** **and Cave Spider:**

Swimming

LeapAtTarget

Spider -
SpiderAttack

Wander

WatchClosest

LookIdle

HurtByTarget

Spider -
SpiderTarget

### **Witch:**

Swimming

ArrowAttack

Wander

WatchClosest

LookIdle

HurtByTarget

NearestAttackableTarget

### **Zombie** **and Giant:**

Swimming

AttackOnCollide

MoveTowardsRestriction

Wander

WatchClosest

LookIdle

MoveThroughVillage

HurtByTarget

NearestAttackableTarget

BreakDoor

### **PigZombie:**

Swimming

AttackOnCollide

MoveTowardsRestriction

Wander

WatchClosest

LookIdle

PigZombie - HurtByAggressor

PigZombie - TargetAggressor

### **Chicken:**

Swimming

Panic

Mate

Tempt

FollowParent

Wander

WatchClosest

LookIdle

### **Cow and Mooshroom:**

Swimming

Panic

Mate

Tempt

FollowParent

Wander

WatchClosest

LookIdle

### **Horse:**

Swimming

Panic

RunAroundLikeCrazy

Mate

Tempt

FollowParent

Wander

WatchClosest

LookIdle

### **Ocelot:**

Swimming

Sit

Tempt

FollowOwner

OcelotSit

LeapAtTarget

OcelotAttack

Mate

Wander

WatchClosest

TargetNonTamed

### **Pig:**

Swimming

Panic

ControlledByPlayer

Mate

Tempt

FollowParent

Wander

WatchClosest

LookIdle

### **Rabbit:**

Swimming

Rabbit  - Panic

Tempt

Mate

Rabbit -
RaidFarm

Wander

WatchClosest

Rabbit -
AvoidEntity

#### **Killer Bunnies additionally have:**

Rabbit -
EvilAttack

HurtByTarget

NearestAttackableTarget

### **Sheep:**

Swimming

Panic

Mate

Tempt

FollowParent

EatGrass

Wander

WatchClosest

LookIdle

### **Squid:**

Squid -
MoveRandom

### **Villager:**

Swimming

AvoidEntity

TradePlayer

LookAtTradePlayer

MoveIndoors

RestrictOpenDoor

OpenDoor

MoveTowardsRestriction

VillagerMate

FollowGolem

WatchClosest2

VillagerInteract

Wander

WatchClosest

.

#### **Farmer Villagers additionally have:**

HarvestFarmland

.

### **Wolf:**

Swimming

Sit

LeapAtTarget

AttackOnCollide

FollowOwner

Mate

Wander

Beg

WatchClosest

LookIdle

OwnerHurtByTarget

OwnerHurtTarget

HurtByTarget

TargetNonTamed

NearestAttackableTarget