rg-bot
TypeScript icon, indicating that this package has built-in type declarations

1.10.0 • Public • Published

Regression Games Bot

NPM

View API Documentation

A stable and user-friendly JavaScript library for creating Bots in a variety of games.

This library was originally created by Regression Games for use in conjunction with our AI platform, but can easily be integrated into your own projects.

Regression Games is currently in its alpha stage and supports Minecraft. Support for other games will be added over time.

Compiling Typescript

For local testing it is necessary to compile the typescript types. This is done automatically when publishing.

sudo npm install -g typescript
tsc

Install

npm install rg-bot

Minecraft

Regression Games uses the Mineflayer API to interact with Minecraft's API, and the Mineflayer-Pathfinder plugin to handle complex movements.

RGBot offers a range of methods for interacting with the Minecraft world including placing and breaking Blocks, looting from and depositing into chests, and initiating combat.

RGBot also supports using Python3 for Mineflayer bots via the https://github.com/extremeheat/JSPyBridge project that bridges from Python into NodeJS Javascript. Note that this works for diehard Python fans, but is slower than using Javascript as all calls into RGBot or Mineflayer APIs use inter process communication to go between the Python and NodeJS runtimes.

!!! Note: Python3 bots will currently only work with NodeJS 14.x.y versions. They will NOT work with 16.x.y versions. !!!

Usage within Regression Games

The Regression Games platform requires an index.js file with an exported configureBot method which acts as an entrypoint into your bot script. When a match is started through the Regression Games platform, an RGBot is created and configured for the player and passed to the configureBot method.

Example:

/**
 * @param {RGBot} rgbot
 */
function configureBot(rgbot) {

    // turn on debug logging 
    // logs are displayed within the Regression Games app during a match
    rgbot.setDebug(true);

    // announce in chat when Bot spawns
    rgbot.on('spawn', function() {
        rgbot.chat('Hello World');
    })

    // use in-game chat to make the Bot collect or drop wood for you
    rgbot.on('chat', async function (username, message) {
        if(username === rgbot.username()) return

        if(message === 'collect wood') {
            await rgbot.findAndDigBlock('log', {partialMatch: true});
        }
        else if (message === 'drop wood') {
            await rgbot.dropInventoryItem('log', {partialMatch: true, quantity: 1});
        }
    })

}

exports.configureBot = configureBot;
import json
import logging
import threading
import rg_javascript

from rg_javascript import require, On

mineflayer = require('mineflayer','4.5.1')
mineflayer_pathfinder = require('mineflayer-pathfinder','2.4.0')
rg_bot = require('rg-bot','1.4.0')
rg_match_info = require('rg-match-info','1.0.0')
Vec3 = require('vec3','0.1.7').Vec3

logging.basicConfig(level=logging.NOTSET)


def configure_bot(bot):

    # turn on debug logging
    # logs are displayed within the Regression Games app during a match
    bot.setDebug(True)

    # announce in chat when Bot spawns
    @On(bot, 'spawn')
    def bot_on_spawn(this):
        bot.chat('Hello World')

    # use in-game chat to make the Bot collect or drop wood for you
    @On(bot, 'chat')
    def bot_on_chat(username, message):
        if username == bot.username():
            return
        if message == 'collect_wood':
            bot.findAndDigBlock('log', {'partialMatch': True})
        elif message == 'drop wood':
            bot.dropInventoryItem('log', {'partialMatch': True, 'quantity': 1});

External use

While rg-bot is primarily developed to support the Regression Games platform, it can also be integrated into non-Regression-Games projects. Usage in unaffiliated projects is nearly identical to Usage within Regression Games with the distinction that you must instantiate and configure your own mineflayer Bot and RGBot.

Example:

// import mineflayer and rg-bot
const mineflayer = require('mineflayer');
const RGBot = require('rg-bot').RGBot;

function setupRGBot(bot) {
    // create an RGBot
    // RGBot interacts directly with your mineflayer Bot instance
    const rgbot = new RGBot(bot);
    rgbot.setDebug(true);

    // you can invoke methods from both the mineflayer Bot and RGBot
    bot.on('spawn', function () {
        rgbot.chat('Hello World');
    });

    // or you can can choose to make calls to mineflayer through the RGBot for consistency
    rgbot.mineflayer().on('chat', async function (username, message) {
        if (username === rgbot.mineflayer().username) return

        if (message === 'collect wood') {
            await rgbot.findAndDigBlock('log', {partialMatch: true});
        }
        else if (message === 'drop wood') {
            await rgbot.dropInventoryItem('log', {partialMatch: true, quantity: 1});
        }
    });
}

// create mineflayer bot
const bot = mineflayer.createBot({username: 'Bot'});

// if the bot.version field is set, then mineflayer has already connected and is ready
if (bot.version) {
    setupRGBot(bot);
} else {
    // wait for inject_allowed if not connected yet before initializing Movements and other things in RGBot
    bot.on('inject_allowed', function () {
        setupRGBot(bot)
    });
}

Additional Examples

For more examples to help you get started with the rg-bot package, see these templates from Regression Games:

Join us on Discord!

Have a question or want to discuss improvements and new ideas? Contact us through the Regression Games Discord Server.

Readme

Keywords

none

Package Sidebar

Install

npm i rg-bot

Weekly Downloads

9

Version

1.10.0

License

ISC

Unpacked Size

174 kB

Total Files

11

Last publish

Collaborators

  • regression_games