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



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...


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


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.


There is a forum thread for this project here

I will be uploading binaries here


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.

  • Player coordinates are stored incorrectly

    Player coordinates are stored incorrectly

    Player coordinates are offset by 64. I believe this behavior was present in the original java version, to offset the broken rendering in negatives so that it did not appear in the world. The broken rendering can be mitigated by increasing this offset.

    However, the player struct currently stores this these offset values. It should not do this, instead the values should be offset when rendering is taking place.

    The player struct should store the real values because more things need the real values than the offset ones.

    opened by sashakoshka 2
  • Player can get stuck in placed blocks in chunks that are not at 0, 0, 0

    Player can get stuck in placed blocks in chunks that are not at 0, 0, 0

    This is part of a larger ongoing issue where the way the game disallows players from placing blocks inside of themselves is by immediately deleting the block. This no longer works with the new terrain system, and it will be replaced by simply preventing the block from being placed.

    opened by sashakoshka 2
  • Player position does not load/save properly on Windows

    Player position does not load/save properly on Windows

    Occasionally when creating a world the player spawns in stone, and the player position seems to reset after restarting the program and reopening the world. Needs further investigation.

    opened by sashakoshka 1
  • Underside of stone and water blocks are too dark, and have holes

    Underside of stone and water blocks are too dark, and have holes


    This seems to be caused by the code that darkens the bottoms of block textures. When it is removed, their undersides look normal (too bright of course, but normal).

    However this only happens on stone and water. Another thing of note is that the "streaking" noise no longer applies on the bottoms of these blocks as it should.

    opened by sashakoshka 1
  • Some chunks are unwilling to generate structures

    Some chunks are unwilling to generate structures

    Significant lack of trees in most chunks. I feel like this has to do with the way it checks whether or not to generate structures based on the heightmap.

    Screenshot from 2021-05-13 22-36-37

    opened by sashakoshka 1
  • Fix 'sticky' block collisions

    Fix 'sticky' block collisions

    Fixes the issue of players being able to stick to walls and not being able to move to the side when running into a block.

    The cause: From what I managed to understand, the 'm' variable is essentially the axis along which the collisions are being checked, 0 -> x 1 -> y 2 -> z, during the check for each axis, the multiplier for the velocity and thus the players future position is moved depending on the value of m.

    If we write out the values by which the speed is multiplied (excluding the / 2) we get the following sequence:

    x -> 2, 0, 1 y -> 1, 2, 0 z -> 2, 0, 1

    Means the checks for whether we collide along the x or the z axis are the same, thus blocking players movement to the side when running into a block.

    Adding a 1 moves the sequence and fixes the issue: z -> 0, 1, 2

    The issue of players being able to stick to walls was caused by the fact that we essentially skip the check along the other axis due to the label208's location

    opened by Tempetas 0
  • Implement basic screenshot functionality

    Implement basic screenshot functionality

    Fixes screenshots not working, the check for the F2 key had to be moved up in the code for it to be able to use the framebuffer before it gets cleared

    opened by Tempetas 0
  • Renderer bugs out in the negatives

    Renderer bugs out in the negatives

    Anything past -64 on any axis becomes distorted. Issue is independent of whether gameLoop uses doubles or floats. May have something to do with modulo.

    This does not pose a problem yet unless the code is edited to loop the world, but it will affect the game once infinite terrain is added.

    Screenshot from 2021-05-11 00-28-48

    opened by sashakoshka 2
  • v0.7(May 7, 2022)

    Version 0.7

    Relax on a procedurally generated beach by an opaque lake in this summer update!

    New Features

    • Twisting, winding caves can be found at the bottoms of chunks
    • Worlds can be saved, loaded, and deleted
    • Options are now saved, and there are many more of them
    • You can now take screenshots of your world by pressing F2
    • Many new blocks
    • Highly configurable world creation menu
      • Different terrain types (including classic terrain)
      • Specify a seed (or leave blank for a random one)
      • Choose between a daylight cycle, always day, or always night
    • Inventory system added
      • Swap items into an offhand slot
      • Breaking blocks adds them to your inventory, placing them removes them from your inventory
      • Reorganize your inventory by picking up and placing down stacks of items
    • Bodies of water naturally generate
      • Water is surrounded by sand
      • You can swim through water
      • Going inside of water reduces FOV and tints the screen blue

    Bug fixes

    • "Sticky" collision has been eliminated, walking is a lot smoother now
    • Structures will now generate in all chunks
    • It is no longer possible to become stuck inside of a block

    What it looks like

    View of the sea World selection menu Brick house Underwater

    Source code(tar.gz)
    Source code(zip)
    M4KC-0.7-linux64.zip(22.30 KB)
    M4KC-0.7-win64.zip(625.45 KB)
  • v0.6(May 13, 2021)

    Version 0.6

    This update brings many technological improvements. Countless hours of debugging went into this :)

    List of changes

    • Terrain has gone from being 64x64x64 to 192x192x192
    • The way that the system generates and stores chunks in memory has been completely changed:
      • Chunks are now stored as sorted structs with a pointer to a blocks array that is allocated upon generation
      • There are currently 27 of them in a 3x3x3 grid
      • They are automatically sorted, and are looked up using a binary search algorithm
    • Debug screen has been redesigned, and shows more info
    • A special debug menu was added to options that provides a 3D xrayable map of the current chunk
    • Terrain generation is far more varied in terms of height

    What it looks like

    Screenshot from 2021-05-13 19-54-13 Screenshot from 2021-05-13 19-55-16 Screenshot from 2021-05-13 19-55-36 Screenshot from 2021-05-13 19-56-25 Screenshot from 2021-05-13 19-56-37

    Source code(tar.gz)
    Source code(zip)
    m4kc(12.39 KB)
    M4KC-0.6-win64.zip(608.36 KB)
  • v0.5(May 11, 2021)

    Version 0.5

    Windows and Linux downloads have been attached. This is the first release to have a windows binary in addition to the Linux version!

    List of changes

    • Many internal changes in preparation for infinite terrain
    • Working options menu
    • View distance can now be changed
    • There is now an option to capture the mouse and use it like normal minecraft, but it is very unpolished at the moment
    • HUD can be toggled with F1
    • Debug screen can be toggled with F3

    What it looks like

    Screenshot from 2021-05-10 22-55-29

    Source code(tar.gz)
    Source code(zip)
    m4kc(10.00 KB)
    M4KC-0.5-win64.zip(605.80 KB)
  • v0.4(May 9, 2021)

    Version 0.4

    List of changes

    • Slightly enhanced performance
    • Trees and pyramids now randomly generate
    • Day and night cycle, with smooth transitions between both

    The game is approaching 10 KB, will probably have to make the goal under 16 KB in order to fit more features in.

    What it looks like

    Screenshot from 2021-05-09 18-59-56

    Source code(tar.gz)
    Source code(zip)
    m4kc(9.17 KB)
  • v0.3(May 9, 2021)

    Version 0.3

    List of changes

    • Enhanced performance
    • A basic user interface (pause menu, hotbar)
    • Two terrain generation options (must edit source code for now)
    • Ability to place any block currently in the game

    ...while still being under 10 kilobytes!

    Source code(tar.gz)
    Source code(zip)
    m4kc(7.76 KB)
Sasha Koshka
Sasha Koshka
A custom launcher for Minecraft that allows you to easily manage multiple installations of Minecraft at once (Fork of MultiMC)

PolyMC is a custom launcher for Minecraft that focuses on predictability, long term stability and simplicity. This is a fork of the MultiMC Launcher a

null 1.7k Dec 4, 2022
A library for high-performance, modern 2D graphics with SDL written in C.

SDL_gpu, a library for making hardware-accelerated 2D graphics easy. by Jonathan Dearborn SDL_gpu is licensed under the terms of the MIT License. See

Jonathan Dearborn 1.1k Nov 30, 2022
A minecraft clone built in c++ opengl for the purpose of prefecting graphics programming skills.

LearnOpenGL - CLion This is a project template for OpenGL development with JetBrains CLion IDE. It was created mainly for LearnOpenGL tutorials. Inclu

Jeremy Dellock 1 Dec 28, 2021
A game console based upon custom hardware.

handheld-game-console A handheld game console that has custom games. The base of the console is an ESP-WROOM-32 DEVKITV1. The display used is an ili94

Builder212 1 Jul 30, 2022
A very simple 2D game engine written in C++, using SDL and Lua.

2D Game Engine written in C++, SDL, and Lua. This is a simple 2D game engine written in C++ and using SDL and Lua scripting

Gustavo Pezzi 22 Oct 31, 2022
A demo test game made from scratch using C++ and SDL

Dethroning Table of contents About This Game How to Compile the game About This Game This is a Cross-Platform Game Demo. How to Compile the game Run t

Haider Mirza 1 Jan 21, 2022
Cross-platform version of Heboris C7EX using a hardware-accelerated SDL 2.0 renderer

Heboris C7EX - unofficial version (YGS2K EX) This version contains the source code for Heboris C7EX. It requires a C compiler, SDL 2.0, SDL 2.0 mixer,

Brandon McGriff 14 Nov 27, 2022
A simple game framework written in C++ using SDL

SGF SGF (Simple Game Framework) is, as the name implies; a very simple and easy to use game framework written in C++ using SDL. Currently the project

Cam K. 1 Nov 4, 2021
Improved version of the X-Ray Engine, the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World.

OpenXRay OpenXRay is an improved version of the X-Ray Engine, the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World. S

null 2.2k Dec 2, 2022
A Binary Clock. Written 3 different ways. C and SDL, Python and PyGame, Python and PyGame Zero.

Super Clock A Binary Clock. Written 3 different ways. Python with PyGame Zero, Python with PyGame and C with SDL2. Time is displayed in 3 groups of 8

null 3 Dec 8, 2021
Simple Directmedia Layer, 1.2 branch ... ***DEPRECATED***, please use https://github.com/libsdl-org/SDL for new projects!

DEPRECATED The 1.2 branch of SDL is deprecated. While we occasionally collect fixes in revision control, there has not been a formal release since 201

Simple Directmedia Layer 52 Dec 2, 2022
sdl based game framework

Hallow Engine an sdl-based game framework Install Procedure Install SDL2[https://libsdl.org] and take the .h(header) files from the include/ folder, t

Hallow - The Game Framework 6 Nov 24, 2021
Raycaster demo in SDL, inspired by 3DSage

raycastersdl -Coded following 3DSage's tutorial. Part 1 -> https://www.youtube.com/watch?v=gYRrGTC7GtA Remeber to install SDL2 libraries first: sudo a

Velorek1 1 Oct 30, 2021
Simple DirectMedia Layer (SDL) 1.2 for Symbian S60v1 devices such as the Nokia N-Gage.

SDL 1.2 Even though SDL 1.2 is outdated and officially no longer supported, this is an attempt to get it running on Symbian S60v1 devices such as the

N-Gage SDK. 4 Apr 4, 2022
Minecraft Classic 0.0.30a reimplemented in C.

MinecraftC - A 0.0.30a implementation in C Features True to the original version Implemented fully in C using SDL2 and OpenGL 1.1 Two different binari

John Payne 228 Nov 27, 2022
Replace Minecraft entity with MMD model.

KAIMyEntity Replace Minecraft entity with MMD model. KAIMyEntitySaba 将Github项目 benikabocha/saba (https://github.com/benikabocha/saba) 魔改成一个以JNI形式Expor

null 30 Oct 16, 2022
A simplified version of the famous game Minecraft.

This program uses the concept of the famous game Minecraft but with better graphics. It procedurally generates an infinite world, the player has an animated character and can break blocks, there are also different biomes and mobs.

Angel Uriot 57 Nov 21, 2022
A voxel game/Minecraft clone for the iCE40 UP5K FPGA

FPGA craft A voxel game/Minecraft clone for the iCE40 UP5K FPGA (for the iCEBreaker board). Disclaimer Use this project at your own risk. This project

null 166 Nov 27, 2022
A Minecraft-clone written in C++/Vulkan

Minecraft A Minecraft-clone written in C++/Vulkan Current state It is currently very bare-bones. Planned features Textures Procedural generation Colli

null 4 Feb 27, 2022