Real-Time Gaming Blog

DIY Minecraft: Multiplayer Voxeljs with PubNub

2 min readPubNub 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

Can Empathy Exist in the Metaverse
News May 16, 20221 min read

Can Empathy Exist in the Metaverse

A roundtable discussion led by PubNub’s COO, Casey Clegg, exploring the topics of what it means to be human in a virtual world.

PubNub Staff

PubNub Staff

How to Advance Telehealth and Virtual Care Technologies
News May 2, 20221 min read

How to Advance Telehealth and Virtual Care Technologies

Dr. Joe Kvedar, Chair of the Board for the American Telemedicine Association, joins our COO, Casey Clegg, to discuss why...

PubNub Staff

PubNub Staff

Another Step Towards Data Security: ISO-27001 Implementation
BuildMay 2, 20221 min read

Another Step Towards Data Security: ISO-27001 Implementation

Today, we are glad to announce that we are currently in the process of implementing ISO-27001 security standards.

PubNub Staff

PubNub Staff