1.2.8 • Public • Published

Code connection for Minecraft Education Edition clone using NodeJS.

To turn on the server run:

npx codeserver-start

To turn off the server run:

npx codeserver-stop

The server runs an expressJS server (port 3001) and a websocket (port 3000). Minecraft connects to port 3000 using the /connect localhost:3000 slash command.

The player script automatically sends http requests to express that relays them to Minecraft. Minecraft responds (eventually) with some JSON data that is parsed with true/false/useful data being sent back to the player.

To get Minecraft to connect to this application you need to turn off secure websockets in Minecraft.

Do this by:

  1. Opening a world and hitting escape to bring up a menu screen
  2. Selecting settings.
  3. You now need to select "Profile" on the left hand menu
  4. At the top of the right, the third toggle at the top should say "Require encrypted websockets". This needs to be switched off. (toggled left) If this option is grayed out you are already connected to a websocket and will need to disconnect before disabling the secure websockets.

Scripts should start with

const { agent, d, blocks } = require('codeconnection')

agent - this gives access to the agent to send commands d - this gives quick access to direction commands LEFT, RIGHT, UP, DOWN, FORWARD, BACK blocks - a list of blocks so yo don't have to type them

Possible agent commands:

Command Details
agent.move(direction, distance) moves agent number of steps in given direction. Returns true/false
agent.turn(direction, times) turns left or right given number of times. Always returns true
agent.getPosition() returns JSON object with x,y,z co-ordinates of the agent
agent.getPlayerPosition() returns JSON object with x,y,z co-ordinates of the player
agent.orientation() returns direction agent is facing
agent.inspect(direction) return block information of block in direction given form the agent perspective
agent.destroy(direction) agent destroys block in given direction. Returns true/false
agent.collect() agent picks thins up nearby
agent.inventory() returns JSON object with inventory data for agent (id aligns with blocks list)
agent.till(direction) agent tills soil in direction given. Returns true/false
agent.attack(direction) agent attacks in direction given
agent.dropAll(direction) agent drops all inventory in direction given
agent.drop(slot,quantity,direction) drops given number of items from the slot in the direction given (will not allow inventory to go negative),slot) agent places item from given inventory slot in direction indicated
agent.detect() detects if any collidable block exists in given direction (returns true/false)
agent.detectRedstone(direction) detects if redstone in direction given
agent.transfer(from slot, to slot, quantity) self explanatory I hope
agent.tpToPlayer() teleports agent to player
agent.face(direction) makes agent face either NORTH, SOUTH, EAST or WEST
agent.radar(block) will attempt to see if there are any potential matching blocks within 16 blocks on the same vertical height in the world as the agent. It runs the /getchunkdata command to get the colour values of nearby blocks and checks these against a list. Many blocks have the same colour value (e.g. all stone and ore blocks are the same) so they may not help you find diamonds easily....
agent.follow(true/false) if true (default) then teleport the player to be close to the agent so the agent can continue executing it's commands. Agent must be within 64 units of distance from the player or throws and error message [this is just how the agent works, Minecraft has this programmed in]. If this is set to false, the program pauses until the user moves to within the distance limit and presses a key on the console to resume the commands being sent to the agent.
agent.getStats() returns a cumulative total of the moves the agent has made as an object. It also includes the current running time.
agent.give(block,slot,quantity) places an item in the agent's inventory. Block is from the block list, slot is 1 to 27 and quantity is an integer. Slot defaults to 1 if missing and quantity defaults to 1. Currently there are some items that aren't able to be 'given' to the agent - I think it is a database issue.

Special feature(s)

Starting with

const { agent, d, blocks, special } = require('codeconnection')

gives access to the 'special' functions.

Command Details
special.about() Prints this message.
createHeightMap()\nThis centers the player on a 256 x 256 world (old world).
It generates a height map as an array of objects and saves it to a file called 'map.json'.
The function also returns this information as an object when it completes.
It contains teh heights, a colour code that matches different items in the database for the
highest block in the world at that location in a 256 x 256 array of objects.
special.createHeightMap() This function centers the players position on an old world (256 x 256). It then scans all the heights of the blocks in the whole world. It produces and object with the following information.
  1. offsetX: x offset of the map in world coordinates
  2. offsetZ: z offset of the map in world coordinates
  3. array of arrays (256 x 256) with all cells containing objects.
    Each object has a height which is the highest block at that X,Z coordinate and a colorcode that matchs the block at the coordinate. This is a Base64 encoded RGB value. The database in this system (look in the node module) contains all the color codes for blocks so you can potentially work out what blocks each height could be

I'm sure there are some bugs in here, eventually I'll probably work them out, either that of Minecraft Education Edition will get updated and break everything.

Package Sidebar


npm i codeconnection

Weekly Downloads






Unpacked Size

610 kB

Total Files


Last publish


  • otwalrus