My Projects > Automatic Minecraft City

Automatic Minecraft City

Technologies Used: Python (pyautogui)

Project Summary:

I've always had an affinity for Minecraft since elementary school, but I wasn't the type of player to mine diamonds or kill zombies. Instead, I'd play in creative mode, where I could build whatever came to my mind whenever I wanted. From schools to large buildings, I had my collection of items that I'd spend weeks working on in this game. But in my junior year of high school, I decided to take on a more ambitious project: building an entire city from scratch.

I wanted this city to be designed and built down to the finest detail, so it could feel like somebody could really live in it. Of course, it didn't start out with much detail at first. The first city I ever built was simply pillars of blocks stacked in random locations in a desert.

Each "skyscraper" took around 5 minutes to build, and they were all about 1,000 blocks each. They were also made out of all of the same materials, had no windows, and weren't laid out in any particular grid as a traditional city. The city also had no roads. With this long and arduous process of building each skyscraper one by one in no particular sense, this project would have taken a very long time to complete.

A bit into this process, I learned that Minecraft had a command line, which could be used to fill in blocks without having to build them by hand. With that, I was able to use the fill command to build pillars one by one with a single line of code. To use this command, I specified the coordinates on the map for the structure to be built, the height, length, width, and material of the building. However, this still took a long time because one fill command fills the entire space, so the buildings weren't hollow. Because of that, I had to go back and do another fill command just to hollow them out. The problems of the buildings not contributing to a city layout was still a problem, as I was just filling pillars of blocks in random locations on the map.

A NEW CITY

I decided to move locations so I could have a better plan for the city and build based on that. I moved to a relatively flat grass land to start this new city.

I planned for this city to have roads and skyscrapers of roughly the same size so there would be a consistent design to the cityscape. In this new location, I also created a new design for my skyscrapers. This design was taller, had windows on the buildings, and introduced different materials for different types of buildings. This design, however, was much more difficult to build, even with commands, as there were many parts to it. It would be easier to build the entire building with separate fill commands, but it would require around 100 different fill commands, which was very time consuming and tedious to write out, as I needed to calculate several different coordinates (one for each window) and switch between materials. It would be much simpler, however, if something could write these commands out for me.

PYTHON IMPLEMENTATION

Doing some research, I learned of a python package called pyautogui, which allowed me to run scripts to control my computer by typing for it, moving the cursor, etc. I realized that I could utilize this functionality to write fill commands for me. With that, I wrote a program in python to build one building of my new design for me using fill commands:

To build the same building with a different material, I just need to change the currentBlock variable to a String that has the material that I desire. I decided to build different buildings made mostly out of Smooth Stone, Quartz, and Iron. Below are the three buildings:

Building one building took around 2 minutes, as each fill command took 1 second to write and execute, and there were around 110 fill commands for one building. Although building the skyscraper took no effort from me, having to wait that long took a while. Also, I still had no way of automating the placing of the buildings, I still had to change the coordinates manually in my code each time I wanted to build something new.

I decided to tackle the first problem of 2 minute builds. I learned of a new Minecraft command called clone, which allowed me to clone blocks at certain coordinates and place them at new coordinates. Utilizing this command, I was able to save the builds for the three buildings and use them to build more.

In my python script, I had variables to store the code to clone these buildings. I also implemented a loop which loops through coordinates, adding them so buildings automatically get built in a predetermined line, so I don't need to manually enter coordinates for each building I need to build. This loop came to determine the bulk of what I used for my automatically generated city, as I used it to generate streets upon streets until I had some resemblance of a city.

Using that loop, I also created a bot that would insert lane markings into roads:

All of these developments from placing down my first block to creating powerful building bots in Python took me around one and a half years. With all of the bots I created put together, I was able to build a shell of a city complete with streets and skyscrapers as far as the eye can see. With this shell of a city done, I was then ready to add things to it to make it come alive, which is what I'm currently working on.

NOW

Currently, I'm working on public transportation methods, neighborhoods building stop lights, and building an interstate highway running adjacent to the city. I'm continuing to utilize python to automate a lot of the arduous and repetitive processes which take a long time. For example, I expanded the road bot to be able to build multiple lanes on a highway and I'm currently building a bot to automatically build stop lights for me.

One of the additions to the city that I've completed making was an entire airport from scratch. This airport is complete with a runway, three main gate terminals, baggage claim, security lines, and an underground luggage system to get luggage from the front entrance to the runway. I also downloaded an airplane addon from the internet and put those on my runway.

Another addition to my city is homes which I'm putting in neighborhoods around my city. I've built a model home which I'm cloning similar to my other skyscrapers and creating neighborhoods out of them. This model home has a balcony, a living room, bedrooms, and a kitchen. I'm still working on putting these homes into neighborhoods and working on creating other homes with different architectures.

This is a project that I intend to never stop working on as my creativity continues to pushes me to keep adding things to my city. I hope every addition I make allows the city to be more realistic and feel like it's an amazing place to live in real life.