Example #1
0
    public static byte GetSkyLightByte(int x, int y, int z)
    {
        int chunkX = Mathf.FloorToInt(x / 16f);
        int chunkZ = Mathf.FloorToInt(z / 16f);

        int xInChunk = x - chunkX * 16;
        int zInChunk = z - chunkZ * 16;

        NBTChunk chunk = GetChunk(chunkX, chunkZ);

        return(chunk.GetSkyLightByte(xInChunk, y, zInChunk));
    }
Example #2
0
    public byte GetSkyLightByte(int xInChunk, int yInChunk, int zInChunk, bool extends = false)
    {
        if (xInChunk < 0 || xInChunk > 15 || zInChunk < 0 || zInChunk > 15)
        {
            if (extends)
            {
                int xOffset = 0;
                int zOffset = 0;

                if (xInChunk < 0)
                {
                    xOffset = -1;
                }
                else if (xInChunk > 15)
                {
                    xOffset = 1;
                }

                if (zInChunk < 0)
                {
                    zOffset = -1;
                }
                else if (zInChunk > 15)
                {
                    zOffset = 1;
                }

                NBTChunk chunk = NBTHelper.GetChunk(x + xOffset, z + zOffset);
                if (chunk != null)
                {
                    return(chunk.GetSkyLightByte(xInChunk - xOffset * 16, yInChunk, zInChunk - zOffset * 16));
                }
                else
                {
                    return(15);
                }
            }
            else
            {
                return(15);
            }
        }


        int sectionIndex = yInChunk / 16;

        if (sectionIndex >= Sections.Count || yInChunk < 0 || yInChunk > 255)
        {
            return(15);
        }

        int yInSection = yInChunk % 16;
        int blockPos   = yInSection * 16 * 16 + zInChunk * 16 + xInChunk;

        TagNodeCompound  Section  = Sections[sectionIndex] as TagNodeCompound;
        TagNodeByteArray SkyLight = Section["SkyLight"] as TagNodeByteArray;
        byte             skyLight = NBTHelper.GetNibble(SkyLight.Data, blockPos);

        //Debug.Log("y=" + x + "," + z + ",section=" + sectionIndex);

        return(skyLight);
    }