chore: remove unused deps

also apply some clippy lints in some places
This commit is contained in:
Alexander Medvedev 2026-02-09 00:07:39 +01:00
parent 8b6c8bbee6
commit b0ab5006ca
82 changed files with 326 additions and 489 deletions

128
Cargo.lock generated
View File

@ -43,56 +43,12 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" 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]] [[package]]
name = "anstyle" name = "anstyle"
version = "1.0.13" version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" 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]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.100" version = "1.0.100"
@ -389,12 +345,6 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de0758edba32d61d1fd9f4d69491b47604b91ee2f7e6b33de7e54ca4ebe55dc3" checksum = "de0758edba32d61d1fd9f4d69491b47604b91ee2f7e6b33de7e54ca4ebe55dc3"
[[package]]
name = "colorchoice"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]] [[package]]
name = "colored" name = "colored"
version = "3.1.1" version = "3.1.1"
@ -856,29 +806,6 @@ dependencies = [
"syn", "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]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.2" version = "1.0.2"
@ -1471,12 +1398,6 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.13.0" version = "0.13.0"
@ -1501,30 +1422,6 @@ version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" 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]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.85" version = "0.3.85"
@ -1789,12 +1686,6 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]] [[package]]
name = "oorandom" name = "oorandom"
version = "11.1.5" version = "11.1.5"
@ -2018,21 +1909,6 @@ dependencies = [
"spki 0.8.0-rc.4", "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]] [[package]]
name = "potential_utf" name = "potential_utf"
version = "0.1.4" version = "0.1.4"
@ -2307,14 +2183,11 @@ dependencies = [
"crossfire", "crossfire",
"dashmap", "dashmap",
"enum_dispatch", "enum_dispatch",
"env_logger",
"flate2", "flate2",
"futures", "futures",
"itertools 0.14.0", "itertools 0.14.0",
"log", "log",
"lz4-java-wrc", "lz4-java-wrc",
"num-derive",
"num-traits",
"num_cpus", "num_cpus",
"pumpkin-config", "pumpkin-config",
"pumpkin-data", "pumpkin-data",
@ -2480,7 +2353,6 @@ dependencies = [
"pkcs1", "pkcs1",
"pkcs8 0.11.0-rc.10", "pkcs8 0.11.0-rc.10",
"rand_core 0.10.0", "rand_core 0.10.0",
"sha1",
"signature 3.0.0-rc.10", "signature 3.0.0-rc.10",
"spki 0.8.0-rc.4", "spki 0.8.0-rc.4",
"zeroize", "zeroize",

View File

@ -122,7 +122,6 @@ crossfire = { version= "3.0.4", features = ["compat"]}
dashmap = "6.1" dashmap = "6.1"
ecdsa = "0.16.9" ecdsa = "0.16.9"
enum_dispatch = "0.3.13" enum_dispatch = "0.3.13"
env_logger = "0.11.8"
flate2 = "1.1.9" flate2 = "1.1.9"
heck = "0.5" heck = "0.5"
hmac = "=0.13.0-rc.5" hmac = "=0.13.0-rc.5"

View File

@ -12,7 +12,7 @@ struct Attributes {
default_value: f64, default_value: f64,
} }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/attributes.json"); println!("cargo:rerun-if-changed=../assets/attributes.json");
let attributes: BTreeMap<String, Attributes> = let attributes: BTreeMap<String, Attributes> =

View File

@ -157,7 +157,7 @@ struct MultiNoiseBiomeSuppliers {
nether: BiomeTree, 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/biome.json");
println!("cargo:rerun-if-changed=../assets/multi_noise_biome_tree.json"); println!("cargo:rerun-if-changed=../assets/multi_noise_biome_tree.json");

View File

@ -69,7 +69,7 @@ impl PropertyCollectionData {
self.blocks.push((block_name, block_id)); self.blocks.push((block_name, block_id));
} }
pub fn from_mappings(variant_mappings: Vec<PropertyVariantMapping>) -> Self { pub const fn from_mappings(variant_mappings: Vec<PropertyVariantMapping>) -> Self {
Self { Self {
variant_mappings, variant_mappings,
blocks: Vec::new(), blocks: Vec::new(),
@ -431,7 +431,7 @@ impl BlockState {
const IS_AIR: u16 = 1 << 0; const IS_AIR: u16 = 1 << 0;
const HAS_RANDOM_TICKS: u16 = 1 << 9; 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 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")] #[serde(tag = "type")]
pub enum GeneratedPropertyType { pub enum GeneratedPropertyType {
#[serde(rename = "boolean")] #[serde(rename = "boolean")]
@ -634,7 +634,7 @@ pub struct BlockAssets {
pub block_entity_types: Vec<String>, pub block_entity_types: Vec<String>,
} }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/blocks.json"); println!("cargo:rerun-if-changed=../assets/blocks.json");
println!("cargo:rerun-if-changed=../assets/bedrock_block_states.nbt"); println!("cargo:rerun-if-changed=../assets/bedrock_block_states.nbt");
println!("cargo:rerun-if-changed=../assets/properties.json"); println!("cargo:rerun-if-changed=../assets/properties.json");

View File

@ -156,7 +156,7 @@ fn compose(first: &[u16], second: &[u16]) -> Vec<u16> {
.collect() .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.7to1.21.9.nbt");
println!("cargo:rerun-if-changed=../assets/viaversion/data/mappings-1.21.9to1.21.11.nbt"); println!("cargo:rerun-if-changed=../assets/viaversion/data/mappings-1.21.9to1.21.11.nbt");

View File

@ -59,10 +59,10 @@ mod world_event;
pub const OUT_DIR: &str = "src/generated"; pub const OUT_DIR: &str = "src/generated";
pub fn main() { pub fn main() {
fs::create_dir_all(OUT_DIR).expect("Failed to create output directory");
type BuilderFn = fn() -> TokenStream; type BuilderFn = fn() -> TokenStream;
fs::create_dir_all(OUT_DIR).expect("Failed to create output directory");
let build_functions: Vec<(BuilderFn, &str)> = vec![ let build_functions: Vec<(BuilderFn, &str)> = vec![
(packet::build, "packet.rs"), (packet::build, "packet.rs"),
(screen::build, "screen.rs"), (screen::build, "screen.rs"),
@ -121,9 +121,10 @@ pub fn main() {
let header = "/* This file is generated. Do not edit manually. */\n"; let header = "/* This file is generated. Do not edit manually. */\n";
let final_code = format_code(&raw_code) let final_code = format_code(&raw_code).map_or_else(
.map(|formatted| format!("{}{}", header, formatted)) |_| format!("{header}{raw_code}"),
.unwrap_or_else(|_| format!("{}{}", header, raw_code)); |formatted| format!("{header}{formatted}"),
);
write_generated_file(&final_code, file); write_generated_file(&final_code, file);
}); });
@ -164,9 +165,8 @@ pub fn format_code(unformatted_code: &str) -> Result<String, RustFmtError> {
.stderr(Stdio::null()) .stderr(Stdio::null())
.spawn(); .spawn();
let mut child = match child_result { let Ok(mut child) = child_result else {
Ok(c) => c, return Err(RustFmtError);
Err(_) => return Err(RustFmtError),
}; };
// Write the code to rustfmt's stdin // Write the code to rustfmt's stdin

View File

@ -41,11 +41,11 @@ pub enum MaterialRuleStruct {
#[serde(rename = "minecraft:block")] #[serde(rename = "minecraft:block")]
Block { result_state: BlockStateCodecStruct }, Block { result_state: BlockStateCodecStruct },
#[serde(rename = "minecraft:sequence")] #[serde(rename = "minecraft:sequence")]
Sequence { sequence: Vec<MaterialRuleStruct> }, Sequence { sequence: Vec<Self> },
#[serde(rename = "minecraft:condition")] #[serde(rename = "minecraft:condition")]
Condition { Condition {
if_true: MaterialConditionStruct, if_true: MaterialConditionStruct,
then_run: Box<MaterialRuleStruct>, then_run: Box<Self>,
}, },
#[serde(rename = "minecraft:bandlands")] #[serde(rename = "minecraft:bandlands")]
Badlands, Badlands,
@ -87,9 +87,7 @@ pub enum MaterialConditionStruct {
#[serde(rename = "minecraft:steep")] #[serde(rename = "minecraft:steep")]
Steep, Steep,
#[serde(rename = "minecraft:not")] #[serde(rename = "minecraft:not")]
Not { Not { invert: Box<Self> },
invert: Box<MaterialConditionStruct>,
},
#[serde(rename = "minecraft:hole")] #[serde(rename = "minecraft:hole")]
Hole, Hole,
#[serde(rename = "minecraft:above_preliminary_surface")] #[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"); println!("cargo:rerun-if-changed=../assets/chunk_gen_settings.json");
let json: BTreeMap<String, GenerationSettingsStruct> = let json: BTreeMap<String, GenerationSettingsStruct> =

View File

@ -4,7 +4,7 @@ use heck::ToPascalCase;
use proc_macro2::TokenStream; use proc_macro2::TokenStream;
use quote::{format_ident, quote}; use quote::{format_ident, quote};
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/chunk_status.json"); println!("cargo:rerun-if-changed=../assets/chunk_status.json");
let chunk_status: Vec<String> = let chunk_status: Vec<String> =

View File

@ -4,7 +4,7 @@ use proc_macro2::{Span, TokenStream};
use quote::quote; use quote::quote;
use syn::LitInt; use syn::LitInt;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/composter_increase_chance.json"); println!("cargo:rerun-if-changed=../assets/composter_increase_chance.json");
let composter_increase_chance: BTreeMap<u16, f32> = serde_json::from_str( let composter_increase_chance: BTreeMap<u16, f32> = serde_json::from_str(

View File

@ -47,7 +47,7 @@ pub enum DeathMessageType {
IntentionalGameDesign, IntentionalGameDesign,
} }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/damage_type.json"); println!("cargo:rerun-if-changed=../assets/damage_type.json");
let damage_types: BTreeMap<String, DamageTypeEntry> = let damage_types: BTreeMap<String, DamageTypeEntry> =

View File

@ -4,7 +4,7 @@ use quote::{format_ident, quote};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::fs; use std::fs;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/data_component.json"); println!("cargo:rerun-if-changed=../assets/data_component.json");
let data_component: BTreeMap<String, u8> = let data_component: BTreeMap<String, u8> =

View File

@ -39,7 +39,7 @@ pub struct Dimension {
// } // }
// } // }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/dimension.json"); println!("cargo:rerun-if-changed=../assets/dimension.json");
let dimensions: BTreeMap<String, Dimension> = serde_json::from_str( let dimensions: BTreeMap<String, Dimension> = serde_json::from_str(

View File

@ -58,7 +58,7 @@ impl MobEffectCategory {
} }
} }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/effect.json"); println!("cargo:rerun-if-changed=../assets/effect.json");
let effects: BTreeMap<String, Effect> = let effects: BTreeMap<String, Effect> =

View File

@ -52,7 +52,7 @@ impl AttributeModifierSlot {
} }
} }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/enchantments.json"); println!("cargo:rerun-if-changed=../assets/enchantments.json");
let enchantments: BTreeMap<String, Enchantment> = let enchantments: BTreeMap<String, Enchantment> =

View File

@ -5,7 +5,7 @@ use quote::quote;
use crate::array_to_tokenstream; use crate::array_to_tokenstream;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/entity_pose.json"); println!("cargo:rerun-if-changed=../assets/entity_pose.json");
let poses: Vec<String> = let poses: Vec<String> =

View File

@ -5,7 +5,7 @@ use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote}; use quote::{format_ident, quote};
use syn::LitInt; use syn::LitInt;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/entity_statuses.json"); println!("cargo:rerun-if-changed=../assets/entity_statuses.json");
let events: BTreeMap<String, u8> = let events: BTreeMap<String, u8> =

View File

@ -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"); println!("cargo:rerun-if-changed=../assets/entities.json");
let json: BTreeMap<String, EntityType> = let json: BTreeMap<String, EntityType> =

View File

@ -2,7 +2,7 @@ use proc_macro2::{Span, TokenStream};
use quote::quote; use quote::quote;
use std::{collections::BTreeMap, fs}; use std::{collections::BTreeMap, fs};
use syn::LitInt; use syn::LitInt;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/flower_pot_transformations.json"); println!("cargo:rerun-if-changed=../assets/flower_pot_transformations.json");
let flower_pot_transformation: BTreeMap<u16, u16> = serde_json::from_str( let flower_pot_transformation: BTreeMap<u16, u16> = serde_json::from_str(

View File

@ -31,7 +31,7 @@ impl PropertyCollectionData {
self.fluid_names.push(fluid_name); self.fluid_names.push(fluid_name);
} }
pub fn from_mappings(variant_mappings: Vec<PropertyVariantMapping>) -> Self { pub const fn from_mappings(variant_mappings: Vec<PropertyVariantMapping>) -> Self {
Self { Self {
variant_mappings, variant_mappings,
fluid_names: Vec::new(), fluid_names: Vec::new(),
@ -330,15 +330,15 @@ pub struct Fluid {
can_convert_to_source: bool, can_convert_to_source: bool,
} }
fn default_flow_speed() -> u32 { const fn default_flow_speed() -> u32 {
5 // Default to water's speed 5 // Default to water's speed
} }
fn default_flow_distance() -> u32 { const fn default_flow_distance() -> u32 {
4 // Default to water's distance 4 // Default to water's distance
} }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/fluids.json"); println!("cargo:rerun-if-changed=../assets/fluids.json");
let fluids: Vec<Fluid> = let fluids: Vec<Fluid> =

View File

@ -1,7 +1,7 @@
use proc_macro2::TokenStream; use proc_macro2::TokenStream;
use quote::quote; use quote::quote;
use std::{collections::BTreeMap, fs}; use std::{collections::BTreeMap, fs};
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/fuels.json"); println!("cargo:rerun-if-changed=../assets/fuels.json");
let fuels: BTreeMap<u16, u16> = let fuels: BTreeMap<u16, u16> =

View File

@ -5,7 +5,7 @@ use quote::quote;
use crate::array_to_tokenstream; use crate::array_to_tokenstream;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/game_event.json"); println!("cargo:rerun-if-changed=../assets/game_event.json");
let game_events: Vec<String> = let game_events: Vec<String> =

View File

@ -5,7 +5,7 @@ use proc_macro2::TokenStream;
use quote::{format_ident, quote}; use quote::{format_ident, quote};
use serde_json::Value; use serde_json::Value;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/game_rules.json"); println!("cargo:rerun-if-changed=../assets/game_rules.json");
let game_rules: BTreeMap<String, Value> = let game_rules: BTreeMap<String, Value> =

View File

@ -339,15 +339,15 @@ impl ToTokens for ItemComponents {
} }
} }
fn return_1u32() -> u32 { const fn return_1u32() -> u32 {
1 1
} }
fn return_1f32() -> f32 { const fn return_1f32() -> f32 {
1. 1.
} }
fn return_true() -> bool { const fn return_true() -> bool {
true true
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -361,7 +361,7 @@ pub struct ToolComponent {
can_destroy_blocks_in_creative: bool, can_destroy_blocks_in_creative: bool,
} }
fn return_false() -> bool { const fn return_false() -> bool {
false false
} }
@ -390,7 +390,7 @@ pub struct Modifier {
pub slot: AttributeModifierSlot, pub slot: AttributeModifierSlot,
} }
fn _true() -> bool { const fn _true() -> bool {
true true
} }
@ -429,7 +429,7 @@ pub struct EquippableComponent {
pub shearing_sound: Option<String>, pub shearing_sound: Option<String>,
} }
#[derive(Deserialize, Clone, Debug, PartialEq)] #[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
#[expect(clippy::enum_variant_names)] #[expect(clippy::enum_variant_names)]
pub enum Operation { pub enum Operation {
@ -438,7 +438,7 @@ pub enum Operation {
AddMultipliedTotal, AddMultipliedTotal,
} }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/items.json"); println!("cargo:rerun-if-changed=../assets/items.json");
let items: BTreeMap<String, Item> = let items: BTreeMap<String, Item> =

View File

@ -178,7 +178,7 @@ fn compose_with_default(first: &[u16], second: &[u16]) -> Vec<u16> {
.collect() .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.7to1.21.9.nbt");
println!("cargo:rerun-if-changed=../assets/viaversion/data/mappings-1.21.9to1.21.11.nbt"); println!("cargo:rerun-if-changed=../assets/viaversion/data/mappings-1.21.9to1.21.11.nbt");

View File

@ -12,7 +12,7 @@ struct JukeboxSongData {
comparator_output: u8, 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/jukebox_song.json");
println!("cargo:rerun-if-changed=../assets/registry/1_21_11_synced_registries.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 variant_name = make_variant_ident(name);
let length = song_data let length = song_data
.get(name) .get(name)
.map(|d| d.length_in_seconds as u32) .map_or(0, |d| d.length_in_seconds as u32);
.unwrap_or(0);
quote! { Self::#variant_name => #length, } quote! { Self::#variant_name => #length, }
}) })
.collect::<TokenStream>(); .collect::<TokenStream>();
@ -92,10 +91,7 @@ pub(crate) fn build() -> TokenStream {
.keys() .keys()
.map(|name| { .map(|name| {
let variant_name = make_variant_ident(name); let variant_name = make_variant_ident(name);
let output = song_data let output = song_data.get(name).map_or(0, |d| d.comparator_output);
.get(name)
.map(|d| d.comparator_output)
.unwrap_or(0);
quote! { Self::#variant_name => #output, } quote! { Self::#variant_name => #output, }
}) })
.collect::<TokenStream>(); .collect::<TokenStream>();

View File

@ -24,7 +24,7 @@ pub struct RawChatType {
// parameters: Vec<String>, // parameters: Vec<String>,
// } // }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/message_type.json"); println!("cargo:rerun-if-changed=../assets/message_type.json");
let json: BTreeMap<String, RawChatType> = let json: BTreeMap<String, RawChatType> =

View File

@ -4,7 +4,7 @@ use heck::ToPascalCase;
use proc_macro2::TokenStream; use proc_macro2::TokenStream;
use quote::{format_ident, quote}; use quote::{format_ident, quote};
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/meta_data_type.json"); println!("cargo:rerun-if-changed=../assets/meta_data_type.json");
let handlers_map: BTreeMap<String, i32> = let handlers_map: BTreeMap<String, i32> =

View File

@ -4,7 +4,7 @@ use proc_macro2::TokenStream;
use pumpkin_util::DoublePerlinNoiseParametersCodec; use pumpkin_util::DoublePerlinNoiseParametersCodec;
use quote::{format_ident, quote}; use quote::{format_ident, quote};
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/noise_parameters.json"); println!("cargo:rerun-if-changed=../assets/noise_parameters.json");
let json: BTreeMap<String, DoublePerlinNoiseParametersCodec> = let json: BTreeMap<String, DoublePerlinNoiseParametersCodec> =

View File

@ -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"); println!("cargo:rerun-if-changed=../assets/density_function.json");
let mut reprs: NoiseRouterReprs = let mut reprs: NoiseRouterReprs =

View File

@ -10,7 +10,7 @@ pub struct Packets {
clientbound: BTreeMap<String, BTreeMap<String, i32>>, clientbound: BTreeMap<String, BTreeMap<String, i32>>,
} }
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_7_packets.json");
println!("cargo:rerun-if-changed=../assets/packet/1_21_11_packets.json"); println!("cargo:rerun-if-changed=../assets/packet/1_21_11_packets.json");

View File

@ -6,7 +6,7 @@ use quote::{format_ident, quote};
use crate::array_to_tokenstream; use crate::array_to_tokenstream;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/particles.json"); println!("cargo:rerun-if-changed=../assets/particles.json");
let particle: Vec<String> = let particle: Vec<String> =

View File

@ -49,7 +49,7 @@ impl Effect {
} }
} }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/potion.json"); println!("cargo:rerun-if-changed=../assets/potion.json");
let potions: BTreeMap<String, Potion> = let potions: BTreeMap<String, Potion> =

View File

@ -71,7 +71,7 @@ impl Recipes {
} }
} }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/potion_brewing.json"); println!("cargo:rerun-if-changed=../assets/potion_brewing.json");
let json: PotionBrewing = let json: PotionBrewing =

View File

@ -2,7 +2,7 @@ use proc_macro2::{Span, TokenStream};
use quote::quote; use quote::quote;
use std::{collections::BTreeMap, fs}; use std::{collections::BTreeMap, fs};
use syn::LitInt; use syn::LitInt;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/recipe_remainder.json"); println!("cargo:rerun-if-changed=../assets/recipe_remainder.json");
let remainder: BTreeMap<u16, u16> = let remainder: BTreeMap<u16, u16> =

View File

@ -46,7 +46,7 @@ pub struct CookingRecipeStruct {
impl CookingRecipeStruct { impl CookingRecipeStruct {
/// Generate a recipe ID based on result, ingredient, and cooking type /// 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 { fn generate_recipe_id(&self, cooking_type: &str) -> String {
let result_name = self let result_name = self
.result .result
@ -66,8 +66,7 @@ impl CookingRecipeStruct {
// Use first item for ID generation // Use first item for ID generation
items items
.first() .first()
.map(|s| s.strip_prefix("minecraft:").unwrap_or(s)) .map_or("unknown", |s| s.strip_prefix("minecraft:").unwrap_or(s))
.unwrap_or("unknown")
.to_string() .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"); println!("cargo:rerun-if-changed=../assets/recipes.json");
let recipes_assets: Vec<RecipeTypes> = let recipes_assets: Vec<RecipeTypes> =

View File

@ -4,7 +4,7 @@ use quote::quote;
use serde_json::Value; use serde_json::Value;
use std::fs; 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_9_synced_registries.json");
println!("cargo:rerun-if-changed=../assets/registry/1_21_11_synced_registries.json"); println!("cargo:rerun-if-changed=../assets/registry/1_21_11_synced_registries.json");

View File

@ -5,7 +5,7 @@ use quote::quote;
use crate::array_to_tokenstream; use crate::array_to_tokenstream;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/scoreboard_display_slot.json"); println!("cargo:rerun-if-changed=../assets/scoreboard_display_slot.json");
let sound_categories: Vec<String> = serde_json::from_str( let sound_categories: Vec<String> = serde_json::from_str(

View File

@ -5,7 +5,7 @@ use quote::quote;
use crate::array_to_tokenstream; use crate::array_to_tokenstream;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/screens.json"); println!("cargo:rerun-if-changed=../assets/screens.json");
let screens: Vec<String> = let screens: Vec<String> =

View File

@ -6,45 +6,28 @@ use quote::{format_ident, quote};
use crate::array_to_tokenstream; use crate::array_to_tokenstream;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/sounds.json"); println!("cargo:rerun-if-changed=../assets/sounds.json");
let sound: Vec<String> = let mut sound: Vec<String> =
serde_json::from_str(&fs::read_to_string("../assets/sounds.json").unwrap()) serde_json::from_str(&fs::read_to_string("../assets/sounds.json").unwrap())
.expect("Failed to parse sounds.json"); .expect("Failed to parse sounds.json");
sound.sort();
let variants = array_to_tokenstream(&sound); let variants = array_to_tokenstream(&sound);
let type_from_name = &sound let lookup_table = sound.iter().map(|s| {
.iter() let variant_name = format_ident!("{}", s.to_pascal_case());
.map(|sound| { quote! { (#s, Self::#variant_name) }
let id = &sound; });
let name = format_ident!("{}", sound.to_pascal_case());
quote! { let variants_list = sound.iter().map(|s| {
#id => Some(Self::#name), let variant_name = format_ident!("{}", s.to_pascal_case());
} quote! { Self::#variant_name, }
}) });
.collect::<TokenStream>();
let type_to_name = &sound let names_list = sound.iter().map(|s| quote! { #s });
.iter()
.map(|sound| {
let id = &sound;
let name = format_ident!("{}", sound.to_pascal_case());
quote! {
Self::#name => #id,
}
})
.collect::<TokenStream>();
let variants_list = sound
.iter()
.map(|sound| {
let name = format_ident!("{}", sound.to_pascal_case());
quote! { Self::#name, }
})
.collect::<TokenStream>();
quote! { quote! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@ -54,21 +37,25 @@ pub(crate) fn build() -> TokenStream {
} }
impl Sound { impl Sound {
const NAMES: &[&str] = &[ #(#names_list),* ];
const LOOKUP: &[(&str, Sound)] = &[
#(#lookup_table),*
];
pub fn from_name(name: &str) -> Option<Self> { pub fn from_name(name: &str) -> Option<Self> {
match name { Self::LOOKUP
#type_from_name .binary_search_by_key(&name, |&(k, _)| k)
_ => None .ok()
} .map(|idx| Self::LOOKUP[idx].1)
} }
pub const fn to_name(&self) -> &'static str { pub const fn to_name(&self) -> &'static str {
match self { Self::NAMES[*self as usize]
#type_to_name
}
} }
pub fn slice() -> &'static [Self] { pub fn slice() -> &'static [Self] {
&[#variants_list] &[#(#variants_list)*]
} }
} }
} }

View File

@ -6,7 +6,7 @@ use quote::{format_ident, quote};
use crate::array_to_tokenstream; use crate::array_to_tokenstream;
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/sound_category.json"); println!("cargo:rerun-if-changed=../assets/sound_category.json");
let sound_categories: Vec<String> = let sound_categories: Vec<String> =

View File

@ -4,7 +4,7 @@ use heck::ToShoutySnakeCase;
use proc_macro2::TokenStream; use proc_macro2::TokenStream;
use quote::{format_ident, quote}; use quote::{format_ident, quote};
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/spawn_egg.json"); println!("cargo:rerun-if-changed=../assets/spawn_egg.json");
let eggs: BTreeMap<u16, String> = let eggs: BTreeMap<u16, String> =

View File

@ -78,17 +78,17 @@ impl ToTokens for WeightedEntryStruct {
impl ToTokens for StructurePlacementStruct { impl ToTokens for StructurePlacementStruct {
fn to_tokens(&self, tokens: &mut TokenStream) { fn to_tokens(&self, tokens: &mut TokenStream) {
let frequency_reduction = match &self.frequency_reduction_method { let frequency_reduction = if let Some(method) = &self.frequency_reduction_method {
Some(method) => {
let method_token = frequency_reduction_to_token(method); let method_token = frequency_reduction_to_token(method);
quote!(Some(#method_token)) quote!(Some(#method_token))
} } else {
None => quote!(None), quote!(None)
}; };
let frequency = match self.frequency { let frequency = if let Some(f) = self.frequency {
Some(f) => quote!(Some(#f)), quote!(Some(#f))
None => quote!(None), } else {
quote!(None)
}; };
let salt = self.salt; let salt = self.salt;
@ -113,12 +113,11 @@ impl ToTokens for StructurePlacementTypeStruct {
separation, separation,
spread_type, spread_type,
} => { } => {
let spread_type_token = match spread_type { let spread_type_token = if let Some(st) = spread_type {
Some(st) => {
let st_token = spread_type_to_token(st); let st_token = spread_type_to_token(st);
quote!(Some(#st_token)) quote!(Some(#st_token))
} } else {
None => quote!(None), quote!(None)
}; };
tokens.extend(quote!( tokens.extend(quote!(
@ -202,7 +201,7 @@ fn structure_key_to_token(key: &str) -> TokenStream {
"ancient_city" => quote!(StructureKeys::AncientCity), "ancient_city" => quote!(StructureKeys::AncientCity),
"trail_ruins" => quote!(StructureKeys::TrailRuins), "trail_ruins" => quote!(StructureKeys::TrailRuins),
"trial_chambers" => quote!(StructureKeys::TrialChambers), "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), "fluid_springs" => quote!(GenerationStep::FluidSprings),
"vegetal_decoration" => quote!(GenerationStep::VegetalDecoration), "vegetal_decoration" => quote!(GenerationStep::VegetalDecoration),
"top_layer_modification" => quote!(GenerationStep::TopLayerModification), "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/structures.json");
println!("cargo:rerun-if-changed=../assets/structure_set.json"); println!("cargo:rerun-if-changed=../assets/structure_set.json");

View File

@ -63,7 +63,7 @@ impl ToTokens for EnumCreator {
} }
} }
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
// --- Rerun Triggers --- // --- Rerun Triggers ---
println!("cargo:rerun-if-changed=../assets/blocks.json"); println!("cargo:rerun-if-changed=../assets/blocks.json");
println!("cargo:rerun-if-changed=../assets/items.json"); println!("cargo:rerun-if-changed=../assets/items.json");

View File

@ -2,7 +2,7 @@ use proc_macro2::TokenStream;
use quote::{format_ident, quote}; use quote::{format_ident, quote};
use std::{collections::BTreeMap, fs}; 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_7_tracked_data.json");
println!("cargo:rerun-if-changed=../assets/tracked_data/1_21_11_tracked_data.json"); println!("cargo:rerun-if-changed=../assets/tracked_data/1_21_11_tracked_data.json");

View File

@ -2,7 +2,7 @@ use proc_macro2::TokenStream;
use quote::{format_ident, quote}; use quote::{format_ident, quote};
use std::{collections::BTreeMap, fs}; use std::{collections::BTreeMap, fs};
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/en_us.json"); println!("cargo:rerun-if-changed=../assets/en_us.json");
let en_us: BTreeMap<String, String> = serde_json::from_str( let en_us: BTreeMap<String, String> = serde_json::from_str(
@ -16,13 +16,13 @@ pub(crate) fn build() -> TokenStream {
let clean_name = name.to_uppercase().replace(['.', '-'], "_"); let clean_name = name.to_uppercase().replace(['.', '-'], "_");
let ident = format_ident!("{}", clean_name); let ident = format_ident!("{}", clean_name);
if !value.is_empty() { if value.is_empty() {
constants.extend(quote! { constants.extend(quote! {
#[doc = #value]
pub const #ident: &str = #name; pub const #ident: &str = #name;
}); });
} else { } else {
constants.extend(quote! { constants.extend(quote! {
#[doc = #value]
pub const #ident: &str = #name; pub const #ident: &str = #name;
}); });
} }

View File

@ -4,7 +4,7 @@ use heck::ToPascalCase;
use proc_macro2::TokenStream; use proc_macro2::TokenStream;
use quote::{format_ident, quote}; use quote::{format_ident, quote};
pub(crate) fn build() -> TokenStream { pub fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/world_event.json"); println!("cargo:rerun-if-changed=../assets/world_event.json");
let events: BTreeMap<String, u16> = let events: BTreeMap<String, u16> =

View File

@ -56,7 +56,7 @@ impl TryFrom<i32> for BlockDirection {
impl BlockDirection { impl BlockDirection {
#[must_use] #[must_use]
pub fn to_index(&self) -> u8 { pub const fn to_index(&self) -> u8 {
match self { match self {
Self::Down => 0, Self::Down => 0,
Self::Up => 1, Self::Up => 1,
@ -68,7 +68,7 @@ impl BlockDirection {
} }
#[must_use] #[must_use]
pub fn from_index(index: u8) -> Option<Self> { pub const fn from_index(index: u8) -> Option<Self> {
match index { match index {
0 => Some(Self::Down), 0 => Some(Self::Down),
1 => Some(Self::Up), 1 => Some(Self::Up),
@ -107,7 +107,7 @@ impl BlockDirection {
} }
#[must_use] #[must_use]
pub fn opposite(&self) -> Self { pub const fn opposite(&self) -> Self {
match self { match self {
Self::Down => Self::Up, Self::Down => Self::Up,
Self::Up => Self::Down, Self::Up => Self::Down,
@ -119,12 +119,12 @@ impl BlockDirection {
} }
#[must_use] #[must_use]
pub fn positive(&self) -> bool { pub const fn positive(&self) -> bool {
matches!(self, Self::South | Self::East | Self::Up) matches!(self, Self::South | Self::East | Self::Up)
} }
#[must_use] #[must_use]
pub fn all() -> [Self; 6] { pub const fn all() -> [Self; 6] {
[ [
Self::Down, Self::Down,
Self::Up, Self::Up,
@ -135,7 +135,7 @@ impl BlockDirection {
] ]
} }
#[must_use] #[must_use]
pub fn update_order() -> [Self; 6] { pub const fn update_order() -> [Self; 6] {
[ [
Self::West, Self::West,
Self::East, Self::East,
@ -147,7 +147,7 @@ impl BlockDirection {
} }
#[must_use] #[must_use]
pub fn abstract_block_update_order() -> [Self; 6] { pub const fn abstract_block_update_order() -> [Self; 6] {
[ [
Self::West, Self::West,
Self::East, Self::East,
@ -159,27 +159,27 @@ impl BlockDirection {
} }
#[must_use] #[must_use]
pub fn horizontal() -> [Self; 4] { pub const fn horizontal() -> [Self; 4] {
[Self::North, Self::South, Self::West, Self::East] [Self::North, Self::South, Self::West, Self::East]
} }
#[must_use] #[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] [Self::Down, Self::North, Self::South, Self::West, Self::East]
} }
#[must_use] #[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) matches!(self, Self::North | Self::South | Self::West | Self::East)
} }
#[must_use] #[must_use]
pub fn vertical() -> [Self; 2] { pub const fn vertical() -> [Self; 2] {
[Self::Down, Self::Up] [Self::Down, Self::Up]
} }
#[must_use] #[must_use]
pub fn to_horizontal_facing(&self) -> Option<HorizontalFacing> { pub const fn to_horizontal_facing(&self) -> Option<HorizontalFacing> {
match self { match self {
Self::North => Some(HorizontalFacing::North), Self::North => Some(HorizontalFacing::North),
Self::South => Some(HorizontalFacing::South), Self::South => Some(HorizontalFacing::South),
@ -190,7 +190,7 @@ impl BlockDirection {
} }
#[must_use] #[must_use]
pub fn to_horizontal_axis(&self) -> Option<HorizontalAxis> { pub const fn to_horizontal_axis(&self) -> Option<HorizontalAxis> {
match self { match self {
Self::North | Self::South => Some(HorizontalAxis::Z), Self::North | Self::South => Some(HorizontalAxis::Z),
Self::West | Self::East => Some(HorizontalAxis::X), Self::West | Self::East => Some(HorizontalAxis::X),
@ -199,7 +199,7 @@ impl BlockDirection {
} }
#[must_use] #[must_use]
pub fn to_cardinal_direction(&self) -> HorizontalFacing { pub const fn to_cardinal_direction(&self) -> HorizontalFacing {
match self { match self {
Self::South => HorizontalFacing::South, Self::South => HorizontalFacing::South,
Self::West => HorizontalFacing::West, Self::West => HorizontalFacing::West,
@ -209,7 +209,7 @@ impl BlockDirection {
} }
#[must_use] #[must_use]
pub fn from_cardinal_direction(direction: HorizontalFacing) -> Self { pub const fn from_cardinal_direction(direction: HorizontalFacing) -> Self {
match direction { match direction {
HorizontalFacing::North => Self::North, HorizontalFacing::North => Self::North,
HorizontalFacing::South => Self::South, HorizontalFacing::South => Self::South,
@ -218,7 +218,7 @@ impl BlockDirection {
} }
} }
#[must_use] #[must_use]
pub fn to_axis(&self) -> Axis { pub const fn to_axis(&self) -> Axis {
match self { match self {
Self::North | Self::South => Axis::Z, Self::North | Self::South => Axis::Z,
Self::West | Self::East => Axis::X, Self::West | Self::East => Axis::X,
@ -227,7 +227,7 @@ impl BlockDirection {
} }
#[must_use] #[must_use]
pub fn to_facing(&self) -> Facing { pub const fn to_facing(&self) -> Facing {
match self { match self {
Self::North => Facing::North, Self::North => Facing::North,
Self::South => Facing::South, Self::South => Facing::South,
@ -239,7 +239,7 @@ impl BlockDirection {
} }
#[must_use] #[must_use]
pub fn rotate_clockwise(&self) -> Self { pub const fn rotate_clockwise(&self) -> Self {
match self { match self {
Self::East => Self::South, Self::East => Self::South,
Self::West => Self::North, Self::West => Self::North,
@ -249,7 +249,7 @@ impl BlockDirection {
} }
#[must_use] #[must_use]
pub fn rotate_counter_clockwise(&self) -> Self { pub const fn rotate_counter_clockwise(&self) -> Self {
match self { match self {
Self::West => Self::South, Self::West => Self::South,
Self::East => Self::North, Self::East => Self::North,

View File

@ -117,12 +117,14 @@ impl Block {
} }
/// Returns whether this block is solid (based on default state) /// 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() self.default_state.is_solid()
} }
/// Returns whether this block is air (based on default state) /// 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() self.default_state.is_air()
} }
} }

View File

@ -8,7 +8,7 @@ pub struct CollisionShape {
impl CollisionShape { impl CollisionShape {
#[must_use] #[must_use]
pub fn to_bounding_box(&self) -> BoundingBox { pub const fn to_bounding_box(&self) -> BoundingBox {
BoundingBox { BoundingBox {
min: self.min, min: self.min,
max: self.max, max: self.max,
@ -16,7 +16,7 @@ impl CollisionShape {
} }
#[must_use] #[must_use]
pub fn new(min: Vector3<f64>, max: Vector3<f64>) -> Self { pub const fn new(min: Vector3<f64>, max: Vector3<f64>) -> Self {
Self { min, max } Self { min, max }
} }

View File

@ -104,13 +104,13 @@ pub fn get<T: DataComponentImpl + 'static>(value: &dyn DataComponentImpl) -> &T
pub fn get_mut<T: DataComponentImpl + 'static>(value: &mut dyn DataComponentImpl) -> &mut T { pub fn get_mut<T: DataComponentImpl + 'static>(value: &mut dyn DataComponentImpl) -> &mut T {
value.as_mut_any().downcast_mut::<T>().unwrap() value.as_mut_any().downcast_mut::<T>().unwrap()
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct CustomDataImpl; pub struct CustomDataImpl;
impl DataComponentImpl for CustomDataImpl { impl DataComponentImpl for CustomDataImpl {
default_impl!(CustomData); default_impl!(CustomData);
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct MaxStackSizeImpl { pub struct MaxStackSizeImpl {
pub size: u8, pub size: u8,
} }
@ -129,14 +129,14 @@ impl DataComponentImpl for MaxStackSizeImpl {
default_impl!(MaxStackSize); default_impl!(MaxStackSize);
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct MaxDamageImpl { pub struct MaxDamageImpl {
pub max_damage: i32, pub max_damage: i32,
} }
impl DataComponentImpl for MaxDamageImpl { impl DataComponentImpl for MaxDamageImpl {
default_impl!(MaxDamage); default_impl!(MaxDamage);
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct DamageImpl { pub struct DamageImpl {
pub damage: i32, pub damage: i32,
} }
@ -154,10 +154,10 @@ impl DataComponentImpl for DamageImpl {
} }
default_impl!(Damage); default_impl!(Damage);
} }
#[derive(Clone, Hash, PartialEq)] #[derive(Clone, Hash, PartialEq, Eq)]
pub struct UnbreakableImpl; pub struct UnbreakableImpl;
impl UnbreakableImpl { impl UnbreakableImpl {
fn read_data(_data: &NbtTag) -> Option<Self> { const fn read_data(_data: &NbtTag) -> Option<Self> {
Some(Self) Some(Self)
} }
} }
@ -170,7 +170,7 @@ impl DataComponentImpl for UnbreakableImpl {
} }
default_impl!(Unbreakable); default_impl!(Unbreakable);
} }
#[derive(Clone, Hash, PartialEq)] #[derive(Clone, Hash, PartialEq, Eq)]
pub struct CustomNameImpl { pub struct CustomNameImpl {
// TODO make TextComponent const // TODO make TextComponent const
pub name: &'static str, pub name: &'static str,
@ -178,7 +178,7 @@ pub struct CustomNameImpl {
impl DataComponentImpl for CustomNameImpl { impl DataComponentImpl for CustomNameImpl {
default_impl!(CustomName); default_impl!(CustomName);
} }
#[derive(Clone, Hash, PartialEq)] #[derive(Clone, Hash, PartialEq, Eq)]
pub struct ItemNameImpl { pub struct ItemNameImpl {
// TODO make TextComponent const // TODO make TextComponent const
pub name: &'static str, pub name: &'static str,
@ -186,13 +186,13 @@ pub struct ItemNameImpl {
impl DataComponentImpl for ItemNameImpl { impl DataComponentImpl for ItemNameImpl {
default_impl!(ItemName); default_impl!(ItemName);
} }
#[derive(Clone, Hash, PartialEq)] #[derive(Clone, Hash, PartialEq, Eq)]
pub struct ItemModelImpl; pub struct ItemModelImpl;
#[derive(Clone, Hash, PartialEq)] #[derive(Clone, Hash, PartialEq, Eq)]
pub struct LoreImpl; pub struct LoreImpl;
#[derive(Clone, Hash, PartialEq)] #[derive(Clone, Hash, PartialEq, Eq)]
pub struct RarityImpl; pub struct RarityImpl;
#[derive(Clone, Hash, PartialEq)] #[derive(Clone, Hash, PartialEq, Eq)]
pub struct EnchantmentsImpl { pub struct EnchantmentsImpl {
pub enchantment: Cow<'static, [(&'static Enchantment, i32)]>, pub enchantment: Cow<'static, [(&'static Enchantment, i32)]>,
} }
@ -261,12 +261,12 @@ impl DataComponentImpl for EnchantmentsImpl {
} }
default_impl!(Enchantments); default_impl!(Enchantments);
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct CanPlaceOnImpl; pub struct CanPlaceOnImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct CanBreakImpl; pub struct CanBreakImpl;
#[derive(Clone, Copy, Debug, PartialEq, Hash)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Operation { pub enum Operation {
AddValue, AddValue,
AddMultipliedBase, AddMultipliedBase,
@ -296,17 +296,17 @@ pub struct AttributeModifiersImpl {
impl DataComponentImpl for AttributeModifiersImpl { impl DataComponentImpl for AttributeModifiersImpl {
default_impl!(AttributeModifiers); default_impl!(AttributeModifiers);
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct CustomModelDataImpl; pub struct CustomModelDataImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct TooltipDisplayImpl; pub struct TooltipDisplayImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct RepairCostImpl; pub struct RepairCostImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct CreativeSlotLockImpl; pub struct CreativeSlotLockImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct EnchantmentGlintOverrideImpl; pub struct EnchantmentGlintOverrideImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct IntangibleProjectileImpl; pub struct IntangibleProjectileImpl;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct FoodImpl { pub struct FoodImpl {
@ -345,14 +345,14 @@ impl Hash for ConsumableImpl {
unsafe { (*(&raw const self.consume_seconds).cast::<u32>()).hash(state) }; unsafe { (*(&raw const self.consume_seconds).cast::<u32>()).hash(state) };
} }
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct UseRemainderImpl; pub struct UseRemainderImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct UseCooldownImpl; pub struct UseCooldownImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct DamageResistantImpl; pub struct DamageResistantImpl;
#[derive(Clone, Hash, PartialEq)] #[derive(Clone, Hash, PartialEq, Eq)]
pub enum IDSet { pub enum IDSet {
Tag(&'static Tag), Tag(&'static Tag),
Blocks(Cow<'static, [&'static Block]>), Blocks(Cow<'static, [&'static Block]>),
@ -394,7 +394,7 @@ impl Hash for ToolImpl {
self.can_destroy_blocks_in_creative.hash(state); self.can_destroy_blocks_in_creative.hash(state);
} }
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct WeaponImpl; pub struct WeaponImpl;
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
@ -486,7 +486,7 @@ impl EquipmentSlot {
}); });
#[must_use] #[must_use]
pub fn get_entity_slot_id(&self) -> i32 { pub const fn get_entity_slot_id(&self) -> i32 {
match self { match self {
Self::MainHand(data) => data.entity_id, Self::MainHand(data) => data.entity_id,
Self::OffHand(data) => data.entity_id, Self::OffHand(data) => data.entity_id,
@ -515,12 +515,12 @@ impl EquipmentSlot {
} }
#[must_use] #[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 self.get_entity_slot_id() + offset
} }
#[must_use] #[must_use]
pub fn slot_type(&self) -> EquipmentType { pub const fn slot_type(&self) -> EquipmentType {
match self { match self {
Self::MainHand(data) => data.slot_type, Self::MainHand(data) => data.slot_type,
Self::OffHand(data) => data.slot_type, Self::OffHand(data) => data.slot_type,
@ -534,7 +534,7 @@ impl EquipmentSlot {
} }
#[must_use] #[must_use]
pub fn is_armor_slot(&self) -> bool { pub const fn is_armor_slot(&self) -> bool {
matches!( matches!(
self.slot_type(), self.slot_type(),
EquipmentType::HumanoidArmor | EquipmentType::AnimalArmor EquipmentType::HumanoidArmor | EquipmentType::AnimalArmor
@ -556,7 +556,7 @@ impl EquipmentSlot {
} }
} }
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq, Eq)]
pub enum EntityTypeOrTag { pub enum EntityTypeOrTag {
Tag(&'static Tag), Tag(&'static Tag),
Single(&'static EntityType), 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; pub struct EnchantableImpl;
#[derive(Clone, Hash, PartialEq)] #[derive(Clone, Hash, PartialEq, Eq)]
pub struct EquippableImpl { pub struct EquippableImpl {
pub slot: &'static EquipmentSlot, pub slot: &'static EquipmentSlot,
pub equip_sound: &'static str, pub equip_sound: &'static str,
@ -596,41 +596,41 @@ pub struct EquippableImpl {
impl DataComponentImpl for EquippableImpl { impl DataComponentImpl for EquippableImpl {
default_impl!(Equippable); default_impl!(Equippable);
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct RepairableImpl; pub struct RepairableImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct GliderImpl; pub struct GliderImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct TooltipStyleImpl; pub struct TooltipStyleImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct DeathProtectionImpl; pub struct DeathProtectionImpl;
impl DataComponentImpl for DeathProtectionImpl { impl DataComponentImpl for DeathProtectionImpl {
default_impl!(DeathProtection); default_impl!(DeathProtection);
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct BlocksAttacksImpl; pub struct BlocksAttacksImpl;
impl DataComponentImpl for BlocksAttacksImpl { impl DataComponentImpl for BlocksAttacksImpl {
default_impl!(BlocksAttacks); default_impl!(BlocksAttacks);
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct StoredEnchantmentsImpl; pub struct StoredEnchantmentsImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct DyedColorImpl; pub struct DyedColorImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct MapColorImpl; pub struct MapColorImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct MapIdImpl; pub struct MapIdImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct MapDecorationsImpl; pub struct MapDecorationsImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct MapPostProcessingImpl; pub struct MapPostProcessingImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct ChargedProjectilesImpl; pub struct ChargedProjectilesImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct BundleContentsImpl; pub struct BundleContentsImpl;
/// Status effect instance for potion contents /// Status effect instance for potion contents
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct StatusEffectInstance { pub struct StatusEffectInstance {
pub effect_id: i32, pub effect_id: i32,
pub amplifier: i32, pub amplifier: i32,
@ -640,7 +640,7 @@ pub struct StatusEffectInstance {
pub show_icon: bool, pub show_icon: bool,
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct PotionContentsImpl { pub struct PotionContentsImpl {
pub potion_id: Option<i32>, pub potion_id: Option<i32>,
pub custom_color: Option<i32>, pub custom_color: Option<i32>,
@ -684,114 +684,114 @@ impl DataComponentImpl for PotionContentsImpl {
default_impl!(PotionContents); default_impl!(PotionContents);
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct PotionDurationScaleImpl; pub struct PotionDurationScaleImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct SuspiciousStewEffectsImpl; pub struct SuspiciousStewEffectsImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct WritableBookContentImpl; pub struct WritableBookContentImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct WrittenBookContentImpl; pub struct WrittenBookContentImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct TrimImpl; pub struct TrimImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct DebugStickStateImpl; pub struct DebugStickStateImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct EntityDataImpl; pub struct EntityDataImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct BucketEntityDataImpl; pub struct BucketEntityDataImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct BlockEntityDataImpl; pub struct BlockEntityDataImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct InstrumentImpl; pub struct InstrumentImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct ProvidesTrimMaterialImpl; pub struct ProvidesTrimMaterialImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct OminousBottleAmplifierImpl; pub struct OminousBottleAmplifierImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct JukeboxPlayableImpl { pub struct JukeboxPlayableImpl {
pub song: &'static str, pub song: &'static str,
} }
impl DataComponentImpl for JukeboxPlayableImpl { impl DataComponentImpl for JukeboxPlayableImpl {
default_impl!(JukeboxPlayable); default_impl!(JukeboxPlayable);
} }
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct ProvidesBannerPatternsImpl; pub struct ProvidesBannerPatternsImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct RecipesImpl; pub struct RecipesImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct LodestoneTrackerImpl; pub struct LodestoneTrackerImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct FireworkExplosionImpl; pub struct FireworkExplosionImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct FireworksImpl; pub struct FireworksImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct ProfileImpl; pub struct ProfileImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct NoteBlockSoundImpl; pub struct NoteBlockSoundImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct BannerPatternsImpl; pub struct BannerPatternsImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct BaseColorImpl; pub struct BaseColorImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct PotDecorationsImpl; pub struct PotDecorationsImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct ContainerImpl; pub struct ContainerImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct BlockStateImpl; pub struct BlockStateImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct BeesImpl; pub struct BeesImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct LockImpl; pub struct LockImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct ContainerLootImpl; pub struct ContainerLootImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct BreakSoundImpl; pub struct BreakSoundImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct VillagerVariantImpl; pub struct VillagerVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct WolfVariantImpl; pub struct WolfVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct WolfSoundVariantImpl; pub struct WolfSoundVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct WolfCollarImpl; pub struct WolfCollarImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct FoxVariantImpl; pub struct FoxVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct SalmonSizeImpl; pub struct SalmonSizeImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct ParrotVariantImpl; pub struct ParrotVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct TropicalFishPatternImpl; pub struct TropicalFishPatternImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct TropicalFishBaseColorImpl; pub struct TropicalFishBaseColorImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct TropicalFishPatternColorImpl; pub struct TropicalFishPatternColorImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct MooshroomVariantImpl; pub struct MooshroomVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct RabbitVariantImpl; pub struct RabbitVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct PigVariantImpl; pub struct PigVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct CowVariantImpl; pub struct CowVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct ChickenVariantImpl; pub struct ChickenVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct FrogVariantImpl; pub struct FrogVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct HorseVariantImpl; pub struct HorseVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct PaintingVariantImpl; pub struct PaintingVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct LlamaVariantImpl; pub struct LlamaVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct AxolotlVariantImpl; pub struct AxolotlVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct CatVariantImpl; pub struct CatVariantImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct CatCollarImpl; pub struct CatCollarImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct SheepColorImpl; pub struct SheepColorImpl;
#[derive(Clone, Debug, Hash, PartialEq)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct ShulkerColorImpl; pub struct ShulkerColorImpl;

View File

@ -16,6 +16,7 @@ bytes.workspace = true
tokio = { workspace = true, features = [ tokio = { workspace = true, features = [
"macros", "macros",
# Maybe remove this in the future
"rt-multi-thread", "rt-multi-thread",
"sync", "sync",
"io-std", "io-std",
@ -31,14 +32,11 @@ serde_json.workspace = true
log.workspace = true log.workspace = true
crossbeam.workspace = true crossbeam.workspace = true
num-derive.workspace = true
sha2.workspace = true sha2.workspace = true
bitflags.workspace = true bitflags.workspace = true
dashmap.workspace = true dashmap.workspace = true
num-traits.workspace = true
# Compression # Compression
flate2.workspace = true flate2.workspace = true
lz4-java-wrc.workspace = true lz4-java-wrc.workspace = true
@ -60,10 +58,6 @@ crossfire.workspace = true
[dev-dependencies] [dev-dependencies]
criterion = { workspace = true, features = ["html_reports", "async_tokio"] } criterion = { workspace = true, features = ["html_reports", "async_tokio"] }
temp-dir.workspace = true 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 # Deserialize NaN and Inf
serde_json5.workspace = true serde_json5.workspace = true

View File

@ -32,7 +32,7 @@ pub struct BlastingFurnaceBlockEntity {
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE], pub items: [Arc<Mutex<ItemStack>>; 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 /// Maps result item ID -> craft count
pub recipes_used: StdMutex<HashMap<String, u32>>, pub recipes_used: StdMutex<HashMap<String, u32>>,
} }

View File

@ -32,7 +32,7 @@ pub struct FurnaceBlockEntity {
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE], pub items: [Arc<Mutex<ItemStack>>; 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 /// Maps result item ID -> craft count
pub recipes_used: StdMutex<HashMap<String, u32>>, pub recipes_used: StdMutex<HashMap<String, u32>>,
} }

View File

@ -10,7 +10,7 @@ use crate::{
}; };
/// Trait for extracting smelting experience from cooking block entities. /// 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 { pub trait ExperienceContainer: Send + Sync {
/// Extract and reset accumulated experience, returning the total as an integer /// Extract and reset accumulated experience, returning the total as an integer
fn extract_experience(&self) -> i32; fn extract_experience(&self) -> i32;
@ -28,7 +28,7 @@ pub trait CookingBlockEntityBase:
/// Uses the result item ID as the recipe identifier /// Uses the result item ID as the recipe identifier
fn add_recipe_used(&self, recipe: &CookingRecipe); fn add_recipe_used(&self, recipe: &CookingRecipe);
/// Extract and reset accumulated experience, returning the total as an integer /// 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 extract_experience_from_recipes(&self) -> i32;
fn get_input_item(&self) -> impl std::future::Future<Output = Arc<Mutex<ItemStack>>>; fn get_input_item(&self) -> impl std::future::Future<Output = Arc<Mutex<ItemStack>>>;

View File

@ -12,10 +12,10 @@ use crate::inventory::{Clearable, Inventory, InventoryFuture};
use crate::world::SimpleWorld; use crate::world::SimpleWorld;
use crate::{block::entities::BlockEntity, item::ItemStack}; use crate::{block::entities::BlockEntity, item::ItemStack};
/// Matches vanilla's JukeboxBlockEntity /// Matches vanilla's `JukeboxBlockEntity`
pub struct JukeboxBlockEntity { pub struct JukeboxBlockEntity {
position: BlockPos, 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<Mutex<ItemStack>>, record_stack: Arc<Mutex<ItemStack>>,
/// Ticks since the current song started playing /// Ticks since the current song started playing
ticks_since_song_started: AtomicU64, ticks_since_song_started: AtomicU64,
@ -129,7 +129,7 @@ impl JukeboxBlockEntity {
self.record_stack.lock().await.clone() 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 /// Note: The caller is responsible for updating block state and playing music
pub async fn set_record(&self, stack: ItemStack) { pub async fn set_record(&self, stack: ItemStack) {
*self.record_stack.lock().await = stack; *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 { impl Inventory for JukeboxBlockEntity {
fn size(&self) -> usize { fn size(&self) -> usize {
1 1

View File

@ -7,12 +7,11 @@ use std::{
}; };
use super::BlockEntity; use super::BlockEntity;
use num_derive::FromPrimitive;
use pumpkin_nbt::{compound::NbtCompound, tag::NbtTag}; use pumpkin_nbt::{compound::NbtCompound, tag::NbtTag};
use pumpkin_util::math::position::BlockPos; use pumpkin_util::math::position::BlockPos;
use tokio::sync::Mutex; use tokio::sync::Mutex;
#[derive(Clone, Default, FromPrimitive)] #[derive(Clone, Default)]
#[repr(i8)] #[repr(i8)]
pub enum DyeColor { pub enum DyeColor {
White = 0, White = 0,

View File

@ -32,7 +32,7 @@ pub struct SmokerBlockEntity {
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE], pub items: [Arc<Mutex<ItemStack>>; 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 /// Maps result item ID -> craft count
pub recipes_used: StdMutex<HashMap<String, u32>>, pub recipes_used: StdMutex<HashMap<String, u32>>,
} }

View File

@ -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] #[must_use]
pub fn to_state_from_blueprint(print: &BlockBlueprint) -> &'static BlockState { pub fn to_state_from_blueprint(print: &BlockBlueprint) -> &'static BlockState {
BlockState::from_id(to_state_id_from_blueprint(print)) BlockState::from_id(to_state_id_from_blueprint(print))

View File

@ -133,12 +133,10 @@ impl ChunkData {
// Map light data to the LightContainer enum // Map light data to the LightContainer enum
let block_light = section let block_light = section
.block_light .block_light
.map(LightContainer::Full) .map_or(LightContainer::Empty(0), LightContainer::Full); // Standard default
.unwrap_or(LightContainer::Empty(0)); // Standard default
let sky_light = section let sky_light = section
.sky_light .sky_light
.map(LightContainer::Full) .map_or(LightContainer::Empty(15), LightContainer::Full); // Sky is usually bright
.unwrap_or(LightContainer::Empty(15)); // Sky is usually bright
// Convert NBT to Palettes // Convert NBT to Palettes
let block_palette = section let block_palette = section

View File

@ -28,7 +28,6 @@ use crossbeam::channel::{Receiver, Sender};
use dashmap::DashMap; use dashmap::DashMap;
use itertools::Itertools; use itertools::Itertools;
use log::{debug, error}; use log::{debug, error};
use num_traits::abs;
use pumpkin_data::biome::Biome; use pumpkin_data::biome::Biome;
use pumpkin_data::fluid::{Fluid, FluidState}; use pumpkin_data::fluid::{Fluid, FluidState};
@ -253,7 +252,7 @@ impl ChunkLoading {
for dx in -range..=range { for dx in -range..=range {
for dy in -range..=range { for dy in -range..=range {
let new_pos = ticket_pos.add_raw(dx as i32, dy as i32); 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); let i = temp.entry(new_pos).or_insert(Self::MAX_LEVEL);
*i = min(*i, level_from_source); *i = min(*i, level_from_source);
} }
@ -416,7 +415,7 @@ impl ChunkLoading {
} }
for (ticket_pos, levels) in &self.ticket { 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(); let level = *levels.iter().min().unwrap();
debug_assert!(level < Self::MAX_LEVEL); debug_assert!(level < Self::MAX_LEVEL);
let old = self.cache.get(&self.pos_level, *ticket_pos); 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 total_sections = dimension.height as usize / 16;
let sections = ChunkSections::new(total_sections, dimension.min_y); 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); let biome_min_y = biome_coords::from_block(dimension.min_y);
for y_offset in 0..proto_biome_height { for y_offset in 0..proto_biome_height {
@ -803,7 +802,7 @@ impl Chunk {
.unwrap() .unwrap()
.get_mut(section_index) .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 z in 0..4 {
for x in 0..4 { for x in 0..4 {
@ -1439,7 +1438,7 @@ impl GenerationSchedule {
let level_clone = level.clone(); let level_clone = level.clone();
let handle = thread::Builder::new() let handle = thread::Builder::new()
.name(format!("Gen-{}", i)) // Identifying dim helps debugging .name(format!("Gen-{i}")) // Identifying dim helps debugging
.spawn(move || { .spawn(move || {
Self::generation_work(recv_gen, send_chunk, level_clone); Self::generation_work(recv_gen, send_chunk, level_clone);
}) })
@ -1448,7 +1447,7 @@ impl GenerationSchedule {
thread_tracker.push(handle); thread_tracker.push(handle);
} }
let level_sched = level.clone(); let level_sched = level;
let handle = thread::Builder::new() let handle = thread::Builder::new()
.name("Schedule".to_string()) .name("Schedule".to_string())
.spawn(move || { .spawn(move || {
@ -1486,7 +1485,7 @@ impl GenerationSchedule {
return last_level.get(&pos).unwrap() + (stage as i8); return last_level.get(&pos).unwrap() + (stage as i8);
} }
for i in last_high_priority { 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 if dst <= StagedChunkEnum::FULL_RADIUS
&& stage <= StagedChunkEnum::FULL_DEPENDENCIES[dst as usize] && stage <= StagedChunkEnum::FULL_DEPENDENCIES[dst as usize]
{ {
@ -1669,15 +1668,13 @@ impl GenerationSchedule {
} }
} else { } else {
// debug!("io read thread receive proto chunk {pos:?}",); // debug!("io read thread receive proto chunk {pos:?}",);
let val = RecvChunk::IO(Chunk::Proto(Box::new( let val =
ProtoChunk::from_chunk_data( RecvChunk::IO(Chunk::Proto(Box::new(ProtoChunk::from_chunk_data(
&chunk, &chunk,
dimension, dimension,
level.world_gen.default_block, level.world_gen.default_block,
biome_mixer_seed, biome_mixer_seed,
) ))));
.await,
)));
if send.send((pos, val)).is_err() { if send.send((pos, val)).is_err() {
break; break;
} }

View File

@ -25,7 +25,7 @@ struct Spike {
} }
impl 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.x) == section_coords::block_to_section(self.center_x)
&& section_coords::block_to_section(pos.0.z) && section_coords::block_to_section(pos.0.z)
== section_coords::block_to_section(self.center_z) == section_coords::block_to_section(self.center_z)

View File

@ -208,7 +208,7 @@ impl OreFeature {
target: &OreTarget, target: &OreTarget,
pos: &BlockPos, pos: &BlockPos,
) -> bool { ) -> bool {
if !target.target.test(&state, random) { if !target.target.test(state, random) {
return false; return false;
} }
if Self::should_not_discard(random, self.discard_chance_on_air_exposure) { if Self::should_not_discard(random, self.discard_chance_on_air_exposure) {

View File

@ -25,11 +25,11 @@ pub trait HeightLimitView {
} }
fn bottom_section_coord(&self) -> i8 { 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 { 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 { fn out_of_height(&self, height: i16) -> bool {

View File

@ -69,44 +69,46 @@ impl GlobalRandomConfig {
} }
pub mod section_coords { pub mod section_coords {
use num_traits::PrimInt;
#[inline] #[inline]
pub fn block_to_section<T: PrimInt>(coord: T) -> T { #[must_use]
pub const fn block_to_section(coord: i32) -> i32 {
coord >> 4 coord >> 4
} }
#[must_use] #[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 section_to_block(chunk_coord) + offset
} }
#[inline] #[inline]
pub fn section_to_block<T: PrimInt>(coord: T) -> T { #[must_use]
pub const fn section_to_block(coord: i32) -> i32 {
coord << 4 coord << 4
} }
} }
pub mod biome_coords { pub mod biome_coords {
use num_traits::PrimInt;
#[inline] #[inline]
pub fn from_block<T: PrimInt>(coord: T) -> T { #[must_use]
pub const fn from_block(coord: i32) -> i32 {
coord >> 2 coord >> 2
} }
#[inline] #[inline]
pub fn to_block<T: PrimInt>(coord: T) -> T { #[must_use]
pub const fn to_block(coord: i32) -> i32 {
coord << 2 coord << 2
} }
#[inline] #[inline]
pub fn from_chunk<T: PrimInt>(coord: T) -> T { #[must_use]
pub const fn from_chunk(coord: i32) -> i32 {
coord << 2 coord << 2
} }
#[inline] #[inline]
pub fn to_chunk<T: PrimInt>(coord: T) -> T { #[must_use]
pub const fn to_chunk(coord: i32) -> i32 {
coord >> 2 coord >> 2
} }
} }

View File

@ -776,13 +776,13 @@ mod random_positions_and_hypot {
let horizontal_cell_count = CHUNK_WIDTH / shape.horizontal_cell_block_count() as usize; let horizontal_cell_count = CHUNK_WIDTH / shape.horizontal_cell_block_count() as usize;
let horizontal_biome_end = biome_coords::from_block( 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( let surface_height_estimator_options = SurfaceHeightSamplerBuilderOptions::new(
chunk_x, chunk_x,
chunk_z, chunk_z,
horizontal_biome_end, horizontal_biome_end as usize,
shape.min_y as i32, shape.min_y as i32,
shape.max_y() as i32, shape.max_y() as i32,
shape.vertical_cell_block_count() as usize, shape.vertical_cell_block_count() as usize,

View File

@ -189,7 +189,7 @@ impl<'a> ChunkNoiseGenerator<'a> {
); );
let horizontal_biome_end = biome_coords::from_block( 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( let vertical_cell_count = floor_div(
generation_shape.height as usize, generation_shape.height as usize,
@ -209,7 +209,7 @@ impl<'a> ChunkNoiseGenerator<'a> {
horizontal_cell_count, horizontal_cell_count,
biome_coords::from_block(start_block_x), biome_coords::from_block(start_block_x),
biome_coords::from_block(start_block_z), biome_coords::from_block(start_block_z),
horizontal_biome_end, horizontal_biome_end as usize,
); );
let aquifer_sampler = if aquifers { let aquifer_sampler = if aquifers {

View File

@ -59,22 +59,22 @@ pub mod chunk_pos {
} }
#[must_use] #[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) get_offset_pos(coord, offset)
} }
#[must_use] #[must_use]
pub fn get_center_x(coord: i32) -> i32 { pub const fn get_center_x(coord: i32) -> i32 {
get_offset_x(coord, 8) get_offset_x(coord, 8)
} }
#[must_use] #[must_use]
pub fn get_center_z(coord: i32) -> i32 { pub const fn get_center_z(coord: i32) -> i32 {
get_offset_z(coord, 8) get_offset_z(coord, 8)
} }
#[must_use] #[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) get_offset_pos(coord, offset)
} }

View File

@ -195,9 +195,9 @@ impl ProtoChunk {
flat_block_map: vec![0; CHUNK_AREA * height as usize].into_boxed_slice(), flat_block_map: vec![0; CHUNK_AREA * height as usize].into_boxed_slice(),
flat_biome_map: vec![ flat_biome_map: vec![
Biome::PLAINS.id; Biome::PLAINS.id;
biome_coords::from_block(CHUNK_DIM as usize) biome_coords::from_block(CHUNK_DIM as i32) as usize
* biome_coords::from_block(CHUNK_DIM as usize) * biome_coords::from_block(CHUNK_DIM as i32) as usize
* biome_coords::from_block(height as usize) * biome_coords::from_block(height as i32) as usize
] ]
.into_boxed_slice(), .into_boxed_slice(),
biome_mixer_seed, biome_mixer_seed,
@ -212,7 +212,7 @@ impl ProtoChunk {
} }
} }
pub async fn from_chunk_data( pub fn from_chunk_data(
chunk_data: &ChunkData, chunk_data: &ChunkData,
dimension: &Dimension, dimension: &Dimension,
default_block: &'static BlockState, default_block: &'static BlockState,
@ -390,9 +390,9 @@ impl ProtoChunk {
#[inline] #[inline]
fn local_pos_to_block_index(&self, x: i32, y: i32, z: i32) -> usize { 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(&x), "x out of bounds: {x}");
debug_assert!((0..16).contains(&z), "z out of bounds: {}", z); 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!(y >= 0 && y < self.height() as i32, "y out of bounds: {y}");
self.height() as usize * CHUNK_DIM as usize * x as usize self.height() as usize * CHUNK_DIM as usize * x as usize
+ CHUNK_DIM as usize * y 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 { pub fn local_biome_pos_to_biome_index(&self, x: i32, y: i32, z: i32) -> usize {
let biome_height = self.height() as usize >> 2; 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(&x), "Biome X out of bounds: {x}");
debug_assert!((0..4).contains(&z), "Biome Z out of bounds: {}", z); debug_assert!((0..4).contains(&z), "Biome Z out of bounds: {z}");
debug_assert!( debug_assert!(
y >= 0 && y < biome_height as i32, y >= 0 && y < biome_height as i32,
"Biome Y out of bounds: {}", "Biome Y out of bounds: {y}"
y
); );
biome_height * biome_coords::from_block(CHUNK_DIM as usize) * x as usize biome_height * biome_coords::from_block(CHUNK_DIM as i32) as usize * x as usize
+ biome_coords::from_block(CHUNK_DIM as usize) * y as usize + biome_coords::from_block(CHUNK_DIM as i32) as usize * y as usize
+ z as usize + z as usize
} }
@ -539,7 +538,7 @@ impl ProtoChunk {
); );
let horizontal_biome_end = biome_coords::from_block( 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( let surface_config = SurfaceHeightSamplerBuilderOptions::new(
biome_coords::from_block(start_x), 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_cell_count = CHUNK_DIM / generation_shape.horizontal_cell_block_count();
let horizontal_biome_end = biome_coords::from_block( 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( let surface_config = SurfaceHeightSamplerBuilderOptions::new(
biome_coords::from_block(start_x), biome_coords::from_block(start_x),
@ -607,7 +606,7 @@ impl ProtoChunk {
multi_noise_sampler: &mut MultiNoiseSampler, multi_noise_sampler: &mut MultiNoiseSampler,
) { ) {
let min_y = self.bottom_y(); 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 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); 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_block_y = section_coords::section_to_block(i);
let start_biome_y = biome_coords::from_block(start_block_y); 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 x in 0..biomes_per_section {
for y in 0..biomes_per_section { for y in 0..biomes_per_section {
for z in 0..biomes_per_section { for z in 0..biomes_per_section {

View File

@ -9,7 +9,7 @@ pub struct BlockMatchRuleTest {
} }
impl 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) state.to_block().name == self.block.strip_prefix("minecraft:").unwrap_or(&self.block)
} }
} }

View File

@ -8,7 +8,7 @@ pub struct BlockStateMatchRuleTest {
} }
impl 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() state.0 == self.block_state.get_state_id()
} }
} }

View File

@ -32,7 +32,7 @@ pub enum RuleTest {
} }
impl 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 { match self {
Self::AlwaysTrue => true, Self::AlwaysTrue => true,
Self::BlockMatch(rule) => rule.test(state), Self::BlockMatch(rule) => rule.test(state),

View File

@ -11,7 +11,7 @@ pub struct RandomBlockMatchRuleTest {
} }
impl 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) state.to_block().name == self.block.strip_prefix("minecraft:").unwrap_or(&self.block)
&& random.next_f32() < self.probability && random.next_f32() < self.probability
} }

View File

@ -10,7 +10,7 @@ pub struct RandomBlockStateMatchRuleTest {
} }
impl 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 state.0 == self.block_state.get_state_id() && random.next_f32() < self.probability
} }
} }

View File

@ -9,7 +9,7 @@ pub struct TagMatchRuleTest {
} }
impl 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(); let values = get_tag_ids(RegistryKey::Block, &self.tag).unwrap();
values.contains(&state.to_block_id()) values.contains(&state.to_block_id())
} }

View File

@ -101,7 +101,6 @@ impl StructurePiece {
const fn apply_x_transform(&self, x: i32, z: i32) -> i32 { const fn apply_x_transform(&self, x: i32, z: i32) -> i32 {
match self.facing { match self.facing {
None => x,
Some(BlockDirection::North | BlockDirection::South) => self.bounding_box.min.x + x, Some(BlockDirection::North | BlockDirection::South) => self.bounding_box.min.x + x,
Some(BlockDirection::West) => self.bounding_box.max.x - z, Some(BlockDirection::West) => self.bounding_box.max.x - z,
Some(BlockDirection::East) => self.bounding_box.min.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 { const fn apply_z_transform(&self, x: i32, z: i32) -> i32 {
match self.facing { match self.facing {
None => z,
Some(BlockDirection::North) => self.bounding_box.max.z - z, Some(BlockDirection::North) => self.bounding_box.max.z - z,
Some(BlockDirection::South) => self.bounding_box.min.z + z, Some(BlockDirection::South) => self.bounding_box.min.z + z,
Some(BlockDirection::West | BlockDirection::East) => self.bounding_box.min.z + x, Some(BlockDirection::West | BlockDirection::East) => self.bounding_box.min.z + x,

View File

@ -53,7 +53,7 @@ pub mod spiral_staircase;
pub mod square_room; pub mod square_room;
pub mod stairs; pub mod stairs;
/// Great reference: https://minecraft.wiki/w/Stronghold /// Great reference: <https://minecraft.wiki/w/Stronghold>
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct StrongholdGenerator; 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 { match self.piece_type {
StrongholdPieceType::Library => self.can_generate() && chain_length > 4, StrongholdPieceType::Library => self.can_generate() && chain_length > 4,
StrongholdPieceType::PortalRoom => self.can_generate() && chain_length > 5, 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 self.limit == 0 || self.generated_count < self.limit
} }
} }

View File

@ -84,7 +84,7 @@ impl StructurePieceBase for PortalRoomPiece {
_collector: &mut StructurePiecesCollector, _collector: &mut StructurePiecesCollector,
_pieces_to_process: &mut Vec<Box<dyn StructurePieceBase>>, _pieces_to_process: &mut Vec<Box<dyn StructurePieceBase>>,
) { ) {
*has_portal_room = true *has_portal_room = true;
} }
fn place(&mut self, chunk: &mut ProtoChunk, random: &mut RandomGenerator, _seed: i64) { fn place(&mut self, chunk: &mut ProtoChunk, random: &mut RandomGenerator, _seed: i64) {

View File

@ -15,7 +15,6 @@ use crate::{
use crossbeam::channel::Sender; use crossbeam::channel::Sender;
use dashmap::DashMap; use dashmap::DashMap;
use log::trace; use log::trace;
use num_traits::Zero;
use pumpkin_config::{chunk::ChunkConfig, world::LevelConfig}; use pumpkin_config::{chunk::ChunkConfig, world::LevelConfig};
use pumpkin_data::biome::Biome; use pumpkin_data::biome::Biome;
use pumpkin_data::dimension::Dimension; use pumpkin_data::dimension::Dimension;
@ -406,7 +405,7 @@ impl Level {
let has_watchers = self let has_watchers = self
.chunk_watchers .chunk_watchers
.get(pos) .get(pos)
.is_some_and(|count| !count.is_zero()); .is_some_and(|count| *count != 0);
if has_watchers { if has_watchers {
return None; 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 { let mut ticks = TickData {
block_ticks: Vec::new(), block_ticks: Vec::new(),
fluid_ticks: Vec::new(), fluid_ticks: Vec::new(),
@ -492,7 +491,7 @@ impl Level {
} }
pub fn clean_memory(&self) { pub fn clean_memory(&self) {
self.chunk_watchers.retain(|_, watcher| !watcher.is_zero()); self.chunk_watchers.retain(|_, watcher| *watcher != 0);
self.loaded_entity_chunks self.loaded_entity_chunks
.retain(|at, _| self.chunk_watchers.get(at).is_some()); .retain(|at, _| self.chunk_watchers.get(at).is_some());
@ -538,7 +537,7 @@ impl Level {
let mut lock = self.chunk_loading.lock().unwrap(); let mut lock = self.chunk_loading.lock().unwrap();
lock.remove_ticket(pos, 31); lock.remove_ticket(pos, 31);
lock.send_change(); lock.send_change();
} };
chunk chunk
} }

View File

@ -107,7 +107,7 @@ pub fn bench_create_and_populate_noise(
biome_coords::from_block(start_z), biome_coords::from_block(start_z),
); );
let horizontal_biome_end = biome_coords::from_block( 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( let surface_config = SurfaceHeightSamplerBuilderOptions::new(
biome_pos.x, biome_pos.x,
@ -153,7 +153,7 @@ pub fn bench_create_and_populate_biome(
biome_coords::from_block(start_z), biome_coords::from_block(start_z),
); );
let horizontal_biome_end = biome_coords::from_block( 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( let multi_noise_config = MultiNoiseSamplerBuilderOptions::new(
biome_pos.x, biome_pos.x,
@ -197,7 +197,7 @@ pub fn bench_create_and_populate_noise_with_surface(
biome_coords::from_block(start_z), biome_coords::from_block(start_z),
); );
let horizontal_biome_end = biome_coords::from_block( 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( let multi_noise_config = MultiNoiseSamplerBuilderOptions::new(
biome_pos.x, biome_pos.x,

View File

@ -9,7 +9,7 @@ rust-version.workspace = true
# FileDescription is handled as the Program name by Windows! # FileDescription is handled as the Program name by Windows!
FileDescription = "Pumpkin" FileDescription = "Pumpkin"
OriginalFilename = "pumpkin.exe" OriginalFilename = "pumpkin.exe"
LegalCopyright = "Copyright © 2025 Aleksander Medvedev" LegalCopyright = "Copyright © 2026 Aleksander Medvedev"
# Required to expose pumpkin plugin API # Required to expose pumpkin plugin API
[lib] [lib]
@ -58,13 +58,12 @@ num-bigint.workspace = true
rustyline.workspace = true rustyline.workspace = true
# encryption # encryption
rsa = { workspace = true, features = ["sha1"] } rsa.workspace = true
pkcs8.workspace = true pkcs8.workspace = true
# authentication # authentication
ureq = { workspace = true, features = ["json"] } ureq = { workspace = true, features = ["json"] }
sha1.workspace = true sha1.workspace = true
# velocity en # velocity en

View File

@ -718,7 +718,7 @@ impl World {
} }
pub async fn tick_chunks(self: &Arc<Self>) { pub async fn tick_chunks(self: &Arc<Self>) {
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 { for scheduled_tick in tick_data.block_ticks {
let block = self.get_block(&scheduled_tick.position).await; let block = self.get_block(&scheduled_tick.position).await;
if let Some(pumpkin_block) = self.block_registry.get_pumpkin_block(block.id) { if let Some(pumpkin_block) = self.block_registry.get_pumpkin_block(block.id) {