Beispiel #1
0
        public Material GetBlock(int x, int y, int z)
        {
            int index = x * 16 * 16 + y * 16 + z;

            if (blocks[index] == 0)
            {
                return(null);
            }
            return(BlockTypes.GetMaterialProperties(blocks[index]).Material);
        }
Beispiel #2
0
        public bool SetBlock(int x, int y, int z, Material m)
        {
            MaterialBlock matProps = BlockTypes.GetMaterialProperties(m);

            int    index = x * 16 * 16 + y * 16 + z;
            ushort type  = m == null ? (ushort)0 : matProps.Id;

            if (blocks[index] == type)
            {
                return(false);
            }

            if ((blocks[index] == 0) != (type == 0))
            {
                if (type == 0)
                {
                    blockCount--;
                }
                else
                {
                    blockCount++;
                }
            }

            blocks[index]      = type;
            blockStates[index] = m == null ? (byte)0 : matProps.BlockState;

            MarkForRemesh();

            // Update nearby chunks
            {
                Chunk c;
                if (x == 15)
                {
                    c = GetNearbyChunk(0);
                    if (c != null)
                    {
                        c.MarkForRemesh();
                    }
                }
                if (x == 0)
                {
                    c = GetNearbyChunk(1);
                    if (c != null)
                    {
                        c.MarkForRemesh();
                    }
                }
                if (y == 15)
                {
                    c = GetNearbyChunk(2);
                    if (c != null)
                    {
                        c.MarkForRemesh();
                    }
                }
                if (y == 0)
                {
                    c = GetNearbyChunk(3);
                    if (c != null)
                    {
                        c.MarkForRemesh();
                    }
                }
                if (z == 15)
                {
                    c = GetNearbyChunk(4);
                    if (c != null)
                    {
                        c.MarkForRemesh();
                    }
                }
                if (z == 0)
                {
                    c = GetNearbyChunk(5);
                    if (c != null)
                    {
                        c.MarkForRemesh();
                    }
                }
            }

            return(true);
        }