public void SetBlock(int x, int y, int z, ClassicBlock block) { var sec = y >> 4; var blocks = _blocks[sec]; if (blocks == null) { _blocks[sec] = blocks = new byte[4096]; } var index = GetBlockIndexByCoord(x, y, z); blocks[index] = unchecked ((byte)(block.Id & 0xff)); if (block.Id >= 256) { if (_add[sec] == null) { _add[sec] = new byte[2048]; } EndianHelper.SetHalfInt(_add[sec], index, block.Id >> 8); } if (block.Data != 0) { if (_data[sec] == null) { _data[sec] = new byte[2048]; } EndianHelper.SetHalfInt(_data[sec], index, block.Data); } }
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]); } } }
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]); } }
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)); } }
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); } }