/Minecraft4k-CPP

A reimagining of Minecraft4k in C++, now with GPU acceleration!

Primary LanguageCGNU General Public License v3.0GPL-3.0

Minecraft4k-CPP

Donate using Liberapay

Minecraft4k-CPP is a port of the original Minecraft4k-Reversed to C++, so that we are able to leverage both the speed of C++ and mainly the GPU itself for raymarching.

Thus far, it already performs much better than the original game, as long as your GPU is powerful enough (make sure it supports OpenGL 4.3 Core). However, it hasn't been tested very thoroughly in different machines.
If you encounter an issue, please let me know by creating an Issue including your PC specs and the beginning of the console output. Thanks!

High resolution raymarched shadows: image

Sunshet at original resolution: image

"Classic" world and graphics (compile-time flag): image



Controls:

  • Move: WASD
  • Jump: Space
  • Break block: Left Click
  • Place block: Right Click
  • Cycle through inventory: Scroll
  • Higher resolution: Dot
  • Lower resolution: Comma
  • Render distance: + and -


This project is a reverse-engineered version of Notch's submission for the 2010 Java 4k Contest, where one would submit Java programs of 4kb or under in size.

Notch submitted Minecraft4k, a heavily optimized and limited Minecraft port. However, the game contained a multitude of bugs and is difficult to play today. The original build can be found at https://archive.org/details/Minecraft4K.
There is a Minecraft wiki page for Minecraft4k: https://minecraft.gamepedia.com/Minecraft_4k.

Minecraft4k-Reversed was created by decompiling this jarfile, and documenting what most of the code does. After fixing some bugs related to movement and collision detection, we moved to expand the game. This resulted in proper terrain generation, raycasted shadows, better graphics, and huge performance improvements thanks to multithreading raymarching on the CPU. However, it became difficult to manage and improve performance further, so we moved to developing this C++ port which uses the GPU for raymarching.

Some interesting things:
- Textures take too much space to store. They are generated on game start by algorithms!
- Notch wrote a custom voxel raymarching algorithm to avoid the filesize penalty of using a rasterizer library
- Block shading is "baked in", where the bottom of every block has extra grayscale applied to it

Building

Please excuse the messy build environment; this was my first time using CMake. Hopefully everythink should just work. When running the executable, make sure the res folder is in the working directory!

Linux

You'll need the linux-devel and glfw packages installed, so you can link against dl and glfw. You'll also need cmake. Run the following commands:

  • mkdir build; cd build
  • cmake ..
  • make
  • cp Minecraft4K ..; cd ..
  • ./Minecraft4k

Windows

Run CMake to generate a .sln file, and open it in Visual Studio. It should build fine from there.