Ejemplo n.º 1
0
        internal override bool IsAirBlock(int x, int y, int z)
        {
            var sec    = y >> 4;
            var blocks = _blocks[sec];

            if (blocks == null)
            {
                return(true);
            }

            var index = GetBlockIndexByCoord(x, y, z);

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

            if (_add[sec] != null)
            {
                if (EndianHelper.GetHalfInt(_add[sec], index) != 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get block's Id and data at a given coordinate
        /// </summary>
        /// <param name="x">World X</param>
        /// <param name="y">World Y</param>
        /// <param name="z">World Z</param>
        /// <returns>Block</returns>
        public ClassicBlock GetBlock(int x, int y, int z)
        {
            var sec    = y >> 4;
            var data   = 0;
            var blocks = _blocks[sec];

            if (blocks == null)
            {
                return(ClassicBlock.AirBlock);
            }

            var index   = GetBlockIndexByCoord(x, y, z);
            var blockId = (int)blocks[index];

            if (_add[sec] != null)
            {
                blockId += (EndianHelper.GetHalfInt(_add[sec], index) << 8);
            }
            if (_data[sec] != null)
            {
                data = EndianHelper.GetHalfInt(_data[sec], index);
            }

            return(new ClassicBlock
            {
                Id = blockId,
                Data = data
            });
        }
Ejemplo n.º 3
0
        public void HalfIntMalformedDataTest()
        {
            var bytes = new byte[16];

            for (var i = 0; i < 32; i++)
            {
                EndianHelper.SetHalfInt(bytes, i, BaseData[i]);
            }

            const int indexUnderflow = 5;
            const int indexOverflow  = 9;

            const int underflow = -999;
            const int overflow  = 999;

            EndianHelper.SetHalfInt(bytes, indexUnderflow, underflow);
            EndianHelper.SetHalfInt(bytes, indexOverflow, overflow);

            for (var i = 0; i < 32; i++)
            {
                if (i == indexUnderflow)
                {
                    Assert.AreEqual(EndianHelper.GetHalfInt(bytes, i), underflow & 0xf);
                }
                else if (i == indexOverflow)
                {
                    Assert.AreEqual(EndianHelper.GetHalfInt(bytes, i), overflow & 0xf);
                }
                else
                {
                    Assert.AreEqual(EndianHelper.GetHalfInt(bytes, i), BaseData[i]);
                }
            }
        }
Ejemplo n.º 4
0
        public void HalfIntTest()
        {
            var bytes = new byte[16];

            for (var i = 0; i < 32; i++)
            {
                EndianHelper.SetHalfInt(bytes, i, BaseData[i]);
            }

            for (var i = 0; i < 32; i++)
            {
                Assert.AreEqual(EndianHelper.GetHalfInt(bytes, i), BaseData[i]);
            }
        }
Ejemplo n.º 5
0
        public void DynBitArrayEquivalentTest()
        {
            var bytes = new byte[16];

            for (var i = 0; i < 32; i++)
            {
                EndianHelper.SetHalfInt(bytes, i, BaseData[i]);
            }

            var dynarray = DynBitArray.CreateFromByteArray(bytes, 4);

            Assert.AreEqual(32, dynarray.Length);

            for (var i = 0; i < 32; i++)
            {
                Assert.AreEqual(dynarray[i], EndianHelper.GetHalfInt(bytes, i));
            }
        }
Ejemplo n.º 6
0
        public void HalfIntInternalMethodTest()
        {
            var bytes = new byte[16];

            for (var i = 0; i < 32; i++)
            {
                EndianHelper.SetHalfInt(bytes, i, BaseData[i]);
            }

            var methodOdd  = typeof(EndianHelper).GetMethod("GetHalfIntOddIndex", BindingFlags.Static | BindingFlags.NonPublic);
            var methodEven = typeof(EndianHelper).GetMethod("GetHalfIntEvenIndex", BindingFlags.Static | BindingFlags.NonPublic);

            for (var i = 0; i < 32; i++)
            {
                var result = (int)((i % 2 == 0) ? methodEven : methodOdd).Invoke(null, new object[] { bytes, i });
                Assert.AreEqual(EndianHelper.GetHalfInt(bytes, i), result);
            }
        }