Пример #1
0
        public void FloorTest()
        {
            const int max = 1000;

            var r = new Random(102);

            for (var i = 0; i < 30; i++)
            {
                var v = new Vector3(r.NextFloat() * max, r.NextFloat() * max, r.NextFloat() * max);
                var c = v.Floor();
                Assert.AreEqual(Math.Floor(v.X), c.X);
                Assert.AreEqual(Math.Floor(v.Y), c.Y);
                Assert.AreEqual(Math.Floor(v.Z), c.Z);
            }
        }
Пример #2
0
        /// <summary>
        /// Sets the block at the given local position.
        /// </summary>
        public void SetBlock(Vector3 position, Block value)
        {
            position = position.Floor();
            Vector3 relativePosition = position;
            position.X = (int)(position.X) / Chunk.Width;
            position.Y = 0;
            position.Z = (int)(position.Z) / Chunk.Depth;

            relativePosition.X = (int)(relativePosition.X) % Chunk.Width;
            relativePosition.Z = (int)(relativePosition.Z) % Chunk.Depth;

            if (!Chunks.ContainsKey(position))
                Chunks.Add(position, WorldGenerator.GenerateChunk(position, this));

            Chunks[position].SetBlock(relativePosition, value);
        }
Пример #3
0
        /// <summary>
        /// Sets a block in this chunk.
        /// </summary>
        /// <param name="pos">The position in local coordinates.</param>
        /// <param name="block">The block to set.</param>
        /// <remarks></remarks>
        public virtual void SetBlock(Vector3 pos, Block block)
        {
            int x = (int)pos.X;
            int y = (int)pos.Y;
            int z = (int)pos.Z;
            int index = x + (z * Width) + (y * Height * Width);
            Metadata[index] = block.Metadata;
            Blocks[index] = block;
            if (block.AdditionalData == null)
            {
                if (AdditionalData.ContainsKey(pos.Floor()))
                    AdditionalData.Remove(pos.Floor());
            }
            if (block.AdditionalData != null)
                AdditionalData[pos.Floor()] = new byte[] {
                    block.AdditionalData.BlockID }.Concat(block.AdditionalData.Serialize()).ToArray();

            if (!(block is AirBlock))
                IsAir = false;
            else
            {
                IsAir = true;
                for (int i = 0; i < Blocks.Length; i++)
                {
                    if (Blocks[i] != 0)
                    {
                        IsAir = false;
                        break;
                    }
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Gets a block from this chunk.
 /// </summary>
 /// <param name="pos">The position, in local chunk coordinates.</param>
 /// <returns>The specified block.</returns>
 /// <remarks></remarks>
 public virtual Block GetBlock(Vector3 pos)
 {
     if (IsAir)
         return new AirBlock();
     int x = (int)pos.X;
     int y = (int)pos.Y;
     int z = (int)pos.Z;
     int index = x + (z * Width) + (y * Height * Width);
     Block b = Blocks[index];
     b.Metadata = Metadata[index];
     if (AdditionalData.ContainsKey(pos.Floor()))
         b.AdditionalData.Deseralize(AdditionalData[pos.Floor()].Skip(1).ToArray());
     return b;
 }