2016-03-16 14:25:35 -04:00
|
|
|
// Copyright 2016 Matthew Collins
|
2015-09-17 11:21:56 -04:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2015-09-12 15:31:26 -04:00
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
use std::io;
|
|
|
|
use std::fmt;
|
2018-11-04 14:48:03 -05:00
|
|
|
use crate::protocol;
|
|
|
|
use crate::protocol::Serializable;
|
|
|
|
use crate::format;
|
|
|
|
use crate::item;
|
|
|
|
use crate::shared::Position;
|
2018-12-02 22:32:52 -05:00
|
|
|
use crate::nbt;
|
2015-09-12 15:31:26 -04:00
|
|
|
|
|
|
|
pub struct MetadataKey<T: MetaValue> {
|
|
|
|
index: i32,
|
|
|
|
ty: PhantomData<T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl <T: MetaValue> MetadataKey<T> {
|
2015-09-17 11:04:25 -04:00
|
|
|
#[allow(dead_code)]
|
2018-11-02 19:57:23 -04:00
|
|
|
fn new(index: i32) -> MetadataKey<T> {
|
2015-09-12 15:31:26 -04:00
|
|
|
MetadataKey {
|
2018-11-04 16:43:30 -05:00
|
|
|
index,
|
2015-09-12 15:31:26 -04:00
|
|
|
ty: PhantomData,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
pub struct Metadata {
|
2015-09-12 15:31:26 -04:00
|
|
|
map: HashMap<i32, Value>,
|
|
|
|
}
|
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
impl Metadata {
|
|
|
|
pub fn new() -> Metadata {
|
|
|
|
Metadata { map: HashMap::new() }
|
2015-09-12 15:31:26 -04:00
|
|
|
}
|
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
pub fn get<T: MetaValue>(&self, key: &MetadataKey<T>) -> Option<&T> {
|
|
|
|
self.map.get(&key.index).map(T::unwrap)
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
}
|
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
pub fn put<T: MetaValue>(&mut self, key: &MetadataKey<T>, val: T) {
|
|
|
|
self.map.insert(key.index, val.wrap());
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
}
|
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
fn put_raw<T: MetaValue>(&mut self, index: i32, val: T) {
|
|
|
|
self.map.insert(index, val.wrap());
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
}
|
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
fn read_from18<R: io::Read>(buf: &mut R) -> Result<Self, protocol::Error> {
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
let mut m = Self::new();
|
|
|
|
loop {
|
|
|
|
let ty_index = u8::read_from(buf)? as i32;
|
|
|
|
if ty_index == 0x7f {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
let index = ty_index & 0x1f;
|
|
|
|
let ty = ty_index >> 5;
|
|
|
|
|
|
|
|
match ty {
|
|
|
|
0 => m.put_raw(index, i8::read_from(buf)?),
|
|
|
|
1 => m.put_raw(index, i16::read_from(buf)?),
|
|
|
|
2 => m.put_raw(index, i32::read_from(buf)?),
|
|
|
|
3 => m.put_raw(index, f32::read_from(buf)?),
|
|
|
|
4 => m.put_raw(index, String::read_from(buf)?),
|
|
|
|
5 => m.put_raw(index, Option::<item::Stack>::read_from(buf)?),
|
|
|
|
6 => m.put_raw(index,
|
|
|
|
[i32::read_from(buf)?,
|
|
|
|
i32::read_from(buf)?,
|
|
|
|
i32::read_from(buf)?]),
|
|
|
|
7 => m.put_raw(index,
|
|
|
|
[f32::read_from(buf)?,
|
|
|
|
f32::read_from(buf)?,
|
|
|
|
f32::read_from(buf)?]),
|
|
|
|
_ => return Err(protocol::Error::Err("unknown metadata type".to_owned())),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(m)
|
|
|
|
}
|
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
fn write_to18<W: io::Write>(&self, buf: &mut W) -> Result<(), protocol::Error> {
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
for (k, v) in &self.map {
|
|
|
|
if (*k as u8) > 0x1f {
|
|
|
|
panic!("write metadata index {:x} > 0x1f", *k as u8);
|
|
|
|
}
|
|
|
|
|
|
|
|
let ty_index: u8 = *k as u8;
|
|
|
|
const TYPE_SHIFT: usize = 5;
|
|
|
|
|
|
|
|
match *v
|
|
|
|
{
|
|
|
|
Value::Byte(ref val) => {
|
|
|
|
u8::write_to(&(ty_index | (0 << TYPE_SHIFT)), buf)?;
|
|
|
|
val.write_to(buf)?;
|
|
|
|
}
|
|
|
|
Value::Short(ref val) => {
|
|
|
|
u8::write_to(&(ty_index | (1 << TYPE_SHIFT)), buf)?;
|
|
|
|
val.write_to(buf)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value::Int(ref val) => {
|
|
|
|
u8::write_to(&(ty_index | (2 << TYPE_SHIFT)), buf)?;
|
|
|
|
val.write_to(buf)?;
|
|
|
|
}
|
|
|
|
Value::Float(ref val) => {
|
|
|
|
u8::write_to(&(ty_index | (3 << TYPE_SHIFT)), buf)?;
|
|
|
|
val.write_to(buf)?;
|
|
|
|
}
|
|
|
|
Value::String(ref val) => {
|
|
|
|
u8::write_to(&(ty_index | (4 << TYPE_SHIFT)), buf)?;
|
|
|
|
val.write_to(buf)?;
|
|
|
|
}
|
|
|
|
Value::OptionalItemStack(ref val) => {
|
|
|
|
u8::write_to(&(ty_index | (5 << TYPE_SHIFT)), buf)?;
|
|
|
|
val.write_to(buf)?;
|
|
|
|
}
|
|
|
|
Value::Vector(ref val) => {
|
|
|
|
u8::write_to(&(ty_index | (6 << TYPE_SHIFT)), buf)?;
|
|
|
|
val[0].write_to(buf)?;
|
|
|
|
val[1].write_to(buf)?;
|
|
|
|
val[2].write_to(buf)?;
|
|
|
|
}
|
|
|
|
Value::Rotation(ref val) => {
|
|
|
|
u8::write_to(&(ty_index | (7 << TYPE_SHIFT)), buf)?;
|
|
|
|
val[0].write_to(buf)?;
|
|
|
|
val[1].write_to(buf)?;
|
|
|
|
val[2].write_to(buf)?;
|
|
|
|
}
|
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
_ => {
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
panic!("attempted to write 1.9+ metadata to 1.8");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
u8::write_to(&0x7f, buf)?;
|
|
|
|
Ok(())
|
2015-09-12 15:31:26 -04:00
|
|
|
}
|
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
fn read_from19<R: io::Read>(buf: &mut R) -> Result<Self, protocol::Error> {
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
let mut m = Self::new();
|
2015-09-12 15:31:26 -04:00
|
|
|
loop {
|
2018-11-04 14:34:53 -05:00
|
|
|
let index = u8::read_from(buf)? as i32;
|
2015-09-12 15:31:26 -04:00
|
|
|
if index == 0xFF {
|
|
|
|
break;
|
|
|
|
}
|
2018-12-02 22:32:52 -05:00
|
|
|
let ty = protocol::VarInt::read_from(buf)?.0;
|
2015-09-12 15:31:26 -04:00
|
|
|
match ty {
|
2018-11-04 14:34:53 -05:00
|
|
|
0 => m.put_raw(index, i8::read_from(buf)?),
|
|
|
|
1 => m.put_raw(index, protocol::VarInt::read_from(buf)?.0),
|
|
|
|
2 => m.put_raw(index, f32::read_from(buf)?),
|
|
|
|
3 => m.put_raw(index, String::read_from(buf)?),
|
|
|
|
4 => m.put_raw(index, format::Component::read_from(buf)?),
|
|
|
|
5 => m.put_raw(index, Option::<item::Stack>::read_from(buf)?),
|
|
|
|
6 => m.put_raw(index, bool::read_from(buf)?),
|
2015-10-07 14:36:59 -04:00
|
|
|
7 => m.put_raw(index,
|
2018-11-04 14:34:53 -05:00
|
|
|
[f32::read_from(buf)?,
|
|
|
|
f32::read_from(buf)?,
|
|
|
|
f32::read_from(buf)?]),
|
|
|
|
8 => m.put_raw(index, Position::read_from(buf)?),
|
2015-09-12 15:31:26 -04:00
|
|
|
9 => {
|
2018-11-04 14:34:53 -05:00
|
|
|
if bool::read_from(buf)? {
|
|
|
|
m.put_raw(index, Option::<Position>::read_from(buf)?);
|
2015-09-12 15:31:26 -04:00
|
|
|
} else {
|
2016-04-03 15:53:40 -04:00
|
|
|
m.put_raw::<Option<Position>>(index, None);
|
2015-09-12 15:31:26 -04:00
|
|
|
}
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2018-11-04 14:34:53 -05:00
|
|
|
10 => m.put_raw(index, protocol::VarInt::read_from(buf)?),
|
2015-09-12 15:31:26 -04:00
|
|
|
11 => {
|
2018-11-04 14:34:53 -05:00
|
|
|
if bool::read_from(buf)? {
|
|
|
|
m.put_raw(index, Option::<protocol::UUID>::read_from(buf)?);
|
2015-09-12 15:31:26 -04:00
|
|
|
} else {
|
|
|
|
m.put_raw::<Option<protocol::UUID>>(index, None);
|
|
|
|
}
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2018-11-04 14:34:53 -05:00
|
|
|
12 => m.put_raw(index, protocol::VarInt::read_from(buf)?.0 as u16),
|
2018-12-02 22:32:52 -05:00
|
|
|
13 => {
|
|
|
|
let ty = u8::read_from(buf)?;
|
|
|
|
if ty != 0 {
|
|
|
|
let name = nbt::read_string(buf)?;
|
|
|
|
let tag = nbt::Tag::read_from(buf)?;
|
|
|
|
|
|
|
|
m.put_raw(index, nbt::NamedTag(name, tag));
|
|
|
|
}
|
|
|
|
}
|
2016-04-08 13:46:07 -04:00
|
|
|
_ => return Err(protocol::Error::Err("unknown metadata type".to_owned())),
|
2015-09-12 15:31:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(m)
|
|
|
|
}
|
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
fn write_to19<W: io::Write>(&self, buf: &mut W) -> Result<(), protocol::Error> {
|
2015-09-12 15:31:26 -04:00
|
|
|
for (k, v) in &self.map {
|
2018-11-04 14:34:53 -05:00
|
|
|
(*k as u8).write_to(buf)?;
|
2015-09-12 15:31:26 -04:00
|
|
|
match *v {
|
|
|
|
Value::Byte(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&0, buf)?;
|
|
|
|
val.write_to(buf)?;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
Value::Int(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&1, buf)?;
|
|
|
|
protocol::VarInt(*val).write_to(buf)?;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
Value::Float(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&2, buf)?;
|
|
|
|
val.write_to(buf)?;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
Value::String(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&3, buf)?;
|
|
|
|
val.write_to(buf)?;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
Value::FormatComponent(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&4, buf)?;
|
|
|
|
val.write_to(buf)?;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
Value::OptionalItemStack(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&5, buf)?;
|
|
|
|
val.write_to(buf)?;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
Value::Bool(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&6, buf)?;
|
|
|
|
val.write_to(buf)?;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
Value::Vector(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&7, buf)?;
|
|
|
|
val[0].write_to(buf)?;
|
|
|
|
val[1].write_to(buf)?;
|
|
|
|
val[2].write_to(buf)?;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
Value::Position(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&8, buf)?;
|
|
|
|
val.write_to(buf)?;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
Value::OptionalPosition(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&9, buf)?;
|
|
|
|
val.is_some().write_to(buf)?;
|
|
|
|
val.write_to(buf)?;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
Value::Direction(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&10, buf)?;
|
|
|
|
val.write_to(buf)?;
|
2015-09-12 15:31:26 -04:00
|
|
|
}
|
|
|
|
Value::OptionalUUID(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&11, buf)?;
|
|
|
|
val.is_some().write_to(buf)?;
|
|
|
|
val.write_to(buf)?;
|
2015-10-07 14:36:59 -04:00
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
Value::Block(ref val) => {
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&11, buf)?;
|
|
|
|
protocol::VarInt(*val as i32).write_to(buf)?;
|
2015-09-12 15:31:26 -04:00
|
|
|
}
|
2018-12-02 22:32:52 -05:00
|
|
|
Value::NBTTag(ref _val) => {
|
|
|
|
u8::write_to(&13, buf)?;
|
|
|
|
// TODO: write NBT tags metadata
|
|
|
|
//nbt::Tag(*val).write_to(buf)?;
|
|
|
|
}
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
_ => panic!("unexpected metadata"),
|
2015-09-12 15:31:26 -04:00
|
|
|
}
|
|
|
|
}
|
2018-11-04 14:34:53 -05:00
|
|
|
u8::write_to(&0xFF, buf)?;
|
2015-09-12 15:31:26 -04:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
impl Serializable for Metadata {
|
|
|
|
fn read_from<R: io::Read>(buf: &mut R) -> Result<Self, protocol::Error> {
|
|
|
|
let protocol_version = unsafe { protocol::CURRENT_PROTOCOL_VERSION };
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
|
2018-12-11 21:18:25 -05:00
|
|
|
if protocol_version >= 74 {
|
|
|
|
Metadata::read_from19(buf)
|
|
|
|
} else {
|
|
|
|
Metadata::read_from18(buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn write_to<W: io::Write>(&self, buf: &mut W) -> Result<(), protocol::Error> {
|
|
|
|
let protocol_version = unsafe { protocol::CURRENT_PROTOCOL_VERSION };
|
|
|
|
|
|
|
|
if protocol_version >= 74 {
|
|
|
|
self.write_to19(buf)
|
|
|
|
} else {
|
|
|
|
self.write_to18(buf)
|
|
|
|
}
|
2015-09-12 15:31:26 -04:00
|
|
|
}
|
|
|
|
}
|
2018-12-11 21:18:25 -05:00
|
|
|
|
|
|
|
impl fmt::Debug for Metadata {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "Metadata[ ")?;
|
|
|
|
for (k, v) in &self.map {
|
|
|
|
write!(f, "{:?}={:?}, ", k, v)?;
|
|
|
|
}
|
|
|
|
write!(f, "]")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Metadata {
|
|
|
|
fn default() -> Metadata {
|
|
|
|
Metadata::new()
|
2015-09-12 15:31:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2016-03-16 14:01:33 -04:00
|
|
|
pub enum Value {
|
2015-09-12 15:31:26 -04:00
|
|
|
Byte(i8),
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
Short(i16),
|
2015-09-12 15:31:26 -04:00
|
|
|
Int(i32),
|
|
|
|
Float(f32),
|
|
|
|
String(String),
|
|
|
|
FormatComponent(format::Component),
|
|
|
|
OptionalItemStack(Option<item::Stack>),
|
|
|
|
Bool(bool),
|
|
|
|
Vector([f32; 3]),
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
Rotation([i32; 3]),
|
2016-04-03 15:53:40 -04:00
|
|
|
Position(Position),
|
|
|
|
OptionalPosition(Option<Position>),
|
2015-09-12 15:31:26 -04:00
|
|
|
Direction(protocol::VarInt), // TODO: Proper type
|
|
|
|
OptionalUUID(Option<protocol::UUID>),
|
|
|
|
Block(u16), // TODO: Proper type
|
2018-12-02 22:32:52 -05:00
|
|
|
NBTTag(nbt::NamedTag),
|
2015-09-12 15:31:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait MetaValue {
|
2018-11-04 14:33:23 -05:00
|
|
|
fn unwrap(_: &Value) -> &Self;
|
2015-09-12 15:31:26 -04:00
|
|
|
fn wrap(self) -> Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MetaValue for i8 {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::Byte(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::Byte(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
impl MetaValue for i16 {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::Short(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::Short(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-12 15:31:26 -04:00
|
|
|
impl MetaValue for i32 {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::Int(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::Int(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MetaValue for f32 {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::Float(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::Float(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MetaValue for String {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::String(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::String(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MetaValue for format::Component {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::FormatComponent(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::FormatComponent(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MetaValue for Option<item::Stack> {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::OptionalItemStack(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::OptionalItemStack(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MetaValue for bool {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::Bool(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::Bool(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1.8.9 (47) multiprotocol support (#57)
Protocol 47 (1.8.9-1.8) is the biggest multiprotocol (https://github.com/iceiix/steven/issues/18) change yet:
* New chunk format (load_chunk18)
* New metadata format (Metadata18)
* New packets and changes to 13 packets
References:
http://wiki.vg/index.php?title=Protocol&oldid=7368
https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite
https://wiki.vg/Protocol_History#1.8
https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/protocol.json
1.8 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=6124
1.9 chunk format: https://wiki.vg/index.php?title=Chunk_Format&oldid=7411
1.8 vs 1.9: https://wiki.vg/index.php?title=Chunk_Format&diff=7411&oldid=6124
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/section.js
https://github.com/PrismarineJS/prismarine-chunk/blob/master/src/pc/1.8/chunk.js
Details:
* Add 1.8.9 packet IDs from https://github.com/iceiix/steven/pull/37
* Add ChunkDataBulk, parse the ChunkMeta and save data in Vec<u8>
* Add EntityEquipment u16 variant, EntityStatus, ChunkData u16 variants
* SpawnPlayer with added held item
https://wiki.vg/Protocol_History#15w31a Removed Current Item short from Spawn Player (0x0C)
* SpawnObject no UUID and optional velocity
https://wiki.vg/index.php?title=Protocol&oldid=7368#Spawn_Object
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Object (0x0E)
Spawn Object always sends velocity, even if data is 0
* SpawnMob no UUID variant
https://wiki.vg/Protocol_History#15w31a
Added Entity UUID after entity ID to Spawn Mob (0x0F)
* Maps packet without tracking position boolean
https://wiki.vg/index.php?title=Protocol&oldid=7368#Map
https://wiki.vg/Protocol_History#15w34a
Added tracking position boolean to Map (0x34)
* Update Entity NBT was removed and Bossbar added (both 0x49) >1.8
https://wiki.vg/index.php?title=Protocol&oldid=7368#Update_Entity_NBT
https://wiki.vg/Protocol_History#15w31a
Removed Update Entity NBT Packet (0x49)
Added Boss Bar packet (0x4
* Use entity without hands
https://wiki.vg/index.php?title=Protocol&oldid=7368#Use_Entity
https://wiki.vg/Protocol_History#15w31a
Added VarInt enum for selected hand in Use Entity (0x02); only sent if type is interact or interact at
* Player block placement, held item stack and face byte variant
https://wiki.vg/index.php?title=Protocol&oldid=7368#Player_Block_Placement
https://wiki.vg/Protocol_History#15w31a
Face for Player Block Placement is now a VarInt enum instead of a byte
Replaced held item (slot) with VarInt enum selected hand in Player Block Placement
* Arm swing without hands, a packet with no fields, uses a ZST
https://wiki.vg/index.php?title=Protocol&oldid=7368#Animation_2
https://github.com/iceiix/steven/pull/57#issuecomment-444289008
https://doc.rust-lang.org/nomicon/exotic-sizes.html
* ClickWindow uses u8 mode, same as in 15w39c
* ClientSettings without hands
* SpectateTeleport is added before ResourcePackStatus
* Copy load_chunk to load_chunk19 and load_chunk18
* 1.8 chunk reading implementation, load_chunk18
* Support both metadata formats, Metadata18/Metadata19
* Remove fmt::Debug
* Implement formatting in MetadataBase and bounce through fmt::Debug
2018-12-09 15:03:55 -05:00
|
|
|
impl MetaValue for [i32; 3] {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::Rotation(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::Rotation(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-12 15:31:26 -04:00
|
|
|
impl MetaValue for [f32; 3] {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::Vector(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::Vector(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-03 15:53:40 -04:00
|
|
|
impl MetaValue for Position {
|
2015-09-12 15:31:26 -04:00
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::Position(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::Position(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-03 15:53:40 -04:00
|
|
|
impl MetaValue for Option<Position> {
|
2015-09-12 15:31:26 -04:00
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::OptionalPosition(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::OptionalPosition(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MetaValue for protocol::VarInt {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::Direction(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::Direction(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MetaValue for Option<protocol::UUID> {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::OptionalUUID(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::OptionalUUID(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MetaValue for u16 {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::Block(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::Block(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-02 22:32:52 -05:00
|
|
|
impl MetaValue for nbt::NamedTag {
|
|
|
|
fn unwrap(value: &Value) -> &Self {
|
|
|
|
match *value {
|
|
|
|
Value::NBTTag(ref val) => val,
|
|
|
|
_ => panic!("incorrect key"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn wrap(self) -> Value {
|
|
|
|
Value::NBTTag(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-12 15:31:26 -04:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
|
|
|
|
const TEST: MetadataKey<String> =
|
|
|
|
MetadataKey {
|
2015-10-07 14:36:59 -04:00
|
|
|
index: 0,
|
|
|
|
ty: PhantomData,
|
|
|
|
};
|
2015-09-12 15:31:26 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn basic() {
|
2018-12-11 21:18:25 -05:00
|
|
|
let mut m = Metadata::new();
|
2015-09-12 15:31:26 -04:00
|
|
|
|
|
|
|
m.put(&TEST, "Hello world".to_owned());
|
|
|
|
|
|
|
|
match m.get(&TEST) {
|
|
|
|
Some(val) => {
|
|
|
|
assert!(val == "Hello world");
|
|
|
|
}
|
|
|
|
None => panic!("failed"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|