API Documentation/Make entities controllable

This documentation page will show you how to take control of an entity.



Take control of a certain entity

  1. Have a look at which entities are controllable (list below)
  2. Get an instance of the entity you want to control
  3. Call a ControllableMobs.putUnderControl() method
  4. You may want to save the instance returned by the putUnderControl()-method (I will reference to this instance as controlledEntity later)
  5. Adjust attributes (see this tutorial), modify the AI of the entity (see this tutorial), or perform actions (see this tutorial)
Quote:

Do not use a ControllableMobs.putUnderControl() method more than one time on the same entity. This will throw an IllegalStateException! If you are not sure whether the entity is already being controlled, use ControllableMobs.getOrPutUnderControl() instead.

List of controllable entities

entitycan be controlled with the API?
Batno
Blazeno
CaveSpiderno
Chickenyes
Cowyes
Creeperyes
EnderDragonno
Endermanno
Ghastno
Giantno
Horseyes
IronGolemyes
MagmaCubeno
MushroomCowyes
Ocelotyes
Pigyes
PigZombieno
PlayerHahahaha, NO.
Sheepyes
Silverfishno
Skeletonyes
Slimeno
Snowmanyes
Spiderno
Squidno
Villageryes
Witchyes
Witheryes
Wolfyes
Zombieyes
Quote:

Q: Why are some entities not controllable?

A: Because these entities are using the old AI system. Yes, the minecraft core is still working with two different types of AI: a (hardcoded!) old one and a better scalable new one. So, unfortunately, the API can only hook into the new one.

Different controlling methods

There are several putUnderControl() methods, of which you can choose that one matching your requirements the best:

Examples

Simple control

Acquire control without altering the behavior of the entity:

Cow cow;
ControllableMob<Cow> controlledEntity = ControllableMobs.putUnderControl(cow);

...

ControllableMobs.releaseControl(controlledEntity);

Control & clear

Acquire control and clear all default behaviors:

Zombie zombie;
ControllableMob<Zombie> controlledEntity = ControllableMobs.putUnderControl(zombie, true);

...

ControllableMobs.releaseControl(controlledEntity);




If you have put your entity under control, change some of its attributes, if needed!