Coder Social home page Coder Social logo

superdinmc / botcraft Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adepierre/botcraft

0.0 0.0 0.0 28.43 MB

Botcraft is a cross-platform C++ library to create bots that connect and interact with Minecraft servers with (optional) integrated OpenGL renderer

License: GNU General Public License v3.0

CMake 3.49% C++ 96.51%

botcraft's Introduction

Linux Windows

Botcraft

Botcraft is a cross-platform C++ library to connect and interact with Minecraft servers with (optional) integrated OpenGL renderer.

This is a "learn-by-doing" code, with some lines dating back to 2017 and never changed since. A lot of things should be improved or refactored. I only code this on my free time, when I feel like it, so don't expect it to be a fully-featured commercial grade library. I share the code because I think it can be interesting for other people, but the goal is not to make it a widely adopted library, or even a useful one. I just do it for fun, it's more a shared private repo than a real team open source project. If you're looking for more features, there are alternative libraries by people with much more time (and probably talent) than myself.

Features

Main features are listed below. To see the eveolution of the project, check the changelog.

  • Connection to minecraft server (both offline mode and online connection with Mojang or Microsoft account)
  • DNS server name resolution with and without SRV record
  • All official releases from 1.12.2 to 1.18.1 supported
  • Compression
  • Physics and collisions
  • World data
  • Full entity support (type, data and metadata)
  • (Optional) Rendering of all the blocks (including entity-blocks like chests, banners...) and entities (bounding box only)
  • Bot programming with a behaviour tree system (see the wiki page for details)
  • Bot control with mouse and keyboard

Available bot behaviours includes:

  • Path finding
  • Block breaking
  • Inventory managing
  • Block placing
  • Block interaction (button, lever etc...)

Example of pathfinding. Right of the screen is the integrated renderer

Example of entity processing. Only monsters are attacked as soon as they are in range. Passive mobs are ignored.

More complex example with 10 survival bots collaborating on a pixel art build. They are all in survival, so they have to pick the right blocks in the chests, eat food and obviously can't fly. There is no global supervision, and they can't communicate with each other.

Dependencies

All the libraries are included either directly(*) or as submodules(†) and are built locally automatically by cmake (if not already found on your system) so you don't have to download/compile/install anything manually.

Optional dependencies (can be disabled with cmake options)

  • glad* for OpenGL stuff
  • glfw† for OpenGL window creation
  • glm† for math stuff
  • imgui† for additional UI display
  • openssl† for encryption
  • rectpack2D† for texture packing
  • stb_image* for texture loading
  • zlib† for compression

The code is cross-platform and requires a C++17 compiler.

ProtocolCraft

ProtocolCraft is a sublibrary of the botcraft repository. It is a full implementation of the minecraft protocol for all supported versions. It's based on the official source code mapping provided by Mojang. I try to keep all the packets and variable names as close as possible to the source code ones. To avoid name conflicts, an underscore is sometimes appended at the end of a variable name.

Building

To build the library for the latest version of the game with both encryption and compression support, but without OpenGL rendering support:

git clone https://github.com/adepierre/Botcraft.git
cd Botcraft
mkdir build
cd build
cmake -DGAME_VERSION=latest -DBOTCRAFT_BUILD_EXAMPLES=ON -DBOTCRAFT_COMPRESSION=ON -DBOTCRAFT_ENCRYPTION=ON -DBOTCRAFT_USE_OPENGL_GUI=OFF ..
make all

At this point, you should have all the examples compiled and ready to run. Plese note that you don't have to clone recursively or download and install the dependencies manually, cmake will automatically take care of these steps based on your build configuration and what is already installed on your machine. On Windows with Visual, you can also use cmake-gui and then compile the .sln directly from Visual.

You can check this discussion for an example of how to use botcraft with your own code.

There are several cmake options you can modify:

  • GAME_VERSION [1.XX.X or latest]
  • BOTCRAFT_BUILD_EXAMPLES [ON/OFF]
  • BOTCRAFT_OUTPUT_DIR [PATH] Base output build path. Binaries, assets and libs will be created in subfolders of this path (default: top project dir)
  • BOTCRAFT_COMPRESSION [ON/OFF] Add compression ability, must be ON to connect to a server with compression enabled
  • BOTCRAFT_ENCRYPTION [ON/OFF] Add encryption ability, must be ON to connect to a server in online mode
  • BOTCRAFT_USE_OPENGL_GUI [ON/OFF] If ON, botcraft will be compiled with the OpenGL GUI enabled
  • BOTCRAFT_USE_IMGUI [ON/OFF] If ON, additional information will be displayed on the GUI (need BOTCRAFT_USE_OPENGL_GUI to be ON)
  • BOTCRAFT_WINDOWS_BETTER_SLEEP [ON/OFF] If ON, thread sleep durations will be more precise (only for Windows 10/11, no effect on other OS)

Examples

Examples can be found in the Examples folder:

  • 0_HelloWorld: Connect to a server, sends Hello World! in the chat then disconnect
  • 1_UserControlledExample: Best with GUI, mouse and keyboard controlled player. Can be used in a dummy offline world (without any server) to test things like physics or rendering
  • 2_ChatCommandExample: Simple bot that obey commands sent through vanilla chat. Known commands at this point:
    • pathfinding
    • disconnecting
    • checking its sourroundings for spawnable blocks (useful if you want to check whether or not a perimeter is spawn proof)
    • placing a block
    • interacting with a block (lever, button ...)
  • 3_SimpleAFKExample: Very leight AFK only bot. Simply connect to a server and stay still doing nothing.
  • 4_MapCreatorExample: Much more complex example, with autonomous behaviour implemented to build a map based pixel art. Can be launched with multiple bot simultaneously. They can share their internal representation of the world to save some RAM, at the cost of slowing down if too many share the same (due to concurrent access). Only extensively tested on 1.16.5, but should work with minor to none adaptation on previous/older versions.
  • 5_MobHitterExample: Entity processing example. Attack every monster in range, with a per-entity cooldown of 0.5s. /!\ This is only an example about entities, no eating is performed, so would starve to death pretty quickly if used as-is.

Clients

Botcraft has multiple XXXClient classes you can inherit from depending on what you want to achieve. For more details, you can check the corresponding wiki page.

Connection

Botcraft supports both servers in offline and online mode. If the server is in online mode, a valid account (Mojang while they still work or Microsoft) owning the game is required. Detailed information about how to connect with Mojang or Microsoft accounts can be found in the wiki page.

License

GPL v3

botcraft's People

Contributors

abasgames avatar adepierre avatar constantins2001 avatar jackobisreal avatar maxsupermanhd avatar nikisalli avatar superdinmc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.