smaller structure gen preparations

This commit is contained in:
Alexander Medvedev 2025-12-08 20:52:03 +01:00
parent e727f06e5a
commit 92fe87e921
77 changed files with 376 additions and 417 deletions

View File

@ -172,7 +172,7 @@ pub(crate) fn build() -> TokenStream {
let mut name_to_type = TokenStream::new();
let mut id_to_type = TokenStream::new();
for (name, biome) in biomes.iter() {
for (name, biome) in biomes.into_iter() {
// let full_name = format!("minecraft:{name}");
let format_name = format_ident!("{}", name.to_shouty_snake_case());
let has_precipitation = biome.has_precipitation;
@ -184,7 +184,6 @@ pub(crate) fn build() -> TokenStream {
let temperature_modifier = biome
.temperature_modifier
.clone()
.unwrap_or(TemperatureModifier::None);
let monster: Vec<_> = biome

View File

@ -331,7 +331,7 @@ impl ToTokens for BlockPropertyStruct {
}
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub struct FlammableStruct {
pub spread_chance: u8,
pub burn_chance: u8,
@ -351,7 +351,7 @@ impl ToTokens for FlammableStruct {
}
}
#[derive(Deserialize, Clone, Copy, Debug)]
#[derive(Deserialize, Clone, Copy)]
pub struct CollisionShape {
pub min: Vector3<f64>,
pub max: Vector3<f64>,
@ -376,7 +376,7 @@ impl ToTokens for CollisionShape {
}
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Clone)]
pub struct BlockState {
pub id: u16,
pub state_flags: u16,
@ -473,7 +473,7 @@ impl BlockState {
}
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub struct Block {
pub id: u16,
pub name: String,
@ -492,7 +492,7 @@ pub struct Block {
pub experience: Option<Experience>,
}
impl Block {
impl ToTokens for Block {
fn to_tokens(&self, tokens: &mut TokenStream) {
let id = LitInt::new(&self.id.to_string(), Span::call_site());
let name = LitStr::new(&self.name, Span::call_site());
@ -567,7 +567,7 @@ pub enum GeneratedPropertyType {
Enum { values: Vec<String> },
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Clone)]
pub struct GeneratedProperty {
hash_key: i32,
enum_name: String,
@ -607,14 +607,14 @@ impl GeneratedProperty {
}
}
#[derive(Clone, Debug)]
#[derive(Clone)]
struct Property {
enum_name: String,
serialized_name: String,
values: Vec<String>,
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub struct BlockAssets {
pub blocks: Vec<Block>,
pub shapes: Vec<CollisionShape>,
@ -626,9 +626,9 @@ pub(crate) fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/bedrock_block_states.nbt");
println!("cargo:rerun-if-changed=../assets/properties.json");
let be_blocks = fs::read("../assets/bedrock_block_states.nbt").unwrap();
let mut be_blocks = Cursor::new(be_blocks);
let be_blocks = get_be_data_from_nbt(&mut be_blocks);
let be_blocks_data = fs::read("../assets/bedrock_block_states.nbt").unwrap();
let mut be_blocks_cursor = Cursor::new(be_blocks_data);
let be_blocks = get_be_data_from_nbt(&mut be_blocks_cursor);
let blocks_assets: BlockAssets =
serde_json::from_str(&fs::read_to_string("../assets/blocks.json").unwrap())
@ -638,30 +638,28 @@ pub(crate) fn build() -> TokenStream {
serde_json::from_str(&fs::read_to_string("../assets/properties.json").unwrap())
.expect("Failed to parse properties.json");
let mut type_from_raw_id_items = TokenStream::new();
let mut block_from_name = TokenStream::new();
let mut raw_id_from_state_id = TokenStream::new();
let mut block_from_item_id = TokenStream::new();
let mut state_from_state_id = TokenStream::new();
let generated_prop_map: std::collections::HashMap<i32, &GeneratedProperty> =
generated_properties
.iter()
.map(|p| (p.hash_key, p))
.collect();
let mut random_tick_states = Vec::new();
let mut block_properties_from_state_and_block_id = TokenStream::new();
let mut block_properties_from_props_and_name = TokenStream::new();
let mut existing_item_ids: Vec<u16> = Vec::new();
let mut constants = TokenStream::new();
let mut constants_list = Vec::new();
let mut block_from_name_entries = Vec::new();
let mut block_from_item_id_arms = Vec::new();
let mut block_state_to_bedrock = Vec::new();
// Used to create property `enum`s.
let mut property_enums: BTreeMap<String, PropertyStruct> = BTreeMap::new();
// Property implementation for a block.
let mut block_properties: Vec<BlockPropertyStruct> = Vec::new();
// Mapping of a collection of property hashes -> blocks that have these properties.
let mut property_collection_map: BTreeMap<Vec<i32>, PropertyCollectionData> = BTreeMap::new();
// Validator that we have no `enum` collisions.
let mut optimized_blocks: Vec<Block> = Vec::new();
for block in blocks_assets.blocks.clone() {
optimized_blocks.push(block.clone());
let mut raw_id_from_state_id_array = Vec::new();
let mut type_from_raw_id_array = Vec::new();
let mut state_from_state_id_array = Vec::<(Ident, usize, u16)>::new();
// Collect state IDs that have random ticks.
let mut property_enums: BTreeMap<String, PropertyStruct> = BTreeMap::new();
let mut block_properties: Vec<BlockPropertyStruct> = Vec::new();
let mut property_collection_map: BTreeMap<Vec<i32>, PropertyCollectionData> = BTreeMap::new();
let mut existing_item_ids: std::collections::HashSet<u16> = std::collections::HashSet::new();
for block in blocks_assets.blocks {
for state in &block.states {
if state.has_random_ticks() {
let state_id = LitInt::new(&state.id.to_string(), Span::call_site());
@ -671,16 +669,20 @@ pub(crate) fn build() -> TokenStream {
let mut property_collection = HashSet::new();
let mut property_mapping = Vec::new();
for property in block.properties {
let generated_property = generated_properties
.iter()
.find(|p| p.hash_key == property)
.unwrap();
for property_hash in &block.properties {
let generated_property = generated_prop_map
.get(property_hash)
.expect("Property hash not found in generated_properties");
property_collection.insert(generated_property.hash_key);
let property = generated_property.to_property();
let renamed_property = property.enum_name.to_upper_camel_case();
let property_type = if property.values == vec!["true".to_string(), "false".to_string()]
let property_type = if property.values.len() == 2
&& property.values.contains(&"true".to_string())
&& property.values.contains(&"false".to_string())
{
PropertyType::Bool
} else {
@ -690,7 +692,7 @@ pub(crate) fn build() -> TokenStream {
};
if let PropertyType::Enum { name } = &property_type {
let _ = property_enums
property_enums
.entry(name.clone())
.or_insert_with(|| PropertyStruct {
name: name.clone(),
@ -699,97 +701,34 @@ pub(crate) fn build() -> TokenStream {
}
property_mapping.push(PropertyVariantMapping {
original_name: property.serialized_name.clone(),
original_name: property.serialized_name,
property_type,
});
}
// The Minecraft Java state manager deterministically produces an index given a set of properties. We must use
// the original property names here when checking for unique combinations of properties, and
// sort them to make a deterministic hash.
if !property_collection.is_empty() {
let mut property_collection = Vec::from_iter(property_collection);
property_collection.sort();
let mut property_collection_vec: Vec<i32> = property_collection.into_iter().collect();
property_collection_vec.sort_unstable();
property_collection_map
.entry(property_collection)
.entry(property_collection_vec)
.or_insert_with(|| PropertyCollectionData::from_mappings(property_mapping))
.add_block(block.name.clone(), block.id);
}
}
for property_group in property_collection_map.into_values() {
for (block_name, id) in &property_group.blocks {
let const_block_name = Ident::new(
&const_block_name_from_block_name(block_name),
Span::call_site(),
);
let property_name = Ident::new(
&property_group_name_from_derived_name(&property_group.derive_name()),
Span::call_site(),
);
let id_lit = LitInt::new(&id.to_string(), Span::call_site());
block_properties_from_state_and_block_id.extend(quote! {
#id_lit => Box::new(#property_name::from_state_id(state_id, &Block::#const_block_name)),
});
block_properties_from_props_and_name.extend(quote! {
#id_lit => Box::new(#property_name::from_props(props, &Block::#const_block_name)),
});
}
block_properties.push(BlockPropertyStruct {
data: property_group,
});
}
// Generate the collision shapes array.
let shapes = blocks_assets
.shapes
.iter()
.map(|shape| shape.to_token_stream());
let random_tick_state_ids = quote! {
#(#random_tick_states)|*
};
//let unique_states_tokens = unique_states.iter().map(|state| state.to_tokens());
let block_props = block_properties.iter().map(|prop| prop.to_token_stream());
let properties = property_enums.values().map(|prop| prop.to_token_stream());
// Generate the block entity types array.
let block_entity_types = blocks_assets
.block_entity_types
.iter()
.map(|entity_type| LitStr::new(entity_type, Span::call_site()));
let mut raw_id_from_state_id_array = vec![];
let mut type_from_raw_id_array = vec![];
let mut state_from_state_id_array = Vec::<(Ident, usize, u16)>::new(); // block index state_id
//let mut file = fs::File::create("../debug/debug.txt").unwrap();
// Generate constants and `match` arms for each block.
for block in optimized_blocks {
let const_ident = format_ident!("{}", const_block_name_from_block_name(&block.name));
let name = &block.name;
let mut block_tokens = TokenStream::new();
block.to_tokens(&mut block_tokens);
let name_str = &block.name;
let id_lit = LitInt::new(&block.id.to_string(), Span::call_site());
let item_id = block.item_id;
constants.extend(quote! {
pub const #const_ident: Block = #block_tokens;
constants_list.push(quote! {
pub const #const_ident: Block = #block;
});
type_from_raw_id_array.push((block.id, quote! { &Self::#const_ident }));
block_from_name.extend(quote! {
#name => Self::#const_ident,
block_from_name_entries.push(quote! {
#name_str => Self::#const_ident,
});
let be_name = match block.name.as_str() {
@ -810,71 +749,93 @@ pub(crate) fn build() -> TokenStream {
for (i, state) in block.states.iter().enumerate() {
if state_count != 0 {
if state_count > i as u32 {
let start_id = id as u16 + i as u16;
block_state_to_bedrock.push((state.id, start_id))
let bedrock_val = if state_count > i as u32 {
id as u16 + i as u16
} else {
block_state_to_bedrock.push((state.id, id as u16))
id as u16
};
block_state_to_bedrock.push((state.id, bedrock_val));
}
}
//else {
//file.write_all(format!("{be_name}\n").as_bytes()).unwrap();
//}
raw_id_from_state_id_array.push((state.id, id_lit.clone()));
state_from_state_id_array.push((const_ident.clone(), i, state.id));
}
for (index, state) in block.states.iter().enumerate() {
state_from_state_id_array.push((const_ident.clone(), index, state.id));
}
if !existing_item_ids.contains(&item_id) {
block_from_item_id.extend(quote! {
if existing_item_ids.insert(item_id) {
block_from_item_id_arms.push(quote! {
#item_id => Some(&Self::#const_ident),
});
existing_item_ids.push(item_id);
}
}
let mut block_properties_from_state_and_block_id_arms = Vec::new();
let mut block_properties_from_props_and_name_arms = Vec::new();
for property_group in property_collection_map.into_values() {
let property_name = Ident::new(
&property_group_name_from_derived_name(&property_group.derive_name()),
Span::call_site(),
);
for (block_name, id) in &property_group.blocks {
let const_block_name = Ident::new(
&const_block_name_from_block_name(block_name),
Span::call_site(),
);
let id_lit = LitInt::new(&id.to_string(), Span::call_site());
block_properties_from_state_and_block_id_arms.push(quote! {
#id_lit => Box::new(#property_name::from_state_id(state_id, &Block::#const_block_name)),
});
block_properties_from_props_and_name_arms.push(quote! {
#id_lit => Box::new(#property_name::from_props(props, &Block::#const_block_name)),
});
}
block_properties.push(BlockPropertyStruct {
data: property_group,
});
}
let shapes = blocks_assets
.shapes
.iter()
.map(|shape| shape.to_token_stream());
let random_tick_state_ids = quote! { #(#random_tick_states)|* };
let block_props = block_properties.iter().map(|prop| prop.to_token_stream());
let properties = property_enums.values().map(|prop| prop.to_token_stream());
let block_entity_types = blocks_assets
.block_entity_types
.iter()
.map(|entity_type| LitStr::new(entity_type, Span::call_site()));
let raw_id_from_state_id_ordered = fill_array(raw_id_from_state_id_array);
let max_state_id = raw_id_from_state_id_ordered.len();
for id_lit in raw_id_from_state_id_ordered {
raw_id_from_state_id.extend(quote! {
#id_lit,
});
}
let raw_id_from_state_id = quote! { #(#raw_id_from_state_id_ordered),* };
let max_index = block_state_to_bedrock
.iter()
.map(|(index, _)| index)
.map(|(idx, _)| *idx)
.max()
.unwrap();
let mut state_to_bedrock_id = vec![quote! { 1 }; (max_index + 1) as usize];
let mut block_state_to_bedrock_t = TokenStream::new();
.unwrap_or(0);
let mut state_to_bedrock_tokens = vec![quote! { 1 }; (max_index + 1) as usize];
for (state_id, id_lit) in block_state_to_bedrock {
state_to_bedrock_id[state_id as usize] = quote! { #id_lit };
let lit = LitInt::new(&id_lit.to_string(), Span::call_site());
state_to_bedrock_tokens[state_id as usize] = quote! { #lit };
}
let block_state_to_bedrock_t = quote! { #(#state_to_bedrock_tokens),* };
for id_lit in state_to_bedrock_id {
block_state_to_bedrock_t.extend(quote! {
#id_lit,
});
}
let type_from_raw_id_vec = fill_array(type_from_raw_id_array);
let max_type_id = type_from_raw_id_vec.len();
let type_from_raw_id_items = quote! { #(#type_from_raw_id_vec),* };
let type_from_raw_id_array = fill_array(type_from_raw_id_array);
let max_type_id = type_from_raw_id_array.len();
for type_lit in type_from_raw_id_array {
type_from_raw_id_items.extend(quote! {
#type_lit,
});
}
let state_from_state_id_array = fill_state_array(state_from_state_id_array);
let max_state_id_2 = state_from_state_id_array.len();
for token in state_from_state_id_array {
state_from_state_id.extend(quote! {
#token,
});
}
let state_from_state_id_vec = fill_state_array(state_from_state_id_array);
let max_state_id_2 = state_from_state_id_vec.len();
let state_from_state_id = quote! { #(#state_from_state_id_vec),* };
assert_eq!(max_state_id, max_state_id_2);
@ -888,7 +849,6 @@ pub(crate) fn build() -> TokenStream {
use std::collections::BTreeMap;
use phf;
#[derive(Clone, Copy, Debug)]
pub struct BlockProperty {
pub name: &'static str,
@ -896,25 +856,13 @@ pub(crate) fn build() -> TokenStream {
}
pub trait BlockProperties where Self: 'static {
// Convert properties to an index (`0` to `N-1`).
fn to_index(&self) -> u16;
// Convert an index back to properties.
fn from_index(index: u16) -> Self where Self: Sized;
// Check if a block uses this property
fn handles_block_id(block_id: u16) -> bool where Self: Sized;
// Convert properties to a state id.
fn to_state_id(&self, block: &Block) -> u16;
// Convert a state id back to properties.
fn from_state_id(state_id: u16, block: &Block) -> Self where Self: Sized;
// Get the default properties.
fn default(block: &Block) -> Self where Self: Sized;
// Convert properties to a `Vec` of `(name, value)`
fn to_props(&self) -> Vec<(&'static str, &'static str)>;
// Convert properties to a block state, and add them onto the default state.
fn from_props(props: &[(&str, &str)], block: &Block) -> Self where Self: Sized;
}
@ -930,10 +878,6 @@ pub(crate) fn build() -> TokenStream {
#(#shapes),*
];
//pub const BLOCK_STATES: &[BlockState] = &[
// #(#unique_states_tokens),*
//];
pub const BLOCK_ENTITY_TYPES: &[&str] = &[
#(#block_entity_types),*
];
@ -976,14 +920,12 @@ pub(crate) fn build() -> TokenStream {
}
impl Block {
#constants
#(#constants_list)*
// String name to block struct
const BLOCK_FROM_NAME_MAP: phf::Map<&'static str, Block> = phf::phf_map!{
#block_from_name
#(#block_from_name_entries)*
};
// Many state ids map to single raw block id
const RAW_ID_FROM_STATE_ID: [u16; #max_state_id] = [
#raw_id_from_state_id
];
@ -1041,7 +983,7 @@ pub(crate) fn build() -> TokenStream {
pub const fn from_item_id(id: u16) -> Option<&'static Self> {
#[allow(unreachable_patterns)]
match id {
#block_from_item_id
#(#block_from_item_id_arms)*
_ => None
}
}
@ -1050,7 +992,7 @@ pub(crate) fn build() -> TokenStream {
#[doc = r" Get the properties of the block."]
pub fn properties(&self, state_id: u16) -> Option<Box<dyn BlockProperties>> {
Some(match self.id {
#block_properties_from_state_and_block_id
#(#block_properties_from_state_and_block_id_arms)*
_ => return None,
})
}
@ -1059,7 +1001,7 @@ pub(crate) fn build() -> TokenStream {
#[doc = r" Get the properties of the block."]
pub fn from_properties(&self, props: &[(&str, &str)]) -> Box<dyn BlockProperties> {
match self.id {
#block_properties_from_props_and_name
#(#block_properties_from_props_and_name_arms)*
_ => panic!("Invalid props")
}
}

View File

@ -5,7 +5,7 @@ use proc_macro2::TokenStream;
use quote::{format_ident, quote};
use serde::Deserialize;
#[derive(Deserialize, Clone)]
#[derive(Deserialize)]
struct Effect {
id: u8,
category: MobEffectCategory,
@ -15,14 +15,14 @@ struct Effect {
}
#[allow(clippy::upper_case_acronyms)]
#[derive(Deserialize, Clone)]
#[derive(Deserialize)]
pub enum MobEffectCategory {
BENEFICIAL,
HARMFUL,
NEUTRAL,
}
#[derive(Deserialize, Clone)]
#[derive(Deserialize)]
pub struct Modifiers {
attribute: String,
id: String,
@ -32,9 +32,9 @@ pub struct Modifiers {
}
impl Modifiers {
pub fn to_tokens(&self) -> TokenStream {
pub fn get_tokens(self) -> TokenStream {
let attribute = format_ident!("{}", self.attribute.to_uppercase());
let id = self.id.clone();
let id = self.id;
let base_value = self.base_value;
let operation = format_ident!("{}", self.operation.to_pascal_case());
quote! {
@ -76,7 +76,7 @@ pub(crate) fn build() -> TokenStream {
let translation_key = effect.translation_key;
let category = effect.category.to_tokens();
let slots = effect.attribute_modifiers;
let slots = slots.iter().map(|slot| slot.to_tokens());
let slots = slots.into_iter().map(|slot| slot.get_tokens());
let minecraft_name = "minecraft:".to_string() + &name;
variants.extend([quote! {
@ -100,7 +100,6 @@ pub(crate) fn build() -> TokenStream {
use crate::attributes::Attributes;
use crate::data_component_impl::Operation;
#[derive(Debug)]
pub struct StatusEffect {
pub minecraft_name: &'static str,
pub id: u8,

View File

@ -140,7 +140,6 @@ pub(crate) fn build() -> TokenStream {
use std::hash::{Hash, Hasher};
use std::slice::Iter;
#[derive(Debug)]
pub struct Enchantment {
pub id: u8,
pub name: &'static str,

View File

@ -599,7 +599,7 @@ pub(crate) fn build() -> TokenStream {
use crate::tag::{Taggable, RegistryKey};
use pumpkin_util::resource_location::{FromResourceLocation, ResourceLocation, ToResourceLocation};
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct PartialFluidState {
pub height: f32,
pub level: i16,
@ -611,7 +611,7 @@ pub(crate) fn build() -> TokenStream {
pub falling: bool,
}
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct FluidState {
pub height: f32,
pub level: i16,
@ -623,13 +623,13 @@ pub(crate) fn build() -> TokenStream {
pub falling: bool,
}
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct FluidStateRef {
pub id: u16,
pub state_idx: u16,
}
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct Fluid {
pub id: u16,
pub name: &'static str,

View File

@ -9,13 +9,13 @@ use serde::Deserialize;
use std::{collections::BTreeMap, fs};
use syn::{Ident, LitBool, LitFloat, LitInt, LitStr};
#[derive(Deserialize, Clone)]
#[derive(Deserialize)]
pub struct Item {
pub id: u16,
pub components: ItemComponents,
}
#[derive(Deserialize, Clone)]
#[derive(Deserialize)]
pub struct ItemComponents {
#[serde(rename = "minecraft:item_name")]
pub item_name: TextComponent,
@ -354,7 +354,7 @@ fn return_1f32() -> f32 {
fn return_true() -> bool {
true
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub struct ToolComponent {
rules: Vec<ToolRule>,
#[serde(default = "return_1f32")]
@ -369,7 +369,7 @@ fn return_false() -> bool {
false
}
#[derive(Deserialize, Copy, Clone, Debug)]
#[derive(Deserialize, Copy, Clone)]
pub struct FoodComponent {
nutrition: u8,
saturation: f32,
@ -377,7 +377,7 @@ pub struct FoodComponent {
can_always_eat: bool,
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Clone)]
pub struct ToolRule {
blocks: RegistryEntryList,
speed: Option<f32>,
@ -398,23 +398,23 @@ fn _true() -> bool {
true
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Clone)]
pub struct Consumable {
consume_seconds: Option<f32>, // TODO
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Clone)]
pub struct DeathProtection {
// TODO
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Clone)]
pub struct BlocksAttacks {
// TODO
}
#[allow(dead_code)]
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Clone)]
pub struct EquippableComponent {
pub slot: String,
pub equip_sound: Option<String>,
@ -493,7 +493,7 @@ pub(crate) fn build() -> TokenStream {
use crate::data_component::DataComponent;
use crate::Block;
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct Item {
pub id: u16,
pub registry_key: &'static str,

View File

@ -7,7 +7,7 @@ use serde::Deserialize;
use syn::LitStr;
/// These are required to be defined twice because serde can't deserialize into static context for obvious reasons.
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub struct LootTableStruct {
r#type: LootTableTypeStruct,
random_sequence: Option<String>,

View File

@ -1,29 +1,28 @@
use std::{collections::BTreeMap, fs};
use proc_macro2::TokenStream;
use pumpkin_util::text::style::Style;
use quote::{format_ident, quote};
use serde::{Deserialize, Serialize};
use serde::Deserialize;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Deserialize)]
pub struct RawChatType {
id: u32,
components: ChatType,
// components: ChatType,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChatType {
chat: Decoration,
narration: Decoration,
}
// #[derive(Deserialize)]
// pub struct ChatType {
// chat: Decoration,
// narration: Decoration,
// }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Decoration {
translation_key: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
style: Option<Style>,
parameters: Vec<String>,
}
// #[derive(Deserialize)]
// pub struct Decoration {
// translation_key: String,
// #[serde(default, skip_serializing_if = "Option::is_none")]
// style: Option<Style>,
// parameters: Vec<String>,
// }
pub(crate) fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/message_type.json");

View File

@ -9,7 +9,6 @@ use quote::{ToTokens, TokenStreamExt, quote};
use serde::Deserialize;
use syn::Ident;
#[derive(Clone)]
struct HashableF32(pub f32);
// Normally this is bad, but we just care about checking if components are the same
@ -45,7 +44,6 @@ impl<'de> Deserialize<'de> for HashableF32 {
}
}
#[derive(Clone)]
struct HashableF64(pub f64);
// Normally this is bad, but we just care about checking if components are the same
@ -81,7 +79,7 @@ impl<'de> Deserialize<'de> for HashableF64 {
}
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
#[serde(tag = "_type", content = "value")]
enum SplineRepr {
#[serde(rename(deserialize = "standard"))]
@ -97,8 +95,8 @@ enum SplineRepr {
}
impl SplineRepr {
fn into_token_stream(
self,
fn get_token_stream(
&self,
stack: &mut Vec<TokenStream>,
hash_to_index_map: &mut BTreeMap<u64, usize>,
) -> TokenStream {
@ -130,7 +128,7 @@ impl SplineRepr {
let point_reprs = points
.into_iter()
.map(|(location, value, derivative)| {
let value_repr = value.into_token_stream(stack, hash_to_index_map);
let value_repr = value.get_token_stream(stack, hash_to_index_map);
quote! {
SplinePoint {
@ -166,7 +164,7 @@ enum BinaryOperation {
}
impl BinaryOperation {
fn into_token_stream(self) -> TokenStream {
fn get_token_stream(&self) -> TokenStream {
match self {
Self::Add => {
quote! {
@ -337,7 +335,7 @@ impl WrapperType {
}
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
struct NoiseData {
#[serde(rename(deserialize = "noise"))]
noise_id: String,
@ -347,7 +345,7 @@ struct NoiseData {
y_scale: HashableF64,
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
struct ShiftedNoiseData {
#[serde(rename(deserialize = "xzScale"))]
xz_scale: HashableF64,
@ -365,7 +363,7 @@ struct WeirdScaledData {
mapper: WeirdScaledMapper,
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
struct InterpolatedNoiseSamplerData {
#[serde(rename(deserialize = "scaledXzScale"))]
scaled_xz_scale: HashableF64,
@ -386,7 +384,7 @@ struct InterpolatedNoiseSamplerData {
//y_scale: HashableF64,
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
struct ClampedYGradientData {
#[serde(rename(deserialize = "fromY"))]
from_y: i32,
@ -398,7 +396,7 @@ struct ClampedYGradientData {
to_value: HashableF64,
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
struct BinaryData {
#[serde(rename(deserialize = "type"))]
operation: BinaryOperation,
@ -408,7 +406,7 @@ struct BinaryData {
max_value: HashableF64,
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
struct LinearData {
#[serde(rename(deserialize = "specificType"))]
operation: LinearOperation,
@ -419,7 +417,7 @@ struct LinearData {
max_value: HashableF64,
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
struct UnaryData {
#[serde(rename(deserialize = "type"))]
operation: UnaryOperation,
@ -429,7 +427,7 @@ struct UnaryData {
max_value: HashableF64,
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
struct ClampData {
#[serde(rename(deserialize = "minValue"))]
min_value: HashableF64,
@ -437,7 +435,7 @@ struct ClampData {
max_value: HashableF64,
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
struct RangeChoiceData {
#[serde(rename(deserialize = "minInclusive"))]
min_inclusive: HashableF64,
@ -445,7 +443,7 @@ struct RangeChoiceData {
max_exclusive: HashableF64,
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
struct SplineData {
#[serde(rename(deserialize = "minValue"))]
min_value: HashableF64,
@ -453,7 +451,7 @@ struct SplineData {
max_value: HashableF64,
}
#[derive(Deserialize, Hash, Clone)]
#[derive(Deserialize, Hash)]
#[serde(tag = "_class", content = "value")]
enum DensityFunctionRepr {
// This is a placeholder for leaving space for world structures
@ -562,7 +560,7 @@ impl DensityFunctionRepr {
}
fn get_index_for_component(
self,
&self,
stack: &mut Vec<TokenStream>,
hash_to_index_map: &mut BTreeMap<u64, usize>,
) -> usize {
@ -570,7 +568,7 @@ impl DensityFunctionRepr {
*index
} else {
let id = self.unique_id();
let repr = self.into_token_stream(stack, hash_to_index_map);
let repr = self.get_token_stream(stack, hash_to_index_map);
stack.push(repr);
let index = stack.len() - 1;
hash_to_index_map.insert(id, index);
@ -578,15 +576,15 @@ impl DensityFunctionRepr {
}
}
fn into_token_stream(
self,
fn get_token_stream(
&self,
stack: &mut Vec<TokenStream>,
hash_to_index_map: &mut BTreeMap<u64, usize>,
) -> TokenStream {
match self {
Self::Spline { spline, data } => {
let _ = data;
let spline_repr = spline.into_token_stream(stack, hash_to_index_map);
let spline_repr = spline.get_token_stream(stack, hash_to_index_map);
quote! {
BaseNoiseFunctionComponent::Spline {
@ -598,9 +596,9 @@ impl DensityFunctionRepr {
BaseNoiseFunctionComponent::EndIslands
},
Self::Noise { data } => {
let noise_id = data.noise_id;
let xz_scale = data.xz_scale;
let y_scale = data.y_scale;
let noise_id = &data.noise_id;
let xz_scale = &data.xz_scale;
let y_scale = &data.y_scale;
quote! {
BaseNoiseFunctionComponent::Noise {
@ -660,9 +658,9 @@ impl DensityFunctionRepr {
let shift_y_index = shift_y.get_index_for_component(stack, hash_to_index_map);
let shift_z_index = shift_z.get_index_for_component(stack, hash_to_index_map);
let xz_scale = data.xz_scale;
let y_scale = data.y_scale;
let noise_id = data.noise_id;
let xz_scale = &data.xz_scale;
let y_scale = &data.y_scale;
let noise_id = &data.noise_id;
quote! {
BaseNoiseFunctionComponent::ShiftedNoise {
@ -688,8 +686,8 @@ impl DensityFunctionRepr {
let when_out_index =
when_out_range.get_index_for_component(stack, hash_to_index_map);
let min_inclusive = data.min_inclusive;
let max_exclusive = data.max_exclusive;
let min_inclusive = &data.min_inclusive;
let max_exclusive = &data.max_exclusive;
quote! {
BaseNoiseFunctionComponent::RangeChoice {
@ -711,7 +709,7 @@ impl DensityFunctionRepr {
let argument1_index = argument1.get_index_for_component(stack, hash_to_index_map);
let argument2_index = argument2.get_index_for_component(stack, hash_to_index_map);
let action = data.operation.into_token_stream();
let action = data.operation.get_token_stream();
quote! {
BaseNoiseFunctionComponent::Binary {
argument1_index: #argument1_index,
@ -725,8 +723,8 @@ impl DensityFunctionRepr {
Self::ClampedYGradient { data } => {
let from_y = data.from_y as f64;
let to_y = data.to_y as f64;
let from_value = data.from_value;
let to_value = data.to_value;
let from_value = &data.from_value;
let to_value = &data.to_value;
quote! {
BaseNoiseFunctionComponent::ClampedYGradient {
@ -761,7 +759,7 @@ impl DensityFunctionRepr {
let input_index = input.get_index_for_component(stack, hash_to_index_map);
let action = data.operation.into_token_stream();
let argument = data.argument;
let argument = &data.argument;
quote! {
BaseNoiseFunctionComponent::Linear {
input_index: #input_index,
@ -775,8 +773,8 @@ impl DensityFunctionRepr {
Self::Clamp { input, data } => {
let input_index = input.get_index_for_component(stack, hash_to_index_map);
let min_value = data.min_value;
let max_value = data.max_value;
let min_value = &data.min_value;
let max_value = &data.max_value;
quote! {
BaseNoiseFunctionComponent::Clamp {
@ -805,7 +803,7 @@ impl DensityFunctionRepr {
Self::WeirdScaled { input, data } => {
let input_index = input.get_index_for_component(stack, hash_to_index_map);
let noise_id = data.noise_id;
let noise_id = &data.noise_id;
let action = data.mapper.into_token_stream();
quote! {
@ -819,11 +817,11 @@ impl DensityFunctionRepr {
}
}
Self::InterpolatedNoiseSampler { data } => {
let scaled_xz_scale = data.scaled_xz_scale;
let scaled_y_scale = data.scaled_y_scale;
let xz_factor = data.xz_factor;
let y_factor = data.y_factor;
let smear_scale_multiplier = data.smear_scale_multiplier;
let scaled_xz_scale = &data.scaled_xz_scale;
let scaled_y_scale = &data.scaled_y_scale;
let xz_factor = &data.xz_factor;
let y_factor = &data.y_factor;
let smear_scale_multiplier = &data.smear_scale_multiplier;
quote! {
BaseNoiseFunctionComponent::InterpolatedNoiseSampler {
@ -918,11 +916,9 @@ impl NoiseRouterRepr {
// These should all be cached so it doesn't matter where their components are
let noise_erosion = self
.erosion
.clone()
.get_index_for_component(&mut noise_component_stack, &mut noise_lookup_map);
let noise_depth = self
.depth
.clone()
.get_index_for_component(&mut noise_component_stack, &mut noise_lookup_map);
let mut surface_component_stack = Vec::new();

View File

@ -5,13 +5,13 @@ use proc_macro2::TokenStream;
use quote::{format_ident, quote};
use serde::Deserialize;
#[derive(Deserialize, Clone)]
#[derive(Deserialize)]
struct Potion {
id: u8,
effects: Vec<Effect>,
}
#[derive(Deserialize, Clone)]
#[derive(Deserialize)]
pub struct Effect {
effect_type: String,
duration: i32,
@ -80,14 +80,13 @@ pub(crate) fn build() -> TokenStream {
use std::hash::Hash;
use crate::effect::StatusEffect;
#[derive(Debug)]
pub struct Potion {
pub id: u8,
pub name: &'static str,
pub effects: &'static [Effect],
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Effect {
pub effect_type: &'static StatusEffect,
pub duration: i32,

View File

@ -3,14 +3,14 @@ use quote::{format_ident, quote};
use serde::Deserialize;
use std::fs;
#[derive(Deserialize, Clone, Hash, Eq, PartialEq)]
#[derive(Deserialize)]
struct PotionBrewing {
potion_types: Vec<Vec<String>>,
//potion_types: Vec<Vec<String>>,
potion_recipes: Vec<Recipes>,
item_recipes: Vec<Recipes>,
}
#[derive(Deserialize, Clone, Hash, Eq, PartialEq)]
#[derive(Deserialize)]
pub struct Recipes {
from: String,
ingredient: Vec<String>,

View File

@ -4,7 +4,7 @@ use proc_macro2::TokenStream;
use quote::{ToTokens, quote};
use serde::Deserialize;
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
#[serde(tag = "type")]
pub enum RecipeTypes {
#[serde(rename = "minecraft:blasting")]
@ -34,7 +34,7 @@ pub enum RecipeTypes {
CraftingSpecial,
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub struct CookingRecipeStruct {
category: Option<RecipeCategoryTypes>,
group: Option<String>,
@ -72,7 +72,7 @@ impl ToTokens for CookingRecipeStruct {
}
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub struct CraftingShapedRecipeStruct {
category: Option<RecipeCategoryTypes>,
group: Option<String>,
@ -121,7 +121,7 @@ impl ToTokens for CraftingShapedRecipeStruct {
}
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub struct CraftingShapelessRecipeStruct {
category: Option<RecipeCategoryTypes>,
group: Option<String>,
@ -157,7 +157,7 @@ impl ToTokens for CraftingShapelessRecipeStruct {
}
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub struct CraftingTransmuteRecipeStruct {
category: Option<RecipeCategoryTypes>,
group: Option<String>,
@ -192,7 +192,7 @@ impl ToTokens for CraftingTransmuteRecipeStruct {
}
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub struct CraftingDecoratedPotStruct {
category: Option<RecipeCategoryTypes>,
}
@ -212,7 +212,7 @@ impl ToTokens for CraftingDecoratedPotStruct {
}
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub struct RecipeResultStruct {
id: String,
count: Option<u8>,
@ -233,7 +233,7 @@ impl ToTokens for RecipeResultStruct {
}
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
#[serde(untagged)]
pub enum RecipeIngredientTypes {
Simple(String),
@ -263,7 +263,7 @@ impl ToTokens for RecipeIngredientTypes {
}
}
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize)]
pub enum RecipeCategoryTypes {
#[serde(rename = "equipment")]
Equipment,

View File

@ -84,7 +84,7 @@ pub(crate) fn build() -> TokenStream {
let mut match_arms_tags_all = Vec::new();
let mut tag_identifiers = Vec::new();
for (key, tag_map) in &tags {
for (key, tag_map) in tags.into_iter() {
let key_pascal = format_ident!("{}", key.to_pascal_case());
let dict_name = format_ident!("{}_TAGS", key.to_pascal_case().to_uppercase());
@ -93,7 +93,7 @@ pub(crate) fn build() -> TokenStream {
// Collect all unique tags
for (tag_name, values) in tag_map {
tag_values.push((tag_name.clone(), values.clone()));
tag_values.push((tag_name, values));
}
tag_values.sort();
@ -103,7 +103,7 @@ pub(crate) fn build() -> TokenStream {
.iter()
.map(|(tag_name, values)| {
let tag_values_array = values.iter().map(|v| quote! { #v }).collect::<Vec<_>>();
let tag_id_array = match key {
let tag_id_array = match &key {
t if t == "worldgen/biome" => values.iter().map(|v| {
let id = biomes.get(v).unwrap().id as u16;
quote! { #id }
@ -128,7 +128,7 @@ pub(crate) fn build() -> TokenStream {
let id = entities.get(v).unwrap().id;
quote! { #id }
}).collect::<Vec<_>>(),
&_ => Vec::new(),
_ => Vec::new(),
};
let mapped_name = format_ident!("{}", tag_name.replace(":", "_").replace("/", "_").to_uppercase());
quote! {

View File

@ -20,7 +20,7 @@ use std::borrow::Cow;
use std::fmt::Debug;
use std::hash::Hash;
pub trait DataComponentImpl: Send + Sync + Debug {
pub trait DataComponentImpl: Send + Sync {
fn write_data(&self) -> NbtTag {
todo!()
}
@ -148,9 +148,9 @@ impl DataComponentImpl for DamageImpl {
}
default_impl!(Damage);
}
#[derive(Clone, Debug, Hash, PartialEq)]
#[derive(Clone, Hash, PartialEq)]
pub struct UnbreakableImpl;
#[derive(Clone, Debug, Hash, PartialEq)]
#[derive(Clone, Hash, PartialEq)]
pub struct CustomNameImpl {
// TODO make TextComponent const
pub name: &'static str,
@ -158,7 +158,7 @@ pub struct CustomNameImpl {
impl DataComponentImpl for CustomNameImpl {
default_impl!(CustomName);
}
#[derive(Clone, Debug, Hash, PartialEq)]
#[derive(Clone, Hash, PartialEq)]
pub struct ItemNameImpl {
// TODO make TextComponent const
pub name: &'static str,
@ -166,13 +166,13 @@ pub struct ItemNameImpl {
impl DataComponentImpl for ItemNameImpl {
default_impl!(ItemName);
}
#[derive(Clone, Debug, Hash, PartialEq)]
#[derive(Clone, Hash, PartialEq)]
pub struct ItemModelImpl;
#[derive(Clone, Debug, Hash, PartialEq)]
#[derive(Clone, Hash, PartialEq)]
pub struct LoreImpl;
#[derive(Clone, Debug, Hash, PartialEq)]
#[derive(Clone, Hash, PartialEq)]
pub struct RarityImpl;
#[derive(Clone, Debug, Hash, PartialEq)]
#[derive(Clone, Hash, PartialEq)]
pub struct EnchantmentsImpl {
pub enchantment: Cow<'static, [(&'static Enchantment, i32)]>,
}
@ -331,13 +331,13 @@ pub struct UseCooldownImpl;
#[derive(Clone, Debug, Hash, PartialEq)]
pub struct DamageResistantImpl;
#[derive(Clone, Debug, Hash, PartialEq)]
#[derive(Clone, Hash, PartialEq)]
pub enum IDSet {
Tag(&'static Tag),
Blocks(Cow<'static, [&'static Block]>),
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, PartialEq)]
pub struct ToolRule {
pub blocks: IDSet,
pub speed: Option<f32>,
@ -355,7 +355,7 @@ impl Hash for ToolRule {
self.correct_for_drops.hash(state);
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, PartialEq)]
pub struct ToolImpl {
pub rules: Cow<'static, [ToolRule]>,
pub default_mining_speed: f32,
@ -384,7 +384,7 @@ pub enum EquipmentType {
Saddle,
}
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
#[derive(Clone, Hash, Eq, PartialEq)]
pub struct EquipmentSlotData {
pub slot_type: EquipmentType,
pub entity_id: i32,
@ -393,7 +393,7 @@ pub struct EquipmentSlotData {
pub name: Cow<'static, str>,
}
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
#[derive(Clone, Hash, Eq, PartialEq)]
#[repr(i8)]
pub enum EquipmentSlot {
MainHand(EquipmentSlotData),
@ -529,7 +529,7 @@ impl EquipmentSlot {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, PartialEq)]
pub enum EntityTypeOrTag {
Tag(&'static Tag),
Single(&'static EntityType),
@ -552,7 +552,7 @@ impl Hash for EntityTypeOrTag {
#[derive(Clone, Debug, Hash, PartialEq)]
pub struct EnchantableImpl;
#[derive(Clone, Debug, Hash, PartialEq)]
#[derive(Clone, Hash, PartialEq)]
pub struct EquippableImpl {
pub slot: &'static EquipmentSlot,
pub equip_sound: &'static str,

View File

@ -8,7 +8,7 @@ use pumpkin_world::inventory::{Clearable, Inventory, InventoryFuture};
use super::recipes::RecipeInputInventory;
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct CraftingInventory {
pub width: u8,
pub height: u8,

View File

@ -26,7 +26,6 @@ use tokio::sync::Mutex;
/// Note: This implementation is different from the original Minecraft code.
/// Particularly, it does not have a 'result' inventory, we directly store it in the slot.
/// This slot should be never modified outside. any modifications to it make change in its input.
#[derive(Debug)]
pub struct ResultSlot {
pub inventory: Arc<dyn RecipeInputInventory>,
pub id: AtomicU8,

View File

@ -6,7 +6,6 @@ use pumpkin_world::{
};
use tokio::sync::Mutex;
#[derive(Debug)]
pub struct DoubleInventory {
first: Arc<dyn Inventory>,
second: Arc<dyn Inventory>,

View File

@ -5,7 +5,7 @@ use pumpkin_world::item::ItemStack;
use tokio::sync::Mutex;
// EntityEquipment.java
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct EntityEquipment {
pub equipment: HashMap<EquipmentSlot, Arc<Mutex<ItemStack>>>,
}

View File

@ -12,7 +12,6 @@ pub enum FurnaceSlotType {
Side = 2,
}
#[derive(Debug)]
pub struct FurnaceSlot {
pub inventory: Arc<dyn Inventory>,
pub slot_type: FurnaceSlotType,

View File

@ -7,7 +7,6 @@ use pumpkin_world::{
};
use tokio::sync::Mutex;
#[derive(Debug)]
pub struct EnderChestInventory {
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
pub tracker: Mutex<Option<Arc<ViewerCountTracker>>>,

View File

@ -15,7 +15,6 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicU8, Ordering};
use tokio::sync::Mutex;
#[derive(Debug)]
pub struct PlayerInventory {
pub main_inventory: [Arc<Mutex<ItemStack>>; Self::MAIN_SIZE],
pub equipment_slots: Arc<HashMap<usize, EquipmentSlot>>,

View File

@ -1,6 +1,4 @@
#![warn(unused)]
use std::{
fmt::Debug,
pin::Pin,
sync::{
Arc,
@ -21,7 +19,7 @@ pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
// Slot.java
// This is a trait due to crafting slots being a thing
pub trait Slot: Send + Sync + Debug {
pub trait Slot: Send + Sync {
fn get_inventory(&self) -> Arc<dyn Inventory>;
fn get_index(&self) -> usize;
@ -257,7 +255,6 @@ pub trait Slot: Send + Sync + Debug {
}
}
#[derive(Debug)]
/// Just called Slot in Vanilla
pub struct NormalSlot {
pub inventory: Arc<dyn Inventory>,
@ -295,7 +292,6 @@ impl Slot for NormalSlot {
}
// ArmorSlot.java
#[derive(Debug)]
pub struct ArmorSlot {
pub inventory: Arc<dyn Inventory>,
pub index: usize,

View File

@ -121,7 +121,7 @@ impl SyncHandler {
}
// TrackedSlot in vanilla
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct TrackedStack {
pub received_stack: Option<ItemStack>,
pub received_hash: Option<OptionalItemStackHash>,

View File

@ -22,7 +22,6 @@ pub(super) fn set_curr_visitor_seq_list_id(tag: Option<u8>) {
});
}
#[derive(Debug)]
pub struct NbtReadHelper<R: Read + Seek> {
reader: R,
}
@ -76,7 +75,6 @@ impl<R: Read + Seek> NbtReadHelper<R> {
}
}
#[derive(Debug)]
pub struct Deserializer<R: Read + Seek> {
input: NbtReadHelper<R>,
tag_to_deserialize_stack: Option<u8>,

View File

@ -11,7 +11,6 @@ use crate::{
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub struct WriteAdaptor<W: Write> {
writer: W,
}

View File

@ -10,7 +10,6 @@ use serde::{
};
use std::borrow::Cow;
#[derive(Debug, Clone)]
pub struct ItemStackSerializer<'a>(pub Cow<'a, ItemStack>);
impl<'de> Deserialize<'de> for ItemStackSerializer<'static> {

View File

@ -3,7 +3,7 @@ use pumpkin_macros::packet;
use crate::codec::item_stack_seralizer::ItemStackSerializer;
#[derive(serde::Deserialize, Debug)]
#[derive(serde::Deserialize)]
#[packet(PLAY_SET_CREATIVE_MODE_SLOT)]
pub struct SSetCreativeSlot {
pub slot: i16,

View File

@ -0,0 +1,31 @@
use crate::math::{position::BlockPos, vector3::Vector3};
#[derive(Clone, Copy, Debug)]
pub struct BlockBox {
pub min: Vector3<i32>,
pub max: Vector3<i32>,
}
impl BlockBox {
pub fn new(min_x: i32, min_y: i32, min_z: i32, max_x: i32, max_y: i32, max_z: i32) -> Self {
BlockBox {
min: Vector3 {
x: min_x,
y: min_y,
z: min_z,
},
max: Vector3 {
x: max_x,
y: max_y,
z: max_z,
},
}
}
pub fn from_pos(pos: BlockPos) -> Self {
Self {
min: pos.0,
max: pos.0,
}
}
}

View File

@ -1,5 +1,6 @@
use num_traits::{Float, One, PrimInt, Zero};
pub mod block_box;
pub mod boundingbox;
pub mod euler_angle;
pub mod experience;

View File

@ -29,7 +29,6 @@ use crate::{
use super::BlockEntity;
#[derive(Debug)]
pub struct BarrelBlockEntity {
pub position: BlockPos,
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],

View File

@ -29,7 +29,6 @@ use crate::{
use super::BlockEntity;
#[derive(Debug)]
pub struct ChestBlockEntity {
pub position: BlockPos,
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],

View File

@ -22,7 +22,6 @@ use crate::{
world::{BlockFlags, SimpleWorld},
};
#[derive(Debug)]
pub struct ChiseledBookshelfBlockEntity {
pub position: BlockPos,
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],

View File

@ -11,7 +11,6 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use tokio::sync::{Mutex, MutexGuard};
#[derive(Debug)]
pub struct DropperBlockEntity {
pub position: BlockPos,
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],

View File

@ -12,7 +12,6 @@ use crate::world::SimpleWorld;
use super::BlockEntity;
#[derive(Debug)]
pub struct EnderChestBlockEntity {
pub position: BlockPos,

View File

@ -26,7 +26,6 @@ use crate::{
use super::{BlockEntity, PropertyDelegate};
#[derive(Debug)]
pub struct FurnaceBlockEntity {
pub position: BlockPos,
pub dirty: AtomicBool,

View File

@ -17,7 +17,6 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicBool, AtomicI32, AtomicI64};
use tokio::sync::Mutex;
#[derive(Debug)]
pub struct HopperBlockEntity {
pub position: BlockPos,
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],

View File

@ -24,7 +24,6 @@ use crate::{
use super::BlockEntity;
#[derive(Debug)]
pub struct ShulkerBoxBlockEntity {
pub position: BlockPos,
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],

View File

@ -10,7 +10,7 @@ pub use state::RawBlockState;
use crate::BlockStateId;
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct BlockStateCodec {
/// Block name

View File

@ -40,9 +40,6 @@ const SECTOR_BYTES: usize = 4096;
// 1.21.10
pub const WORLD_DATA_VERSION: i32 = 4556;
#[derive(Clone, Default)]
pub struct AnvilChunkFormat;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum Compression {
@ -72,7 +69,6 @@ impl<R: Read> Read for CompressionRead<R> {
}
}
#[derive(Default, Clone)]
pub struct AnvilChunkData {
compression: Option<Compression>,
// Length is always the length of this + compression byte (1) so we dont need to save a length

View File

@ -20,7 +20,7 @@ use super::anvil::CHUNK_COUNT;
/// used as a header and footer described in https://gist.github.com/Aaron2550/5701519671253d4c6190bde6706f9f98
const SIGNATURE: [u8; 8] = u64::to_be_bytes(0xc3ff13183cca9d9a);
#[derive(Default, Clone, Copy)]
#[derive(Default, Copy, Clone)]
struct LinearChunkHeader {
size: u32,
timestamp: u32,

View File

@ -330,7 +330,7 @@ impl ChunkEntityData {
}
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize)]
struct ChunkSectionNBT {
#[serde(skip_serializing_if = "Option::is_none")]
block_states: Option<ChunkSectionBlockStates>,
@ -362,7 +362,7 @@ pub struct PaletteBiomeEntry {
pub name: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct ChunkSectionBlockStates {
#[serde(
serialize_with = "nbt_long_array",
@ -444,7 +444,7 @@ impl Default for LightContainer {
}
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
struct ChunkNbt {
data_version: i32,

View File

@ -95,7 +95,7 @@ pub struct ChunkEntityData {
///
/// A chunk can be:
/// - Subchunks: 24 separate subchunks are stored.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct ChunkSections {
pub sections: Box<[SubChunk]>,
pub min_y: i32,
@ -127,13 +127,13 @@ impl ChunkSections {
}
}
#[derive(Debug, Default, Clone)]
#[derive(Default, Clone)]
pub struct SubChunk {
pub block_states: BlockPalette,
pub biomes: BiomePalette,
}
#[derive(Debug, Default, Clone)]
#[derive(Default, Clone)]
pub struct ChunkLight {
pub sky_light: Box<[LightContainer]>,
pub block_light: Box<[LightContainer]>,

View File

@ -10,7 +10,7 @@ use super::format::{ChunkSectionBiomes, ChunkSectionBlockStates, PaletteBiomeEnt
/// 3d array indexed by y,z,x
type AbstractCube<T, const DIM: usize> = [[[T; DIM]; DIM]; DIM];
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct HeterogeneousPaletteData<V: Hash + Eq + Copy, const DIM: usize> {
cube: Box<AbstractCube<V, DIM>>,
palette: Vec<V>,
@ -59,7 +59,7 @@ impl<V: Hash + Eq + Copy, const DIM: usize> HeterogeneousPaletteData<V, DIM> {
/// A paletted container is a cube of registry ids. It uses a custom compression scheme based on how
/// may distinct registry ids are in the cube.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub enum PalettedContainer<V: Hash + Eq + Copy + Default, const DIM: usize> {
Homogeneous(V),
Heterogeneous(Box<HeterogeneousPaletteData<V, DIM>>),

View File

@ -2,7 +2,7 @@ use std::num::NonZeroU8;
use pumpkin_util::math::vector2::Vector2;
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Clone, Copy, PartialEq)]
pub struct Cylindrical {
pub center: Vector2<i32>,
pub view_distance: NonZeroU8,

View File

@ -20,8 +20,7 @@ impl AttachedToLogsTreeDecorator {
&self,
chunk: &mut T,
random: &mut RandomGenerator,
_root_positions: Vec<BlockPos>,
log_positions: Vec<BlockPos>,
log_positions: &[BlockPos],
) {
// TODO: shuffle
for pos in log_positions {

View File

@ -53,8 +53,8 @@ impl TreeDecorator {
&self,
chunk: &mut T,
random: &mut RandomGenerator,
root_positions: Vec<BlockPos>,
log_positions: Vec<BlockPos>,
root_positions: &[BlockPos],
log_positions: &[BlockPos],
) {
match self {
TreeDecorator::TrunkVine(decorator) => decorator.generate(chunk, random, log_positions),
@ -69,25 +69,25 @@ impl TreeDecorator {
}
TreeDecorator::AttachedToLeaves(_decorator) => {}
TreeDecorator::AttachedToLogs(decorator) => {
decorator.generate(chunk, random, root_positions, log_positions)
decorator.generate(chunk, random, log_positions)
}
}
}
pub(super) fn get_leaf_litter_positions(
root_positions: Vec<BlockPos>,
log_positions: Vec<BlockPos>,
root_positions: &[BlockPos],
log_positions: &[BlockPos],
) -> Vec<BlockPos> {
let mut list = Vec::new();
if root_positions.is_empty() {
list.extend_from_slice(&log_positions);
list.extend_from_slice(log_positions);
} else if !log_positions.is_empty()
&& root_positions.first().unwrap().0.y == log_positions.first().unwrap().0.y
{
list.extend_from_slice(&log_positions);
list.extend_from_slice(&root_positions);
list.extend_from_slice(log_positions);
list.extend_from_slice(root_positions);
} else {
list.extend_from_slice(&root_positions);
list.extend_from_slice(root_positions);
}
list

View File

@ -22,8 +22,8 @@ impl PlaceOnGroundTreeDecorator {
&self,
chunk: &mut T,
random: &mut RandomGenerator,
root_positions: Vec<BlockPos>,
log_positions: Vec<BlockPos>,
root_positions: &[BlockPos],
log_positions: &[BlockPos],
) {
let list = TreeDecorator::get_leaf_litter_positions(root_positions, log_positions);

View File

@ -17,7 +17,7 @@ impl TrunkVineTreeDecorator {
&self,
chunk: &mut T,
random: &mut RandomGenerator,
log_positions: Vec<BlockPos>,
log_positions: &[BlockPos],
) {
for pos in log_positions {
if random.next_bounded_i32(3) > 0

View File

@ -46,7 +46,7 @@ impl TreeFeature {
let log_positions = self.generate_main(chunk, min_y, height, feature_name, random, pos);
for decorator in &self.decorators {
decorator.generate(chunk, random, Vec::new(), log_positions.clone());
decorator.generate(chunk, random, &[], &log_positions);
}
true
}

View File

@ -1,5 +1,3 @@
use std::fmt::Debug;
use enum_dispatch::enum_dispatch;
use pumpkin_data::noise_router::WrapperType;
@ -20,13 +18,12 @@ mod test;
#[cfg(test)]
mod test_deserializer;
pub trait NoisePos: Debug {
pub trait NoisePos {
fn x(&self) -> i32;
fn y(&self) -> i32;
fn z(&self) -> i32;
}
#[derive(Debug)]
pub struct UnblendedNoisePos {
x: i32,
y: i32,

View File

@ -6,6 +6,7 @@ use pumpkin_data::tag;
use pumpkin_data::{
Block, BlockState, block_properties::blocks_movement, chunk::Biome, tag::Taggable,
};
use pumpkin_util::math::block_box::BlockBox;
use pumpkin_util::{
HeightMap,
math::{position::BlockPos, vector2::Vector2, vector3::Vector3},
@ -918,6 +919,7 @@ impl ProtoChunk {
let population_seed =
Xoroshiro::get_population_seed(random_config.seed, block_pos.0.x, block_pos.0.z);
let _chunk_box = chunk.get_block_box_for_chunk();
for (_structure, (pos, stype)) in chunk.structure_starts.clone() {
dbg!("generating structure");
stype.generate(pos.clone(), chunk);
@ -973,6 +975,15 @@ impl ProtoChunk {
}
}
fn get_block_box_for_chunk(&self) -> BlockBox {
let pos = self.chunk_pos;
let x = start_block_x(&pos);
let z = start_block_z(&pos);
let bottom = self.bottom_y() as i32 + 1;
let top = self.top_y() as i32;
BlockBox::new(x, bottom, z, x + 15, top, z + 15)
}
fn start_cell_x(&self, horizontal_cell_block_count: u8) -> i32 {
self.start_block_x() / horizontal_cell_block_count as i32
}

View File

@ -1,7 +1,7 @@
use pumpkin_data::{Block, BlockDirection};
use pumpkin_util::{
HeightMap,
math::{position::BlockPos, vector2::Vector2, vector3::Vector3},
math::{block_box::BlockBox, position::BlockPos, vector2::Vector2, vector3::Vector3},
};
use serde::Deserialize;
@ -22,11 +22,11 @@ impl StructureGenerator for BuriedTreasureGenerator {
let z = get_center_z(chunk.chunk_pos.y);
let y = chunk.get_top_y(&HeightMap::OceanFloorWg, &Vector2::new(x, z)) - 1;
let generator = StructurePiecesCollector {
pieces_positions: vec![BlockPos::new(
pieces_positions: vec![BlockBox::from_pos(BlockPos::new(
get_offset_x(chunk.chunk_pos.x, 9),
90,
get_offset_z(chunk.chunk_pos.y, 9),
)],
))],
};
StructurePosition {
position: BlockPos(Vector3::new(x, y, z)),
@ -34,12 +34,12 @@ impl StructureGenerator for BuriedTreasureGenerator {
}
}
fn generate(&self, position: BlockPos, chunk: &mut crate::ProtoChunk) {
fn generate(&self, bounding_box: BlockBox, chunk: &mut crate::ProtoChunk) {
let y = chunk.get_top_y(
&HeightMap::OceanFloorWg,
&Vector2::new(position.0.x, position.0.z),
&Vector2::new(bounding_box.min.x, bounding_box.min.z),
);
let mut pos = BlockPos::new(position.0.x, y, position.0.z);
let mut pos = BlockPos::new(bounding_box.min.x, y, bounding_box.min.z);
for _ in y..chunk.bottom_y() as i32 {
let state = chunk.get_block_state(&pos.0);
let down_raw_state = chunk.get_block_state(&pos.down().0);

View File

@ -1,15 +1,16 @@
use pumpkin_data::BlockState;
use pumpkin_util::math::{position::BlockPos, vector3::Vector3};
use pumpkin_util::math::{block_box::BlockBox, position::BlockPos, vector3::Vector3};
use crate::ProtoChunk;
pub mod buried_treasure;
pub mod nether_fortress;
pub mod swamp_hut;
pub trait StructureGenerator {
fn get_structure_position(&self, chunk: &ProtoChunk) -> StructurePosition;
fn generate(&self, position: BlockPos, chunk: &mut crate::ProtoChunk);
fn generate(&self, position: BlockBox, chunk: &mut crate::ProtoChunk);
}
#[expect(clippy::too_many_arguments)]
@ -72,5 +73,5 @@ pub struct StructurePosition {
#[derive(Default, Clone, Debug)]
pub struct StructurePiecesCollector {
pub pieces_positions: Vec<BlockPos>,
pub pieces_positions: Vec<BlockBox>,
}

View File

@ -1,5 +1,5 @@
use pumpkin_data::Block;
use pumpkin_util::math::{position::BlockPos, vector3::Vector3};
use pumpkin_util::math::{block_box::BlockBox, position::BlockPos, vector3::Vector3};
use serde::Deserialize;
use crate::{
@ -29,7 +29,7 @@ impl StructureGenerator for NetherFortressGenerator {
generator,
}
}
fn generate(&self, position: BlockPos, chunk: &mut crate::ProtoChunk) {
fn generate(&self, position: BlockBox, chunk: &mut crate::ProtoChunk) {
BridgePlatform::generate(&BridgePlatform, position, chunk);
}
}
@ -37,7 +37,7 @@ impl StructureGenerator for NetherFortressGenerator {
pub struct BridgePlatform;
impl BridgePlatform {
fn generate(&self, _position: BlockPos, chunk: &mut crate::ProtoChunk) {
fn generate(&self, _box: BlockBox, chunk: &mut crate::ProtoChunk) {
super::fill(0, 2, 0, 6, 7, 7, Block::AIR.default_state, chunk);
super::fill(1, 0, 0, 5, 1, 7, Block::NETHER_BRICKS.default_state, chunk);
super::fill(1, 2, 1, 5, 2, 7, Block::NETHER_BRICKS.default_state, chunk);

View File

@ -0,0 +1,17 @@
use pumpkin_util::math::block_box::BlockBox;
use serde::Deserialize;
use crate::{ProtoChunk, generation::structure::structures::StructureGenerator};
#[derive(Deserialize, Clone, Debug)]
pub struct SwampHutGenerator;
impl StructureGenerator for SwampHutGenerator {
fn get_structure_position(&self, _chunk: &ProtoChunk) -> super::StructurePosition {
todo!()
}
fn generate(&self, _position: BlockBox, _chunk: &mut crate::ProtoChunk) {
todo!()
}
}

View File

@ -4,7 +4,6 @@ use pumpkin_nbt::{compound::NbtCompound, tag::NbtTag};
use std::any::Any;
use std::pin::Pin;
use std::{
fmt::Debug,
hash::{Hash, Hasher},
sync::Arc,
};
@ -12,7 +11,7 @@ use tokio::sync::{Mutex, OwnedMutexGuard};
pub type InventoryFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub trait Inventory: Send + Sync + Debug + Clearable {
pub trait Inventory: Send + Sync + Clearable {
fn size(&self) -> usize;
// --- Asynchronous Methods (Using BlockFuture) ---

View File

@ -15,7 +15,7 @@ use std::cmp::{max, min};
mod categories;
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct ItemStack {
pub item_count: u8,
pub item: &'static Item,

View File

@ -52,7 +52,7 @@ impl From<i32> for TickPriority {
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct ScheduledTick<T> {
pub delay: u8,
pub priority: TickPriority,
@ -60,7 +60,7 @@ pub struct ScheduledTick<T> {
pub value: T,
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct OrderedTick<T> {
pub priority: TickPriority,
pub sub_tick_order: u64,

View File

@ -4,7 +4,7 @@ use pumpkin_util::math::position::BlockPos;
use crate::tick::{MAX_TICK_DELAY, OrderedTick, ScheduledTick};
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct ChunkTickScheduler<T> {
tick_queue: [Vec<OrderedTick<T>>; MAX_TICK_DELAY],
queued_ticks: HashSet<(BlockPos, T)>,

View File

@ -43,7 +43,7 @@ impl FireBlock {
.to_props()
.into_iter()
.find(|p| p.0 == "waterlogged")
.map(|(_, v)| v == true.to_string())
.map(|(_, v)| v == "true")
})
.unwrap_or(false)
{
@ -415,7 +415,7 @@ impl BlockBehaviour for FireBlock {
fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> {
Box::pin(async move {
FireBlockBase::broken(args.world.clone(), *args.position).await;
FireBlockBase::broken(args.world, *args.position).await;
})
}
}

View File

@ -115,7 +115,7 @@ impl FireBlockBase {
.is_some();
}
async fn broken(world: Arc<World>, block_pos: BlockPos) {
async fn broken(world: &World, block_pos: BlockPos) {
world
.sync_world_event(WorldEvent::FireExtinguished, block_pos, 0)
.await;

View File

@ -41,7 +41,7 @@ impl BlockBehaviour for SoulFireBlock {
fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> {
Box::pin(async move {
FireBlockBase::broken(args.world.clone(), *args.position).await;
FireBlockBase::broken(args.world, *args.position).await;
})
}
}

View File

@ -69,7 +69,8 @@ impl<'a> PistonHandler<'a> {
}
for block_pos in self.moved_blocks.clone() {
let block = self.world.get_block(&block_pos).await;
if Self::is_block_sticky(block) && !self.try_move_adjacent_block(block, block_pos).await
if Self::is_block_sticky(block)
&& !self.try_move_adjacent_block(block, &block_pos).await
{
return false;
}
@ -146,7 +147,7 @@ impl<'a> PistonHandler<'a> {
let block_pos3 = self.moved_blocks[m];
let block = self.world.get_block(&block_pos3).await;
if Self::is_block_sticky(block)
&& !Box::pin(self.try_move_adjacent_block(block, block_pos3)).await
&& !Box::pin(self.try_move_adjacent_block(block, &block_pos3)).await
{
return false;
}
@ -193,7 +194,7 @@ impl<'a> PistonHandler<'a> {
self.moved_blocks.extend(list3);
}
async fn try_move_adjacent_block(&mut self, block: &Block, pos: BlockPos) -> bool {
async fn try_move_adjacent_block(&mut self, block: &Block, pos: &BlockPos) -> bool {
for direction in BlockDirection::all() {
if direction.to_axis() == self.motion_direction.to_axis() {
continue;

View File

@ -39,7 +39,7 @@ impl ArgumentConsumer for MsgArgConsumer {
let mut msg = match first_word_opt {
Some(word) => word.to_string(),
None => return Box::pin(async move { None }),
None => return Box::pin(async { None }),
};
while let Some(word) = args.pop() {

View File

@ -52,7 +52,6 @@ pub async fn send_c_commands_packet(player: &Arc<Player>, dispatcher: &CommandDi
player.client.enqueue_packet(&packet).await;
}
#[derive(Debug)]
struct ProtoNodeBuilder<'a> {
child_nodes: Vec<Self>,
node_type: ProtoNodeType<'a>,

View File

@ -403,9 +403,9 @@ impl CommandDispatcher {
}
/// Register a command with the dispatcher.
pub fn register(&mut self, tree: CommandTree, permission: &str) {
pub fn register<P: Into<String>>(&mut self, tree: CommandTree, permission: P) {
let mut names = tree.names.iter();
let permission = permission.to_string();
let permission = permission.into();
let primary_name = names.next().expect("at least one name must be provided");

View File

@ -3,7 +3,6 @@ use crate::entity::{ai::goal::GoalFuture, mob::Mob};
use rand::Rng;
#[allow(dead_code)]
#[derive(Default)]
pub struct AmbientStandGoal {
goal_control: Controls,
cooldown: i32,

View File

@ -66,7 +66,7 @@ pub trait Goal: Send + Sync {
}
}
#[derive(Default, Clone, Copy)]
#[derive(Clone, Copy, Default)]
// We actually only use the first 4 bits ;)
pub struct Controls(u8);

View File

@ -2198,7 +2198,7 @@ impl NBTStorage for PlayerInventory {
equipment_compound.put_component("head", item_compound);
}
_ => {
warn!("Invalid equipment slot for a player {slot:?}");
warn!("Invalid equipment slot for a player");
}
}
}

View File

@ -94,11 +94,15 @@ impl Context {
/// # Example
///
/// ```
/// context.register_service("my_service".to_string(), Arc::new(MyService::new())).await;
/// context.register_service("my_service", Arc::new(MyService::new())).await;
/// ```
pub async fn register_service<T: Payload + 'static>(&self, name: String, service: Arc<T>) {
pub async fn register_service<N: Into<String>, T: Payload + 'static>(
&self,
name: N,
service: Arc<T>,
) {
let mut services = self.plugin_manager.services.write().await;
services.insert(name, service);
services.insert(name.into(), service);
}
/// Retrieves a registered service by name and type.
@ -136,21 +140,23 @@ impl Context {
/// # Arguments
/// - `tree`: The command tree to register.
/// - `permission`: The permission level required to execute the command.
pub async fn register_command(
pub async fn register_command<P: Into<String>>(
&self,
tree: crate::command::tree::CommandTree,
permission_node: &str,
permission: P,
) {
let plugin_name = self.metadata.name;
let full_permission_node = if permission_node.contains(':') {
permission_node.to_string()
let permission = permission.into();
let full_permission_node = if permission.contains(':') {
permission
} else {
format!("{plugin_name}:{permission_node}")
format!("{plugin_name}:{permission}")
};
{
let mut dispatcher_lock = self.server.command_dispatcher.write().await;
dispatcher_lock.register(tree, full_permission_node.as_str());
dispatcher_lock.register(tree, full_permission_node);
};
for world in self.server.worlds.read().await.iter() {

View File

@ -6,7 +6,6 @@ use crate::plugin::loader::{PluginLoadFuture, PluginUnloadFuture};
use super::{LoaderError, Path, Plugin, PluginLoader, PluginMetadata};
#[derive(Debug)]
pub struct NativePluginLoader;
impl PluginLoader for NativePluginLoader {

View File

@ -817,7 +817,7 @@ impl Server {
} else if target_selector.get_limit() == 1 {
// If the limit is 1, we just return a random entity
return if let Some(entity) = iter.choose(&mut rand::rng()) {
vec![entity.clone()]
vec![entity]
} else {
vec![]
};

View File

@ -9,7 +9,6 @@ use crate::entity::player::Player;
use crate::server::Server;
const NANOSECONDS_PER_SECOND: i64 = 1_000_000_000;
#[derive(Debug)]
pub struct ServerTickRateManager {
tickrate: AtomicCell<f32>,
nanoseconds_per_tick: AtomicI64,

View File

@ -81,9 +81,8 @@ impl CustomBossbars {
);
}
pub fn replace_bossbar(&mut self, resource_location: &str, bossbar_data: CustomBossbar) {
self.custom_bossbars
.insert(resource_location.to_string(), bossbar_data);
pub fn replace_bossbar(&mut self, resource_location: String, bossbar_data: CustomBossbar) {
self.custom_bossbars.insert(resource_location, bossbar_data);
}
#[must_use]

View File

@ -219,7 +219,7 @@ impl World {
level_info,
players: Arc::new(RwLock::new(HashMap::new())),
entities: Arc::new(RwLock::new(HashMap::new())),
scoreboard: Mutex::new(Scoreboard::new()),
scoreboard: Mutex::new(Scoreboard::default()),
worldborder: Mutex::new(Worldborder::new(0.0, 0.0, 30_000_000.0, 0, 0, 0)),
level_time: Mutex::new(LevelTime::new()),
dimension_type,
@ -594,6 +594,7 @@ impl World {
// Entity ticks
for entity in entities_to_tick {
entity.get_entity().age.fetch_add(1, Relaxed);
entity.tick(entity.clone(), server).await;
for player in self.players.read().await.values() {
if player
@ -767,7 +768,6 @@ impl World {
);
// log::debug!("spawning list size {}", spawn_list.len());
log::trace!("spawning counter {:?}", spawn_state.mob_category_counts);
spawning_chunks.shuffle(&mut rng());

View File

@ -17,13 +17,6 @@ pub struct Scoreboard {
}
impl Scoreboard {
#[must_use]
pub fn new() -> Self {
Self {
objectives: HashMap::new(),
}
}
pub async fn add_objective(&mut self, world: &World, objective: ScoreboardObjective<'_>) {
if self.objectives.contains_key(objective.name) {
// Maybe make this an error?