public void TestWorldItemPacket() { Serial serial = 0x1000; var itemId = 1; // Move to fixture TileData.ItemTable[itemId] = new ItemData( "Test Item Data", TileFlag.Generic, 1, 1, 1, 1, 1 ); var item = new Item(serial) { ItemID = itemId, Hue = 0x1024, Amount = 10, Location = new Point3D(1000, 100, -10), Direction = Direction.Left }; var data = new WorldItem(item).Compile(); Span <byte> expectedData = stackalloc byte[20]; // Max size var pos = 0; expectedData.Write(ref pos, (byte)0x1A); pos += 2; // Length if (item.Amount != 0) { expectedData.Write(ref pos, serial | 0x80000000); } else { expectedData.Write(ref pos, serial & 0x7FFFFFFF); } if (item is BaseMulti) { expectedData.Write(ref pos, (ushort)(item.ItemID | 0x4000)); } else { expectedData.Write(ref pos, (ushort)item.ItemID); } if (item.Amount != 0) { expectedData.Write(ref pos, (ushort)item.Amount); } var direction = (byte)item.Direction; var x = (ushort)(item.X & 0x7FFF); if (direction != 0) { x |= 0x8000; } expectedData.Write(ref pos, x); var hue = item.Hue; var flags = item.GetPacketFlags(); var y = (ushort)(item.Y & 0x3FFF); if (hue != 0) { y |= 0x8000; } if (flags != 0) { y |= 0x4000; } expectedData.Write(ref pos, y); if (direction != 0) { expectedData.Write(ref pos, direction); } expectedData.Write(ref pos, (byte)item.Z); if (hue != 0) { expectedData.Write(ref pos, (ushort)hue); } if (flags != 0) { expectedData.Write(ref pos, (byte)flags); } // Length expectedData.Slice(1, 2).Write((ushort)pos); // Slice the data to match in size data = data.Slice(0, pos); AssertThat.Equal(data, expectedData); }