/m4kc

Minecraft 4k: decompiled, translated to C using SDL for graphics and input, and improved upon

Primary LanguageC

M4KC

Grass block icon

Minecraft 4K - C Rewrite

For those who don't know, Minecraft 4K was a stripped down version of Minecraft submitted by Notch to the Java 4K Game Programming Contest, where each submission had to be under 4 kilobytes in size. Its wiki page can be found here.

Being so small, the game proved somewhat easy to de-compile and edit. Multiple people have given this a go, including me.

This project is an attempt to translate the game into C in order to increase its performance, and to provide a platform upon which to add new features.

Bug list

  • "Sticky" block collision - this behavior is present in the original version and I have been trying to work out ways to fix it for a while.
  • Raycaster breaks at -64 along any axis

Some goals for this project

  • Maintaining the original look and feel as closely as possible. ✅️
  • Keeping the final executable under 20 KB (on Linux, with the system I have set up in the makefile) ✅️
  • More blocks 🏗️
  • Perlin noise terrain generation ✅️ (water, caves, etc) 🏗️
  • Infinite worlds, possibly vertically too 🏗️
  • Mobs and multiplayer (this would require changing the rendering engine to some degree) 🏗️
  • Day/night ✅️

✅️ - got that!

🏗️ - not yet...

Dependencies

Bare minimum to make this code run

  • SDL2
  • A C compiler

To get it down to a small size, you need

  • gcc (have not tried the flags with other compilers)
  • gzexe

On windows, you will need

  • Mingw-w64 installed

Build instructions

Linux, unix, etc

  • To just get a binary, run make or make m4kc
  • To run an uncompressed version, run make run
  • To install the program, run make install
  • To uninstall, run make uninstall
  • To clean, run make clean

Windows

Run win-build.bat. Inside of the win directory, you will find m4kc.exe and SDL2.dll. In order for m4kc.exe to run, these two must be in the same folder.

Places

There is a forum thread for this project here

I will be uploading binaries here

FAQ

I've either been asked these, or I expect to be at some point.

What's with the cryptic variable names like f22 and i6?

A lot of this code is decompiled from the original java version, and those are names the compiler assigned to the variables.

Why is it so slow?

The game uses a 3D voxel raycaster to render things, which is a lot slower than more traditional methods of rendering. Luckily, C provides more powerful ways to optimize something like this than Java - and optimizations will keep coming.