Custom Minecraft Client

OVERVIEW

Context

During the Christmas break in 2022, I had come to the conclusion that I had all the skills I needed to create my own Minecraft clone, a dream of mine for a very long time. I wanted to have a very clear goal and scope for the project, because I wanted to learn as much as I possibly could about programming, and I didn't want to waste time contemplating features or content. I decided I would do my absolute best to recreate Minecraft Beta 1.7.3, as this version came out in 2011 and had less content. This project has taught me the most out of any project I have ever undertaken.

Most Valuable Skill Learned

It's hard to pin down an individual skill this project taught me, because I learned such an incredible amount. I Believe that this project has taught me that there is nothing I can't overcome, as long as I do my research and continue to build my skills.

Content

I took a stab at most of the features included in Minecraft. The current build has the following:

  • Infinite terrain generation
  • Runs at 60fps on a GTX 1650 with a 24 Chunk render distance
  • Survival mechanics, such as mining blocks, inventory, crafting
  • Day/Night cycle, with an optimised lighting system that surpases that of the original b1.7.3 client.
  • Smooth block lighting done via a vertex shader.
  • Custom block models, supporting objects like stairs, flowers, torches.
  • Can load worlds saved by the official Minecraft client.
  • Can connect to official Minecraft b1.7.3 servers.
  • Custom font renderer.
  • Entity system, physics, colliders, raycasting & more.

I created this project without the help of a game engine. It is written as a C# .NET Core application, and utilises Raylib as a simple graphics library.

BREAKDOWN

Optimisation, Multithreading & Profiling

Completing this project taught me how to optimise my code, and ensure the application is running as efficiently as possible.

For recreating a game like Minecraft, performance is paramount. I created my own performance profiler, that I could use to measure the performance of my code across multiple threads. The first, naive implementation of my chunk building code took 80ms. This is far, far, to much time to build a single chunk. (16x128x16 meters). With the help of my profiler, I reduced this time to take less than 8ms on average, a 10x performance increase.

I also learned how to utilise multithreading to its maximum potential. To make the performance impact of building chunks negligible, I delegated this task to multiple threads. Typically, the main thread would run the game, and there would be helper threads generating, and then building chunk meshes.

A very, very early look at the chunk building and rendering.

An early iteration of my profiler being used to test performance.

The result of my hard work: 30 chunk render distance, 78 FPS. (on a GTX 1650)

Data Serialisation, Interoperability & Networking

This project taught me how to follow a file format specification, and parse and write my own files of that format. Minecraft uses a standard developed for the game called NBT (Nested Binary Tags). It is a compact and efficient format used for storage of large amounts of data. Understanding and utilising this format is essential to allow a Minecraft clone to communicate with and process files from a real Minecraft client or server.

With the NBT format implemented into my engine, I was able to load real minecraft worlds created in the official Minecraft client.

I also used the Minecraft Multiplayer Protocol specification from Wiki.vg To learn and create my own implementation of the protocol. This meant I was able to connect to a real Minecraft server, download the terrain and interact with players through the chat.

Playing on a world generated using a real Minecraft client. (Note the cave generation)

Playing on a real Minecraft server using my client.

Looking at that player from a perspective of another client.

Systems & Mechanics

Inventory management and crafting system

Building a house to demonstrate lighting and custom block models.

I created my own UI library for the project to mimic the style of Minecraft's UI.