aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoey Sacchini <joey@sacchini.net>2020-12-01 21:10:23 -0500
committerJoey Sacchini <joey@sacchini.net>2020-12-01 21:10:23 -0500
commitad887b92acdc302caf628e2772a1c4625e31877e (patch)
treeb3bc1f46c018fd3fc4f12bc0954b461a7e57e1dd /src
parent2bc1e9b20a7ba5fd4144a860f054f5bd799feb27 (diff)
downloadmcproto-rs-ad887b92acdc302caf628e2772a1c4625e31877e.tar.gz
mcproto-rs-ad887b92acdc302caf628e2772a1c4625e31877e.tar.bz2
mcproto-rs-ad887b92acdc302caf628e2772a1c4625e31877e.zip
support previous gamemode
Diffstat (limited to 'src')
-rw-r--r--src/types.rs1
-rw-r--r--src/v1_16_3.rs57
2 files changed, 56 insertions, 2 deletions
diff --git a/src/types.rs b/src/types.rs
index 3a96b22..3c317a2 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -10,7 +10,6 @@ pub use super::chat::*;
#[cfg(all(test, feature = "std"))]
use crate::protocol::TestRandom;
use crate::byte_order::{ProtoByteOrder, ByteOrder};
-use std::ops::Deref;
// bool
impl Serialize for bool {
diff --git a/src/v1_16_3.rs b/src/v1_16_3.rs
index 3eb5e03..a3c4e68 100644
--- a/src/v1_16_3.rs
+++ b/src/v1_16_3.rs
@@ -244,7 +244,7 @@ define_protocol!(753, Packet753, RawPacket753, RawPacket753Body => {
entity_id: i32,
is_hardcore: bool,
gamemode: GameMode,
- previous_gamemode: GameMode,
+ previous_gamemode: PreviousGameMode,
worlds: CountedArray<String, VarInt>,
dimension_codec: NamedNbtTag,
dimension: NamedNbtTag,
@@ -1636,6 +1636,61 @@ proto_byte_enum!(GameMode,
0x03 :: Spectator
);
+#[derive(Clone, Debug, PartialEq)]
+pub enum PreviousGameMode {
+ NoPrevious,
+ Previous(GameMode)
+}
+
+impl PreviousGameMode {
+ pub fn id(&self) -> i8 {
+ use PreviousGameMode::*;
+ match self {
+ NoPrevious => -1,
+ Previous(mode) => mode.id() as i8,
+ }
+ }
+}
+
+impl Serialize for PreviousGameMode {
+ fn mc_serialize<S: Serializer>(&self, to: &mut S) -> SerializeResult {
+ to.serialize_byte(self.id() as u8)
+ }
+}
+
+impl Deserialize for PreviousGameMode {
+ fn mc_deserialize(data: &[u8]) -> DeserializeResult<'_, Self> {
+ let Deserialized{ value: id, data } = i8::mc_deserialize(data)?;
+
+ use PreviousGameMode::*;
+ match id {
+ -1 => Deserialized::ok(NoPrevious, data),
+ other => Ok(GameMode::deserialize_with_id(other as u8, data)?.map(move |gm| Previous(gm)))
+ }
+ }
+}
+
+impl Into<Option<GameMode>> for PreviousGameMode {
+ fn into(self) -> Option<GameMode> {
+ use PreviousGameMode::*;
+ match self {
+ NoPrevious => None,
+ Previous(mode) => Some(mode),
+ }
+ }
+}
+
+#[cfg(all(test, feature = "std"))]
+impl TestRandom for PreviousGameMode {
+ fn test_gen_random() -> Self {
+ use PreviousGameMode::*;
+ match <Option<GameMode> as TestRandom>::test_gen_random() {
+ Some(gamemode) => Previous(gamemode),
+ None => NoPrevious
+ }
+ }
+}
+
proto_byte_enum!(WinGameAction,
0x00 :: Respawn,
0x01 :: RollCreditsAndRespawn