npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rg-bot

v1.10.0

Published

A library allowing users to easily design and control Regression Games bots in a variety of games

Downloads

70

Readme

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.