11-13 yrs old
14-18 yrs old
Art and Design
This project shows you how you can use just a little bit of code to randomly generate large, diverse cities.
May 2, 2017
What does it take to create a large, diverse city in Minecraft?
Modders should be familiar with:
We'll be walking through the code one Actor at a time: buildings, then rails, then Stage.
The "buildings" Actor contains all the code used to randomly generate a city.
Let's look at that code first...
All the skyscrapers in Gen City are created one layer at a time.
The "build skyscraper layer" function builds a single using just two bot code blocks:
The glass windows are built by creating a hollow box of glass using the bot.
The floor for the level is created by building a filled box one block tall in the same spot.
This function is using several variables to dictate the way it will build a layer. Here's how they're working:
The "floor blocktype" parameter allows you to specify a different material for the layer. This variable only has a value inside the function.
The "building width" variable is a global variable and can be used anywhere in the project.
By defining the "building width" as a variable:
The "generate skyscraper" function creates a random skyscraper. Here's how it works:
It uses two script variables.
Then it sets "floor blocktype" to a random blocktype.
It sets "num floors" to a random number.
Finally, it places a roof on top of the skyscraper using a box 1 block tall.
"max stories" is a global variable and can be used anywhere in the project.
By defining the "max stories" as a variable, you can make your cities taller or shorter by changing the variable.
"floor blocktypes" is another global variable, a list that is used to pick a random blocktype for a skyscraper.
Add or remove blocktypes from this list to choose what kind of blocks to use for your random buildings.
Replace the code that builds the roof with this code to give each building a 50% chance of having a rooftop garden.
The "generate city block" function creates a city block by placing 9 skyscrapers and a roadway around them.
First it places a square of road, then moves the bot to place skyscrapers in the middle of the square.
It then creates 9 random skyscrapers by placing 3 rows of 3 skyscrapers, with 1 block of empty space between each skyscraper.
The "generate city" function creates a city from city blocks.
Can you modify the "generate city block" function to also create sidewalks around the skyscrapers?
How do you need to position the bot so that the sidewalk is placed perfectly around the buildings? You'll need this block:
The "rails" Actor contains all the code to build a custom railway.
Let's take a look at that code now...
The railway is generated by 5 basic functions that lay railway tracks using the bot tool.
The "lay track forward" function:
The "turn track left" and "turn track right" functions work similarly; they both:
The "lay track up" and "lay track down" functions both:
These functions allow the track to be placed while ascending or descending.
Now that you understand how the Railway System works, you can build your own custom railway and create your own rides.
Change the code blocks in the "create railway" function to make the railway the way you want.
Start your rail system with an unpowered track so you can place a Minecart on it without it automatically rolling away.
For the rest of the railway, use these blocks in sequence and it should create a connected and powered railway:
You can use this block to delete the previous city before building a new one.
Your might need to change the code to look like this:
To see this lesson with all of the attached images, we suggest that you download the attached PDF.
Sign in with your Microsoft account and sign up for the Minecraft: Education Edition newsletter. We promise to respect your inbox.