-
Notifications
You must be signed in to change notification settings - Fork 48
Javascript API
With /minebot js, a custom javascript file can be executed. This is the documentation of this feature.
The Javascript file is executed independently from the main game loop. That means that you could compute pi and the game would still continue to run as normal. But as soon as you want to influence the game state, the game is paused for it, so that you do not need to care about that. The game stays paused and you can do whatever, like scanning for entities, but you need to call a resume operation after you are finished so that the game may continue.
Mind that you can freeze Minecraft by adding an infinite loop to your Javascript.
Please only use the Javascript API as intended. If you break this and e.g. access Minecraft methods while the game loop is not paused, you might end up having big problems.
Still to decide how this is done. Events that should be handled:
- A generic Tick-Event (called every tick)
- A death event
- Hurt event
- Bot errors (like not standing on ...)
Minebot works with strategies. A strategy tells the bot what to do until the strategy states that it is done. Strategies can be stacked, in which case the strategies higher up the stack act as dominant strategies. Lower strategies get can work as soon as the higher strategies are done. The higher ones can take over any time, but most of them let the lower strategies finish the current piece of work before they take over.
Higher strategies can also force the lower ones to abort. This can be used to stop strategies.
All commands are accessible using the minescript-Object. You can use a with-Statement if you want to, mind that there might also be other, undocumented functions.
Evaluates a given minebot command and returns the strategy that it would result it. This strategy is added with some safeguards according to the settings.
This gives you the single strategy that command would result in. For mining this would be the mine strategy, without any protective strategies. The mine command would look like: strategy("minebot", ["mine", "coal_ore"]);
A fast way to create a walk towards strategy. You can directly pass double values.
Stacks multiple strategies. The first one is the most important one, and so on.
Starts executing the strategy. Your script will pause until the strategy is done.
Continue the game. Call this every time you accessed some minescript functions and you want the player to keep playing. This will let the game loop continue to run. Mind that your next minescript call is delayed until the next game tick and will then pause the game loop again.
Send a command or a chat message to the server as if the user typed it. This will also let the game loop continue.
Display a message in the (local) player chat.
Gets an array of all chat messages received since the client was started. This also includes chat messages from previous games.
New messages are appended, so you can simply remember the length of this array to filter for new messages.
Get the player object to access position, ...
Gets the experience level (the green number at the bottom of the screen)
Checks whether the player is still living. Returns false when the respawn screen is shown.
Get the current player inventory.
Returns a position object for the player position.
Returns an array of entities with the given class in the given range (rectangular). Use the full class path as class (net.minecraft...)
Gets the current time of day. 0 <= time < 24000.
The name is global. On windows, it is not case sensitive.
Store a string to retrive it later using getString.
Sets the description that is displayed in the top right hand corner of the screen.
There is no direct entity
Get the position of the entity.
Gets the class of the entity.
Gets the simple class name of the entity.
For other methods, see the javadoc to Pos. All methods can be called from Javascript.
The position of the entity.
The speed vector of the entity.
The absolute speed of the entity
Computes the distance between the centers of two entities.
Compute the distance to that position.
A java date
The chat message that was sent.
The chat message including the §x-format flags
True if this is a real chat message.