Пример #1
0
        public override void WriteData(ByteBufferWriter bbw)
        {
            var count = 0;

            for (var y = 0; y < _grid.GetLength(1); y++)
            {
                for (var x = 0; x < _grid.GetLength(0); x++)
                {
                    if (_grid[x, y] is ItemStack stack && !stack.IsEmpty)
                    {
                        count++;
                    }
                }
            }

            bbw.WriteInt32(count);

            for (var y = 0; y < _grid.GetLength(1); y++)
            {
                for (var x = 0; x < _grid.GetLength(0); x++)
                {
                    if (_grid[x, y] is ItemStack stack && !stack.IsEmpty)
                    {
                        bbw.WriteInt32(x);
                        bbw.WriteInt32(y);
                        bbw.WriteInt32(stack.Meta);
                        bbw.WriteString(stack.Item.UnlocalizedName);
                    }
                }
            }
        }
Пример #2
0
        private void Save()
        {
            using (var fs = File.OpenWrite("map0.ssmap"))
            {
                var payload = new ByteBufferWriter(0);

                var floats = new List <float>();

                var count = 0;
                for (; count < _boxes.Count; count++)
                {
                    var box = _boxes[count];

                    floats.Add(box.Min.X);
                    floats.Add(box.Min.Y);
                    floats.Add(box.Max.X);
                    floats.Add(box.Max.Y);
                }

                payload.WriteInt32(count);

                foreach (var f in floats)
                {
                    payload.WriteFloat(f);
                }

                var data = payload.ToArray();

                fs.Write(data, 0, data.Length);
            }
        }
Пример #3
0
        private void writeDataByteBuffer(ByteBufferWriter writer, int index, object data)
        {
            Assert.IsNotNull(writer);
            Assert.IsNotNull(data);
            writer.WriteVarint32((uint)index);
            switch (index)
            {
            case 0:
                writer.WriteBool((bool)data);
                break;

            case 1:
                writer.WriteByte((byte)data);
                break;

            case 2:
                writer.WriteUint16((ushort)data);
                break;

            case 3:
                writer.WriteUint32((uint)data);
                break;

            case 4:
                writer.WriteUint64((ulong)data);
                break;

            case 5:
                writer.WriteInt16((short)data);
                break;

            case 6:
                writer.WriteInt32((int)data);
                break;

            case 7:
                writer.WriteInt64((long)data);
                break;

            case 8:
                writer.WriteVarint32((uint)data);
                break;

            case 9:
                writer.WriteVarint64((ulong)data);
                break;

            case 10:
                writer.WriteSVarint32((int)data);
                break;

            case 11:
                writer.WriteSVarint64((long)data);
                break;

            case 12:
                writer.WriteFloat((float)data);
                break;

            case 13:
                writer.WriteDouble((double)data);
                break;

            case 14:
                writer.WriteString((string)data);
                break;

            case 15: {
                var buffer = (byte[])data;
                writer.WriteVarint32((uint)buffer.Length);
                writer.WriteBuffer(buffer, 0, buffer.Length);
            }
            break;

            case 16: {
                writer.WriteVarint32((uint)(int)data);
                writer.Skip((int)data);
            }
            break;

            default:
                Assert.Fail();
                break;
            }
        }