4

I am thinking of something like a 3x3 matrix for each of the x,y,z coordinates. But that would be a waste of memory since a lot of block spaces are empty. Another solution would be to have a hashmap ((x,y,z) -> BlockObject), but that doesn't seem too efficient either.

When I say efficient, I do not mean optimal. It simply means that it would be enough to run smoothly on your modern day computer. Keep in mind, that the worlds generated by minecraft are quite huge, efficiency is important regardless. There's is also tons of meta-data that needs to be stored.

TheOne
  • 10,819
  • 20
  • 81
  • 119
  • What makes this "not a real question"? – TheOne Feb 05 '12 at 19:06
  • This probably belongs at http://gamedev.stackexchange.com – Paul Feb 05 '12 at 19:06
  • 3
    All those stackoverflow derivatives are starting to turn into a pain in the a**. There's a new one out everyday. – TheOne Feb 05 '12 at 19:09
  • Requesting to move this question to the appropriate stackexchange site. – TheOne Feb 05 '12 at 19:13
  • I won't disagree with you there...there's too much fragmentation in the SE world, though game development is a good choice to have as a separate community. – Paul Feb 05 '12 at 19:15
  • 1
    One thing that makes this "not a real question" is that you are asking two separate questions, not just one. (And, beyond that, "how does minecraft efficiently render the world?" is a vague question that requires an essay to answer reasonably.) The other thing that makes it not a real "programming" question is that it's very localized to a specific closed-source program which very few of us have access to, and thus is unlikely to get a real answer. Asking, "What are the standard data structures for storing this sort of data?" is a much more answerable question. – Brooks Moses Feb 05 '12 at 19:23
  • @BrooksMoses thanks for the suggestion. Regarding the "openness" of the source, a simple java decompiler would suffice. Not sure about the legality of that. :) Notch is fine with his game being pirated, so it shouldn't cause too much trouble. – TheOne Feb 11 '12 at 14:16

4 Answers4

3

As noted in my comment, I have no idea how MineCraft does this, but a common efficient way of representing this sort of data is an Octree; http://en.wikipedia.org/wiki/Octree. The general idea is that it's like a binary tree but in three-space. You recursively divide each block of space in each dimension to get eight smaller blocks, and each block contains the pointers to the smaller blocks and a pointer to its parent block.

This allows you to be efficient about storing large blocks of the same material (e.g., "empty space"), because you can terminate the recursion whenever you get to a block that is made up of all the same thing, even if you haven't recursed down to the level of individual "cube" units.

Also, this means that you can efficiently find all the cubes in a given region by taking your current block and going up the tree just far enough to get to a block that contains all you can see -- and that way, you can very easily ignore all the cubes that are somewhere else.

Brooks Moses
  • 9,267
  • 2
  • 33
  • 57
1

If you're interested in exploring alternative means to represent Minecraft world (chunk)data, you can also look into the idea of bitstrings. Each 'chunk' is comprised of a volume 16*16*128, whereas 16*16 can adequately be represented by a single byte character and can be consolidated into a binary string.

As this approach is highly specific to a certain goal of trading client-computation vs highly optimized storage and transfer time, it seems imprudent to attempt to explain all the details, but I have created a specification for just this purpose, if you're interested.

Using this method, calculating storage cost is drastically different than the current 1byte-per-block, but instead is 'variable-bit-rate': ((1bit-per-block, rounded up to a multiple of 8) * (number of unique layers a blocktype appears in a chunk) + 2bytes)

This is then summed for the (unique number of blocktypes in that chunk).

Pretty much only in deliberate edgecases can this be more expensive than a normally structured chunk, in excess of 99% of Minecraft chunks are naturally generated and would benefit from this variable-bit-representation by a ratio of 8:1 or more in many of my tests.

hexparrot
  • 3,399
  • 1
  • 24
  • 33
0

Your best bet is to decompile Minecraft and look at the source. Modifying Minecraft: The Source Code is a nice walkthrough on how to do that.

Paul
  • 19,704
  • 14
  • 78
  • 96
-1

Minecraft is very far from efficent. It just stores "chunks" of data.

Check out the "Map formats" in the Development Resources at Minecraft Wiki. AFAIK, the internal representation is exactly the same.

kaoD
  • 1,534
  • 14
  • 25