Example #1
0
        public override Block Read()
        {
            var v     = new MinecraftVarInt(Stream).Read();
            var value = Block.GetBlock(v);

            return(value);
        }
Example #2
0
        public override Metadata Read()
        {
            var v    = new Metadata();
            var v2   = new Dictionary <int, Metadata.MetadataInfo>();
            var vi   = new MinecraftVarInt(Stream);
            var b    = new MinecraftByte(Stream);
            var func = typeof(MinecraftPacket).GetMethod("ReadFromStream");

            while (true)
            {
                byte val = b.Read();
                if (val == 0xff)
                {
                    break;
                }
                var t = Types.Forward[vi.Read()];
                v2.Add(val, new Metadata.MetadataInfo()
                {
                    Type  = t,
                    value = func.MakeGenericMethod(t).Invoke(null, new object[] { Stream })
                });
            }
            v.Infos = v2;
            return(v);
        }
Example #3
0
        public override String Read()
        {
            Int32 length = new MinecraftVarInt(Stream).Read();

            if (length == 0)
            {
                return(string.Empty);
            }
            var data  = new MinecraftByte(Stream).ReadArray(length);
            var value = Encoding.UTF8.GetString(data);

            return(value);
        }
Example #4
0
        public override void Write(Metadata value)
        {
            var vi   = new MinecraftVarInt(Stream);
            var b    = new MinecraftByte(Stream);
            var func = typeof(MinecraftPacket).GetMethod("WriteToStream", BindingFlags.Static | BindingFlags.Public);
            var f2   = typeof(MinecraftMetadata).GetMethod("C", BindingFlags.Static | BindingFlags.Public);

            foreach (var v in value.Infos)
            {
                b.Write((byte)v.Key);
                vi.Write(Types.Reverse[v.Value.Type]);
                var v2 = f2.MakeGenericMethod(v.Value.Type).Invoke(null, new object[] { v.Value.value });
                func.MakeGenericMethod(v.Value.Type).Invoke(null, new object[] { Stream, v2 });
            }
            b.Write(0xff);
        }