Repository navigation
Makin' a Bot
BotAPI provides you with controllable bots to control Game Entities.
Hence it is very important to know how to make a Bot bind to a specific entity for controlling it.
To bind the Bot one has to perform three simple steps :-
- Get a reference to the Entity.
- Create a compatible Body and bind the Entity to it.
- Create a Bot and bind the Body to it.
You can skip the last two steps if you want the Bot to decide a Body automatically.
Assuming, for this example, that we have a reference to the EntityPlayerSP object, i.e. the Player object controlled by the user, as player.
The Body compatible with the EntityPlayerSP in this case is the mod.jd.botapi.Bot.Body.PlayerBody and so we make an instance of the PlayerBody as such
Body body = new PlayerBody(player);
After creating the Body above (as body), the Bot can be instantiated as such
Bot bot = new Bot(body);
NOTE : All Bots must be killed by the kill() method after use, to stop the Bot's thread and unregister it from the EventBus.This is done as such
bot.kill();If the bot is not killed, it will keep executing and thus consume CPU time.
Assuming, for this example, that we have a reference to the EntityPlayerSP object, i.e. the Player object controlled by the user, as player.
The Bot can be instantiated directly with the entity instance(here player) as such
Bot bot = Bot.getInstanceFromFactory(player);
