The “UI update” V0.6 released

Version 0.6 was planned to be the storyline update, but it turns out creating storyline elements takes ages, and you end up creating a bunch of other content as you go along. So while I continue working on the storyline features I’m releasing an assortment of random other stuff I created along the way. However, the most obvious change is a complete overall of the UI, so thats what this update is getting called.

Major features in this version:

  • Video Command Chairs – A kind of command chair that can have a camera feed connected to it; allowing you to remotely control a turret and still see whats going on
  • Reinforced glass panels – A bunch of shaped glass panels to produce more interesting cockpits
  • Ants and ant colonies
  • Improved inventory interaction – shift clicking on an item will auto move it
  • Improved cave creation algorithm – look more like caves and less like a knife has been passed through the planet
  • Glow mushrooms – primarily found in any colonies
  • A bunch of bug fixes – by which I mean there were never any bugs
  • And of course, the complete overhaul of the UI

One Million Worlds is released!

One Million Worlds is officially released (as early access) and available to buy on steam. Because its early access the updates will come thick and fast but this is a major milestone towards finishing the game!

Main Capsule

So, the games out, now to thoughts of Major Update 1 (no not a rest). This comes out of my research of open world games (read; playing games) where you can feel a little lost in the early game; not quite sure what you’re supposed to do. The One Million Worlds intro was built in response to that but it doesn’t go far enough so the first major update will be the Story Lines Update, this will be an (optional) guided path through the game taking you around the world and presenting you with challenges unique to the game.

Building that is going to be interesting as it will mesh a procedurally generated world with predefined story line elements. This means that the elements of the story line will appear in different contexts each play through; being familiar, but not quite the same. Should be fun.

Steam and Wiki

As I get closer to releasing the game in alpha (sometime in March) I’m starting to build and improve the non game parts of the project.

So the word doc manual (boo!) is now a wiki: (yay!). And the the download from is now a steam page:

Its not actually available to buy and download from Steam yet, and won’t be until the game comes out in alpha. But you can wishlist the game there so you’ll be informed as soon as its own.

Scripting blocks

As a developer when you put a programming language inside your program its a good sign you’ve gone off the deep end. That is what I have done. I’m now going to try to justify why I’ve done this in an attempt to lie to myself that it was a good idea.

Scripting blocks are a response to wiring getting too complicated and ugly and look like this:

script block

The idea is that they can accept a small text program and replace a huge load of wiring with just a little bit of text. So they can convert something like this (which is an automated turret that tracks and fires at the player):


Into something like this:


This turret is actually something I intend to exist within spawned structures so I wanted the scripting block for my own use but I’m putting it as a general block for advanced players to use (see, justification).

Here’s a video of how its used:

The scripting block is available in the most recent version of One Million Worlds (version 0.4.3 onward)

So, that’s that done. Now its time for the documentation! Yay!


Once you’ve placed a script block look at it and press e to open up the script.

Inputs and outputs

The inputs and outputs are all referred to by the letters N,S,E,W,U,D for north, south, east, west, up and down. The N,S,E,W are shown on the chip itself, the up and down you’ll just have to figure out for yourself.

You can set a direction equal to a value and that value will be output to that directions. e.g.

N = 5


W = 'Hi there'

You can output to multiple directions in a single program

N = 5
W = 'Hi there'

You refer to the inputs in the same way, so say you have a number inputted in the West port and wanted North to be twice the West value you could use the following script

N = 2 * W //note that * means multiply

// indicates a comment, the rest of the line is ignored, so you can add notes to your script

Implicit outputs

If you only have one output equal to a simple equation (or want all your outputs to be the same) you can omit specifying what output you want the value to go to, so you can simplify the previous program to this:

2 * W //all outputs will receive a value twice the size of WEST

Asking questions

You can use the “if” keyword (and a whole bunch of brackets!) to do different things based on a question. So lets say you have an input W that is the distance away a player is (reported by a scanner block) and if the player is closer than 5 meters away you want to show on a screen (connected to N) “Go away” and raise a door (a Rail block connected to S) but if they do go away reopen the door you could use this program:

if(W<5){        // W is the distance away the player is
  N = 'Go away!'
  S = 4         //S is connected to a rail set to position mode, 4 is fully closed
  S = 1         //position 1 is fully open   


Sometimes you want to calculate something once and then use it several times, you can store it in a variable

someComplicatedCalculation= 2 * N + S
W = someComplicatedCalculation
E = 2 * someComplicatedCalculation


Sometimes a piece of data has several parts, like a position might have an x, y and z. These can be both read and creating within scripts. The main place you’ll see these is inputs coming from scanner blocks which report positions as an array of 3 numbers. For arrays that enter on inputs you can refer to them in 2 ways:

As x,y,z:

distanceAway = N.x      //N.x is the first value in the array, N.y is the second, N.z is the third
S = distanceAway

This way of referring to arrays only works with arrays entering on inputs, not ones you create yourself.

As a number:

distanceAway = N[0]      //N[0] is the first value in the array, N[1] is the second, N[2] is the third
S = distanceAway

Note that the first value is N[0], not N[1], arrays start at zero. 

You can create arrays using square brackets. for example this program would return an array of the numbers 1,2,3

N = [1,2,3]

You can of course use variables

distanceAway = N.x 
N = [distanceAway, 2*distanceAway, 3*distanceAway]

Inbuilt information

Some data is provided in variables for use in your script. At present these are:

  • firstRun – if this is the first time this script has run (i.e. you just edited it) this is true, otherwise its false
  • timeSlice – how much time this run of the script represents (aka how long there is between runs of the script)
  • scriptTime – the total time this script has run (its the sum of all the timeSlices since the script was changed)

Remembering things from the last time the script was run

Usually the script runs a fresh each time, forgetting all its variables, but it is possible to remember things from run to run, this is done using the persistent (or p) scope. Also because I really struggle to spell persistent you can also use the persistant scope and that will work fine. Anything in the persistent scope will still be available the next time the script runs.

So lets say we want to modify the “go away” script from the “asking questions” section so that if starts saying go away if you come within 5 meters but then it keeps saying it until you are 10 meters away:

    p.goAway = false //when the script first starts up default to not saying anything

if(W<5){     p.goAway = true } if(W>10){
    p.goAway = false
//note that if W is between 5 and 10 it is left at whatever value it had previously

    N = 'Go away!'

Inbuilt functions

I’ll be creating inbuilt functions as I need them (I’m selfish like that) for now these are available:

  • clamp – This will take a value and ensure it remains between two other values
N=clamp(W,5,10) //This will output the value of W, or 5 if W is below 5, or 10 if W is above 10
  • stabilise – This will provide functionality to stabilise a system, e.g. if you have a turret that’s looking at the player controlling a rotator block to make it look directly at the player…… its best explained by watching the above video. It is a PID controller that is used like:
stabilise(errorValue, proportionalTerm, integralTerm, derivitiveTerm)

The meaning of the terms are as follows:

errorValue –  how far the recorded value is from what you want it to be. E.g. if the player is 30 degrees to the left and you want to be looking at them the errorvalue is 30.
proportionalTerm – this is a tuning parameter, you need to play with it to see what works. You want to set it to a value such that your system swings quickly to the desired position (even if it overshoots)
intergralTerm – this is a tuning parameter, you need to play with it to see what works (you’ll probably want it to be zero. You can use it if you need to apply some force even if you are at the correct position (e.g. when you hold a weight up with your arm you still need to apply force even when you’re in the right position
derivitiveTerm –  this is a tuning parameter, you need to play with it to see what works. This controls overshoot, if the system keeps osculating about a set point increase the derivitiveTerm.


You don’t need loops, please skip this section.

Ok fine, loops are useful when you want to do something more than once.

A simple loop could be like this:

for(i = 0; i<5; i++){
   /*this area will be executed 5 times, 
   once with i as 0, then 1 etc until finally when i is 4*/

Lets say, in the “go away” example the closer they get the more you want to say go away, lets say one exclamation mark for every meter they get towards you. A loop can do that.

distanceAway = W
permittedDistance = 10
if(distanceAway < permittedDistance){
    message = "Go Away"
    exclamationMarksToShow = permittedDistance - distanceAway //closer they get the more exclamation marks

    for( i = 0; i < exclamationMarksToShow; i++){
        message = message + "!"
    N = message

Reading errors

If any problems occur with your script the errors are shown when you next open the script panel (note it doesn’t refresh until you open and close it). It will tell you the line number and letter number where it knew for sure that your script was wrong, its possible it went wrong before this but that’s its best guess at where it went wrong

Secretly its JavaScript

The script used within OneMillionWorlds is actually a variant of JavaScript. I’ve made some additions but broadly if your script is valid javascript it will work. I haven’t covered anywhere near the full features of the language so if you’ve got to this point and want more there are may resources for javascript available online.

Hover rails

This is a feature I’ve added based on some feedback from my friend Vincent, he was trying to create a floating city with a transport system and the existing rails didn’t really cut it since the rails going up to the floating city make it look like its not floating.

So: hover rails (or railless rails), these behave like a regular rail system exect you tell it what the waypoints are rather than it following real physical rails. So you can go up to the floating city on a predefined route without creating an eyesore


The UI for creating waypoints works but I think I need a more intuitive way to place waypoints, I’m thinking the way building are placed in real time strategy games might work, so you move a ghost version of the machine to the place where it will travel to and then click to place the waypoint

Automated Rocket Factory

At the end of the last video I promised that I would could create a load of circuitry to fully automate the rocket factory, and while that is possible it would have been a lot of circuitry so instead of that I created a new block, the procedure block that allows the “do this, then this, then that” to be a lot easier to set up.


When you click into this block you get a simple UI that allows you to set up a series of outputs to run through


So with just that addition we can automate the rocket factory! Which I’ve put on top of a space ship, because why not.


Now due to certain, explosion related issues I realize I didn’t give you a close up view of the factory running, so here it is:


I’ve had a few videos of fairly military technology, but in the next video I plan on going in a more peaceful direction with a tunnel boring machine (that also collects and sorts any resources it finds along the way).

Rocket Factory!

I’ve been creating a couple of new blocks that help automate building:

A placer block that can place blocks, either as a new machine or attached to an existing machine


The placement block is part of the pipes system so you can use pipes to fill it up with things to place (or just open it and put things in manually)

And an attractor block that can pull other machines towards it (and lock them in position when they are close enough)


And with enough of them you can build a rocket factory:


An interesting question is if a sign post is a sensible way to input data into a machine, ………., its a fair point.

I mentioned a “more complicated circuit” running it all in the video but that feels a little complicated so I’m planning on adding a “procedure block” that you can set to [output the number 6 for 5 seconds then output the number 7 for 2 seconds] etc that should simplify that sort of thing.

A Block Battle

I’ve been looking at improving the sunspear AI this weekend (making it attack things that aren’t imaginary for example). Here’s a video of three of them attacking a player controlled vehicle.


3 verses one was never really going to go very well, still got 1 one of them!

You’ll probably have noticed the next item for improvement; the AI doesn’t 100% care about the ground, or trees, or other AIs and will happily crash into anything that isn’t its target.

You’ll see none of these ships are shielded, that’s deliberate, I’m making shield blocks very heavy so that you end up with a choice; heavy and shielded or light, maneuverable but vulnerable.

I’d like to end with a video of me actually winning, but well, this is the closest I ever got

Sunspears – a hostile fighter

The previous Ai controlled ship; the trade ships, were large and neutral by default. I wanted to add something more like a fighter; small, nimble, forward firing and hostile by default.

Here’s the work in progress:



This ship is attacking an imaginary object just above the tower. I’m imagining a few of these surrounding a base and attacking intruders (as hostile ships them wandering around in the world might be a little player hostile, maybe for a hardcore mode).

I don’t think this ship body will be its final form as I wanted it to be more… like a spear. It will also probably attack things that aren’t in its imagination.

As a computer controlled ship this is all good but it immediately made me want to create something human controlled with equal maneuverability to fight it but the command  chair as is stands requires far to much external wiring to process the outputs before they go to the engines. So; I’m planning on allowing simple formulas to be put in the keybindings for the command chair as well as vectors

So the current command chair allows you to select a single key to output in each direction, so for example you might type “a” to bind the a key to the SOUTH output which means to get forwards, fire, up, down, left, right you need 6 outputs, which already means you need 2 layers of outputs which is fine for a capital ship but big for a fighter. But if instead you allow simple formulas you can have:

SOUTH = a-d (controlling left and right together, press a and SOUTH is +1, press d and its is -1, press both and achieve nothing, don’t do that)
EAST = w (for forwards)
WEST = o-l (for up and down)
NORTH = x (for fire)

Great, now were’re at a single layer of outputs, except we’ve got wires coming forwards from the cockpit, that’s going to obscure our view, and the game already supports vectors so how about this:

SOUTH = w, a-d, o-l
EAST = x (for fire)

Now we can get all the signals away from the player nice and easily!

So that’s the plan, if all goes well you should see us in a fighter battle with that sunspear soon

Night and Day (done not stupidly)

In my game I have “sunlight” and “source light”, sunlight provided by the sun, remarkably, and source light provided by light blocks. However, in blockworlds light tends to be “prebaked” that is calculated once then each vertex knows how bright it is, this is great for efficiency! However in this prebaking I ended up combining the sunlight and sourcelight into one value; the bigger of the sunlight or the sourcelight, so a vertex (corner) is say 0.7 in brightness because its near a light block. Great!

Now, try to implement night and day, if you want to turn down the sun from 1 to 0.95 you have to regenerate everything to do the combination of sourcelights (still full power) and sunlight (now at 0.95 power). And you can’t rerender everything at once, its just not fast enough. So that mountain over there; its still day over there! But over here its twilight. Not to mention the fact that the whole game is now lagging under the strain. Turns out this is a really stupid way to do it.

So how do you do it not stupidly? You still prebake the light, but you prebake sunlight at full intensity and sourcelight separately for each vertex. Then you let the graphics card sort it out. Or more precisely; you write shaders to have the graphics card combine those prebaked values every frame and get the best of both worlds; you can do millisecond by millisecond adjustments to the sunlight level without any regenerating of geometry at all.


So that’s a nice video of a timelapsed day/night cycle, but how did I do it in practice, well we’ll need:

  • A custom mesh, where we’ll set TWO colour buffers, one for sunlight and one for sourcelight
  • A custom jMonkey material with custom fragment and vertex shaders (the fragment shader is where the real work will be). Btw a vertex is a corner of your geometry and a fragment is sort-of kind-of a pixel  and the shaders allow you to manipulate them on the graphics card, and graphics cards are really really good at that sort of thing.

Now; code!

(Incidentally this is fairly advanced, you can get a long way with jMonkey without worrying about custom meshes at all)

The main java class:


public class Main extends SimpleApplication {

private Material mat;
 private float dayNightPeriod = 4;
 private float time;

 public static void main(String[] args) {
 Main app = new Main();

 public void simpleInitApp() {

 //the points in 3d space where the geometry will be
 Vector3f [] vertices = new Vector3f[8];
 //one square
 vertices[0] = new Vector3f(0,0,0);
 vertices[1] = new Vector3f(3,0,0);
 vertices[2] = new Vector3f(0,3,0);
 vertices[3] = new Vector3f(3,3,0);
 //a second square
 vertices[4] = new Vector3f(3,0,0);
 vertices[5] = new Vector3f(6,0,0);
 vertices[6] = new Vector3f(3,3,0);
 vertices[7] = new Vector3f(6,3,0);

 //combine those vetexes into triangles 
 int [] indexes = { 
 //first square
 //second square 

 //we're not using a texture but if we were this would define whtich parts of the image are where 
 Vector2f[] texCoord = new Vector2f[8];
 texCoord[0] = new Vector2f(0,0);
 texCoord[1] = new Vector2f(1,0);
 texCoord[2] = new Vector2f(0,1);
 texCoord[3] = new Vector2f(1,1);
 texCoord[4] = new Vector2f(0,0);
 texCoord[5] = new Vector2f(1,0);
 texCoord[6] = new Vector2f(0,1);
 texCoord[7] = new Vector2f(1,1);

 //Set the first colour buffer, this will be the sunlight color
 Vector4f[] sunlightColour = new Vector4f[8]; //these are Vector4f because we have a red, green, blue and transparency per vertex
 //both the squares at full brightness in sunlight
 sunlightColour[0] = new Vector4f(1,1,1,1);
 sunlightColour[1] = new Vector4f(1,1,1,1);
 sunlightColour[2] = new Vector4f(1,1,1,1);
 sunlightColour[3] = new Vector4f(1,1,1,1);

 sunlightColour[4] = new Vector4f(1,1,1,1);
 sunlightColour[5] = new Vector4f(1,1,1,1);
 sunlightColour[6] = new Vector4f(1,1,1,1);
 sunlightColour[7] = new Vector4f(1,1,1,1);

 Vector4f[] sourceLightColour = new Vector4f[8];
 sourceLightColour[0] = new Vector4f(0.9f,0.9f,0.9f,1); //first square at 90% brightness in sourcelight
 sourceLightColour[1] = new Vector4f(0.9f,0.9f,0.9f,1);
 sourceLightColour[2] = new Vector4f(0.9f,0.9f,0.9f,1);
 sourceLightColour[3] = new Vector4f(0.9f,0.9f,0.9f,1);

 sourceLightColour[4] = new Vector4f(0.3f,0.3f,0.3f,1);//second square at 30% brightness in sourcelight
 sourceLightColour[5] = new Vector4f(0.3f,0.3f,0.3f,1);
 sourceLightColour[6] = new Vector4f(0.3f,0.3f,0.3f,1);
 sourceLightColour[7] = new Vector4f(0.3f,0.3f,0.3f,1);

 //now we have all the data we create the mesh
 //for more details
 Mesh mesh = new Mesh();
 mesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
 mesh.setBuffer(VertexBuffer.Type.Index, 3, BufferUtils.createIntBuffer(indexes));
 mesh.setBuffer(VertexBuffer.Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
 mesh.setBuffer(VertexBuffer.Type.Color, 4, BufferUtils.createFloatBuffer(sunlightColour));
 //we're using the conventional Color buffer for sunlight and using one of the (usually) unused TexCoord5 to hold the source light
 mesh.setBuffer(VertexBuffer.Type.TexCoord5, 4, BufferUtils.createFloatBuffer(sourceLightColour));

 Geometry geom = new Geometry("mesh", mesh);

mat = new Material(assetManager, "MatDefs/RepeatingUnshaded.j3md");
 //mat = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md"); 
 mat.setBoolean("VertexColor", true);


 public void simpleUpdate(float tpf) {
 time += tpf;
 if (time>dayNightPeriod){
 time = 0; 
 mat.setParam("SunlightIntensity", VarType.Float,time/dayNightPeriod); 


Now if I posted the whole of the shaders they’d look crazy complicated, but I’ve mostly stolen them from the built in Common/MatDefs/Misc/Unshaded.j3md and just edited what I needed to combine the colour rather than just pass it though. So to avoid a code dump I’ll just pull out the important bits and here’s a repository version for the full project

A jMonkey Material def contains all the uniforms (things that are common to the whole material) and references to the shaders to use. The only thing we need to add here is the SunlightIntensity uniform. We can vary this to tell the shader how much to use the sunlight prebaked light

MaterialDef Unshaded {
MaterialParameters {
Float SunlightIntensity // This is send to the shaders to tell them how combine light levels.

The vertex shader can affect the verticies of the mesh, we don’t really want to do much here so we just recieve the extra color data and pass it on to the fragment shader, where the real work will be

attribute vec4 inTexCoord5; // this is the source light that is passed to us
varying vec4 texCoord5; //and this is how we'll pass it through to the fragment shader

void main(){
texCoord5 = inTexCoord5; //its the fragment shader that wants this so we just pass it on

The fragment shader is where the real work happens, we’ll declare that we want the uniform m_SunlightIntensity and use that to combine the sun and source light. Each fragment (soft-of pixel) will combine the sunlight and sourcelight according to the current sunlight level.

uniform float m_SunlightIntensity; //just by declaring the uniform we'll receive it automatically
varying vec4 texCoord5; //this is the source color passed through to us
void main(){
vec4 color = vec4(1.0);
color.x *= max(vertColor.x * m_SunlightIntensity,texCoord5.x);
color.y *= max(vertColor.y * m_SunlightIntensity,texCoord5.y);
color.z *= max(vertColor.z * m_SunlightIntensity,texCoord5.z);
color.a *= vertColor.a;

So with all that together you get this:


Personally I thought the forest was prettier but nevermind.

Anyway, that’s light done non stupidly (or at least less stupidly). A few thoughts you may immediately have; what about machines? Sourcelight coming from the main world affecting moving machines would need to regenerate geometry each tick to truely track the light through it (slow!) so my plan is to have the light sampled by the machines at a single point and used as the sunlight level; that will give me not quite right but hopefully good enough lighting for the machines.