From 6ef634ca2c6b17feab9f985bd18c58cd3aea6bee Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 30 Jun 2022 13:22:08 -0700 Subject: [PATCH] Use Rust 1.62.0 features --- Cargo.toml | 3 -- src/biome.rs | 9 ++---- src/entity/meta.rs | 72 +++++++++-------------------------------- src/protocol/packets.rs | 18 +++-------- src/server.rs | 7 ++-- 5 files changed, 25 insertions(+), 84 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa8661e..d6af761 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ base64 = "0.13" bitfield-struct = "0.1" bitvec = "1" byteorder = "1" -bytes = "1" cfb8 = "0.7" flate2 = "1" flume = "0.10" @@ -26,8 +25,6 @@ futures = "0.3" hematite-nbt = "0.5" log = "0.4" num = "0.4" -ordered-float = "3.0.0" -parking_lot = "0.12" paste = "1" rand = "0.8" rayon = "1" diff --git a/src/biome.rs b/src/biome.rs index fea6234..4ba1a49 100644 --- a/src/biome.rs +++ b/src/biome.rs @@ -61,19 +61,14 @@ impl Default for Biome { } } -#[derive(Clone, Copy, PartialEq, Eq, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)] pub enum BiomePrecipitation { + #[default] Rain, Snow, None, } -impl Default for BiomePrecipitation { - fn default() -> Self { - Self::Rain - } -} - /// Minecraft handles grass colors for swamps and dark oak forests in a special /// way. #[derive(Clone, Copy, PartialEq, Eq, Debug)] diff --git a/src/entity/meta.rs b/src/entity/meta.rs index 3950ebc..40f8220 100644 --- a/src/entity/meta.rs +++ b/src/entity/meta.rs @@ -79,10 +79,11 @@ impl Encode for VillagerData { } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] pub enum VillagerType { Desert, Jungle, + #[default] Plains, Savanna, Snow, @@ -90,14 +91,9 @@ pub enum VillagerType { Taiga, } -impl Default for VillagerType { - fn default() -> Self { - Self::Plains - } -} - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] pub enum VillagerProfession { + #[default] None, Armorer, Butcher, @@ -115,14 +111,9 @@ pub enum VillagerProfession { Weaponsmith, } -impl Default for VillagerProfession { - fn default() -> Self { - Self::None - } -} - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] pub enum Pose { + #[default] Standing, FallFlying, Sleeping, @@ -139,12 +130,6 @@ pub enum Pose { Digging, } -impl Default for Pose { - fn default() -> Self { - Self::Standing - } -} - impl Encode for Pose { fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> { VarInt(*self as i32).encode(w) @@ -152,26 +137,22 @@ impl Encode for Pose { } /// The main hand of a player. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] pub enum MainHand { Left, + #[default] Right, } -impl Default for MainHand { - fn default() -> Self { - Self::Right - } -} - impl Encode for MainHand { fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> { (*self as u8).encode(w) } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] pub enum BoatVariant { + #[default] Oak, Spruce, Birch, @@ -180,21 +161,16 @@ pub enum BoatVariant { DarkOak, } -impl Default for BoatVariant { - fn default() -> Self { - Self::Oak - } -} - impl Encode for BoatVariant { fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> { VarInt(*self as i32).encode(w) } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] pub enum CatVariant { Tabby, + #[default] Black, Red, Siamese, @@ -207,48 +183,32 @@ pub enum CatVariant { AllBlack, } -impl Default for CatVariant { - fn default() -> Self { - CatVariant::Black - } -} - impl Encode for CatVariant { fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> { VarInt(*self as i32).encode(w) } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] pub enum FrogVariant { + #[default] Temperate, Warm, Cold, } -impl Default for FrogVariant { - fn default() -> Self { - FrogVariant::Temperate - } -} - impl Encode for FrogVariant { fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> { VarInt(*self as i32).encode(w) } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] pub enum PaintingVariant { + #[default] Default, // TODO } -impl Default for PaintingVariant { - fn default() -> Self { - PaintingVariant::Default - } -} - impl Encode for PaintingVariant { fn encode(&self, w: &mut impl Write) -> anyhow::Result<()> { VarInt(*self as i32).encode(w) diff --git a/src/protocol/packets.rs b/src/protocol/packets.rs index 57310c9..643b223 100644 --- a/src/protocol/packets.rs +++ b/src/protocol/packets.rs @@ -944,8 +944,9 @@ pub mod play { } def_enum! { - #[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash)] GameMode: u8 { + #[default] Survival = 0, Creative = 1, Adventure = 2, @@ -953,12 +954,6 @@ pub mod play { } } - impl Default for GameMode { - fn default() -> Self { - GameMode::Survival - } - } - def_struct! { EntityPosition 0x26 { entity_id: VarInt, @@ -996,8 +991,9 @@ pub mod play { } def_enum! { - #[derive(Copy, PartialEq, Eq)] + #[derive(Copy, PartialEq, Eq, Default)] ChatMessageType: VarInt { + #[default] Chat = 0, SystemMessage = 1, GameInfo = 2, @@ -1009,12 +1005,6 @@ pub mod play { } } - impl Default for ChatMessageType { - fn default() -> Self { - ChatMessageType::Chat - } - } - def_enum! { PlayerInfo 0x34: VarInt { AddPlayer: Vec = 0, diff --git a/src/server.rs b/src/server.rs index 5cbe152..235b0ff 100644 --- a/src/server.rs +++ b/src/server.rs @@ -3,14 +3,13 @@ use std::error::Error; use std::iter::FusedIterator; use std::net::SocketAddr; use std::sync::atomic::{AtomicI64, Ordering}; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use std::thread; use std::time::{Duration, Instant}; use anyhow::{bail, ensure, Context}; use flume::{Receiver, Sender}; use num::BigInt; -use parking_lot::Mutex; use rand::rngs::OsRng; use rayon::iter::ParallelIterator; use reqwest::Client as HttpClient; @@ -199,7 +198,7 @@ impl Server { E: Into>, { self.0.connection_sema.close(); - *self.0.shutdown_result.lock() = Some(res.into().map_err(|e| e.into())); + *self.0.shutdown_result.lock().unwrap() = Some(res.into().map_err(|e| e.into())); } } @@ -351,7 +350,7 @@ fn do_update_loop(server: Server, worlds: &mut Worlds) -> ShutdownResult { let mut tick_start = Instant::now(); loop { - if let Some(res) = server.0.shutdown_result.lock().take() { + if let Some(res) = server.0.shutdown_result.lock().unwrap().take() { return res; }