diff --git a/Cargo.lock b/Cargo.lock index 2147f3e79..df79d54bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,56 +43,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" -[[package]] -name = "anstream" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - [[package]] name = "anstyle" version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" -[[package]] -name = "anstyle-parse" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" -dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys 0.61.2", -] - [[package]] name = "anyhow" version = "1.0.100" @@ -389,12 +345,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de0758edba32d61d1fd9f4d69491b47604b91ee2f7e6b33de7e54ca4ebe55dc3" -[[package]] -name = "colorchoice" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" - [[package]] name = "colored" version = "3.1.1" @@ -856,29 +806,6 @@ dependencies = [ "syn", ] -[[package]] -name = "env_filter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "env_logger" -version = "0.11.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "jiff", - "log", -] - [[package]] name = "equivalent" version = "1.0.2" @@ -1471,12 +1398,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "is_terminal_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" - [[package]] name = "itertools" version = "0.13.0" @@ -1501,30 +1422,6 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" -[[package]] -name = "jiff" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e67e8da4c49d6d9909fe03361f9b620f58898859f5c7aded68351e85e71ecf50" -dependencies = [ - "jiff-static", - "log", - "portable-atomic", - "portable-atomic-util", - "serde_core", -] - -[[package]] -name = "jiff-static" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0c84ee7f197eca9a86c6fd6cb771e55eb991632f15f2bc3ca6ec838929e6e78" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "js-sys" version = "0.3.85" @@ -1789,12 +1686,6 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" -[[package]] -name = "once_cell_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" - [[package]] name = "oorandom" version = "11.1.5" @@ -2018,21 +1909,6 @@ dependencies = [ "spki 0.8.0-rc.4", ] -[[package]] -name = "portable-atomic" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" - -[[package]] -name = "portable-atomic-util" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" -dependencies = [ - "portable-atomic", -] - [[package]] name = "potential_utf" version = "0.1.4" @@ -2307,14 +2183,11 @@ dependencies = [ "crossfire", "dashmap", "enum_dispatch", - "env_logger", "flate2", "futures", "itertools 0.14.0", "log", "lz4-java-wrc", - "num-derive", - "num-traits", "num_cpus", "pumpkin-config", "pumpkin-data", @@ -2480,7 +2353,6 @@ dependencies = [ "pkcs1", "pkcs8 0.11.0-rc.10", "rand_core 0.10.0", - "sha1", "signature 3.0.0-rc.10", "spki 0.8.0-rc.4", "zeroize", diff --git a/Cargo.toml b/Cargo.toml index 12235ad4b..a272f1b36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -122,7 +122,6 @@ crossfire = { version= "3.0.4", features = ["compat"]} dashmap = "6.1" ecdsa = "0.16.9" enum_dispatch = "0.3.13" -env_logger = "0.11.8" flate2 = "1.1.9" heck = "0.5" hmac = "=0.13.0-rc.5" diff --git a/pumpkin-data/build/attributes.rs b/pumpkin-data/build/attributes.rs index 5379a12db..e53c1cf29 100644 --- a/pumpkin-data/build/attributes.rs +++ b/pumpkin-data/build/attributes.rs @@ -12,7 +12,7 @@ struct Attributes { default_value: f64, } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/attributes.json"); let attributes: BTreeMap = diff --git a/pumpkin-data/build/biome.rs b/pumpkin-data/build/biome.rs index 8da8d1e8f..7ff52a37e 100644 --- a/pumpkin-data/build/biome.rs +++ b/pumpkin-data/build/biome.rs @@ -157,7 +157,7 @@ struct MultiNoiseBiomeSuppliers { nether: BiomeTree, } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/biome.json"); println!("cargo:rerun-if-changed=../assets/multi_noise_biome_tree.json"); diff --git a/pumpkin-data/build/block.rs b/pumpkin-data/build/block.rs index 4f662d2bf..33262fc09 100644 --- a/pumpkin-data/build/block.rs +++ b/pumpkin-data/build/block.rs @@ -69,7 +69,7 @@ impl PropertyCollectionData { self.blocks.push((block_name, block_id)); } - pub fn from_mappings(variant_mappings: Vec) -> Self { + pub const fn from_mappings(variant_mappings: Vec) -> Self { Self { variant_mappings, blocks: Vec::new(), @@ -431,7 +431,7 @@ impl BlockState { const IS_AIR: u16 = 1 << 0; const HAS_RANDOM_TICKS: u16 = 1 << 9; - fn has_random_ticks(&self) -> bool { + const fn has_random_ticks(&self) -> bool { self.state_flags & Self::HAS_RANDOM_TICKS != 0 } @@ -569,7 +569,7 @@ impl ToTokens for Block { } } -#[derive(Deserialize, Clone, Debug, PartialEq)] +#[derive(Deserialize, Clone, Debug, PartialEq, Eq)] #[serde(tag = "type")] pub enum GeneratedPropertyType { #[serde(rename = "boolean")] @@ -634,7 +634,7 @@ pub struct BlockAssets { pub block_entity_types: Vec, } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/blocks.json"); println!("cargo:rerun-if-changed=../assets/bedrock_block_states.nbt"); println!("cargo:rerun-if-changed=../assets/properties.json"); diff --git a/pumpkin-data/build/block_state_remap.rs b/pumpkin-data/build/block_state_remap.rs index a51d30696..8c3287f45 100644 --- a/pumpkin-data/build/block_state_remap.rs +++ b/pumpkin-data/build/block_state_remap.rs @@ -156,7 +156,7 @@ fn compose(first: &[u16], second: &[u16]) -> Vec { .collect() } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/viaversion/data/mappings-1.21.7to1.21.9.nbt"); println!("cargo:rerun-if-changed=../assets/viaversion/data/mappings-1.21.9to1.21.11.nbt"); diff --git a/pumpkin-data/build/build.rs b/pumpkin-data/build/build.rs index 7c776e184..6a35d7d29 100644 --- a/pumpkin-data/build/build.rs +++ b/pumpkin-data/build/build.rs @@ -59,10 +59,10 @@ mod world_event; pub const OUT_DIR: &str = "src/generated"; pub fn main() { - fs::create_dir_all(OUT_DIR).expect("Failed to create output directory"); - type BuilderFn = fn() -> TokenStream; + fs::create_dir_all(OUT_DIR).expect("Failed to create output directory"); + let build_functions: Vec<(BuilderFn, &str)> = vec![ (packet::build, "packet.rs"), (screen::build, "screen.rs"), @@ -121,9 +121,10 @@ pub fn main() { let header = "/* This file is generated. Do not edit manually. */\n"; - let final_code = format_code(&raw_code) - .map(|formatted| format!("{}{}", header, formatted)) - .unwrap_or_else(|_| format!("{}{}", header, raw_code)); + let final_code = format_code(&raw_code).map_or_else( + |_| format!("{header}{raw_code}"), + |formatted| format!("{header}{formatted}"), + ); write_generated_file(&final_code, file); }); @@ -164,9 +165,8 @@ pub fn format_code(unformatted_code: &str) -> Result { .stderr(Stdio::null()) .spawn(); - let mut child = match child_result { - Ok(c) => c, - Err(_) => return Err(RustFmtError), + let Ok(mut child) = child_result else { + return Err(RustFmtError); }; // Write the code to rustfmt's stdin diff --git a/pumpkin-data/build/chunk_gen_settings.rs b/pumpkin-data/build/chunk_gen_settings.rs index f3e731892..5d450edae 100644 --- a/pumpkin-data/build/chunk_gen_settings.rs +++ b/pumpkin-data/build/chunk_gen_settings.rs @@ -41,11 +41,11 @@ pub enum MaterialRuleStruct { #[serde(rename = "minecraft:block")] Block { result_state: BlockStateCodecStruct }, #[serde(rename = "minecraft:sequence")] - Sequence { sequence: Vec }, + Sequence { sequence: Vec }, #[serde(rename = "minecraft:condition")] Condition { if_true: MaterialConditionStruct, - then_run: Box, + then_run: Box, }, #[serde(rename = "minecraft:bandlands")] Badlands, @@ -87,9 +87,7 @@ pub enum MaterialConditionStruct { #[serde(rename = "minecraft:steep")] Steep, #[serde(rename = "minecraft:not")] - Not { - invert: Box, - }, + Not { invert: Box }, #[serde(rename = "minecraft:hole")] Hole, #[serde(rename = "minecraft:above_preliminary_surface")] @@ -347,7 +345,7 @@ impl ToTokens for MaterialRuleStruct { } } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/chunk_gen_settings.json"); let json: BTreeMap = diff --git a/pumpkin-data/build/chunk_status.rs b/pumpkin-data/build/chunk_status.rs index 11c7aebc3..f464f6bd2 100644 --- a/pumpkin-data/build/chunk_status.rs +++ b/pumpkin-data/build/chunk_status.rs @@ -4,7 +4,7 @@ use heck::ToPascalCase; use proc_macro2::TokenStream; use quote::{format_ident, quote}; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/chunk_status.json"); let chunk_status: Vec = diff --git a/pumpkin-data/build/composter_increase_chance.rs b/pumpkin-data/build/composter_increase_chance.rs index 401e7bf09..f25c1e461 100644 --- a/pumpkin-data/build/composter_increase_chance.rs +++ b/pumpkin-data/build/composter_increase_chance.rs @@ -4,7 +4,7 @@ use proc_macro2::{Span, TokenStream}; use quote::quote; use syn::LitInt; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/composter_increase_chance.json"); let composter_increase_chance: BTreeMap = serde_json::from_str( diff --git a/pumpkin-data/build/damage_type.rs b/pumpkin-data/build/damage_type.rs index 967e9123e..38e10face 100644 --- a/pumpkin-data/build/damage_type.rs +++ b/pumpkin-data/build/damage_type.rs @@ -47,7 +47,7 @@ pub enum DeathMessageType { IntentionalGameDesign, } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/damage_type.json"); let damage_types: BTreeMap = diff --git a/pumpkin-data/build/data_component.rs b/pumpkin-data/build/data_component.rs index 0bc9ac842..f27fabb8b 100644 --- a/pumpkin-data/build/data_component.rs +++ b/pumpkin-data/build/data_component.rs @@ -4,7 +4,7 @@ use quote::{format_ident, quote}; use std::collections::BTreeMap; use std::fs; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/data_component.json"); let data_component: BTreeMap = diff --git a/pumpkin-data/build/dimension.rs b/pumpkin-data/build/dimension.rs index 0916de403..1f6a5c421 100644 --- a/pumpkin-data/build/dimension.rs +++ b/pumpkin-data/build/dimension.rs @@ -39,7 +39,7 @@ pub struct Dimension { // } // } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/dimension.json"); let dimensions: BTreeMap = serde_json::from_str( diff --git a/pumpkin-data/build/effect.rs b/pumpkin-data/build/effect.rs index 26ed69f54..150b8d531 100644 --- a/pumpkin-data/build/effect.rs +++ b/pumpkin-data/build/effect.rs @@ -58,7 +58,7 @@ impl MobEffectCategory { } } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/effect.json"); let effects: BTreeMap = diff --git a/pumpkin-data/build/enchantments.rs b/pumpkin-data/build/enchantments.rs index 9a47e5ca1..996744dde 100644 --- a/pumpkin-data/build/enchantments.rs +++ b/pumpkin-data/build/enchantments.rs @@ -52,7 +52,7 @@ impl AttributeModifierSlot { } } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/enchantments.json"); let enchantments: BTreeMap = diff --git a/pumpkin-data/build/entity_pose.rs b/pumpkin-data/build/entity_pose.rs index 6c1d0986e..2a2685b0a 100644 --- a/pumpkin-data/build/entity_pose.rs +++ b/pumpkin-data/build/entity_pose.rs @@ -5,7 +5,7 @@ use quote::quote; use crate::array_to_tokenstream; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/entity_pose.json"); let poses: Vec = diff --git a/pumpkin-data/build/entity_status.rs b/pumpkin-data/build/entity_status.rs index cd1e7ef50..16560dc24 100644 --- a/pumpkin-data/build/entity_status.rs +++ b/pumpkin-data/build/entity_status.rs @@ -5,7 +5,7 @@ use proc_macro2::{Span, TokenStream}; use quote::{format_ident, quote}; use syn::LitInt; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/entity_statuses.json"); let events: BTreeMap = diff --git a/pumpkin-data/build/entity_type.rs b/pumpkin-data/build/entity_type.rs index 016db2760..d1a66a400 100644 --- a/pumpkin-data/build/entity_type.rs +++ b/pumpkin-data/build/entity_type.rs @@ -157,7 +157,7 @@ impl ToTokens for NamedEntityType<'_> { } } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/entities.json"); let json: BTreeMap = diff --git a/pumpkin-data/build/flower_pot_transformations.rs b/pumpkin-data/build/flower_pot_transformations.rs index 7fb9f7b13..064cd9b81 100644 --- a/pumpkin-data/build/flower_pot_transformations.rs +++ b/pumpkin-data/build/flower_pot_transformations.rs @@ -2,7 +2,7 @@ use proc_macro2::{Span, TokenStream}; use quote::quote; use std::{collections::BTreeMap, fs}; use syn::LitInt; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/flower_pot_transformations.json"); let flower_pot_transformation: BTreeMap = serde_json::from_str( diff --git a/pumpkin-data/build/fluid.rs b/pumpkin-data/build/fluid.rs index 0afb9ed99..03447d9a5 100644 --- a/pumpkin-data/build/fluid.rs +++ b/pumpkin-data/build/fluid.rs @@ -31,7 +31,7 @@ impl PropertyCollectionData { self.fluid_names.push(fluid_name); } - pub fn from_mappings(variant_mappings: Vec) -> Self { + pub const fn from_mappings(variant_mappings: Vec) -> Self { Self { variant_mappings, fluid_names: Vec::new(), @@ -330,15 +330,15 @@ pub struct Fluid { can_convert_to_source: bool, } -fn default_flow_speed() -> u32 { +const fn default_flow_speed() -> u32 { 5 // Default to water's speed } -fn default_flow_distance() -> u32 { +const fn default_flow_distance() -> u32 { 4 // Default to water's distance } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/fluids.json"); let fluids: Vec = diff --git a/pumpkin-data/build/fuels.rs b/pumpkin-data/build/fuels.rs index d3f6c2083..cd112ad43 100644 --- a/pumpkin-data/build/fuels.rs +++ b/pumpkin-data/build/fuels.rs @@ -1,7 +1,7 @@ use proc_macro2::TokenStream; use quote::quote; use std::{collections::BTreeMap, fs}; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/fuels.json"); let fuels: BTreeMap = diff --git a/pumpkin-data/build/game_event.rs b/pumpkin-data/build/game_event.rs index 480535271..c8c61b976 100644 --- a/pumpkin-data/build/game_event.rs +++ b/pumpkin-data/build/game_event.rs @@ -5,7 +5,7 @@ use quote::quote; use crate::array_to_tokenstream; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/game_event.json"); let game_events: Vec = diff --git a/pumpkin-data/build/game_rules.rs b/pumpkin-data/build/game_rules.rs index 2761755a2..45a7fcd29 100644 --- a/pumpkin-data/build/game_rules.rs +++ b/pumpkin-data/build/game_rules.rs @@ -5,7 +5,7 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote}; use serde_json::Value; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/game_rules.json"); let game_rules: BTreeMap = diff --git a/pumpkin-data/build/item.rs b/pumpkin-data/build/item.rs index 0b6375bf3..b2c26983a 100644 --- a/pumpkin-data/build/item.rs +++ b/pumpkin-data/build/item.rs @@ -339,15 +339,15 @@ impl ToTokens for ItemComponents { } } -fn return_1u32() -> u32 { +const fn return_1u32() -> u32 { 1 } -fn return_1f32() -> f32 { +const fn return_1f32() -> f32 { 1. } -fn return_true() -> bool { +const fn return_true() -> bool { true } #[derive(Deserialize)] @@ -361,7 +361,7 @@ pub struct ToolComponent { can_destroy_blocks_in_creative: bool, } -fn return_false() -> bool { +const fn return_false() -> bool { false } @@ -390,7 +390,7 @@ pub struct Modifier { pub slot: AttributeModifierSlot, } -fn _true() -> bool { +const fn _true() -> bool { true } @@ -429,7 +429,7 @@ pub struct EquippableComponent { pub shearing_sound: Option, } -#[derive(Deserialize, Clone, Debug, PartialEq)] +#[derive(Deserialize, Clone, Debug, PartialEq, Eq)] #[serde(rename_all = "snake_case")] #[expect(clippy::enum_variant_names)] pub enum Operation { @@ -438,7 +438,7 @@ pub enum Operation { AddMultipliedTotal, } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/items.json"); let items: BTreeMap = diff --git a/pumpkin-data/build/item_id_remap.rs b/pumpkin-data/build/item_id_remap.rs index 55089f7f5..72f805f47 100644 --- a/pumpkin-data/build/item_id_remap.rs +++ b/pumpkin-data/build/item_id_remap.rs @@ -178,7 +178,7 @@ fn compose_with_default(first: &[u16], second: &[u16]) -> Vec { .collect() } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/viaversion/data/mappings-1.21.7to1.21.9.nbt"); println!("cargo:rerun-if-changed=../assets/viaversion/data/mappings-1.21.9to1.21.11.nbt"); diff --git a/pumpkin-data/build/jukebox_song.rs b/pumpkin-data/build/jukebox_song.rs index f43b5be99..812f97c0c 100644 --- a/pumpkin-data/build/jukebox_song.rs +++ b/pumpkin-data/build/jukebox_song.rs @@ -12,7 +12,7 @@ struct JukeboxSongData { comparator_output: u8, } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/jukebox_song.json"); println!("cargo:rerun-if-changed=../assets/registry/1_21_11_synced_registries.json"); @@ -82,8 +82,7 @@ pub(crate) fn build() -> TokenStream { let variant_name = make_variant_ident(name); let length = song_data .get(name) - .map(|d| d.length_in_seconds as u32) - .unwrap_or(0); + .map_or(0, |d| d.length_in_seconds as u32); quote! { Self::#variant_name => #length, } }) .collect::(); @@ -92,10 +91,7 @@ pub(crate) fn build() -> TokenStream { .keys() .map(|name| { let variant_name = make_variant_ident(name); - let output = song_data - .get(name) - .map(|d| d.comparator_output) - .unwrap_or(0); + let output = song_data.get(name).map_or(0, |d| d.comparator_output); quote! { Self::#variant_name => #output, } }) .collect::(); diff --git a/pumpkin-data/build/message_type.rs b/pumpkin-data/build/message_type.rs index b7adc22c3..a1d454b61 100644 --- a/pumpkin-data/build/message_type.rs +++ b/pumpkin-data/build/message_type.rs @@ -24,7 +24,7 @@ pub struct RawChatType { // parameters: Vec, // } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/message_type.json"); let json: BTreeMap = diff --git a/pumpkin-data/build/meta_data_type.rs b/pumpkin-data/build/meta_data_type.rs index 124ba055e..af34ddfb5 100644 --- a/pumpkin-data/build/meta_data_type.rs +++ b/pumpkin-data/build/meta_data_type.rs @@ -4,7 +4,7 @@ use heck::ToPascalCase; use proc_macro2::TokenStream; use quote::{format_ident, quote}; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/meta_data_type.json"); let handlers_map: BTreeMap = diff --git a/pumpkin-data/build/noise_parameter.rs b/pumpkin-data/build/noise_parameter.rs index 1440635e7..d4e5792ed 100644 --- a/pumpkin-data/build/noise_parameter.rs +++ b/pumpkin-data/build/noise_parameter.rs @@ -4,7 +4,7 @@ use proc_macro2::TokenStream; use pumpkin_util::DoublePerlinNoiseParametersCodec; use quote::{format_ident, quote}; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/noise_parameters.json"); let json: BTreeMap = diff --git a/pumpkin-data/build/noise_router.rs b/pumpkin-data/build/noise_router.rs index fbdc6257f..ae1a61e49 100644 --- a/pumpkin-data/build/noise_router.rs +++ b/pumpkin-data/build/noise_router.rs @@ -996,7 +996,7 @@ macro_rules! fix_final_density { }}; } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/density_function.json"); let mut reprs: NoiseRouterReprs = diff --git a/pumpkin-data/build/packet.rs b/pumpkin-data/build/packet.rs index 9fa49d854..a7d01a5f5 100644 --- a/pumpkin-data/build/packet.rs +++ b/pumpkin-data/build/packet.rs @@ -10,7 +10,7 @@ pub struct Packets { clientbound: BTreeMap>, } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/packet/1_21_7_packets.json"); println!("cargo:rerun-if-changed=../assets/packet/1_21_11_packets.json"); diff --git a/pumpkin-data/build/particle.rs b/pumpkin-data/build/particle.rs index 12f1ee0c3..11a09bb7a 100644 --- a/pumpkin-data/build/particle.rs +++ b/pumpkin-data/build/particle.rs @@ -6,7 +6,7 @@ use quote::{format_ident, quote}; use crate::array_to_tokenstream; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/particles.json"); let particle: Vec = diff --git a/pumpkin-data/build/potion.rs b/pumpkin-data/build/potion.rs index a770379f0..0eb5c7744 100644 --- a/pumpkin-data/build/potion.rs +++ b/pumpkin-data/build/potion.rs @@ -49,7 +49,7 @@ impl Effect { } } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/potion.json"); let potions: BTreeMap = diff --git a/pumpkin-data/build/potion_brewing.rs b/pumpkin-data/build/potion_brewing.rs index cea29b4da..e0063cb97 100644 --- a/pumpkin-data/build/potion_brewing.rs +++ b/pumpkin-data/build/potion_brewing.rs @@ -71,7 +71,7 @@ impl Recipes { } } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/potion_brewing.json"); let json: PotionBrewing = diff --git a/pumpkin-data/build/recipe_remainder.rs b/pumpkin-data/build/recipe_remainder.rs index 8b167ecda..a4963fcf6 100644 --- a/pumpkin-data/build/recipe_remainder.rs +++ b/pumpkin-data/build/recipe_remainder.rs @@ -2,7 +2,7 @@ use proc_macro2::{Span, TokenStream}; use quote::quote; use std::{collections::BTreeMap, fs}; use syn::LitInt; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/recipe_remainder.json"); let remainder: BTreeMap = diff --git a/pumpkin-data/build/recipes.rs b/pumpkin-data/build/recipes.rs index 0a8c10734..555d52a5b 100644 --- a/pumpkin-data/build/recipes.rs +++ b/pumpkin-data/build/recipes.rs @@ -46,7 +46,7 @@ pub struct CookingRecipeStruct { impl CookingRecipeStruct { /// Generate a recipe ID based on result, ingredient, and cooking type - /// Format: minecraft:{result}_from_{cooking_type}_{ingredient} + /// Format: minecraft:{result}_from_{`cooking_type`}_{ingredient} fn generate_recipe_id(&self, cooking_type: &str) -> String { let result_name = self .result @@ -66,8 +66,7 @@ impl CookingRecipeStruct { // Use first item for ID generation items .first() - .map(|s| s.strip_prefix("minecraft:").unwrap_or(s)) - .unwrap_or("unknown") + .map_or("unknown", |s| s.strip_prefix("minecraft:").unwrap_or(s)) .to_string() } }; @@ -367,7 +366,7 @@ impl ToTokens for RecipeCategoryTypes { } } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/recipes.json"); let recipes_assets: Vec = diff --git a/pumpkin-data/build/registry.rs b/pumpkin-data/build/registry.rs index 7a3fd1cd7..fbc8ba9d3 100644 --- a/pumpkin-data/build/registry.rs +++ b/pumpkin-data/build/registry.rs @@ -4,7 +4,7 @@ use quote::quote; use serde_json::Value; use std::fs; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/registry/1_21_9_synced_registries.json"); println!("cargo:rerun-if-changed=../assets/registry/1_21_11_synced_registries.json"); diff --git a/pumpkin-data/build/scoreboard_slot.rs b/pumpkin-data/build/scoreboard_slot.rs index 031803148..ead248b9b 100644 --- a/pumpkin-data/build/scoreboard_slot.rs +++ b/pumpkin-data/build/scoreboard_slot.rs @@ -5,7 +5,7 @@ use quote::quote; use crate::array_to_tokenstream; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/scoreboard_display_slot.json"); let sound_categories: Vec = serde_json::from_str( diff --git a/pumpkin-data/build/screen.rs b/pumpkin-data/build/screen.rs index 02cc8fa37..0c3b23cdc 100644 --- a/pumpkin-data/build/screen.rs +++ b/pumpkin-data/build/screen.rs @@ -5,7 +5,7 @@ use quote::quote; use crate::array_to_tokenstream; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/screens.json"); let screens: Vec = diff --git a/pumpkin-data/build/sound.rs b/pumpkin-data/build/sound.rs index 76e05ff29..60d191778 100644 --- a/pumpkin-data/build/sound.rs +++ b/pumpkin-data/build/sound.rs @@ -6,45 +6,28 @@ use quote::{format_ident, quote}; use crate::array_to_tokenstream; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/sounds.json"); - let sound: Vec = + let mut sound: Vec = serde_json::from_str(&fs::read_to_string("../assets/sounds.json").unwrap()) .expect("Failed to parse sounds.json"); + + sound.sort(); + let variants = array_to_tokenstream(&sound); - let type_from_name = &sound - .iter() - .map(|sound| { - let id = &sound; - let name = format_ident!("{}", sound.to_pascal_case()); + let lookup_table = sound.iter().map(|s| { + let variant_name = format_ident!("{}", s.to_pascal_case()); + quote! { (#s, Self::#variant_name) } + }); - quote! { - #id => Some(Self::#name), - } - }) - .collect::(); + let variants_list = sound.iter().map(|s| { + let variant_name = format_ident!("{}", s.to_pascal_case()); + quote! { Self::#variant_name, } + }); - let type_to_name = &sound - .iter() - .map(|sound| { - let id = &sound; - let name = format_ident!("{}", sound.to_pascal_case()); - - quote! { - Self::#name => #id, - } - }) - .collect::(); - - let variants_list = sound - .iter() - .map(|sound| { - let name = format_ident!("{}", sound.to_pascal_case()); - quote! { Self::#name, } - }) - .collect::(); + let names_list = sound.iter().map(|s| quote! { #s }); quote! { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -54,21 +37,25 @@ pub(crate) fn build() -> TokenStream { } impl Sound { + const NAMES: &[&str] = &[ #(#names_list),* ]; + + const LOOKUP: &[(&str, Sound)] = &[ + #(#lookup_table),* + ]; + pub fn from_name(name: &str) -> Option { - match name { - #type_from_name - _ => None - } + Self::LOOKUP + .binary_search_by_key(&name, |&(k, _)| k) + .ok() + .map(|idx| Self::LOOKUP[idx].1) } - pub const fn to_name(&self) -> &'static str { - match self { - #type_to_name - } + pub const fn to_name(&self) -> &'static str { + Self::NAMES[*self as usize] } pub fn slice() -> &'static [Self] { - &[#variants_list] + &[#(#variants_list)*] } } } diff --git a/pumpkin-data/build/sound_category.rs b/pumpkin-data/build/sound_category.rs index 11c104152..165830d1b 100644 --- a/pumpkin-data/build/sound_category.rs +++ b/pumpkin-data/build/sound_category.rs @@ -6,7 +6,7 @@ use quote::{format_ident, quote}; use crate::array_to_tokenstream; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/sound_category.json"); let sound_categories: Vec = diff --git a/pumpkin-data/build/spawn_egg.rs b/pumpkin-data/build/spawn_egg.rs index 95b73cf99..d2efcef16 100644 --- a/pumpkin-data/build/spawn_egg.rs +++ b/pumpkin-data/build/spawn_egg.rs @@ -4,7 +4,7 @@ use heck::ToShoutySnakeCase; use proc_macro2::TokenStream; use quote::{format_ident, quote}; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/spawn_egg.json"); let eggs: BTreeMap = diff --git a/pumpkin-data/build/structures.rs b/pumpkin-data/build/structures.rs index a471c3310..55c483a42 100644 --- a/pumpkin-data/build/structures.rs +++ b/pumpkin-data/build/structures.rs @@ -78,17 +78,17 @@ impl ToTokens for WeightedEntryStruct { impl ToTokens for StructurePlacementStruct { fn to_tokens(&self, tokens: &mut TokenStream) { - let frequency_reduction = match &self.frequency_reduction_method { - Some(method) => { - let method_token = frequency_reduction_to_token(method); - quote!(Some(#method_token)) - } - None => quote!(None), + let frequency_reduction = if let Some(method) = &self.frequency_reduction_method { + let method_token = frequency_reduction_to_token(method); + quote!(Some(#method_token)) + } else { + quote!(None) }; - let frequency = match self.frequency { - Some(f) => quote!(Some(#f)), - None => quote!(None), + let frequency = if let Some(f) = self.frequency { + quote!(Some(#f)) + } else { + quote!(None) }; let salt = self.salt; @@ -113,12 +113,11 @@ impl ToTokens for StructurePlacementTypeStruct { separation, spread_type, } => { - let spread_type_token = match spread_type { - Some(st) => { - let st_token = spread_type_to_token(st); - quote!(Some(#st_token)) - } - None => quote!(None), + let spread_type_token = if let Some(st) = spread_type { + let st_token = spread_type_to_token(st); + quote!(Some(#st_token)) + } else { + quote!(None) }; tokens.extend(quote!( @@ -202,7 +201,7 @@ fn structure_key_to_token(key: &str) -> TokenStream { "ancient_city" => quote!(StructureKeys::AncientCity), "trail_ruins" => quote!(StructureKeys::TrailRuins), "trial_chambers" => quote!(StructureKeys::TrialChambers), - _ => panic!("Unknown structure key: {}", stripped), + _ => panic!("Unknown structure key: {stripped}"), } } @@ -237,11 +236,11 @@ fn generation_step_to_token(step: &str) -> TokenStream { "fluid_springs" => quote!(GenerationStep::FluidSprings), "vegetal_decoration" => quote!(GenerationStep::VegetalDecoration), "top_layer_modification" => quote!(GenerationStep::TopLayerModification), - _ => panic!("Unknown generation step: {}", step), + _ => panic!("Unknown generation step: {step}"), } } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/structures.json"); println!("cargo:rerun-if-changed=../assets/structure_set.json"); diff --git a/pumpkin-data/build/tag.rs b/pumpkin-data/build/tag.rs index 0ecfbd717..563f9f324 100644 --- a/pumpkin-data/build/tag.rs +++ b/pumpkin-data/build/tag.rs @@ -63,7 +63,7 @@ impl ToTokens for EnumCreator { } } -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { // --- Rerun Triggers --- println!("cargo:rerun-if-changed=../assets/blocks.json"); println!("cargo:rerun-if-changed=../assets/items.json"); diff --git a/pumpkin-data/build/tracked_data.rs b/pumpkin-data/build/tracked_data.rs index d561db060..e8eae5fbe 100644 --- a/pumpkin-data/build/tracked_data.rs +++ b/pumpkin-data/build/tracked_data.rs @@ -2,7 +2,7 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote}; use std::{collections::BTreeMap, fs}; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/tracked_data/1_21_7_tracked_data.json"); println!("cargo:rerun-if-changed=../assets/tracked_data/1_21_11_tracked_data.json"); diff --git a/pumpkin-data/build/translations.rs b/pumpkin-data/build/translations.rs index 671dc0d6e..27b9ff85c 100644 --- a/pumpkin-data/build/translations.rs +++ b/pumpkin-data/build/translations.rs @@ -2,7 +2,7 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote}; use std::{collections::BTreeMap, fs}; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/en_us.json"); let en_us: BTreeMap = serde_json::from_str( @@ -16,13 +16,13 @@ pub(crate) fn build() -> TokenStream { let clean_name = name.to_uppercase().replace(['.', '-'], "_"); let ident = format_ident!("{}", clean_name); - if !value.is_empty() { + if value.is_empty() { constants.extend(quote! { - #[doc = #value] pub const #ident: &str = #name; }); } else { constants.extend(quote! { + #[doc = #value] pub const #ident: &str = #name; }); } diff --git a/pumpkin-data/build/world_event.rs b/pumpkin-data/build/world_event.rs index 44de81349..5d7b17528 100644 --- a/pumpkin-data/build/world_event.rs +++ b/pumpkin-data/build/world_event.rs @@ -4,7 +4,7 @@ use heck::ToPascalCase; use proc_macro2::TokenStream; use quote::{format_ident, quote}; -pub(crate) fn build() -> TokenStream { +pub fn build() -> TokenStream { println!("cargo:rerun-if-changed=../assets/world_event.json"); let events: BTreeMap = diff --git a/pumpkin-data/src/block_direction.rs b/pumpkin-data/src/block_direction.rs index 995cde1f5..f5cb653a3 100644 --- a/pumpkin-data/src/block_direction.rs +++ b/pumpkin-data/src/block_direction.rs @@ -56,7 +56,7 @@ impl TryFrom for BlockDirection { impl BlockDirection { #[must_use] - pub fn to_index(&self) -> u8 { + pub const fn to_index(&self) -> u8 { match self { Self::Down => 0, Self::Up => 1, @@ -68,7 +68,7 @@ impl BlockDirection { } #[must_use] - pub fn from_index(index: u8) -> Option { + pub const fn from_index(index: u8) -> Option { match index { 0 => Some(Self::Down), 1 => Some(Self::Up), @@ -107,7 +107,7 @@ impl BlockDirection { } #[must_use] - pub fn opposite(&self) -> Self { + pub const fn opposite(&self) -> Self { match self { Self::Down => Self::Up, Self::Up => Self::Down, @@ -119,12 +119,12 @@ impl BlockDirection { } #[must_use] - pub fn positive(&self) -> bool { + pub const fn positive(&self) -> bool { matches!(self, Self::South | Self::East | Self::Up) } #[must_use] - pub fn all() -> [Self; 6] { + pub const fn all() -> [Self; 6] { [ Self::Down, Self::Up, @@ -135,7 +135,7 @@ impl BlockDirection { ] } #[must_use] - pub fn update_order() -> [Self; 6] { + pub const fn update_order() -> [Self; 6] { [ Self::West, Self::East, @@ -147,7 +147,7 @@ impl BlockDirection { } #[must_use] - pub fn abstract_block_update_order() -> [Self; 6] { + pub const fn abstract_block_update_order() -> [Self; 6] { [ Self::West, Self::East, @@ -159,27 +159,27 @@ impl BlockDirection { } #[must_use] - pub fn horizontal() -> [Self; 4] { + pub const fn horizontal() -> [Self; 4] { [Self::North, Self::South, Self::West, Self::East] } #[must_use] - pub fn flow_directions() -> [Self; 5] { + pub const fn flow_directions() -> [Self; 5] { [Self::Down, Self::North, Self::South, Self::West, Self::East] } #[must_use] - pub fn is_horizontal(&self) -> bool { + pub const fn is_horizontal(&self) -> bool { matches!(self, Self::North | Self::South | Self::West | Self::East) } #[must_use] - pub fn vertical() -> [Self; 2] { + pub const fn vertical() -> [Self; 2] { [Self::Down, Self::Up] } #[must_use] - pub fn to_horizontal_facing(&self) -> Option { + pub const fn to_horizontal_facing(&self) -> Option { match self { Self::North => Some(HorizontalFacing::North), Self::South => Some(HorizontalFacing::South), @@ -190,7 +190,7 @@ impl BlockDirection { } #[must_use] - pub fn to_horizontal_axis(&self) -> Option { + pub const fn to_horizontal_axis(&self) -> Option { match self { Self::North | Self::South => Some(HorizontalAxis::Z), Self::West | Self::East => Some(HorizontalAxis::X), @@ -199,7 +199,7 @@ impl BlockDirection { } #[must_use] - pub fn to_cardinal_direction(&self) -> HorizontalFacing { + pub const fn to_cardinal_direction(&self) -> HorizontalFacing { match self { Self::South => HorizontalFacing::South, Self::West => HorizontalFacing::West, @@ -209,7 +209,7 @@ impl BlockDirection { } #[must_use] - pub fn from_cardinal_direction(direction: HorizontalFacing) -> Self { + pub const fn from_cardinal_direction(direction: HorizontalFacing) -> Self { match direction { HorizontalFacing::North => Self::North, HorizontalFacing::South => Self::South, @@ -218,7 +218,7 @@ impl BlockDirection { } } #[must_use] - pub fn to_axis(&self) -> Axis { + pub const fn to_axis(&self) -> Axis { match self { Self::North | Self::South => Axis::Z, Self::West | Self::East => Axis::X, @@ -227,7 +227,7 @@ impl BlockDirection { } #[must_use] - pub fn to_facing(&self) -> Facing { + pub const fn to_facing(&self) -> Facing { match self { Self::North => Facing::North, Self::South => Facing::South, @@ -239,7 +239,7 @@ impl BlockDirection { } #[must_use] - pub fn rotate_clockwise(&self) -> Self { + pub const fn rotate_clockwise(&self) -> Self { match self { Self::East => Self::South, Self::West => Self::North, @@ -249,7 +249,7 @@ impl BlockDirection { } #[must_use] - pub fn rotate_counter_clockwise(&self) -> Self { + pub const fn rotate_counter_clockwise(&self) -> Self { match self { Self::West => Self::South, Self::East => Self::North, diff --git a/pumpkin-data/src/blocks.rs b/pumpkin-data/src/blocks.rs index 29309ac23..3629aa058 100644 --- a/pumpkin-data/src/blocks.rs +++ b/pumpkin-data/src/blocks.rs @@ -117,12 +117,14 @@ impl Block { } /// Returns whether this block is solid (based on default state) - pub fn is_solid(&self) -> bool { + #[must_use] + pub const fn is_solid(&self) -> bool { self.default_state.is_solid() } /// Returns whether this block is air (based on default state) - pub fn is_air(&self) -> bool { + #[must_use] + pub const fn is_air(&self) -> bool { self.default_state.is_air() } } diff --git a/pumpkin-data/src/collision_shape.rs b/pumpkin-data/src/collision_shape.rs index 8a7f0c040..213aa0804 100644 --- a/pumpkin-data/src/collision_shape.rs +++ b/pumpkin-data/src/collision_shape.rs @@ -8,7 +8,7 @@ pub struct CollisionShape { impl CollisionShape { #[must_use] - pub fn to_bounding_box(&self) -> BoundingBox { + pub const fn to_bounding_box(&self) -> BoundingBox { BoundingBox { min: self.min, max: self.max, @@ -16,7 +16,7 @@ impl CollisionShape { } #[must_use] - pub fn new(min: Vector3, max: Vector3) -> Self { + pub const fn new(min: Vector3, max: Vector3) -> Self { Self { min, max } } diff --git a/pumpkin-data/src/data_component_impl.rs b/pumpkin-data/src/data_component_impl.rs index c30bed48a..c32739bb2 100644 --- a/pumpkin-data/src/data_component_impl.rs +++ b/pumpkin-data/src/data_component_impl.rs @@ -104,13 +104,13 @@ pub fn get(value: &dyn DataComponentImpl) -> &T pub fn get_mut(value: &mut dyn DataComponentImpl) -> &mut T { value.as_mut_any().downcast_mut::().unwrap() } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct CustomDataImpl; impl DataComponentImpl for CustomDataImpl { default_impl!(CustomData); } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct MaxStackSizeImpl { pub size: u8, } @@ -129,14 +129,14 @@ impl DataComponentImpl for MaxStackSizeImpl { default_impl!(MaxStackSize); } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct MaxDamageImpl { pub max_damage: i32, } impl DataComponentImpl for MaxDamageImpl { default_impl!(MaxDamage); } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct DamageImpl { pub damage: i32, } @@ -154,10 +154,10 @@ impl DataComponentImpl for DamageImpl { } default_impl!(Damage); } -#[derive(Clone, Hash, PartialEq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub struct UnbreakableImpl; impl UnbreakableImpl { - fn read_data(_data: &NbtTag) -> Option { + const fn read_data(_data: &NbtTag) -> Option { Some(Self) } } @@ -170,7 +170,7 @@ impl DataComponentImpl for UnbreakableImpl { } default_impl!(Unbreakable); } -#[derive(Clone, Hash, PartialEq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub struct CustomNameImpl { // TODO make TextComponent const pub name: &'static str, @@ -178,7 +178,7 @@ pub struct CustomNameImpl { impl DataComponentImpl for CustomNameImpl { default_impl!(CustomName); } -#[derive(Clone, Hash, PartialEq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub struct ItemNameImpl { // TODO make TextComponent const pub name: &'static str, @@ -186,13 +186,13 @@ pub struct ItemNameImpl { impl DataComponentImpl for ItemNameImpl { default_impl!(ItemName); } -#[derive(Clone, Hash, PartialEq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub struct ItemModelImpl; -#[derive(Clone, Hash, PartialEq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub struct LoreImpl; -#[derive(Clone, Hash, PartialEq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub struct RarityImpl; -#[derive(Clone, Hash, PartialEq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub struct EnchantmentsImpl { pub enchantment: Cow<'static, [(&'static Enchantment, i32)]>, } @@ -261,12 +261,12 @@ impl DataComponentImpl for EnchantmentsImpl { } default_impl!(Enchantments); } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct CanPlaceOnImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct CanBreakImpl; -#[derive(Clone, Copy, Debug, PartialEq, Hash)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Operation { AddValue, AddMultipliedBase, @@ -296,17 +296,17 @@ pub struct AttributeModifiersImpl { impl DataComponentImpl for AttributeModifiersImpl { default_impl!(AttributeModifiers); } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct CustomModelDataImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct TooltipDisplayImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct RepairCostImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct CreativeSlotLockImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct EnchantmentGlintOverrideImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct IntangibleProjectileImpl; #[derive(Clone, Debug, PartialEq)] pub struct FoodImpl { @@ -345,14 +345,14 @@ impl Hash for ConsumableImpl { unsafe { (*(&raw const self.consume_seconds).cast::()).hash(state) }; } } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct UseRemainderImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct UseCooldownImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct DamageResistantImpl; -#[derive(Clone, Hash, PartialEq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub enum IDSet { Tag(&'static Tag), Blocks(Cow<'static, [&'static Block]>), @@ -394,7 +394,7 @@ impl Hash for ToolImpl { self.can_destroy_blocks_in_creative.hash(state); } } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct WeaponImpl; #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] @@ -486,7 +486,7 @@ impl EquipmentSlot { }); #[must_use] - pub fn get_entity_slot_id(&self) -> i32 { + pub const fn get_entity_slot_id(&self) -> i32 { match self { Self::MainHand(data) => data.entity_id, Self::OffHand(data) => data.entity_id, @@ -515,12 +515,12 @@ impl EquipmentSlot { } #[must_use] - pub fn get_offset_entity_slot_id(&self, offset: i32) -> i32 { + pub const fn get_offset_entity_slot_id(&self, offset: i32) -> i32 { self.get_entity_slot_id() + offset } #[must_use] - pub fn slot_type(&self) -> EquipmentType { + pub const fn slot_type(&self) -> EquipmentType { match self { Self::MainHand(data) => data.slot_type, Self::OffHand(data) => data.slot_type, @@ -534,7 +534,7 @@ impl EquipmentSlot { } #[must_use] - pub fn is_armor_slot(&self) -> bool { + pub const fn is_armor_slot(&self) -> bool { matches!( self.slot_type(), EquipmentType::HumanoidArmor | EquipmentType::AnimalArmor @@ -556,7 +556,7 @@ impl EquipmentSlot { } } -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub enum EntityTypeOrTag { Tag(&'static Tag), Single(&'static EntityType), @@ -577,9 +577,9 @@ impl Hash for EntityTypeOrTag { } } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct EnchantableImpl; -#[derive(Clone, Hash, PartialEq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub struct EquippableImpl { pub slot: &'static EquipmentSlot, pub equip_sound: &'static str, @@ -596,41 +596,41 @@ pub struct EquippableImpl { impl DataComponentImpl for EquippableImpl { default_impl!(Equippable); } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct RepairableImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct GliderImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct TooltipStyleImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct DeathProtectionImpl; impl DataComponentImpl for DeathProtectionImpl { default_impl!(DeathProtection); } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BlocksAttacksImpl; impl DataComponentImpl for BlocksAttacksImpl { default_impl!(BlocksAttacks); } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct StoredEnchantmentsImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct DyedColorImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct MapColorImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct MapIdImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct MapDecorationsImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct MapPostProcessingImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ChargedProjectilesImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BundleContentsImpl; /// Status effect instance for potion contents -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct StatusEffectInstance { pub effect_id: i32, pub amplifier: i32, @@ -640,7 +640,7 @@ pub struct StatusEffectInstance { pub show_icon: bool, } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct PotionContentsImpl { pub potion_id: Option, pub custom_color: Option, @@ -684,114 +684,114 @@ impl DataComponentImpl for PotionContentsImpl { default_impl!(PotionContents); } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct PotionDurationScaleImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct SuspiciousStewEffectsImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct WritableBookContentImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct WrittenBookContentImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct TrimImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct DebugStickStateImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct EntityDataImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BucketEntityDataImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BlockEntityDataImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct InstrumentImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ProvidesTrimMaterialImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct OminousBottleAmplifierImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct JukeboxPlayableImpl { pub song: &'static str, } impl DataComponentImpl for JukeboxPlayableImpl { default_impl!(JukeboxPlayable); } -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ProvidesBannerPatternsImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct RecipesImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct LodestoneTrackerImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct FireworkExplosionImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct FireworksImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ProfileImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct NoteBlockSoundImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BannerPatternsImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BaseColorImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct PotDecorationsImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ContainerImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BlockStateImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BeesImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct LockImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ContainerLootImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BreakSoundImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct VillagerVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct WolfVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct WolfSoundVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct WolfCollarImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct FoxVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct SalmonSizeImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ParrotVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct TropicalFishPatternImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct TropicalFishBaseColorImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct TropicalFishPatternColorImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct MooshroomVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct RabbitVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct PigVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct CowVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ChickenVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct FrogVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct HorseVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct PaintingVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct LlamaVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct AxolotlVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct CatVariantImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct CatCollarImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct SheepColorImpl; -#[derive(Clone, Debug, Hash, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ShulkerColorImpl; diff --git a/pumpkin-world/Cargo.toml b/pumpkin-world/Cargo.toml index 4943d21e0..5db92b47e 100644 --- a/pumpkin-world/Cargo.toml +++ b/pumpkin-world/Cargo.toml @@ -16,6 +16,7 @@ bytes.workspace = true tokio = { workspace = true, features = [ "macros", + # Maybe remove this in the future "rt-multi-thread", "sync", "io-std", @@ -31,14 +32,11 @@ serde_json.workspace = true log.workspace = true crossbeam.workspace = true -num-derive.workspace = true sha2.workspace = true bitflags.workspace = true dashmap.workspace = true -num-traits.workspace = true - # Compression flate2.workspace = true lz4-java-wrc.workspace = true @@ -60,10 +58,6 @@ crossfire.workspace = true [dev-dependencies] criterion = { workspace = true, features = ["html_reports", "async_tokio"] } temp-dir.workspace = true -# Print log info inside tests when needed -env_logger.workspace = true -# Allows us to modify the config -pumpkin-config = { workspace = true, features = ["test_helper"] } # Deserialize NaN and Inf serde_json5.workspace = true diff --git a/pumpkin-world/src/block/entities/blasting_furnace.rs b/pumpkin-world/src/block/entities/blasting_furnace.rs index 963e9f93f..f46dda154 100644 --- a/pumpkin-world/src/block/entities/blasting_furnace.rs +++ b/pumpkin-world/src/block/entities/blasting_furnace.rs @@ -32,7 +32,7 @@ pub struct BlastingFurnaceBlockEntity { pub items: [Arc>; Self::INVENTORY_SIZE], - /// Tracks recipes used for XP calculation (vanilla RecipesUsed NBT format) + /// Tracks recipes used for XP calculation (vanilla `RecipesUsed` NBT format) /// Maps result item ID -> craft count pub recipes_used: StdMutex>, } diff --git a/pumpkin-world/src/block/entities/furnace.rs b/pumpkin-world/src/block/entities/furnace.rs index 5762ccfc6..79186dfcc 100644 --- a/pumpkin-world/src/block/entities/furnace.rs +++ b/pumpkin-world/src/block/entities/furnace.rs @@ -32,7 +32,7 @@ pub struct FurnaceBlockEntity { pub items: [Arc>; Self::INVENTORY_SIZE], - /// Tracks recipes used for XP calculation (vanilla RecipesUsed NBT format) + /// Tracks recipes used for XP calculation (vanilla `RecipesUsed` NBT format) /// Maps result item ID -> craft count pub recipes_used: StdMutex>, } diff --git a/pumpkin-world/src/block/entities/furnace_like_block_entity.rs b/pumpkin-world/src/block/entities/furnace_like_block_entity.rs index e3012c9b4..52940f7b8 100644 --- a/pumpkin-world/src/block/entities/furnace_like_block_entity.rs +++ b/pumpkin-world/src/block/entities/furnace_like_block_entity.rs @@ -10,7 +10,7 @@ use crate::{ }; /// Trait for extracting smelting experience from cooking block entities. -/// This is a separate dyn-compatible trait since CookingBlockEntityBase is not. +/// This is a separate dyn-compatible trait since `CookingBlockEntityBase` is not. pub trait ExperienceContainer: Send + Sync { /// Extract and reset accumulated experience, returning the total as an integer fn extract_experience(&self) -> i32; @@ -28,7 +28,7 @@ pub trait CookingBlockEntityBase: /// Uses the result item ID as the recipe identifier fn add_recipe_used(&self, recipe: &CookingRecipe); /// Extract and reset accumulated experience, returning the total as an integer - /// Calculates XP from tracked recipes and clears the recipes_used map + /// Calculates XP from tracked recipes and clears the `recipes_used` map fn extract_experience_from_recipes(&self) -> i32; fn get_input_item(&self) -> impl std::future::Future>>; diff --git a/pumpkin-world/src/block/entities/jukebox.rs b/pumpkin-world/src/block/entities/jukebox.rs index 7b2a5024e..f0ea101ee 100644 --- a/pumpkin-world/src/block/entities/jukebox.rs +++ b/pumpkin-world/src/block/entities/jukebox.rs @@ -12,10 +12,10 @@ use crate::inventory::{Clearable, Inventory, InventoryFuture}; use crate::world::SimpleWorld; use crate::{block::entities::BlockEntity, item::ItemStack}; -/// Matches vanilla's JukeboxBlockEntity +/// Matches vanilla's `JukeboxBlockEntity` pub struct JukeboxBlockEntity { position: BlockPos, - /// The record item stored in the jukebox (RecordItem in NBT) + /// The record item stored in the jukebox (`RecordItem` in NBT) record_stack: Arc>, /// Ticks since the current song started playing ticks_since_song_started: AtomicU64, @@ -129,7 +129,7 @@ impl JukeboxBlockEntity { self.record_stack.lock().await.clone() } - /// Set the record stack - matches vanilla's setStack() + /// Set the record stack - matches vanilla's `setStack()` /// Note: The caller is responsible for updating block state and playing music pub async fn set_record(&self, stack: ItemStack) { *self.record_stack.lock().await = stack; @@ -176,7 +176,7 @@ impl JukeboxBlockEntity { } } -/// Implements single-slot inventory for jukebox (matches vanilla's SingleStackInventory) +/// Implements single-slot inventory for jukebox (matches vanilla's `SingleStackInventory`) impl Inventory for JukeboxBlockEntity { fn size(&self) -> usize { 1 diff --git a/pumpkin-world/src/block/entities/sign.rs b/pumpkin-world/src/block/entities/sign.rs index 3e77907e2..f922a9f9d 100644 --- a/pumpkin-world/src/block/entities/sign.rs +++ b/pumpkin-world/src/block/entities/sign.rs @@ -7,12 +7,11 @@ use std::{ }; use super::BlockEntity; -use num_derive::FromPrimitive; use pumpkin_nbt::{compound::NbtCompound, tag::NbtTag}; use pumpkin_util::math::position::BlockPos; use tokio::sync::Mutex; -#[derive(Clone, Default, FromPrimitive)] +#[derive(Clone, Default)] #[repr(i8)] pub enum DyeColor { White = 0, diff --git a/pumpkin-world/src/block/entities/smoker.rs b/pumpkin-world/src/block/entities/smoker.rs index c3958a62c..35d77726f 100644 --- a/pumpkin-world/src/block/entities/smoker.rs +++ b/pumpkin-world/src/block/entities/smoker.rs @@ -32,7 +32,7 @@ pub struct SmokerBlockEntity { pub items: [Arc>; Self::INVENTORY_SIZE], - /// Tracks recipes used for XP calculation (vanilla RecipesUsed NBT format) + /// Tracks recipes used for XP calculation (vanilla `RecipesUsed` NBT format) /// Maps result item ID -> craft count pub recipes_used: StdMutex>, } diff --git a/pumpkin-world/src/block/mod.rs b/pumpkin-world/src/block/mod.rs index 2706c1aa1..9edd4d426 100644 --- a/pumpkin-world/src/block/mod.rs +++ b/pumpkin-world/src/block/mod.rs @@ -80,7 +80,7 @@ pub fn to_state_id_from_blueprint(print: &BlockBlueprint) -> BlockStateId { } } -/// Helper to get the full BlockState reference from the blueprint +/// Helper to get the full `BlockState` reference from the blueprint #[must_use] pub fn to_state_from_blueprint(print: &BlockBlueprint) -> &'static BlockState { BlockState::from_id(to_state_id_from_blueprint(print)) diff --git a/pumpkin-world/src/chunk/format/mod.rs b/pumpkin-world/src/chunk/format/mod.rs index fb8d31a93..df2d4cd96 100644 --- a/pumpkin-world/src/chunk/format/mod.rs +++ b/pumpkin-world/src/chunk/format/mod.rs @@ -133,12 +133,10 @@ impl ChunkData { // Map light data to the LightContainer enum let block_light = section .block_light - .map(LightContainer::Full) - .unwrap_or(LightContainer::Empty(0)); // Standard default + .map_or(LightContainer::Empty(0), LightContainer::Full); // Standard default let sky_light = section .sky_light - .map(LightContainer::Full) - .unwrap_or(LightContainer::Empty(15)); // Sky is usually bright + .map_or(LightContainer::Empty(15), LightContainer::Full); // Sky is usually bright // Convert NBT to Palettes let block_palette = section diff --git a/pumpkin-world/src/chunk_system.rs b/pumpkin-world/src/chunk_system.rs index 4aca7119b..32b3a7a76 100644 --- a/pumpkin-world/src/chunk_system.rs +++ b/pumpkin-world/src/chunk_system.rs @@ -28,7 +28,6 @@ use crossbeam::channel::{Receiver, Sender}; use dashmap::DashMap; use itertools::Itertools; use log::{debug, error}; -use num_traits::abs; use pumpkin_data::biome::Biome; use pumpkin_data::fluid::{Fluid, FluidState}; @@ -253,7 +252,7 @@ impl ChunkLoading { for dx in -range..=range { for dy in -range..=range { let new_pos = ticket_pos.add_raw(dx as i32, dy as i32); - let level_from_source = level + abs(dx).max(abs(dy)); + let level_from_source = level + dx.abs().max(dy.abs()); let i = temp.entry(new_pos).or_insert(Self::MAX_LEVEL); *i = min(*i, level_from_source); } @@ -416,7 +415,7 @@ impl ChunkLoading { } for (ticket_pos, levels) in &self.ticket { - if abs(ticket_pos.x - pos.x) <= range && abs(ticket_pos.y - pos.y) <= range { + if (ticket_pos.x - pos.x).abs() <= range && (ticket_pos.y - pos.y).abs() <= range { let level = *levels.iter().min().unwrap(); debug_assert!(level < Self::MAX_LEVEL); let old = self.cache.get(&self.pos_level, *ticket_pos); @@ -790,7 +789,7 @@ impl Chunk { let total_sections = dimension.height as usize / 16; let sections = ChunkSections::new(total_sections, dimension.min_y); - let proto_biome_height = biome_coords::from_block(proto_chunk.height()); + let proto_biome_height = biome_coords::from_block(proto_chunk.height() as i32); let biome_min_y = biome_coords::from_block(dimension.min_y); for y_offset in 0..proto_biome_height { @@ -803,7 +802,7 @@ impl Chunk { .unwrap() .get_mut(section_index) { - let absolute_biome_y = biome_min_y + y_offset as i32; + let absolute_biome_y = biome_min_y + y_offset; for z in 0..4 { for x in 0..4 { @@ -1439,7 +1438,7 @@ impl GenerationSchedule { let level_clone = level.clone(); let handle = thread::Builder::new() - .name(format!("Gen-{}", i)) // Identifying dim helps debugging + .name(format!("Gen-{i}")) // Identifying dim helps debugging .spawn(move || { Self::generation_work(recv_gen, send_chunk, level_clone); }) @@ -1448,7 +1447,7 @@ impl GenerationSchedule { thread_tracker.push(handle); } - let level_sched = level.clone(); + let level_sched = level; let handle = thread::Builder::new() .name("Schedule".to_string()) .spawn(move || { @@ -1486,7 +1485,7 @@ impl GenerationSchedule { return last_level.get(&pos).unwrap() + (stage as i8); } for i in last_high_priority { - let dst = max(abs(i.x - pos.x), abs(i.y - pos.y)); + let dst = max((i.x - pos.x).abs(), (i.y - pos.y).abs()); if dst <= StagedChunkEnum::FULL_RADIUS && stage <= StagedChunkEnum::FULL_DEPENDENCIES[dst as usize] { @@ -1669,15 +1668,13 @@ impl GenerationSchedule { } } else { // debug!("io read thread receive proto chunk {pos:?}",); - let val = RecvChunk::IO(Chunk::Proto(Box::new( - ProtoChunk::from_chunk_data( + let val = + RecvChunk::IO(Chunk::Proto(Box::new(ProtoChunk::from_chunk_data( &chunk, dimension, level.world_gen.default_block, biome_mixer_seed, - ) - .await, - ))); + )))); if send.send((pos, val)).is_err() { break; } diff --git a/pumpkin-world/src/generation/feature/features/end_spike.rs b/pumpkin-world/src/generation/feature/features/end_spike.rs index 9062a4cd1..8a35bf304 100644 --- a/pumpkin-world/src/generation/feature/features/end_spike.rs +++ b/pumpkin-world/src/generation/feature/features/end_spike.rs @@ -25,7 +25,7 @@ struct Spike { } impl Spike { - pub fn is_in_chunk(&self, pos: &BlockPos) -> bool { + pub const fn is_in_chunk(&self, pos: &BlockPos) -> bool { section_coords::block_to_section(pos.0.x) == section_coords::block_to_section(self.center_x) && section_coords::block_to_section(pos.0.z) == section_coords::block_to_section(self.center_z) diff --git a/pumpkin-world/src/generation/feature/features/ore.rs b/pumpkin-world/src/generation/feature/features/ore.rs index 029e5db35..e1e193233 100644 --- a/pumpkin-world/src/generation/feature/features/ore.rs +++ b/pumpkin-world/src/generation/feature/features/ore.rs @@ -208,7 +208,7 @@ impl OreFeature { target: &OreTarget, pos: &BlockPos, ) -> bool { - if !target.target.test(&state, random) { + if !target.target.test(state, random) { return false; } if Self::should_not_discard(random, self.discard_chance_on_air_exposure) { diff --git a/pumpkin-world/src/generation/height_limit.rs b/pumpkin-world/src/generation/height_limit.rs index 2dc42058f..65da583cb 100644 --- a/pumpkin-world/src/generation/height_limit.rs +++ b/pumpkin-world/src/generation/height_limit.rs @@ -25,11 +25,11 @@ pub trait HeightLimitView { } fn bottom_section_coord(&self) -> i8 { - section_coords::block_to_section(self.bottom_y()) + section_coords::block_to_section(self.bottom_y() as i32) as i8 } fn top_section_coord(&self) -> u16 { - section_coords::block_to_section(self.top_y() - 1) + 1 + section_coords::block_to_section(self.top_y() as i32 - 1) as u16 + 1 } fn out_of_height(&self, height: i16) -> bool { diff --git a/pumpkin-world/src/generation/mod.rs b/pumpkin-world/src/generation/mod.rs index b0f91d5c8..161235cc8 100644 --- a/pumpkin-world/src/generation/mod.rs +++ b/pumpkin-world/src/generation/mod.rs @@ -69,44 +69,46 @@ impl GlobalRandomConfig { } pub mod section_coords { - use num_traits::PrimInt; - #[inline] - pub fn block_to_section(coord: T) -> T { + #[must_use] + pub const fn block_to_section(coord: i32) -> i32 { coord >> 4 } #[must_use] - pub fn get_offset_pos(chunk_coord: i32, offset: i32) -> i32 { + pub const fn get_offset_pos(chunk_coord: i32, offset: i32) -> i32 { section_to_block(chunk_coord) + offset } #[inline] - pub fn section_to_block(coord: T) -> T { + #[must_use] + pub const fn section_to_block(coord: i32) -> i32 { coord << 4 } } pub mod biome_coords { - use num_traits::PrimInt; - #[inline] - pub fn from_block(coord: T) -> T { + #[must_use] + pub const fn from_block(coord: i32) -> i32 { coord >> 2 } #[inline] - pub fn to_block(coord: T) -> T { + #[must_use] + pub const fn to_block(coord: i32) -> i32 { coord << 2 } #[inline] - pub fn from_chunk(coord: T) -> T { + #[must_use] + pub const fn from_chunk(coord: i32) -> i32 { coord << 2 } #[inline] - pub fn to_chunk(coord: T) -> T { + #[must_use] + pub const fn to_chunk(coord: i32) -> i32 { coord >> 2 } } diff --git a/pumpkin-world/src/generation/noise/aquifer_sampler.rs b/pumpkin-world/src/generation/noise/aquifer_sampler.rs index c8f40c47d..64a218391 100644 --- a/pumpkin-world/src/generation/noise/aquifer_sampler.rs +++ b/pumpkin-world/src/generation/noise/aquifer_sampler.rs @@ -776,13 +776,13 @@ mod random_positions_and_hypot { let horizontal_cell_count = CHUNK_WIDTH / shape.horizontal_cell_block_count() as usize; let horizontal_biome_end = biome_coords::from_block( - horizontal_cell_count * shape.horizontal_cell_block_count() as usize, + horizontal_cell_count as i32 * shape.horizontal_cell_block_count() as i32, ); let surface_height_estimator_options = SurfaceHeightSamplerBuilderOptions::new( chunk_x, chunk_z, - horizontal_biome_end, + horizontal_biome_end as usize, shape.min_y as i32, shape.max_y() as i32, shape.vertical_cell_block_count() as usize, diff --git a/pumpkin-world/src/generation/noise/mod.rs b/pumpkin-world/src/generation/noise/mod.rs index 31dba698b..a77bdae88 100644 --- a/pumpkin-world/src/generation/noise/mod.rs +++ b/pumpkin-world/src/generation/noise/mod.rs @@ -189,7 +189,7 @@ impl<'a> ChunkNoiseGenerator<'a> { ); let horizontal_biome_end = biome_coords::from_block( - horizontal_cell_count * generation_shape.horizontal_cell_block_count() as usize, + horizontal_cell_count as i32 * generation_shape.horizontal_cell_block_count() as i32, ); let vertical_cell_count = floor_div( generation_shape.height as usize, @@ -209,7 +209,7 @@ impl<'a> ChunkNoiseGenerator<'a> { horizontal_cell_count, biome_coords::from_block(start_block_x), biome_coords::from_block(start_block_z), - horizontal_biome_end, + horizontal_biome_end as usize, ); let aquifer_sampler = if aquifers { diff --git a/pumpkin-world/src/generation/positions.rs b/pumpkin-world/src/generation/positions.rs index 66731bf5b..0bb1c9c66 100644 --- a/pumpkin-world/src/generation/positions.rs +++ b/pumpkin-world/src/generation/positions.rs @@ -59,22 +59,22 @@ pub mod chunk_pos { } #[must_use] - pub fn get_offset_x(coord: i32, offset: i32) -> i32 { + pub const fn get_offset_x(coord: i32, offset: i32) -> i32 { get_offset_pos(coord, offset) } #[must_use] - pub fn get_center_x(coord: i32) -> i32 { + pub const fn get_center_x(coord: i32) -> i32 { get_offset_x(coord, 8) } #[must_use] - pub fn get_center_z(coord: i32) -> i32 { + pub const fn get_center_z(coord: i32) -> i32 { get_offset_z(coord, 8) } #[must_use] - pub fn get_offset_z(coord: i32, offset: i32) -> i32 { + pub const fn get_offset_z(coord: i32, offset: i32) -> i32 { get_offset_pos(coord, offset) } diff --git a/pumpkin-world/src/generation/proto_chunk.rs b/pumpkin-world/src/generation/proto_chunk.rs index 1990bd63c..1ad2cf37b 100644 --- a/pumpkin-world/src/generation/proto_chunk.rs +++ b/pumpkin-world/src/generation/proto_chunk.rs @@ -195,9 +195,9 @@ impl ProtoChunk { flat_block_map: vec![0; CHUNK_AREA * height as usize].into_boxed_slice(), flat_biome_map: vec![ Biome::PLAINS.id; - biome_coords::from_block(CHUNK_DIM as usize) - * biome_coords::from_block(CHUNK_DIM as usize) - * biome_coords::from_block(height as usize) + biome_coords::from_block(CHUNK_DIM as i32) as usize + * biome_coords::from_block(CHUNK_DIM as i32) as usize + * biome_coords::from_block(height as i32) as usize ] .into_boxed_slice(), biome_mixer_seed, @@ -212,7 +212,7 @@ impl ProtoChunk { } } - pub async fn from_chunk_data( + pub fn from_chunk_data( chunk_data: &ChunkData, dimension: &Dimension, default_block: &'static BlockState, @@ -390,9 +390,9 @@ impl ProtoChunk { #[inline] fn local_pos_to_block_index(&self, x: i32, y: i32, z: i32) -> usize { - debug_assert!((0..16).contains(&x), "x out of bounds: {}", x); - debug_assert!((0..16).contains(&z), "z out of bounds: {}", z); - debug_assert!(y >= 0 && y < self.height() as i32, "y out of bounds: {}", y); + debug_assert!((0..16).contains(&x), "x out of bounds: {x}"); + debug_assert!((0..16).contains(&z), "z out of bounds: {z}"); + debug_assert!(y >= 0 && y < self.height() as i32, "y out of bounds: {y}"); self.height() as usize * CHUNK_DIM as usize * x as usize + CHUNK_DIM as usize * y as usize @@ -404,16 +404,15 @@ impl ProtoChunk { pub fn local_biome_pos_to_biome_index(&self, x: i32, y: i32, z: i32) -> usize { let biome_height = self.height() as usize >> 2; - debug_assert!((0..4).contains(&x), "Biome X out of bounds: {}", x); - debug_assert!((0..4).contains(&z), "Biome Z out of bounds: {}", z); + debug_assert!((0..4).contains(&x), "Biome X out of bounds: {x}"); + debug_assert!((0..4).contains(&z), "Biome Z out of bounds: {z}"); debug_assert!( y >= 0 && y < biome_height as i32, - "Biome Y out of bounds: {}", - y + "Biome Y out of bounds: {y}" ); - biome_height * biome_coords::from_block(CHUNK_DIM as usize) * x as usize - + biome_coords::from_block(CHUNK_DIM as usize) * y as usize + biome_height * biome_coords::from_block(CHUNK_DIM as i32) as usize * x as usize + + biome_coords::from_block(CHUNK_DIM as i32) as usize * y as usize + z as usize } @@ -539,7 +538,7 @@ impl ProtoChunk { ); let horizontal_biome_end = biome_coords::from_block( - horizontal_cell_count * generation_shape.horizontal_cell_block_count(), + horizontal_cell_count as i32 * generation_shape.horizontal_cell_block_count() as i32, ); let surface_config = SurfaceHeightSamplerBuilderOptions::new( biome_coords::from_block(start_x), @@ -577,7 +576,7 @@ impl ProtoChunk { let horizontal_cell_count = CHUNK_DIM / generation_shape.horizontal_cell_block_count(); let horizontal_biome_end = biome_coords::from_block( - horizontal_cell_count * generation_shape.horizontal_cell_block_count(), + horizontal_cell_count as i32 * generation_shape.horizontal_cell_block_count() as i32, ); let surface_config = SurfaceHeightSamplerBuilderOptions::new( biome_coords::from_block(start_x), @@ -607,7 +606,7 @@ impl ProtoChunk { multi_noise_sampler: &mut MultiNoiseSampler, ) { let min_y = self.bottom_y(); - let bottom_section = section_coords::block_to_section(min_y) as i32; + let bottom_section = section_coords::block_to_section(min_y as i32); let top_section = section_coords::block_to_section(min_y as i32 + self.height() as i32 - 1); let start_block_x = start_block_x(self.x); @@ -620,7 +619,7 @@ impl ProtoChunk { let start_block_y = section_coords::section_to_block(i); let start_biome_y = biome_coords::from_block(start_block_y); - let biomes_per_section = biome_coords::from_block(CHUNK_DIM) as i32; + let biomes_per_section = biome_coords::from_block(CHUNK_DIM as i32); for x in 0..biomes_per_section { for y in 0..biomes_per_section { for z in 0..biomes_per_section { diff --git a/pumpkin-world/src/generation/rule/block_match.rs b/pumpkin-world/src/generation/rule/block_match.rs index a06bfabb2..84dc83496 100644 --- a/pumpkin-world/src/generation/rule/block_match.rs +++ b/pumpkin-world/src/generation/rule/block_match.rs @@ -9,7 +9,7 @@ pub struct BlockMatchRuleTest { } impl BlockMatchRuleTest { - pub fn test(&self, state: &RawBlockState) -> bool { + pub fn test(&self, state: RawBlockState) -> bool { state.to_block().name == self.block.strip_prefix("minecraft:").unwrap_or(&self.block) } } diff --git a/pumpkin-world/src/generation/rule/block_state_match.rs b/pumpkin-world/src/generation/rule/block_state_match.rs index ea8895c16..1ceccad8c 100644 --- a/pumpkin-world/src/generation/rule/block_state_match.rs +++ b/pumpkin-world/src/generation/rule/block_state_match.rs @@ -8,7 +8,7 @@ pub struct BlockStateMatchRuleTest { } impl BlockStateMatchRuleTest { - pub fn test(&self, state: &RawBlockState) -> bool { + pub fn test(&self, state: RawBlockState) -> bool { state.0 == self.block_state.get_state_id() } } diff --git a/pumpkin-world/src/generation/rule/mod.rs b/pumpkin-world/src/generation/rule/mod.rs index 7500679b1..668dc6f50 100644 --- a/pumpkin-world/src/generation/rule/mod.rs +++ b/pumpkin-world/src/generation/rule/mod.rs @@ -32,7 +32,7 @@ pub enum RuleTest { } impl RuleTest { - pub fn test(&self, state: &RawBlockState, random: &mut RandomGenerator) -> bool { + pub fn test(&self, state: RawBlockState, random: &mut RandomGenerator) -> bool { match self { Self::AlwaysTrue => true, Self::BlockMatch(rule) => rule.test(state), diff --git a/pumpkin-world/src/generation/rule/random_block_match.rs b/pumpkin-world/src/generation/rule/random_block_match.rs index f44c87371..1e0022fde 100644 --- a/pumpkin-world/src/generation/rule/random_block_match.rs +++ b/pumpkin-world/src/generation/rule/random_block_match.rs @@ -11,7 +11,7 @@ pub struct RandomBlockMatchRuleTest { } impl RandomBlockMatchRuleTest { - pub fn test(&self, state: &RawBlockState, random: &mut RandomGenerator) -> bool { + pub fn test(&self, state: RawBlockState, random: &mut RandomGenerator) -> bool { state.to_block().name == self.block.strip_prefix("minecraft:").unwrap_or(&self.block) && random.next_f32() < self.probability } diff --git a/pumpkin-world/src/generation/rule/random_block_state_match.rs b/pumpkin-world/src/generation/rule/random_block_state_match.rs index e57809912..89803828a 100644 --- a/pumpkin-world/src/generation/rule/random_block_state_match.rs +++ b/pumpkin-world/src/generation/rule/random_block_state_match.rs @@ -10,7 +10,7 @@ pub struct RandomBlockStateMatchRuleTest { } impl RandomBlockStateMatchRuleTest { - pub fn test(&self, state: &RawBlockState, random: &mut RandomGenerator) -> bool { + pub fn test(&self, state: RawBlockState, random: &mut RandomGenerator) -> bool { state.0 == self.block_state.get_state_id() && random.next_f32() < self.probability } } diff --git a/pumpkin-world/src/generation/rule/tag_match.rs b/pumpkin-world/src/generation/rule/tag_match.rs index fa06f3cfb..d1e9d5693 100644 --- a/pumpkin-world/src/generation/rule/tag_match.rs +++ b/pumpkin-world/src/generation/rule/tag_match.rs @@ -9,7 +9,7 @@ pub struct TagMatchRuleTest { } impl TagMatchRuleTest { - pub fn test(&self, state: &RawBlockState) -> bool { + pub fn test(&self, state: RawBlockState) -> bool { let values = get_tag_ids(RegistryKey::Block, &self.tag).unwrap(); values.contains(&state.to_block_id()) } diff --git a/pumpkin-world/src/generation/structure/structures/mod.rs b/pumpkin-world/src/generation/structure/structures/mod.rs index 70448c6b5..615eafc85 100644 --- a/pumpkin-world/src/generation/structure/structures/mod.rs +++ b/pumpkin-world/src/generation/structure/structures/mod.rs @@ -101,7 +101,6 @@ impl StructurePiece { const fn apply_x_transform(&self, x: i32, z: i32) -> i32 { match self.facing { - None => x, Some(BlockDirection::North | BlockDirection::South) => self.bounding_box.min.x + x, Some(BlockDirection::West) => self.bounding_box.max.x - z, Some(BlockDirection::East) => self.bounding_box.min.x + z, @@ -118,7 +117,6 @@ impl StructurePiece { const fn apply_z_transform(&self, x: i32, z: i32) -> i32 { match self.facing { - None => z, Some(BlockDirection::North) => self.bounding_box.max.z - z, Some(BlockDirection::South) => self.bounding_box.min.z + z, Some(BlockDirection::West | BlockDirection::East) => self.bounding_box.min.z + x, diff --git a/pumpkin-world/src/generation/structure/structures/stronghold/mod.rs b/pumpkin-world/src/generation/structure/structures/stronghold/mod.rs index f3332bf93..04d77984c 100644 --- a/pumpkin-world/src/generation/structure/structures/stronghold/mod.rs +++ b/pumpkin-world/src/generation/structure/structures/stronghold/mod.rs @@ -53,7 +53,7 @@ pub mod spiral_staircase; pub mod square_room; pub mod stairs; -/// Great reference: https://minecraft.wiki/w/Stronghold +/// Great reference: #[derive(Deserialize)] pub struct StrongholdGenerator; @@ -223,7 +223,7 @@ impl PieceWeight { } } - fn can_generate_chained(&self, chain_length: u32) -> bool { + const fn can_generate_chained(&self, chain_length: u32) -> bool { match self.piece_type { StrongholdPieceType::Library => self.can_generate() && chain_length > 4, StrongholdPieceType::PortalRoom => self.can_generate() && chain_length > 5, @@ -231,7 +231,7 @@ impl PieceWeight { } } - fn can_generate(&self) -> bool { + const fn can_generate(&self) -> bool { self.limit == 0 || self.generated_count < self.limit } } diff --git a/pumpkin-world/src/generation/structure/structures/stronghold/portal_room.rs b/pumpkin-world/src/generation/structure/structures/stronghold/portal_room.rs index c978740ef..b3ca51cf5 100644 --- a/pumpkin-world/src/generation/structure/structures/stronghold/portal_room.rs +++ b/pumpkin-world/src/generation/structure/structures/stronghold/portal_room.rs @@ -84,7 +84,7 @@ impl StructurePieceBase for PortalRoomPiece { _collector: &mut StructurePiecesCollector, _pieces_to_process: &mut Vec>, ) { - *has_portal_room = true + *has_portal_room = true; } fn place(&mut self, chunk: &mut ProtoChunk, random: &mut RandomGenerator, _seed: i64) { diff --git a/pumpkin-world/src/level.rs b/pumpkin-world/src/level.rs index a3bb95413..959d97fd8 100644 --- a/pumpkin-world/src/level.rs +++ b/pumpkin-world/src/level.rs @@ -15,7 +15,6 @@ use crate::{ use crossbeam::channel::Sender; use dashmap::DashMap; use log::trace; -use num_traits::Zero; use pumpkin_config::{chunk::ChunkConfig, world::LevelConfig}; use pumpkin_data::biome::Biome; use pumpkin_data::dimension::Dimension; @@ -406,7 +405,7 @@ impl Level { let has_watchers = self .chunk_watchers .get(pos) - .is_some_and(|count| !count.is_zero()); + .is_some_and(|count| *count != 0); if has_watchers { return None; @@ -428,7 +427,7 @@ impl Level { }); } - pub async fn get_tick_data(&self) -> TickData { + pub fn get_tick_data(&self) -> TickData { let mut ticks = TickData { block_ticks: Vec::new(), fluid_ticks: Vec::new(), @@ -492,7 +491,7 @@ impl Level { } pub fn clean_memory(&self) { - self.chunk_watchers.retain(|_, watcher| !watcher.is_zero()); + self.chunk_watchers.retain(|_, watcher| *watcher != 0); self.loaded_entity_chunks .retain(|at, _| self.chunk_watchers.get(at).is_some()); @@ -538,7 +537,7 @@ impl Level { let mut lock = self.chunk_loading.lock().unwrap(); lock.remove_ticket(pos, 31); lock.send_change(); - } + }; chunk } diff --git a/pumpkin-world/src/lib.rs b/pumpkin-world/src/lib.rs index a1cb007aa..d5a61cdc0 100644 --- a/pumpkin-world/src/lib.rs +++ b/pumpkin-world/src/lib.rs @@ -107,7 +107,7 @@ pub fn bench_create_and_populate_noise( biome_coords::from_block(start_z), ); let horizontal_biome_end = biome_coords::from_block( - horizontal_cell_count * generation_shape.horizontal_cell_block_count(), + horizontal_cell_count as i32 * generation_shape.horizontal_cell_block_count() as i32, ); let surface_config = SurfaceHeightSamplerBuilderOptions::new( biome_pos.x, @@ -153,7 +153,7 @@ pub fn bench_create_and_populate_biome( biome_coords::from_block(start_z), ); let horizontal_biome_end = biome_coords::from_block( - horizontal_cell_count * generation_shape.horizontal_cell_block_count(), + horizontal_cell_count as i32 * generation_shape.horizontal_cell_block_count() as i32, ); let multi_noise_config = MultiNoiseSamplerBuilderOptions::new( biome_pos.x, @@ -197,7 +197,7 @@ pub fn bench_create_and_populate_noise_with_surface( biome_coords::from_block(start_z), ); let horizontal_biome_end = biome_coords::from_block( - horizontal_cell_count * generation_shape.horizontal_cell_block_count(), + horizontal_cell_count as i32 * generation_shape.horizontal_cell_block_count() as i32, ); let multi_noise_config = MultiNoiseSamplerBuilderOptions::new( biome_pos.x, diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index e98bea0fd..6a19f8d84 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -9,7 +9,7 @@ rust-version.workspace = true # FileDescription is handled as the Program name by Windows! FileDescription = "Pumpkin" OriginalFilename = "pumpkin.exe" -LegalCopyright = "Copyright © 2025 Aleksander Medvedev" +LegalCopyright = "Copyright © 2026 Aleksander Medvedev" # Required to expose pumpkin plugin API [lib] @@ -58,13 +58,12 @@ num-bigint.workspace = true rustyline.workspace = true # encryption -rsa = { workspace = true, features = ["sha1"] } +rsa.workspace = true pkcs8.workspace = true # authentication ureq = { workspace = true, features = ["json"] } - sha1.workspace = true # velocity en diff --git a/pumpkin/src/world/mod.rs b/pumpkin/src/world/mod.rs index 45d6dddd4..079caa41c 100644 --- a/pumpkin/src/world/mod.rs +++ b/pumpkin/src/world/mod.rs @@ -718,7 +718,7 @@ impl World { } pub async fn tick_chunks(self: &Arc) { - let tick_data = self.level.get_tick_data().await; + let tick_data = self.level.get_tick_data(); for scheduled_tick in tick_data.block_ticks { let block = self.get_block(&scheduled_tick.position).await; if let Some(pumpkin_block) = self.block_registry.get_pumpkin_block(block.id) {