Skip to content

Latest commit

 

History

History
97 lines (69 loc) · 3.13 KB

README.md

File metadata and controls

97 lines (69 loc) · 3.13 KB

PixelWalker SDK

NPM | GitHub | Reference

Example

import Client from 'pixelwalker.js'
import CommandManager from './hello.js'
const client = new Client({ token: 'YOUR TOKEN HERE' })

client.on('start', () => client.say('🤖 Connected!'))
client.on('error', ([error]) => {throw error})

client
    .include(CommandManager)
    .connect('WORLD ID')
import Client from 'pixelwalker.js'

export default (client) => 
    client.onCommand('hello', async ([player, _]) => {
        client.say(`🤖 Hello, ${player.username}! `)
    })

Installation

npm i --save pixelwalker.js

Examples

Give God Mode on Join
client.on('player:join', ([player]) => player.god(true))

The above example is a simple module that gives every player god mode upon joining.

Snake Trail
const blocks = ['glass_red', 'glass_orange', 'glass_yellow', 'glass_green', 'glass_cyan', 'glass_blue', 'glass_purple', 'glass_magenta', 0]

client.on('player:block', async ([player, pos, block]) => {
    if (block.name == 'empty') return
    if (!blocks.includes(block.name)) return

    await client.wait(250)
    client.block(pos[0], pos[1], pos[2], blocks[blocks.indexOf(block.name) + 1])
})

In this example a very simple snake trail is generated. The block types are stored and iterated over in the array. Note: Client.block(...) returns a promise that awaits if the block was placed by the internal queue manager. Awaiting blocks will cause low performance.

Replace Block Types
client.onCommand('replace', async ([player, _, from, to]) => {
    if (BlockMappings[from] == undefined || BlockMappings[to] == undefined) return
    const blocks = client.world.list(from)
    blocks.map(([x, y, layer]) => client.block(x, y, layer, to))
    await Promise.all(blocks)
    client.say(`🤖 Replaced ${blocks.length} blocks!`)
})

To replace all blocks of a kind, you can use the following procedure: List all blocks of replacing type in the world data, then place on all given coordinates the wished block type. If you want to make sure, that code continues to run only after all blocks are placed (without caring about placement order), await all promises.

Brush Size Variations
const brushes = {}

client.on('player:block', async ([player, pos, block]) => {
    let brush = brushes[player.id]
    if (brush == undefined) return
    for (let x = -Math.floor(brush / 2); x < brush / 2; x++)
    for (let y = -Math.floor(brush / 2); y < brush / 2; y++)
    if ((x +.5) ** 2 + (y+.5) ** 2 <= (brush/2) ** 2)
        client.block(pos[0] + x, pos[1] + y, pos[2], block)
})

client.onCommand('brush', ([player, _, size]) => {
    const value = parseInt(size)
    brushes[player.id] = value != NaN ? value : 1
})

In this example you create a public command !brush <size> which will store an individual brush setting for every player. This will be then used by the bot to create a a circle of the given radius. To make it a square, you can remove the if-condition that uses the pythagorean theorem.