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

@nxg-org/mineflayer-static-statemachine

v0.3.4

Published

A state machine plugin for Mineflayer to aid in designing more complex behavior trees.

Downloads

7

Readme


What is it?

Mineflayer-Static-Statemachine is a plugin for Mineflayer. It aims to add a flexible and customizable state machine API on top of Mineflayer to make it easier to write and scale bots.

Writing a complex bot AI can be difficult, especially if it has to be convincing. Finite state machines make this process much eaiser by offloading the fine details into isolated modules which only serve a single function or behavior. These modules can then be connected together in a top level component to customize how these seperate modules should interact and pass around control of the bot and state machine parameters.

Showcase

Videos

Webserver Demo

Mining Demo

Getting Started

This plugin is built using Node and can be installed using:

npm install --save @nxg-org/mineflayer-static-statemachine

This plugin relies on mineflayer-pathfinder for movement related behaviors. If these behaviors are used, this plugin must be loaded before starting the state machine object.

Simple Bot

The API for Mineflayer-StateMachine aims to be simple and intuitive, requiring minimal effort to setup a working state machine. The example below creates a three-state finite state machine which finds and follows the nearest player, stopping and looking at them when they are close.

// Create your bot
const mineflayer = require("mineflayer");
const bot = mineflayer.createBot({ username: "Player" });

// Load your dependency plugins.
bot.loadPlugin(require('mineflayer-pathfinder').pathfinder);

// load library
const { BotStateMachine, getTransition, getNestedMachine, behaviors } = require("@nxg-org/mineflayer-static-statemachine");

// Import required behaviors.
const {
  BehaviorExit: Exit,
  BehaviorFindEntity: FindEntity,
  BehaviorLookAtEntity: LookAtTarget,
  BehaviorFollowEntity: FollowEntity,
} = behaviors;

const transitions = [
  // If we do not find an entity, we should exit this machine.
  // We will transition if we have not found an entity.
  // On our transition, say a message that other players can see.
  getTransition("findToFollow", FindEntity, Exit)
    .setShouldTransition((state) => !state.foundEntity())
    .setOnTransition(() => bot.chat("Could not find entity!"))
    .build(),

  // We want to start following the player immediately after finding them.
  // Since BehaviorFindEntity finishes instantly, we will transition almost immediately.
  getTransition("findToFollow", FindEntity, FollowEntity)
    .setShouldTransition((state) => state.foundEntity())
    .build(),

  // If the distance to the player is less than two blocks, switch from the followPlayer
  // state to the lookAtPlayer state.
  getTransition("followToLook", FollowEntity, LookAtTarget)
    .setShouldTransition((state) => state.distanceToTarget() < 2)
    .build(),

  // If the distance to the player is more than two blocks, switch from the lookAtPlayer
  // state to the followPlayer state.
  getTransition("lookToFollow", LookAtTarget, FollowEntity)
    .setShouldTransition((state) => state.distanceToTarget() >= 2)
    .build(),
];

// Now we just wrap our transition list in a nested state machine layer. We want the bot
// to start on the getClosestPlayer state, so we'll specify that here.
// We can specify entry arguments to our entry class here as well.
const root = getNestedMachine("root", transitions, FindEntity)
  .setBuildArgs((e) => e.type === "player")
  .build();

// We can start our state machine simply by creating a new instance.
// We can delay the start of our machine by using autoStart: false
const machine = new BotStateMachine({ bot, root, autoStart: false });

// Start the machine anytime using <name>.start()
bot.once("spawn", () => machine.start());

Documentation

API

Roadmap

Implemented

  • Web View
  • Look at Entity Behavior
  • Nested State Machines
  • Movement Behaviors
  • Mining/Placing Behaviors
  • Get Nearby Entities
  • Equip Items and Armor

To Do

  • Show Targets in Web View
  • Camera Controls in Web View
  • Collection-based Behaviors
  • Fighting-based Behaviors
  • Conversation-based Behaviors

License

This project uses the MIT license.

Contributions

This project is accepting PRs and Issues. See something you think can be improved? Go for it! Any and all help is highly appreciated!

For larger changes, it is recommended to discuss these changes in the issues tab before writing any code. It's also preferred to make many smaller PRs than one large one, where applicable.