API Documentation/Make entities controllable
This documentation page will show you how to take control of an entity.
Take control of a certain entity
- Have a look at which entities are controllable (list below)
- Get an instance of the entity you want to control
- Call a ControllableMobs.putUnderControl() method
- You may want to save the instance returned by the putUnderControl()-method (I will reference to this instance as controlledEntity later)
- 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
entity | can be controlled with the API? |
---|---|
Bat | no |
Blaze | no |
CaveSpider | no |
Chicken | yes |
Cow | yes |
Creeper | yes |
EnderDragon | no |
Enderman | no |
Ghast | no |
Giant | no |
Horse | yes |
IronGolem | yes |
MagmaCube | no |
MushroomCow | yes |
Ocelot | yes |
Pig | yes |
PigZombie | no |
Player | Hahahaha, NO. |
Sheep | yes |
Silverfish | no |
Skeleton | yes |
Slime | no |
Snowman | yes |
Spider | no |
Squid | no |
Villager | yes |
Witch | yes |
Wither | yes |
Wolf | yes |
Zombie | yes |
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:
- ControllableMobs.putUnderControl(LivingEntity entity)
Simply puts the entity under your control. Nothing fancy here. Since this method does not clear the entity's AI, the entity will behave normally until you give a specific order. - ControllableMobs.putUnderControl(LivingEntity entity, boolean clearAI)
Puts the entity under your control and optionally clears its default AI. If you choose to clear the AI, the entity will remain motionless until you give a specific order. - ControllableMobs.getOrPutUnderControl(LivingEntity entity)
- ControllableMobs.getOrPutUnderControl(LivingEntity entity, boolean clearAI)
These methods are doing the same as their putUnderControl() pendants, with a small difference: If the entity is already being controlled, the control handle is being returned without altering anything (clearAI is being ignored in this case). - ControllableMobs.getControl(LivingEntity entity)
This method does not put an entity under your control, it just returns the control handle when you previously called one of the putUnderControl() methods. Caution: An IllegalStateException is thrown if the entity is not being controlled. You can check with ControllableMobs.isUnderControl(LivingEntity entity) first.
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!