Real-Time Gaming Blog

DIY Minecraft: Multiplayer Voxeljs with PubNub

2 min read Michael Carroll 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

NPP and HIPAA: Notice of Privacy Practices Definition
Healthcare CategoryJan 6, 20235 min read

NPP and HIPAA: Notice of Privacy Practices Definition

A Notice of Privacy Practices (NPP) is one of the requirements of HIPAA and helps patients understand their personal data rights.

Michael Carroll

Michael Carroll

HIPAA Technical Safeguards: How To Protect Sensitive Data
Healthcare CategoryJan 5, 20236 min read

HIPAA Technical Safeguards: How To Protect Sensitive Data

HIPAA covered entities must follow the five technical safeguards to achieve HIPAA compliance and prevent data corruption.

Michael Carroll

Michael Carroll