Real-Time Gaming Blog

DIY Minecraft: Multiplayer Voxeljs with PubNub

2 min read PubNub Staff on Sep 4, 2014
Try PubNub Today

Free up to 1MM monthly messages. No credit card required.

Subscribe to our newsletter

By submitting this form, you are agreeing to our Terms and Conditions and Privacy Policy.

I recently stumbled across the awesome Voxeljs library which allows anybody to create Minecraft style games (Voxel) that run in the browser with NodeJS. In this tutorial, we'll walk you through how to...

I recently stumbled across the awesome Voxeljs library which allows anybody to create Minecraft style games (Voxel) that run in the browser with NodeJS. In this tutorial, we’ll walk you through how to develop multiplayer Voxeljs to build a DIY Minecraft!

I decided I was going to take an afternoon to add the power of PubNub to Voxeljs, creating the basis for an MMO version of Minecraft. Want to see it in action and go for a stroll around? Here’s the multiplayer Voxeljs demo.
multiplayer voxeljs

Getting Started with Multiplayer Voxeljs

I started with the Voxel Hello World example. It didn’t include any textures, so I got them from the Occulus Rift demo.

I modified the “hello world” example to include our standard PubNub initialization.

First I added the script into index.html.

And then I initialize PubNub. In this special case the PUBNUB object needs to be referenced by window.PUBNUB.

Then I created a User object and list of Users so I could keep track of who was online and what their position in game was.

I then pubnub.subscribe, and add a player when I get a join event. I subscribe to notifications on our channel, and update the player position when I receive a message.

All that’s left is to send out player positions! I use setInterval() to publish the player position every second.

That’s it! It’s very crude but was easy enough to set up in an afternoon. We can open two windows and see the player position update in real time. It wouldn’t take much to add smoother animations and the ability to place and delete blocks.

Want to see it in action? Check out the live multiplayer Voxeljs demo here, or watch the quick overview video below:

Get Started
Sign up for free and use PubNub to power multiplayer games

More from PubNub

Comparing Game Engines: Unity vs Unreal vs the Rest
Real-Time Gaming BlogSep 21, 20225 min read

Comparing Game Engines: Unity vs Unreal vs the Rest

Comparing the major game engines: Unity vs Unreal Engine vs Corona SDK vs GameMaker Studio, including the benefits and cons of...

PubNub Staff

PubNub Staff

Python Socket Programming: Client, Server and Peer Libraries
BuildSep 21, 20226 min read

Python Socket Programming: Client, Server and Peer Libraries

Sockets (aka socket programming) enable programs to send and receive data, bi-directionally, at any given moment. This tutorial...

PubNub Staff

PubNub Staff

Node.js WebSocket Programming Examples
BuildSep 21, 20226 min read

Node.js WebSocket Programming Examples

An overview and examples of basic socket and WebSocket programming with Node.js.

PubNub Staff

PubNub Staff