private void RenderChunk(Chunk c, Bitmap b, int offsetX, int offsetY)
{
int[] heightmap = (int[])c.Root["Level"]["HeightMap"];
TAG_Compound[] sections = new TAG_Compound[16];
int highest = -1;
foreach (TAG t in (TAG[])c.Root["Level"]["Sections"])
{
byte index = (byte)t["Y"];
if (index > highest)
highest = index;
sections[index] = (TAG_Compound)t;
}
//chunk exists but all blocks are air
if (highest < 0)
return;
highest = ((highest + 1) * 16) - 1;
if (highest > UpperLimit)
highest = UpperLimit;
if (highest < LowerLimit)
highest = LowerLimit;
TAG biomes = null;
c.Root["Level"].TryGetValue("Biomes", out biomes);
for (int z = 0; z < 16; z++)
{
for (int x = 0; x < 16; x++)
{
int y = GetHeight(sections, x, z, highest, LowerLimit, Only, Exclude);
if (y < LowerLimit)
continue;
byte id, data;
GetBlock(sections, x, y, z, out id, out data);
byte biome = 255;
if(ConsiderBiomes && biomes != null)
biome = ((byte[])biomes)[x + z * 16];
Color color = ColorPalette.Lookup(id, data, biome);
if (Transparency)
{
y--;
while (color.A < 255 && y >= LowerLimit)
{
GetBlock(sections, x, y, z, out id, out data);
if (Only != null && !Only.Contains(id))
id = 0;
if (Exclude != null && Exclude.Contains(id))
id = 0;
Color c2 = ColorPalette.Lookup(id, data, biome);
color = Blend(color, c2);
y--;
}
}
else
color = Color.FromArgb(255, color.R, color.G, color.B);
if (ShowHeight)
{
//brighten/darken by height; arbitrary value, but /seems/ to look okay
color = AddtoColor(color, (int)(y / 1.7 - 42));
}
b.SetPixel(offsetX + x, offsetY + z, color);
}
}
}