Example #1
0
    public void GetLightsByte(int xInChunk, int yInChunk, int zInChunk, out byte skyLight, out byte blockLight, bool extends = false)
    {
        skyLight   = 15;
        blockLight = 0;
        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)
                {
                    chunk.GetLightsByte(xInChunk - xOffset * 16, yInChunk, zInChunk - zOffset * 16, out skyLight, out blockLight);
                }
            }
            return;
        }

        int sectionIndex = yInChunk / 16;

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

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

        TagNodeCompound  Section  = Sections[sectionIndex] as TagNodeCompound;
        TagNodeByteArray SkyLight = Section["SkyLight"] as TagNodeByteArray;

        skyLight = NBTHelper.GetNibble(SkyLight.Data, blockPos);
        TagNodeByteArray BlockLight = Section["BlockLight"] as TagNodeByteArray;

        blockLight = NBTHelper.GetNibble(BlockLight.Data, blockPos);
    }
Example #2
0
    public static void GetLightsByte(int x, int y, int z, out byte skyLight, out byte blockLight)
    {
        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);

        chunk.GetLightsByte(xInChunk, y, zInChunk, out skyLight, out blockLight);
    }
Example #3
0
    BlockLightAttributes InitBlockLightAttributes(NBTChunk chunk, int xInChunk, int worldY, int zInChunk)
    {
        BlockLightAttributes bla = new BlockLightAttributes();

        bla.exist = chunk.HasOpaqueBlock(xInChunk, worldY, zInChunk) ? HAS_BLOCK : NO_BLOCK;
        if (bla.exist == 0)
        {
            chunk.GetLightsByte(xInChunk, worldY, zInChunk, out bla.skyLight, out bla.blockLight, true);
        }
        else
        {
            bla.skyLight   = 0;
            bla.blockLight = 0;
        }
        return(bla);
    }