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 🙏

© 2026 – Pkg Stats / Ryan Hefner

turtle-handler

v1.1.0

Published

CC:Tweaked Turtle Handler and Controller

Readme

turtle-handler

library to help handle and control computerCraft CC:Tweaked turtles. Uses a class to store all active turtles by unique ids and holds all turtles in a class of their own which stores the websocket client connection. The turtle class also has various commands to make controlling the turtles individually from within node.js easier. Not all commands are in the Turtle class however, see CC:Tweaked Turtle Docs for a list of all commands for the turtles.

Websocket configuration

const ws = require("ws");
const {Turtle,TurtleStore} = require("turtle-handler");

// create websocket server
const wss = new ws.Server({port:9999});
// create turtleStorage
const turtleArray = new TurtleStore();

wss.on("connection", (ws) => {
    // for each websocket connection create a new turtle and add it to array

    // add websocket client to turtle
    let turtle = new Turtle(ws);
    turtleArray.addTurtle(turtle);

    // turtle added to array and can be commanded with class methods
});

In-game configuration

install json library on turtle

$ pastebin get 4nRg9CHU json

create startup.lua file on turtle

os.loadAPI("json")

local ws,err = http.websocket("WEBSOCKET URL (NGROK)")

if err then
    print(err)
end

if ws then
    while true do
        -- receive message
        local msg = ws.receive()
        print(msg)

        -- receive function and load it to variable
        local obj = json.decode(msg)
        local func = loadstring(obj["func"])

        -- run function and send values back
        local bool,other = func()
        local fullReturn = json.encode({bool,other})
        ws.send(fullReturn)
    end
end

Turtle Storage Handling

Handling of turtles in the TurtleStore class

const turtleStore = new TurtleStore();

.addTurtle(turtle)

let turtle = new Turtle(ws);
turtleStore.addTurtle(turtle);

.removeTurtle(turtle)

let turtle = new Turtle(ws);
turtleStore.removeTurtle(turtle);

.removeTurtleById(id)

let turtle = new Turtle(ws);
let turtleId = turtle.id; // get randomly generated id
turtleStore.removeTurtleById(turtleId); // for times where you don't have direct access to the turtle class but can know the id

.getTurtleById(id)

let turtleId = "turtleId";
let farAwayTurtle = turtleStore.getTurtleById(turtleId); // get turtle class when you don't have access to turtle class by know id

Turtle Commands

All Commands are asynchronous (does something in game)

.sendCommand()

send custom command to turtle { print("hello world") } must be prefixed by "return "

turtle.sendCommand("return print("hello world)").then(complete => {
    console.log(complete);
}, err => {
    console.error(err);
});

.scanInventory()

scans all 16 slots of a turtles inventory and updates the turtle.inventory object

await turtle.scanInventory()
// returns nothing, updates turtle.inventory object

Movement

all movement actions

turtle.moveForward().then(complete => {
    console.log(complete)
    // returns {
    //  bool: true, // move complete
    //  obj: null
    //}
}, err => {
    console.error(err);
    // returns {
        bool: false, // unable to move
        obj: STRING // reason why
    }
});

all other movement commands work the same and return the same things

Fuel

.getFuelLevel() and .getFuelLimit()

turtle.getFuelLevel().then(level => {
    console.log(level);
    // returns number for fuel level or "unlimited" if turtles do not use fuel when moving is enabled
});

.getFuelLimit() operates the same and returns the same thing

Inspect

.inspect(), .inspectUp(), .inspectDown() all operate and return the same

turtle.inspect().then(data => {
    console.log(data)
    // returns {
        bool: true // if there is a block in front of the turtle
        obj: // block data
    }
}, err => {
    // does nothing
});

Inventory

.select(slot) selects a slot in the 16 slot turtle inventory

turtle.select(2).then(complete => {
    console.log(complete);
    // returns true if slot was selected
}, err => {
    // does nothing
});

.getItemDetail(slot) gets details of item in selected slot (used by scanInventory)

turtle.getItemDetail(slot).then(data => {
    console.log(data)
    // returns block data or null if there is no block
}, err => {
    // does nothing
});