コード例 #1
0
    public void SetSkyLightByte(int xInChunk, int yInChunk, int zInChunk, byte skyLight, 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)
                {
                    chunk.SetSkyLightByte(xInChunk - xOffset * 16, yInChunk, zInChunk - zOffset * 16, skyLight);
                }
            }
            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;

        NBTHelper.SetNibble(SkyLight.Data, blockPos, skyLight);
    }
コード例 #2
0
    //input is local position
    public void SetBlockData(int xInChunk, int worldY, int zInChunk, byte type, byte data)
    {
        int sectionIndex = Mathf.FloorToInt(worldY / 16f);

        if (sectionIndex >= 0 && sectionIndex < Sections.Count)
        {
            TagNodeCompound  section = Sections[sectionIndex] as TagNodeCompound;
            TagNodeByteArray Blocks  = section["Blocks"] as TagNodeByteArray;
            TagNodeByteArray Data    = section["Data"] as TagNodeByteArray;

            int yInSection = worldY - sectionIndex * 16;
            int blockPos   = yInSection * 16 * 16 + zInChunk * 16 + xInChunk;

            if (blockPos >= 0 && blockPos < 4096)
            {
                Blocks.Data[blockPos] = type;
                NBTHelper.SetNibble(Data.Data, blockPos, data);
            }
        }
    }