-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
140 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,129 @@ | ||
## MineSharp.Bot | ||
|
||
Connect and interact with Minecraft servers. \ | ||
A `MinecraftBot` is a composition of multiple `Plugin`s. \ | ||
Currently, these are the default plugins: | ||
A `MineSharpBot` uses a `MinecraftClient` (see MineSharp.Protocol) to connect to a Minecraft Server. \ | ||
The bot can have multiple plugins. Each plugin can handle some packets sent by the server and/or provide methods to interact with the world. | ||
|
||
## Creating Bots | ||
A bot can be created using a `MinecraftClient`. | ||
To help out, you can use the `BotBuilder` class to fluently create a bot. | ||
|
||
### Bot Builder | ||
- `.Host()` configure the hostname | ||
- `.Port()` configure the port (default = 25565) | ||
- `.Data()` configure the `MinecraftData` instance | ||
- `.AutoDetectData()` (default) auto detect minecraft data version if none was configured | ||
- `.Session()` configure the session object | ||
- `.OfflineSession()` configure session to be an offline session | ||
- `.OnlineSession()` configure session to be an online session (login happens when calling `Create()` or `CreateAsync()`) | ||
- `.WithPlugin<T>()` add Plugin of type `T` | ||
- `.ExcludeDefaultPlugins()` do not add default plugins (listed below) | ||
- `.AutoConnect()` automatically connect to the server when creating the bot | ||
- `.WithProxy()` configure a proxy | ||
- `.CreateAsync()` create a new bot with the configuration | ||
- `.Create()` equivalent of `CreateAsync().Result` | ||
|
||
## Plugins | ||
|
||
A plugin can handle packets sent by the server and/or provide methods to interact with the server. | ||
|
||
Currently, these are the plugins enabled by default: | ||
- Chat Plugin (Read and Write chat messages) | ||
- Crafting Plugin (Craft items) | ||
- Entity Plugin (Keeps track of entities) | ||
- Physics Plugin (Simulate player physics) | ||
- Player Plugin (Keeps track of the bot himself as well as other players and the weather) | ||
- Window Plugin (Bot's inventory and open chests or other blocks) | ||
- World Plugin (Keep track of the world) | ||
|
||
### Example | ||
This is an example for a simple chat bot. | ||
```csharp | ||
using MineSharp.Bot; | ||
using MineSharp.Bot.Plugins; | ||
|
||
MineSharpBot bot = await MineSharpBot.CreateBot( | ||
"MineSharpBot", | ||
"127.0.0.1", | ||
25565, | ||
offline: true); | ||
|
||
var chat = bot.GetPlugin<ChatPlugin>(); | ||
|
||
if (!await bot.Connect()) | ||
{ | ||
Console.WriteLine("Could not connect to server!"); | ||
Environment.Exit(1); | ||
} | ||
|
||
while (true) | ||
{ | ||
var input = Console.ReadLine(); | ||
if (input == "exit") | ||
{ | ||
await bot.Disconnect(); | ||
break; | ||
} | ||
|
||
if (input != null) | ||
await chat.SendChat(input); | ||
} | ||
``` | ||
|
||
TODO: Docs for every plugin | ||
Other plugins not enabled by default: | ||
- Auto Respawn (Automatically respawn when dead) | ||
|
||
To add a plugin to the bot, `bot.LoadPlugin(plugin)` can be used. \ | ||
To access a plugin, use `bot.GetPlugin<>()` | ||
|
||
#### Chat Plugin | ||
- Handles all chat packets and provides abstraction for different minecraft versions | ||
- Handle and parse the CommandTree | ||
- โก `OnChatMessageReceived` event. Fired when any chat message or game information message is received | ||
- ๐จ `SendChat()` method. Send a chat message to the server. | ||
- ๐ง `SendCommand()` method. Send a '/' command to the server. Only for mc >= 1.19 | ||
|
||
#### Crafting Plugin | ||
- ๐ `FindRecipes()`. Find recipes for a given item that can be crafted with the items in the bots inventory | ||
- ๐ `FindRecipe()`. Equivalent of `FindRecipes().FirstOrDefault()` | ||
- ๐ข `CraftableAmount()`. Calculate how often a recipe can be crafting with the items in the bots inventory. | ||
- ๐ช `Craft()`. Craft the given recipe `n` times. | ||
|
||
#### Entity Plugin | ||
- Handles all packets regarding entities (position, effects, etc..) | ||
- โก `OnEntitySpawn`. Fired when an entity spawned | ||
- โก `OnEntityDespawned`. Fired when an entity despawned | ||
- โก `OnEntityMoved`. Fired when an entity moved | ||
- ๐ท `Entities`. Dictionary mapping all entities from their numerical server id to the `Entity` object | ||
|
||
#### Physics Plugin | ||
- Update the bots position on the server | ||
- โก `BotMoved`. Fired when the bot moved | ||
- โก `PhysicsTick`. Fired after each tick of the physics simulation | ||
- ๐ฎ `InputControls`. Input controls used to control movement | ||
- ๐ช `Engine`. The underlying physics simulation / engine | ||
- โณ `WaitForTicks()`. Wait until a number of physics ticks are completed | ||
- โฐ๏ธ `WaitForOnGround()`. Wait until the bot is on the ground | ||
- ๐ `ForceSetRotation()`. Set the bots rotation in a single tick | ||
- ๐ `ForceLookAt()`. Look at the given position in a single tick | ||
- ๐ `Look()`. Slowly transition to the given rotation | ||
- ๐ `LookAt()`. Slowly look at the given position | ||
- ๐ซ `Raycast()`. Returns the block the bot is currently looking at | ||
|
||
#### Player Plugin | ||
- Handles packets regarding the Bot entity and other players on the server | ||
- โก `OnHealthChanged`. Fired when the bots health, food or saturation was updated. | ||
- โก `OnRespawed`. Fired when the bot respawned or changed the dimension. | ||
- โก `OnDied`. Fired when the bot died. | ||
- โก `OnPlayerJoined`. Fired when another player joined the server | ||
- โก `OnPlayerLeft`. Fired when another player left the server | ||
- โก `OnPlayerLoaded`. Fired when another player came into the visible range of the bot and their entity was loaded. | ||
- โก `OnWeatherChanged`. Fired when the weather has changed. (TODO: Move to WorldPlugin) | ||
- ๐ค `Self`. The `MinecraftPlayer` representing the bot itself | ||
- ๐ค `Entity`. The `Entity` representing the bot itself (equivalent of `Self.Entity`) | ||
- ๐จโ๐งโ๐ฆ `Players`. A dictionary mapping all player's uuids to their `MinecraftPlayer` object | ||
- ๐จโ๐งโ๐ฆ `PlayerMap`. A dictionary mapping all player's numerical server id to their `MinecraftPlayer` object. | ||
- ๐ `Health`. Health of the Bot (value between 0.0 - 20.0) | ||
- ๐ `Saturation`. The Saturation level of the bot | ||
- ๐ `Food`. The food level of the bot | ||
- ๐ `Dimension`. The name of the dimension the bot is currently in | ||
- ๐ `IsAlive`. Boolean indicating whether the bot is alive | ||
- ๐ง๏ธ `IsRaining`. Boolean indicating whether it is raining | ||
- โ `RainLevel`. Float indicating how much it is raining | ||
- โ๏ธ `ThunderLevel`. The thunder level | ||
- โ๏ธ `Respawn()`. Respawn the bot if it is dead. | ||
- ๐ช `SwingArm()`. Plays the swing arm animation. | ||
- ๐คบ `Attack()`. Attack the given entity | ||
|
||
#### Window Plugin | ||
- Handles packets regarding windows | ||
- โก `OnWindowOpened`. Fired when a window opened | ||
- โก `OnHeldItemChanged`. Fired when the held item changed | ||
- ๐ฆ `Inventory`. The *Window* representing the bots inventory | ||
- ๐ช `CurrentlyOpenedWindow`. The window which is currently open. | ||
- ๐ `HeldItem`. The *Item* the bot is currently holding in the main hand | ||
- ๐ `SelectedHotbarIndex`. The index of the selected hotbar slot | ||
- โ `WaitForInventory()`. Wait until the inventory's item are loaded | ||
- ๐งฐ `OpenContainer()`. Try to open the given block (eg. chest, crafting table, ...) | ||
- โ `CloseWindow()`. Close the window | ||
- ๐ `SelectHotbarIndex()`. Set the selected hotbar index | ||
- ๐ `UseItem()`. Use the item the bot is currently holding | ||
- ๐จโ๐ง `EquipItem()`. Find and equip an item | ||
|
||
#### World Plugin | ||
- Handles all block and chunk packets | ||
- ๐ `World`. The world of the minecraft server | ||
- โณ `WaitForChunks()`. Wait until all chunks in a radius around the bot are loaded | ||
- โจ๏ธ `UpdateCommandBlock()`. Update a command block | ||
- โ๏ธ `MineBlock()`. Mine the given block | ||
- ๐ท `PlaceBlock()`. Place a block at the given position | ||
|
||
#### Auto Respawn | ||
- Automatically respawns the bot when it died | ||
- โฐ๏ธ `RespawnDelay`. Delay before respawning |