-
Notifications
You must be signed in to change notification settings - Fork 1
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,"Player Bot");
Here the String Player Bot
is the name we give to the Bot. Every Bot must have a name.
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,"Player Bot");
Here the String Player Bot
is the name we give to the Bot. Every Bot must have a name.