updated "Assembling a chunk" section for anvil format
This commit is contained in:
@@ -344,39 +344,24 @@ So the total size of a chunk section in pixels is 384 wide by 384 tall.
|
|||||||
|
|
||||||
Assembling a Chunk
|
Assembling a Chunk
|
||||||
------------------
|
------------------
|
||||||
Now that we know how to place blocks, assembling the chunk is a relatively
|
|
||||||
simple process. Frist, create an image 384 by 1728 pixels. Then, paste the
|
|
||||||
blocks in order from back to front, bottom to top. This ensures that block
|
|
||||||
visually closer to the viewer are drawn on top, while blocks that should be
|
|
||||||
obstructed are drawn first and get hidden.
|
|
||||||
|
|
||||||
From the data file on disk, block information in a chunk is a three-dimensional
|
Now that we know how to place blocks, here's how they are arranged to form an
|
||||||
array of bytes, each representing a `block id
|
entire chunk section. The coordinate system is arranged as shown, with the
|
||||||
<http://www.minecraftwiki.net/wiki/Data_values#Block_IDs_.28Minecraft_Beta.29>`_.
|
origin being at the left corner.
|
||||||
The process of assembling a chunk is essentially reading these values, looking
|
|
||||||
up the appropriate pre-rendered image representing that block type, and pasting
|
|
||||||
it on the chunk image at the appropriate location.
|
|
||||||
|
|
||||||
First, a bit about how blocks are addressed in a chunk. Consider this diagram of
|
|
||||||
the *bottom* layer of a chunk: Y=0.
|
|
||||||
|
|
||||||
.. image:: cubepositionimgs/chunk_coords.png
|
.. image:: cubepositionimgs/chunk_coords.png
|
||||||
:alt: Illustrating how cubes are addressed in a chunk
|
:alt: Illustrating how cubes are addressed in a chunk
|
||||||
|
|
||||||
The 16x128x16 array of block is iterated over. The inner loop iterates over the
|
To ensure that block closer to the viewer are drawn on top while blocks that
|
||||||
Y axis from bottom to top, the middle loop iterates over the Z axis from 0 to
|
should be obstructed are drawn are hidden, the blocks are drawn one layer at a
|
||||||
15, and the outer loop iterates over the X axis from 15 down to 0.
|
time from bottom to top (Y=0 to Y=15) and from back to front.
|
||||||
|
|
||||||
.. note::
|
From the data file on disk, block information in a chunk is a three-dimensional
|
||||||
|
array of bytes, each representing a `block id
|
||||||
The iteration happens in ``iterate.c`` in the :c:func:`chunk_render`
|
<http://www.minecraftwiki.net/wiki/Data_values#Block_IDs_.28Minecraft_Beta.29>`_.
|
||||||
function. In the code, the Y and Z axes are switched in name only. (oops)
|
The process of assembling a chunk is simply a matter of iterating over this
|
||||||
|
array, reading the blockid values, looking up the appropriate sprite, and
|
||||||
In other words, the column of blocks at X=15, Z=0 is drawn from bottom to top.
|
pasting it on the chunk image at the appropriate location.
|
||||||
Then the next column over on the Z axis (X=15, Z=1) is drawn, and so fourth
|
|
||||||
until the entire plane of cubes at X=15 is drawn (the upper-right face). Then it
|
|
||||||
starts with the next plane at X=14, and so fourth until the entire chunk is
|
|
||||||
drawn.
|
|
||||||
|
|
||||||
Tile Rendering
|
Tile Rendering
|
||||||
==============
|
==============
|
||||||
|
|||||||
Reference in New Issue
Block a user