smaller structure gen preparations
This commit is contained in:
parent
e727f06e5a
commit
92fe87e921
@ -172,7 +172,7 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
let mut name_to_type = TokenStream::new();
|
let mut name_to_type = TokenStream::new();
|
||||||
let mut id_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 full_name = format!("minecraft:{name}");
|
||||||
let format_name = format_ident!("{}", name.to_shouty_snake_case());
|
let format_name = format_ident!("{}", name.to_shouty_snake_case());
|
||||||
let has_precipitation = biome.has_precipitation;
|
let has_precipitation = biome.has_precipitation;
|
||||||
@ -184,7 +184,6 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
|
|
||||||
let temperature_modifier = biome
|
let temperature_modifier = biome
|
||||||
.temperature_modifier
|
.temperature_modifier
|
||||||
.clone()
|
|
||||||
.unwrap_or(TemperatureModifier::None);
|
.unwrap_or(TemperatureModifier::None);
|
||||||
|
|
||||||
let monster: Vec<_> = biome
|
let monster: Vec<_> = biome
|
||||||
|
|||||||
@ -331,7 +331,7 @@ impl ToTokens for BlockPropertyStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct FlammableStruct {
|
pub struct FlammableStruct {
|
||||||
pub spread_chance: u8,
|
pub spread_chance: u8,
|
||||||
pub burn_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 struct CollisionShape {
|
||||||
pub min: Vector3<f64>,
|
pub min: Vector3<f64>,
|
||||||
pub max: 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 struct BlockState {
|
||||||
pub id: u16,
|
pub id: u16,
|
||||||
pub state_flags: u16,
|
pub state_flags: u16,
|
||||||
@ -473,7 +473,7 @@ impl BlockState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct Block {
|
pub struct Block {
|
||||||
pub id: u16,
|
pub id: u16,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@ -492,7 +492,7 @@ pub struct Block {
|
|||||||
pub experience: Option<Experience>,
|
pub experience: Option<Experience>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Block {
|
impl ToTokens for Block {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||||
let id = LitInt::new(&self.id.to_string(), Span::call_site());
|
let id = LitInt::new(&self.id.to_string(), Span::call_site());
|
||||||
let name = LitStr::new(&self.name, Span::call_site());
|
let name = LitStr::new(&self.name, Span::call_site());
|
||||||
@ -567,7 +567,7 @@ pub enum GeneratedPropertyType {
|
|||||||
Enum { values: Vec<String> },
|
Enum { values: Vec<String> },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct GeneratedProperty {
|
pub struct GeneratedProperty {
|
||||||
hash_key: i32,
|
hash_key: i32,
|
||||||
enum_name: String,
|
enum_name: String,
|
||||||
@ -607,14 +607,14 @@ impl GeneratedProperty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
struct Property {
|
struct Property {
|
||||||
enum_name: String,
|
enum_name: String,
|
||||||
serialized_name: String,
|
serialized_name: String,
|
||||||
values: Vec<String>,
|
values: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct BlockAssets {
|
pub struct BlockAssets {
|
||||||
pub blocks: Vec<Block>,
|
pub blocks: Vec<Block>,
|
||||||
pub shapes: Vec<CollisionShape>,
|
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/bedrock_block_states.nbt");
|
||||||
println!("cargo:rerun-if-changed=../assets/properties.json");
|
println!("cargo:rerun-if-changed=../assets/properties.json");
|
||||||
|
|
||||||
let be_blocks = fs::read("../assets/bedrock_block_states.nbt").unwrap();
|
let be_blocks_data = fs::read("../assets/bedrock_block_states.nbt").unwrap();
|
||||||
let mut be_blocks = Cursor::new(be_blocks);
|
let mut be_blocks_cursor = Cursor::new(be_blocks_data);
|
||||||
let be_blocks = get_be_data_from_nbt(&mut be_blocks);
|
let be_blocks = get_be_data_from_nbt(&mut be_blocks_cursor);
|
||||||
|
|
||||||
let blocks_assets: BlockAssets =
|
let blocks_assets: BlockAssets =
|
||||||
serde_json::from_str(&fs::read_to_string("../assets/blocks.json").unwrap())
|
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())
|
serde_json::from_str(&fs::read_to_string("../assets/properties.json").unwrap())
|
||||||
.expect("Failed to parse properties.json");
|
.expect("Failed to parse properties.json");
|
||||||
|
|
||||||
let mut type_from_raw_id_items = TokenStream::new();
|
let generated_prop_map: std::collections::HashMap<i32, &GeneratedProperty> =
|
||||||
let mut block_from_name = TokenStream::new();
|
generated_properties
|
||||||
let mut raw_id_from_state_id = TokenStream::new();
|
.iter()
|
||||||
let mut block_from_item_id = TokenStream::new();
|
.map(|p| (p.hash_key, p))
|
||||||
let mut state_from_state_id = TokenStream::new();
|
.collect();
|
||||||
|
|
||||||
let mut random_tick_states = Vec::new();
|
let mut random_tick_states = Vec::new();
|
||||||
let mut block_properties_from_state_and_block_id = TokenStream::new();
|
let mut constants_list = Vec::new();
|
||||||
let mut block_properties_from_props_and_name = TokenStream::new();
|
let mut block_from_name_entries = Vec::new();
|
||||||
let mut existing_item_ids: Vec<u16> = Vec::new();
|
let mut block_from_item_id_arms = Vec::new();
|
||||||
let mut constants = TokenStream::new();
|
|
||||||
let mut block_state_to_bedrock = Vec::new();
|
let mut block_state_to_bedrock = Vec::new();
|
||||||
|
|
||||||
// Used to create property `enum`s.
|
let mut raw_id_from_state_id_array = Vec::new();
|
||||||
let mut property_enums: BTreeMap<String, PropertyStruct> = BTreeMap::new();
|
let mut type_from_raw_id_array = Vec::new();
|
||||||
// Property implementation for a block.
|
let mut state_from_state_id_array = Vec::<(Ident, usize, u16)>::new();
|
||||||
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());
|
|
||||||
|
|
||||||
// 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 {
|
for state in &block.states {
|
||||||
if state.has_random_ticks() {
|
if state.has_random_ticks() {
|
||||||
let state_id = LitInt::new(&state.id.to_string(), Span::call_site());
|
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_collection = HashSet::new();
|
||||||
let mut property_mapping = Vec::new();
|
let mut property_mapping = Vec::new();
|
||||||
for property in block.properties {
|
|
||||||
let generated_property = generated_properties
|
for property_hash in &block.properties {
|
||||||
.iter()
|
let generated_property = generated_prop_map
|
||||||
.find(|p| p.hash_key == property)
|
.get(property_hash)
|
||||||
.unwrap();
|
.expect("Property hash not found in generated_properties");
|
||||||
|
|
||||||
property_collection.insert(generated_property.hash_key);
|
property_collection.insert(generated_property.hash_key);
|
||||||
|
|
||||||
let property = generated_property.to_property();
|
let property = generated_property.to_property();
|
||||||
let renamed_property = property.enum_name.to_upper_camel_case();
|
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
|
PropertyType::Bool
|
||||||
} else {
|
} else {
|
||||||
@ -690,7 +692,7 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let PropertyType::Enum { name } = &property_type {
|
if let PropertyType::Enum { name } = &property_type {
|
||||||
let _ = property_enums
|
property_enums
|
||||||
.entry(name.clone())
|
.entry(name.clone())
|
||||||
.or_insert_with(|| PropertyStruct {
|
.or_insert_with(|| PropertyStruct {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
@ -699,97 +701,34 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
property_mapping.push(PropertyVariantMapping {
|
property_mapping.push(PropertyVariantMapping {
|
||||||
original_name: property.serialized_name.clone(),
|
original_name: property.serialized_name,
|
||||||
property_type,
|
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() {
|
if !property_collection.is_empty() {
|
||||||
let mut property_collection = Vec::from_iter(property_collection);
|
let mut property_collection_vec: Vec<i32> = property_collection.into_iter().collect();
|
||||||
property_collection.sort();
|
property_collection_vec.sort_unstable();
|
||||||
|
|
||||||
property_collection_map
|
property_collection_map
|
||||||
.entry(property_collection)
|
.entry(property_collection_vec)
|
||||||
.or_insert_with(|| PropertyCollectionData::from_mappings(property_mapping))
|
.or_insert_with(|| PropertyCollectionData::from_mappings(property_mapping))
|
||||||
.add_block(block.name.clone(), block.id);
|
.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 const_ident = format_ident!("{}", const_block_name_from_block_name(&block.name));
|
||||||
let name = &block.name;
|
let name_str = &block.name;
|
||||||
let mut block_tokens = TokenStream::new();
|
|
||||||
block.to_tokens(&mut block_tokens);
|
|
||||||
let id_lit = LitInt::new(&block.id.to_string(), Span::call_site());
|
let id_lit = LitInt::new(&block.id.to_string(), Span::call_site());
|
||||||
|
|
||||||
let item_id = block.item_id;
|
let item_id = block.item_id;
|
||||||
|
|
||||||
constants.extend(quote! {
|
constants_list.push(quote! {
|
||||||
pub const #const_ident: Block = #block_tokens;
|
pub const #const_ident: Block = #block;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
type_from_raw_id_array.push((block.id, quote! { &Self::#const_ident }));
|
type_from_raw_id_array.push((block.id, quote! { &Self::#const_ident }));
|
||||||
|
|
||||||
block_from_name.extend(quote! {
|
block_from_name_entries.push(quote! {
|
||||||
#name => Self::#const_ident,
|
#name_str => Self::#const_ident,
|
||||||
});
|
});
|
||||||
|
|
||||||
let be_name = match block.name.as_str() {
|
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() {
|
for (i, state) in block.states.iter().enumerate() {
|
||||||
if state_count != 0 {
|
if state_count != 0 {
|
||||||
if state_count > i as u32 {
|
let bedrock_val = if state_count > i as u32 {
|
||||||
let start_id = id as u16 + i as u16;
|
id as u16 + i as u16
|
||||||
block_state_to_bedrock.push((state.id, start_id))
|
|
||||||
} else {
|
} 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()));
|
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() {
|
if existing_item_ids.insert(item_id) {
|
||||||
state_from_state_id_array.push((const_ident.clone(), index, state.id));
|
block_from_item_id_arms.push(quote! {
|
||||||
}
|
|
||||||
|
|
||||||
if !existing_item_ids.contains(&item_id) {
|
|
||||||
block_from_item_id.extend(quote! {
|
|
||||||
#item_id => Some(&Self::#const_ident),
|
#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 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();
|
let max_state_id = raw_id_from_state_id_ordered.len();
|
||||||
for id_lit in raw_id_from_state_id_ordered {
|
let raw_id_from_state_id = quote! { #(#raw_id_from_state_id_ordered),* };
|
||||||
raw_id_from_state_id.extend(quote! {
|
|
||||||
#id_lit,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let max_index = block_state_to_bedrock
|
let max_index = block_state_to_bedrock
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(index, _)| index)
|
.map(|(idx, _)| *idx)
|
||||||
.max()
|
.max()
|
||||||
.unwrap();
|
.unwrap_or(0);
|
||||||
let mut state_to_bedrock_id = vec![quote! { 1 }; (max_index + 1) as usize];
|
let mut state_to_bedrock_tokens = vec![quote! { 1 }; (max_index + 1) as usize];
|
||||||
let mut block_state_to_bedrock_t = TokenStream::new();
|
|
||||||
|
|
||||||
for (state_id, id_lit) in block_state_to_bedrock {
|
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 {
|
let type_from_raw_id_vec = fill_array(type_from_raw_id_array);
|
||||||
block_state_to_bedrock_t.extend(quote! {
|
let max_type_id = type_from_raw_id_vec.len();
|
||||||
#id_lit,
|
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 state_from_state_id_vec = fill_state_array(state_from_state_id_array);
|
||||||
let max_type_id = type_from_raw_id_array.len();
|
let max_state_id_2 = state_from_state_id_vec.len();
|
||||||
for type_lit in type_from_raw_id_array {
|
let state_from_state_id = quote! { #(#state_from_state_id_vec),* };
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
assert_eq!(max_state_id, max_state_id_2);
|
assert_eq!(max_state_id, max_state_id_2);
|
||||||
|
|
||||||
@ -888,7 +849,6 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use phf;
|
use phf;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct BlockProperty {
|
pub struct BlockProperty {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
@ -896,25 +856,13 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait BlockProperties where Self: 'static {
|
pub trait BlockProperties where Self: 'static {
|
||||||
// Convert properties to an index (`0` to `N-1`).
|
|
||||||
fn to_index(&self) -> u16;
|
fn to_index(&self) -> u16;
|
||||||
// Convert an index back to properties.
|
|
||||||
fn from_index(index: u16) -> Self where Self: Sized;
|
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;
|
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;
|
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;
|
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;
|
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)>;
|
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;
|
fn from_props(props: &[(&str, &str)], block: &Block) -> Self where Self: Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -930,10 +878,6 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
#(#shapes),*
|
#(#shapes),*
|
||||||
];
|
];
|
||||||
|
|
||||||
//pub const BLOCK_STATES: &[BlockState] = &[
|
|
||||||
// #(#unique_states_tokens),*
|
|
||||||
//];
|
|
||||||
|
|
||||||
pub const BLOCK_ENTITY_TYPES: &[&str] = &[
|
pub const BLOCK_ENTITY_TYPES: &[&str] = &[
|
||||||
#(#block_entity_types),*
|
#(#block_entity_types),*
|
||||||
];
|
];
|
||||||
@ -976,14 +920,12 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Block {
|
impl Block {
|
||||||
#constants
|
#(#constants_list)*
|
||||||
|
|
||||||
// String name to block struct
|
|
||||||
const BLOCK_FROM_NAME_MAP: phf::Map<&'static str, Block> = phf::phf_map!{
|
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] = [
|
const RAW_ID_FROM_STATE_ID: [u16; #max_state_id] = [
|
||||||
#raw_id_from_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> {
|
pub const fn from_item_id(id: u16) -> Option<&'static Self> {
|
||||||
#[allow(unreachable_patterns)]
|
#[allow(unreachable_patterns)]
|
||||||
match id {
|
match id {
|
||||||
#block_from_item_id
|
#(#block_from_item_id_arms)*
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1050,7 +992,7 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
#[doc = r" Get the properties of the block."]
|
#[doc = r" Get the properties of the block."]
|
||||||
pub fn properties(&self, state_id: u16) -> Option<Box<dyn BlockProperties>> {
|
pub fn properties(&self, state_id: u16) -> Option<Box<dyn BlockProperties>> {
|
||||||
Some(match self.id {
|
Some(match self.id {
|
||||||
#block_properties_from_state_and_block_id
|
#(#block_properties_from_state_and_block_id_arms)*
|
||||||
_ => return None,
|
_ => return None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1059,7 +1001,7 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
#[doc = r" Get the properties of the block."]
|
#[doc = r" Get the properties of the block."]
|
||||||
pub fn from_properties(&self, props: &[(&str, &str)]) -> Box<dyn BlockProperties> {
|
pub fn from_properties(&self, props: &[(&str, &str)]) -> Box<dyn BlockProperties> {
|
||||||
match self.id {
|
match self.id {
|
||||||
#block_properties_from_props_and_name
|
#(#block_properties_from_props_and_name_arms)*
|
||||||
_ => panic!("Invalid props")
|
_ => panic!("Invalid props")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use proc_macro2::TokenStream;
|
|||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize)]
|
||||||
struct Effect {
|
struct Effect {
|
||||||
id: u8,
|
id: u8,
|
||||||
category: MobEffectCategory,
|
category: MobEffectCategory,
|
||||||
@ -15,14 +15,14 @@ struct Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::upper_case_acronyms)]
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize)]
|
||||||
pub enum MobEffectCategory {
|
pub enum MobEffectCategory {
|
||||||
BENEFICIAL,
|
BENEFICIAL,
|
||||||
HARMFUL,
|
HARMFUL,
|
||||||
NEUTRAL,
|
NEUTRAL,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize)]
|
||||||
pub struct Modifiers {
|
pub struct Modifiers {
|
||||||
attribute: String,
|
attribute: String,
|
||||||
id: String,
|
id: String,
|
||||||
@ -32,9 +32,9 @@ pub struct Modifiers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Modifiers {
|
impl Modifiers {
|
||||||
pub fn to_tokens(&self) -> TokenStream {
|
pub fn get_tokens(self) -> TokenStream {
|
||||||
let attribute = format_ident!("{}", self.attribute.to_uppercase());
|
let attribute = format_ident!("{}", self.attribute.to_uppercase());
|
||||||
let id = self.id.clone();
|
let id = self.id;
|
||||||
let base_value = self.base_value;
|
let base_value = self.base_value;
|
||||||
let operation = format_ident!("{}", self.operation.to_pascal_case());
|
let operation = format_ident!("{}", self.operation.to_pascal_case());
|
||||||
quote! {
|
quote! {
|
||||||
@ -76,7 +76,7 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
let translation_key = effect.translation_key;
|
let translation_key = effect.translation_key;
|
||||||
let category = effect.category.to_tokens();
|
let category = effect.category.to_tokens();
|
||||||
let slots = effect.attribute_modifiers;
|
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;
|
let minecraft_name = "minecraft:".to_string() + &name;
|
||||||
variants.extend([quote! {
|
variants.extend([quote! {
|
||||||
@ -100,7 +100,6 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
use crate::attributes::Attributes;
|
use crate::attributes::Attributes;
|
||||||
use crate::data_component_impl::Operation;
|
use crate::data_component_impl::Operation;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct StatusEffect {
|
pub struct StatusEffect {
|
||||||
pub minecraft_name: &'static str,
|
pub minecraft_name: &'static str,
|
||||||
pub id: u8,
|
pub id: u8,
|
||||||
|
|||||||
@ -140,7 +140,6 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::slice::Iter;
|
use std::slice::Iter;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Enchantment {
|
pub struct Enchantment {
|
||||||
pub id: u8,
|
pub id: u8,
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
|
|||||||
@ -599,7 +599,7 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
use crate::tag::{Taggable, RegistryKey};
|
use crate::tag::{Taggable, RegistryKey};
|
||||||
use pumpkin_util::resource_location::{FromResourceLocation, ResourceLocation, ToResourceLocation};
|
use pumpkin_util::resource_location::{FromResourceLocation, ResourceLocation, ToResourceLocation};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct PartialFluidState {
|
pub struct PartialFluidState {
|
||||||
pub height: f32,
|
pub height: f32,
|
||||||
pub level: i16,
|
pub level: i16,
|
||||||
@ -611,7 +611,7 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
pub falling: bool,
|
pub falling: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct FluidState {
|
pub struct FluidState {
|
||||||
pub height: f32,
|
pub height: f32,
|
||||||
pub level: i16,
|
pub level: i16,
|
||||||
@ -623,13 +623,13 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
pub falling: bool,
|
pub falling: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct FluidStateRef {
|
pub struct FluidStateRef {
|
||||||
pub id: u16,
|
pub id: u16,
|
||||||
pub state_idx: u16,
|
pub state_idx: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct Fluid {
|
pub struct Fluid {
|
||||||
pub id: u16,
|
pub id: u16,
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
|
|||||||
@ -9,13 +9,13 @@ use serde::Deserialize;
|
|||||||
use std::{collections::BTreeMap, fs};
|
use std::{collections::BTreeMap, fs};
|
||||||
use syn::{Ident, LitBool, LitFloat, LitInt, LitStr};
|
use syn::{Ident, LitBool, LitFloat, LitInt, LitStr};
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
pub id: u16,
|
pub id: u16,
|
||||||
pub components: ItemComponents,
|
pub components: ItemComponents,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize)]
|
||||||
pub struct ItemComponents {
|
pub struct ItemComponents {
|
||||||
#[serde(rename = "minecraft:item_name")]
|
#[serde(rename = "minecraft:item_name")]
|
||||||
pub item_name: TextComponent,
|
pub item_name: TextComponent,
|
||||||
@ -354,7 +354,7 @@ fn return_1f32() -> f32 {
|
|||||||
fn return_true() -> bool {
|
fn return_true() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct ToolComponent {
|
pub struct ToolComponent {
|
||||||
rules: Vec<ToolRule>,
|
rules: Vec<ToolRule>,
|
||||||
#[serde(default = "return_1f32")]
|
#[serde(default = "return_1f32")]
|
||||||
@ -369,7 +369,7 @@ fn return_false() -> bool {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Copy, Clone, Debug)]
|
#[derive(Deserialize, Copy, Clone)]
|
||||||
pub struct FoodComponent {
|
pub struct FoodComponent {
|
||||||
nutrition: u8,
|
nutrition: u8,
|
||||||
saturation: f32,
|
saturation: f32,
|
||||||
@ -377,7 +377,7 @@ pub struct FoodComponent {
|
|||||||
can_always_eat: bool,
|
can_always_eat: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct ToolRule {
|
pub struct ToolRule {
|
||||||
blocks: RegistryEntryList,
|
blocks: RegistryEntryList,
|
||||||
speed: Option<f32>,
|
speed: Option<f32>,
|
||||||
@ -398,23 +398,23 @@ fn _true() -> bool {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct Consumable {
|
pub struct Consumable {
|
||||||
consume_seconds: Option<f32>, // TODO
|
consume_seconds: Option<f32>, // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct DeathProtection {
|
pub struct DeathProtection {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct BlocksAttacks {
|
pub struct BlocksAttacks {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct EquippableComponent {
|
pub struct EquippableComponent {
|
||||||
pub slot: String,
|
pub slot: String,
|
||||||
pub equip_sound: Option<String>,
|
pub equip_sound: Option<String>,
|
||||||
@ -493,7 +493,7 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
use crate::data_component::DataComponent;
|
use crate::data_component::DataComponent;
|
||||||
use crate::Block;
|
use crate::Block;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
pub id: u16,
|
pub id: u16,
|
||||||
pub registry_key: &'static str,
|
pub registry_key: &'static str,
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use serde::Deserialize;
|
|||||||
use syn::LitStr;
|
use syn::LitStr;
|
||||||
|
|
||||||
/// These are required to be defined twice because serde can't deserialize into static context for obvious reasons.
|
/// 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 {
|
pub struct LootTableStruct {
|
||||||
r#type: LootTableTypeStruct,
|
r#type: LootTableTypeStruct,
|
||||||
random_sequence: Option<String>,
|
random_sequence: Option<String>,
|
||||||
|
|||||||
@ -1,29 +1,28 @@
|
|||||||
use std::{collections::BTreeMap, fs};
|
use std::{collections::BTreeMap, fs};
|
||||||
|
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use pumpkin_util::text::style::Style;
|
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct RawChatType {
|
pub struct RawChatType {
|
||||||
id: u32,
|
id: u32,
|
||||||
components: ChatType,
|
// components: ChatType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
// #[derive(Deserialize)]
|
||||||
pub struct ChatType {
|
// pub struct ChatType {
|
||||||
chat: Decoration,
|
// chat: Decoration,
|
||||||
narration: Decoration,
|
// narration: Decoration,
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
// #[derive(Deserialize)]
|
||||||
pub struct Decoration {
|
// pub struct Decoration {
|
||||||
translation_key: String,
|
// translation_key: String,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
// #[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
style: Option<Style>,
|
// style: Option<Style>,
|
||||||
parameters: Vec<String>,
|
// parameters: Vec<String>,
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub(crate) fn build() -> TokenStream {
|
pub(crate) fn build() -> TokenStream {
|
||||||
println!("cargo:rerun-if-changed=../assets/message_type.json");
|
println!("cargo:rerun-if-changed=../assets/message_type.json");
|
||||||
|
|||||||
@ -9,7 +9,6 @@ use quote::{ToTokens, TokenStreamExt, quote};
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use syn::Ident;
|
use syn::Ident;
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
struct HashableF32(pub f32);
|
struct HashableF32(pub f32);
|
||||||
|
|
||||||
// Normally this is bad, but we just care about checking if components are the same
|
// 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);
|
struct HashableF64(pub f64);
|
||||||
|
|
||||||
// Normally this is bad, but we just care about checking if components are the same
|
// 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")]
|
#[serde(tag = "_type", content = "value")]
|
||||||
enum SplineRepr {
|
enum SplineRepr {
|
||||||
#[serde(rename(deserialize = "standard"))]
|
#[serde(rename(deserialize = "standard"))]
|
||||||
@ -97,8 +95,8 @@ enum SplineRepr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SplineRepr {
|
impl SplineRepr {
|
||||||
fn into_token_stream(
|
fn get_token_stream(
|
||||||
self,
|
&self,
|
||||||
stack: &mut Vec<TokenStream>,
|
stack: &mut Vec<TokenStream>,
|
||||||
hash_to_index_map: &mut BTreeMap<u64, usize>,
|
hash_to_index_map: &mut BTreeMap<u64, usize>,
|
||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
@ -130,7 +128,7 @@ impl SplineRepr {
|
|||||||
let point_reprs = points
|
let point_reprs = points
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(location, value, derivative)| {
|
.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! {
|
quote! {
|
||||||
SplinePoint {
|
SplinePoint {
|
||||||
@ -166,7 +164,7 @@ enum BinaryOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BinaryOperation {
|
impl BinaryOperation {
|
||||||
fn into_token_stream(self) -> TokenStream {
|
fn get_token_stream(&self) -> TokenStream {
|
||||||
match self {
|
match self {
|
||||||
Self::Add => {
|
Self::Add => {
|
||||||
quote! {
|
quote! {
|
||||||
@ -337,7 +335,7 @@ impl WrapperType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Hash, Clone)]
|
#[derive(Deserialize, Hash)]
|
||||||
struct NoiseData {
|
struct NoiseData {
|
||||||
#[serde(rename(deserialize = "noise"))]
|
#[serde(rename(deserialize = "noise"))]
|
||||||
noise_id: String,
|
noise_id: String,
|
||||||
@ -347,7 +345,7 @@ struct NoiseData {
|
|||||||
y_scale: HashableF64,
|
y_scale: HashableF64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Hash, Clone)]
|
#[derive(Deserialize, Hash)]
|
||||||
struct ShiftedNoiseData {
|
struct ShiftedNoiseData {
|
||||||
#[serde(rename(deserialize = "xzScale"))]
|
#[serde(rename(deserialize = "xzScale"))]
|
||||||
xz_scale: HashableF64,
|
xz_scale: HashableF64,
|
||||||
@ -365,7 +363,7 @@ struct WeirdScaledData {
|
|||||||
mapper: WeirdScaledMapper,
|
mapper: WeirdScaledMapper,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Hash, Clone)]
|
#[derive(Deserialize, Hash)]
|
||||||
struct InterpolatedNoiseSamplerData {
|
struct InterpolatedNoiseSamplerData {
|
||||||
#[serde(rename(deserialize = "scaledXzScale"))]
|
#[serde(rename(deserialize = "scaledXzScale"))]
|
||||||
scaled_xz_scale: HashableF64,
|
scaled_xz_scale: HashableF64,
|
||||||
@ -386,7 +384,7 @@ struct InterpolatedNoiseSamplerData {
|
|||||||
//y_scale: HashableF64,
|
//y_scale: HashableF64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Hash, Clone)]
|
#[derive(Deserialize, Hash)]
|
||||||
struct ClampedYGradientData {
|
struct ClampedYGradientData {
|
||||||
#[serde(rename(deserialize = "fromY"))]
|
#[serde(rename(deserialize = "fromY"))]
|
||||||
from_y: i32,
|
from_y: i32,
|
||||||
@ -398,7 +396,7 @@ struct ClampedYGradientData {
|
|||||||
to_value: HashableF64,
|
to_value: HashableF64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Hash, Clone)]
|
#[derive(Deserialize, Hash)]
|
||||||
struct BinaryData {
|
struct BinaryData {
|
||||||
#[serde(rename(deserialize = "type"))]
|
#[serde(rename(deserialize = "type"))]
|
||||||
operation: BinaryOperation,
|
operation: BinaryOperation,
|
||||||
@ -408,7 +406,7 @@ struct BinaryData {
|
|||||||
max_value: HashableF64,
|
max_value: HashableF64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Hash, Clone)]
|
#[derive(Deserialize, Hash)]
|
||||||
struct LinearData {
|
struct LinearData {
|
||||||
#[serde(rename(deserialize = "specificType"))]
|
#[serde(rename(deserialize = "specificType"))]
|
||||||
operation: LinearOperation,
|
operation: LinearOperation,
|
||||||
@ -419,7 +417,7 @@ struct LinearData {
|
|||||||
max_value: HashableF64,
|
max_value: HashableF64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Hash, Clone)]
|
#[derive(Deserialize, Hash)]
|
||||||
struct UnaryData {
|
struct UnaryData {
|
||||||
#[serde(rename(deserialize = "type"))]
|
#[serde(rename(deserialize = "type"))]
|
||||||
operation: UnaryOperation,
|
operation: UnaryOperation,
|
||||||
@ -429,7 +427,7 @@ struct UnaryData {
|
|||||||
max_value: HashableF64,
|
max_value: HashableF64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Hash, Clone)]
|
#[derive(Deserialize, Hash)]
|
||||||
struct ClampData {
|
struct ClampData {
|
||||||
#[serde(rename(deserialize = "minValue"))]
|
#[serde(rename(deserialize = "minValue"))]
|
||||||
min_value: HashableF64,
|
min_value: HashableF64,
|
||||||
@ -437,7 +435,7 @@ struct ClampData {
|
|||||||
max_value: HashableF64,
|
max_value: HashableF64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Hash, Clone)]
|
#[derive(Deserialize, Hash)]
|
||||||
struct RangeChoiceData {
|
struct RangeChoiceData {
|
||||||
#[serde(rename(deserialize = "minInclusive"))]
|
#[serde(rename(deserialize = "minInclusive"))]
|
||||||
min_inclusive: HashableF64,
|
min_inclusive: HashableF64,
|
||||||
@ -445,7 +443,7 @@ struct RangeChoiceData {
|
|||||||
max_exclusive: HashableF64,
|
max_exclusive: HashableF64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Hash, Clone)]
|
#[derive(Deserialize, Hash)]
|
||||||
struct SplineData {
|
struct SplineData {
|
||||||
#[serde(rename(deserialize = "minValue"))]
|
#[serde(rename(deserialize = "minValue"))]
|
||||||
min_value: HashableF64,
|
min_value: HashableF64,
|
||||||
@ -453,7 +451,7 @@ struct SplineData {
|
|||||||
max_value: HashableF64,
|
max_value: HashableF64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Hash, Clone)]
|
#[derive(Deserialize, Hash)]
|
||||||
#[serde(tag = "_class", content = "value")]
|
#[serde(tag = "_class", content = "value")]
|
||||||
enum DensityFunctionRepr {
|
enum DensityFunctionRepr {
|
||||||
// This is a placeholder for leaving space for world structures
|
// This is a placeholder for leaving space for world structures
|
||||||
@ -562,7 +560,7 @@ impl DensityFunctionRepr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_index_for_component(
|
fn get_index_for_component(
|
||||||
self,
|
&self,
|
||||||
stack: &mut Vec<TokenStream>,
|
stack: &mut Vec<TokenStream>,
|
||||||
hash_to_index_map: &mut BTreeMap<u64, usize>,
|
hash_to_index_map: &mut BTreeMap<u64, usize>,
|
||||||
) -> usize {
|
) -> usize {
|
||||||
@ -570,7 +568,7 @@ impl DensityFunctionRepr {
|
|||||||
*index
|
*index
|
||||||
} else {
|
} else {
|
||||||
let id = self.unique_id();
|
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);
|
stack.push(repr);
|
||||||
let index = stack.len() - 1;
|
let index = stack.len() - 1;
|
||||||
hash_to_index_map.insert(id, index);
|
hash_to_index_map.insert(id, index);
|
||||||
@ -578,15 +576,15 @@ impl DensityFunctionRepr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_token_stream(
|
fn get_token_stream(
|
||||||
self,
|
&self,
|
||||||
stack: &mut Vec<TokenStream>,
|
stack: &mut Vec<TokenStream>,
|
||||||
hash_to_index_map: &mut BTreeMap<u64, usize>,
|
hash_to_index_map: &mut BTreeMap<u64, usize>,
|
||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
match self {
|
match self {
|
||||||
Self::Spline { spline, data } => {
|
Self::Spline { spline, data } => {
|
||||||
let _ = 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! {
|
quote! {
|
||||||
BaseNoiseFunctionComponent::Spline {
|
BaseNoiseFunctionComponent::Spline {
|
||||||
@ -598,9 +596,9 @@ impl DensityFunctionRepr {
|
|||||||
BaseNoiseFunctionComponent::EndIslands
|
BaseNoiseFunctionComponent::EndIslands
|
||||||
},
|
},
|
||||||
Self::Noise { data } => {
|
Self::Noise { data } => {
|
||||||
let noise_id = data.noise_id;
|
let noise_id = &data.noise_id;
|
||||||
let xz_scale = data.xz_scale;
|
let xz_scale = &data.xz_scale;
|
||||||
let y_scale = data.y_scale;
|
let y_scale = &data.y_scale;
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
BaseNoiseFunctionComponent::Noise {
|
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_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 shift_z_index = shift_z.get_index_for_component(stack, hash_to_index_map);
|
||||||
|
|
||||||
let xz_scale = data.xz_scale;
|
let xz_scale = &data.xz_scale;
|
||||||
let y_scale = data.y_scale;
|
let y_scale = &data.y_scale;
|
||||||
let noise_id = data.noise_id;
|
let noise_id = &data.noise_id;
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
BaseNoiseFunctionComponent::ShiftedNoise {
|
BaseNoiseFunctionComponent::ShiftedNoise {
|
||||||
@ -688,8 +686,8 @@ impl DensityFunctionRepr {
|
|||||||
let when_out_index =
|
let when_out_index =
|
||||||
when_out_range.get_index_for_component(stack, hash_to_index_map);
|
when_out_range.get_index_for_component(stack, hash_to_index_map);
|
||||||
|
|
||||||
let min_inclusive = data.min_inclusive;
|
let min_inclusive = &data.min_inclusive;
|
||||||
let max_exclusive = data.max_exclusive;
|
let max_exclusive = &data.max_exclusive;
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
BaseNoiseFunctionComponent::RangeChoice {
|
BaseNoiseFunctionComponent::RangeChoice {
|
||||||
@ -711,7 +709,7 @@ impl DensityFunctionRepr {
|
|||||||
let argument1_index = argument1.get_index_for_component(stack, hash_to_index_map);
|
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 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! {
|
quote! {
|
||||||
BaseNoiseFunctionComponent::Binary {
|
BaseNoiseFunctionComponent::Binary {
|
||||||
argument1_index: #argument1_index,
|
argument1_index: #argument1_index,
|
||||||
@ -725,8 +723,8 @@ impl DensityFunctionRepr {
|
|||||||
Self::ClampedYGradient { data } => {
|
Self::ClampedYGradient { data } => {
|
||||||
let from_y = data.from_y as f64;
|
let from_y = data.from_y as f64;
|
||||||
let to_y = data.to_y as f64;
|
let to_y = data.to_y as f64;
|
||||||
let from_value = data.from_value;
|
let from_value = &data.from_value;
|
||||||
let to_value = data.to_value;
|
let to_value = &data.to_value;
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
BaseNoiseFunctionComponent::ClampedYGradient {
|
BaseNoiseFunctionComponent::ClampedYGradient {
|
||||||
@ -761,7 +759,7 @@ impl DensityFunctionRepr {
|
|||||||
let input_index = input.get_index_for_component(stack, hash_to_index_map);
|
let input_index = input.get_index_for_component(stack, hash_to_index_map);
|
||||||
|
|
||||||
let action = data.operation.into_token_stream();
|
let action = data.operation.into_token_stream();
|
||||||
let argument = data.argument;
|
let argument = &data.argument;
|
||||||
quote! {
|
quote! {
|
||||||
BaseNoiseFunctionComponent::Linear {
|
BaseNoiseFunctionComponent::Linear {
|
||||||
input_index: #input_index,
|
input_index: #input_index,
|
||||||
@ -775,8 +773,8 @@ impl DensityFunctionRepr {
|
|||||||
Self::Clamp { input, data } => {
|
Self::Clamp { input, data } => {
|
||||||
let input_index = input.get_index_for_component(stack, hash_to_index_map);
|
let input_index = input.get_index_for_component(stack, hash_to_index_map);
|
||||||
|
|
||||||
let min_value = data.min_value;
|
let min_value = &data.min_value;
|
||||||
let max_value = data.max_value;
|
let max_value = &data.max_value;
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
BaseNoiseFunctionComponent::Clamp {
|
BaseNoiseFunctionComponent::Clamp {
|
||||||
@ -805,7 +803,7 @@ impl DensityFunctionRepr {
|
|||||||
Self::WeirdScaled { input, data } => {
|
Self::WeirdScaled { input, data } => {
|
||||||
let input_index = input.get_index_for_component(stack, hash_to_index_map);
|
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();
|
let action = data.mapper.into_token_stream();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
@ -819,11 +817,11 @@ impl DensityFunctionRepr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::InterpolatedNoiseSampler { data } => {
|
Self::InterpolatedNoiseSampler { data } => {
|
||||||
let scaled_xz_scale = data.scaled_xz_scale;
|
let scaled_xz_scale = &data.scaled_xz_scale;
|
||||||
let scaled_y_scale = data.scaled_y_scale;
|
let scaled_y_scale = &data.scaled_y_scale;
|
||||||
let xz_factor = data.xz_factor;
|
let xz_factor = &data.xz_factor;
|
||||||
let y_factor = data.y_factor;
|
let y_factor = &data.y_factor;
|
||||||
let smear_scale_multiplier = data.smear_scale_multiplier;
|
let smear_scale_multiplier = &data.smear_scale_multiplier;
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
BaseNoiseFunctionComponent::InterpolatedNoiseSampler {
|
BaseNoiseFunctionComponent::InterpolatedNoiseSampler {
|
||||||
@ -918,11 +916,9 @@ impl NoiseRouterRepr {
|
|||||||
// These should all be cached so it doesn't matter where their components are
|
// These should all be cached so it doesn't matter where their components are
|
||||||
let noise_erosion = self
|
let noise_erosion = self
|
||||||
.erosion
|
.erosion
|
||||||
.clone()
|
|
||||||
.get_index_for_component(&mut noise_component_stack, &mut noise_lookup_map);
|
.get_index_for_component(&mut noise_component_stack, &mut noise_lookup_map);
|
||||||
let noise_depth = self
|
let noise_depth = self
|
||||||
.depth
|
.depth
|
||||||
.clone()
|
|
||||||
.get_index_for_component(&mut noise_component_stack, &mut noise_lookup_map);
|
.get_index_for_component(&mut noise_component_stack, &mut noise_lookup_map);
|
||||||
|
|
||||||
let mut surface_component_stack = Vec::new();
|
let mut surface_component_stack = Vec::new();
|
||||||
|
|||||||
@ -5,13 +5,13 @@ use proc_macro2::TokenStream;
|
|||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize)]
|
||||||
struct Potion {
|
struct Potion {
|
||||||
id: u8,
|
id: u8,
|
||||||
effects: Vec<Effect>,
|
effects: Vec<Effect>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize)]
|
||||||
pub struct Effect {
|
pub struct Effect {
|
||||||
effect_type: String,
|
effect_type: String,
|
||||||
duration: i32,
|
duration: i32,
|
||||||
@ -80,14 +80,13 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use crate::effect::StatusEffect;
|
use crate::effect::StatusEffect;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Potion {
|
pub struct Potion {
|
||||||
pub id: u8,
|
pub id: u8,
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub effects: &'static [Effect],
|
pub effects: &'static [Effect],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Effect {
|
pub struct Effect {
|
||||||
pub effect_type: &'static StatusEffect,
|
pub effect_type: &'static StatusEffect,
|
||||||
pub duration: i32,
|
pub duration: i32,
|
||||||
|
|||||||
@ -3,14 +3,14 @@ use quote::{format_ident, quote};
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Hash, Eq, PartialEq)]
|
#[derive(Deserialize)]
|
||||||
struct PotionBrewing {
|
struct PotionBrewing {
|
||||||
potion_types: Vec<Vec<String>>,
|
//potion_types: Vec<Vec<String>>,
|
||||||
potion_recipes: Vec<Recipes>,
|
potion_recipes: Vec<Recipes>,
|
||||||
item_recipes: Vec<Recipes>,
|
item_recipes: Vec<Recipes>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Hash, Eq, PartialEq)]
|
#[derive(Deserialize)]
|
||||||
pub struct Recipes {
|
pub struct Recipes {
|
||||||
from: String,
|
from: String,
|
||||||
ingredient: Vec<String>,
|
ingredient: Vec<String>,
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use proc_macro2::TokenStream;
|
|||||||
use quote::{ToTokens, quote};
|
use quote::{ToTokens, quote};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum RecipeTypes {
|
pub enum RecipeTypes {
|
||||||
#[serde(rename = "minecraft:blasting")]
|
#[serde(rename = "minecraft:blasting")]
|
||||||
@ -34,7 +34,7 @@ pub enum RecipeTypes {
|
|||||||
CraftingSpecial,
|
CraftingSpecial,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct CookingRecipeStruct {
|
pub struct CookingRecipeStruct {
|
||||||
category: Option<RecipeCategoryTypes>,
|
category: Option<RecipeCategoryTypes>,
|
||||||
group: Option<String>,
|
group: Option<String>,
|
||||||
@ -72,7 +72,7 @@ impl ToTokens for CookingRecipeStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct CraftingShapedRecipeStruct {
|
pub struct CraftingShapedRecipeStruct {
|
||||||
category: Option<RecipeCategoryTypes>,
|
category: Option<RecipeCategoryTypes>,
|
||||||
group: Option<String>,
|
group: Option<String>,
|
||||||
@ -121,7 +121,7 @@ impl ToTokens for CraftingShapedRecipeStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct CraftingShapelessRecipeStruct {
|
pub struct CraftingShapelessRecipeStruct {
|
||||||
category: Option<RecipeCategoryTypes>,
|
category: Option<RecipeCategoryTypes>,
|
||||||
group: Option<String>,
|
group: Option<String>,
|
||||||
@ -157,7 +157,7 @@ impl ToTokens for CraftingShapelessRecipeStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct CraftingTransmuteRecipeStruct {
|
pub struct CraftingTransmuteRecipeStruct {
|
||||||
category: Option<RecipeCategoryTypes>,
|
category: Option<RecipeCategoryTypes>,
|
||||||
group: Option<String>,
|
group: Option<String>,
|
||||||
@ -192,7 +192,7 @@ impl ToTokens for CraftingTransmuteRecipeStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct CraftingDecoratedPotStruct {
|
pub struct CraftingDecoratedPotStruct {
|
||||||
category: Option<RecipeCategoryTypes>,
|
category: Option<RecipeCategoryTypes>,
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ impl ToTokens for CraftingDecoratedPotStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub struct RecipeResultStruct {
|
pub struct RecipeResultStruct {
|
||||||
id: String,
|
id: String,
|
||||||
count: Option<u8>,
|
count: Option<u8>,
|
||||||
@ -233,7 +233,7 @@ impl ToTokens for RecipeResultStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum RecipeIngredientTypes {
|
pub enum RecipeIngredientTypes {
|
||||||
Simple(String),
|
Simple(String),
|
||||||
@ -263,7 +263,7 @@ impl ToTokens for RecipeIngredientTypes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize)]
|
||||||
pub enum RecipeCategoryTypes {
|
pub enum RecipeCategoryTypes {
|
||||||
#[serde(rename = "equipment")]
|
#[serde(rename = "equipment")]
|
||||||
Equipment,
|
Equipment,
|
||||||
|
|||||||
@ -84,7 +84,7 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
let mut match_arms_tags_all = Vec::new();
|
let mut match_arms_tags_all = Vec::new();
|
||||||
let mut tag_identifiers = 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 key_pascal = format_ident!("{}", key.to_pascal_case());
|
||||||
let dict_name = format_ident!("{}_TAGS", key.to_pascal_case().to_uppercase());
|
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
|
// Collect all unique tags
|
||||||
for (tag_name, values) in tag_map {
|
for (tag_name, values) in tag_map {
|
||||||
tag_values.push((tag_name.clone(), values.clone()));
|
tag_values.push((tag_name, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
tag_values.sort();
|
tag_values.sort();
|
||||||
@ -103,7 +103,7 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|(tag_name, values)| {
|
.map(|(tag_name, values)| {
|
||||||
let tag_values_array = values.iter().map(|v| quote! { #v }).collect::<Vec<_>>();
|
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| {
|
t if t == "worldgen/biome" => values.iter().map(|v| {
|
||||||
let id = biomes.get(v).unwrap().id as u16;
|
let id = biomes.get(v).unwrap().id as u16;
|
||||||
quote! { #id }
|
quote! { #id }
|
||||||
@ -128,7 +128,7 @@ pub(crate) fn build() -> TokenStream {
|
|||||||
let id = entities.get(v).unwrap().id;
|
let id = entities.get(v).unwrap().id;
|
||||||
quote! { #id }
|
quote! { #id }
|
||||||
}).collect::<Vec<_>>(),
|
}).collect::<Vec<_>>(),
|
||||||
&_ => Vec::new(),
|
_ => Vec::new(),
|
||||||
};
|
};
|
||||||
let mapped_name = format_ident!("{}", tag_name.replace(":", "_").replace("/", "_").to_uppercase());
|
let mapped_name = format_ident!("{}", tag_name.replace(":", "_").replace("/", "_").to_uppercase());
|
||||||
quote! {
|
quote! {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ use std::borrow::Cow;
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
pub trait DataComponentImpl: Send + Sync + Debug {
|
pub trait DataComponentImpl: Send + Sync {
|
||||||
fn write_data(&self) -> NbtTag {
|
fn write_data(&self) -> NbtTag {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
@ -148,9 +148,9 @@ impl DataComponentImpl for DamageImpl {
|
|||||||
}
|
}
|
||||||
default_impl!(Damage);
|
default_impl!(Damage);
|
||||||
}
|
}
|
||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Hash, PartialEq)]
|
||||||
pub struct UnbreakableImpl;
|
pub struct UnbreakableImpl;
|
||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Hash, PartialEq)]
|
||||||
pub struct CustomNameImpl {
|
pub struct CustomNameImpl {
|
||||||
// TODO make TextComponent const
|
// TODO make TextComponent const
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
@ -158,7 +158,7 @@ pub struct CustomNameImpl {
|
|||||||
impl DataComponentImpl for CustomNameImpl {
|
impl DataComponentImpl for CustomNameImpl {
|
||||||
default_impl!(CustomName);
|
default_impl!(CustomName);
|
||||||
}
|
}
|
||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Hash, PartialEq)]
|
||||||
pub struct ItemNameImpl {
|
pub struct ItemNameImpl {
|
||||||
// TODO make TextComponent const
|
// TODO make TextComponent const
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
@ -166,13 +166,13 @@ pub struct ItemNameImpl {
|
|||||||
impl DataComponentImpl for ItemNameImpl {
|
impl DataComponentImpl for ItemNameImpl {
|
||||||
default_impl!(ItemName);
|
default_impl!(ItemName);
|
||||||
}
|
}
|
||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Hash, PartialEq)]
|
||||||
pub struct ItemModelImpl;
|
pub struct ItemModelImpl;
|
||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Hash, PartialEq)]
|
||||||
pub struct LoreImpl;
|
pub struct LoreImpl;
|
||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Hash, PartialEq)]
|
||||||
pub struct RarityImpl;
|
pub struct RarityImpl;
|
||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Hash, PartialEq)]
|
||||||
pub struct EnchantmentsImpl {
|
pub struct EnchantmentsImpl {
|
||||||
pub enchantment: Cow<'static, [(&'static Enchantment, i32)]>,
|
pub enchantment: Cow<'static, [(&'static Enchantment, i32)]>,
|
||||||
}
|
}
|
||||||
@ -331,13 +331,13 @@ pub struct UseCooldownImpl;
|
|||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||||
pub struct DamageResistantImpl;
|
pub struct DamageResistantImpl;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Hash, PartialEq)]
|
||||||
pub enum IDSet {
|
pub enum IDSet {
|
||||||
Tag(&'static Tag),
|
Tag(&'static Tag),
|
||||||
Blocks(Cow<'static, [&'static Block]>),
|
Blocks(Cow<'static, [&'static Block]>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct ToolRule {
|
pub struct ToolRule {
|
||||||
pub blocks: IDSet,
|
pub blocks: IDSet,
|
||||||
pub speed: Option<f32>,
|
pub speed: Option<f32>,
|
||||||
@ -355,7 +355,7 @@ impl Hash for ToolRule {
|
|||||||
self.correct_for_drops.hash(state);
|
self.correct_for_drops.hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct ToolImpl {
|
pub struct ToolImpl {
|
||||||
pub rules: Cow<'static, [ToolRule]>,
|
pub rules: Cow<'static, [ToolRule]>,
|
||||||
pub default_mining_speed: f32,
|
pub default_mining_speed: f32,
|
||||||
@ -384,7 +384,7 @@ pub enum EquipmentType {
|
|||||||
Saddle,
|
Saddle,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
#[derive(Clone, Hash, Eq, PartialEq)]
|
||||||
pub struct EquipmentSlotData {
|
pub struct EquipmentSlotData {
|
||||||
pub slot_type: EquipmentType,
|
pub slot_type: EquipmentType,
|
||||||
pub entity_id: i32,
|
pub entity_id: i32,
|
||||||
@ -393,7 +393,7 @@ pub struct EquipmentSlotData {
|
|||||||
pub name: Cow<'static, str>,
|
pub name: Cow<'static, str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
|
#[derive(Clone, Hash, Eq, PartialEq)]
|
||||||
#[repr(i8)]
|
#[repr(i8)]
|
||||||
pub enum EquipmentSlot {
|
pub enum EquipmentSlot {
|
||||||
MainHand(EquipmentSlotData),
|
MainHand(EquipmentSlotData),
|
||||||
@ -529,7 +529,7 @@ impl EquipmentSlot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub enum EntityTypeOrTag {
|
pub enum EntityTypeOrTag {
|
||||||
Tag(&'static Tag),
|
Tag(&'static Tag),
|
||||||
Single(&'static EntityType),
|
Single(&'static EntityType),
|
||||||
@ -552,7 +552,7 @@ impl Hash for EntityTypeOrTag {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||||
pub struct EnchantableImpl;
|
pub struct EnchantableImpl;
|
||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Hash, PartialEq)]
|
||||||
pub struct EquippableImpl {
|
pub struct EquippableImpl {
|
||||||
pub slot: &'static EquipmentSlot,
|
pub slot: &'static EquipmentSlot,
|
||||||
pub equip_sound: &'static str,
|
pub equip_sound: &'static str,
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use pumpkin_world::inventory::{Clearable, Inventory, InventoryFuture};
|
|||||||
|
|
||||||
use super::recipes::RecipeInputInventory;
|
use super::recipes::RecipeInputInventory;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CraftingInventory {
|
pub struct CraftingInventory {
|
||||||
pub width: u8,
|
pub width: u8,
|
||||||
pub height: u8,
|
pub height: u8,
|
||||||
|
|||||||
@ -26,7 +26,6 @@ use tokio::sync::Mutex;
|
|||||||
/// Note: This implementation is different from the original Minecraft code.
|
/// 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.
|
/// 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.
|
/// This slot should be never modified outside. any modifications to it make change in its input.
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ResultSlot {
|
pub struct ResultSlot {
|
||||||
pub inventory: Arc<dyn RecipeInputInventory>,
|
pub inventory: Arc<dyn RecipeInputInventory>,
|
||||||
pub id: AtomicU8,
|
pub id: AtomicU8,
|
||||||
|
|||||||
@ -6,7 +6,6 @@ use pumpkin_world::{
|
|||||||
};
|
};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct DoubleInventory {
|
pub struct DoubleInventory {
|
||||||
first: Arc<dyn Inventory>,
|
first: Arc<dyn Inventory>,
|
||||||
second: Arc<dyn Inventory>,
|
second: Arc<dyn Inventory>,
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use pumpkin_world::item::ItemStack;
|
|||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
// EntityEquipment.java
|
// EntityEquipment.java
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EntityEquipment {
|
pub struct EntityEquipment {
|
||||||
pub equipment: HashMap<EquipmentSlot, Arc<Mutex<ItemStack>>>,
|
pub equipment: HashMap<EquipmentSlot, Arc<Mutex<ItemStack>>>,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,6 @@ pub enum FurnaceSlotType {
|
|||||||
Side = 2,
|
Side = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct FurnaceSlot {
|
pub struct FurnaceSlot {
|
||||||
pub inventory: Arc<dyn Inventory>,
|
pub inventory: Arc<dyn Inventory>,
|
||||||
pub slot_type: FurnaceSlotType,
|
pub slot_type: FurnaceSlotType,
|
||||||
|
|||||||
@ -7,7 +7,6 @@ use pumpkin_world::{
|
|||||||
};
|
};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct EnderChestInventory {
|
pub struct EnderChestInventory {
|
||||||
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
||||||
pub tracker: Mutex<Option<Arc<ViewerCountTracker>>>,
|
pub tracker: Mutex<Option<Arc<ViewerCountTracker>>>,
|
||||||
|
|||||||
@ -15,7 +15,6 @@ use std::sync::Arc;
|
|||||||
use std::sync::atomic::{AtomicU8, Ordering};
|
use std::sync::atomic::{AtomicU8, Ordering};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct PlayerInventory {
|
pub struct PlayerInventory {
|
||||||
pub main_inventory: [Arc<Mutex<ItemStack>>; Self::MAIN_SIZE],
|
pub main_inventory: [Arc<Mutex<ItemStack>>; Self::MAIN_SIZE],
|
||||||
pub equipment_slots: Arc<HashMap<usize, EquipmentSlot>>,
|
pub equipment_slots: Arc<HashMap<usize, EquipmentSlot>>,
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
#![warn(unused)]
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Debug,
|
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
sync::{
|
sync::{
|
||||||
Arc,
|
Arc,
|
||||||
@ -21,7 +19,7 @@ pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
|
|||||||
|
|
||||||
// Slot.java
|
// Slot.java
|
||||||
// This is a trait due to crafting slots being a thing
|
// 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_inventory(&self) -> Arc<dyn Inventory>;
|
||||||
|
|
||||||
fn get_index(&self) -> usize;
|
fn get_index(&self) -> usize;
|
||||||
@ -257,7 +255,6 @@ pub trait Slot: Send + Sync + Debug {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
/// Just called Slot in Vanilla
|
/// Just called Slot in Vanilla
|
||||||
pub struct NormalSlot {
|
pub struct NormalSlot {
|
||||||
pub inventory: Arc<dyn Inventory>,
|
pub inventory: Arc<dyn Inventory>,
|
||||||
@ -295,7 +292,6 @@ impl Slot for NormalSlot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ArmorSlot.java
|
// ArmorSlot.java
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ArmorSlot {
|
pub struct ArmorSlot {
|
||||||
pub inventory: Arc<dyn Inventory>,
|
pub inventory: Arc<dyn Inventory>,
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
|
|||||||
@ -121,7 +121,7 @@ impl SyncHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TrackedSlot in vanilla
|
// TrackedSlot in vanilla
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TrackedStack {
|
pub struct TrackedStack {
|
||||||
pub received_stack: Option<ItemStack>,
|
pub received_stack: Option<ItemStack>,
|
||||||
pub received_hash: Option<OptionalItemStackHash>,
|
pub received_hash: Option<OptionalItemStackHash>,
|
||||||
|
|||||||
@ -22,7 +22,6 @@ pub(super) fn set_curr_visitor_seq_list_id(tag: Option<u8>) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct NbtReadHelper<R: Read + Seek> {
|
pub struct NbtReadHelper<R: Read + Seek> {
|
||||||
reader: R,
|
reader: R,
|
||||||
}
|
}
|
||||||
@ -76,7 +75,6 @@ impl<R: Read + Seek> NbtReadHelper<R> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Deserializer<R: Read + Seek> {
|
pub struct Deserializer<R: Read + Seek> {
|
||||||
input: NbtReadHelper<R>,
|
input: NbtReadHelper<R>,
|
||||||
tag_to_deserialize_stack: Option<u8>,
|
tag_to_deserialize_stack: Option<u8>,
|
||||||
|
|||||||
@ -11,7 +11,6 @@ use crate::{
|
|||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct WriteAdaptor<W: Write> {
|
pub struct WriteAdaptor<W: Write> {
|
||||||
writer: W,
|
writer: W,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,6 @@ use serde::{
|
|||||||
};
|
};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct ItemStackSerializer<'a>(pub Cow<'a, ItemStack>);
|
pub struct ItemStackSerializer<'a>(pub Cow<'a, ItemStack>);
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for ItemStackSerializer<'static> {
|
impl<'de> Deserialize<'de> for ItemStackSerializer<'static> {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use pumpkin_macros::packet;
|
|||||||
|
|
||||||
use crate::codec::item_stack_seralizer::ItemStackSerializer;
|
use crate::codec::item_stack_seralizer::ItemStackSerializer;
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Debug)]
|
#[derive(serde::Deserialize)]
|
||||||
#[packet(PLAY_SET_CREATIVE_MODE_SLOT)]
|
#[packet(PLAY_SET_CREATIVE_MODE_SLOT)]
|
||||||
pub struct SSetCreativeSlot {
|
pub struct SSetCreativeSlot {
|
||||||
pub slot: i16,
|
pub slot: i16,
|
||||||
|
|||||||
31
pumpkin-util/src/math/block_box.rs
Normal file
31
pumpkin-util/src/math/block_box.rs
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
use num_traits::{Float, One, PrimInt, Zero};
|
use num_traits::{Float, One, PrimInt, Zero};
|
||||||
|
|
||||||
|
pub mod block_box;
|
||||||
pub mod boundingbox;
|
pub mod boundingbox;
|
||||||
pub mod euler_angle;
|
pub mod euler_angle;
|
||||||
pub mod experience;
|
pub mod experience;
|
||||||
|
|||||||
@ -29,7 +29,6 @@ use crate::{
|
|||||||
|
|
||||||
use super::BlockEntity;
|
use super::BlockEntity;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct BarrelBlockEntity {
|
pub struct BarrelBlockEntity {
|
||||||
pub position: BlockPos,
|
pub position: BlockPos,
|
||||||
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
||||||
|
|||||||
@ -29,7 +29,6 @@ use crate::{
|
|||||||
|
|
||||||
use super::BlockEntity;
|
use super::BlockEntity;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ChestBlockEntity {
|
pub struct ChestBlockEntity {
|
||||||
pub position: BlockPos,
|
pub position: BlockPos,
|
||||||
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
||||||
|
|||||||
@ -22,7 +22,6 @@ use crate::{
|
|||||||
world::{BlockFlags, SimpleWorld},
|
world::{BlockFlags, SimpleWorld},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ChiseledBookshelfBlockEntity {
|
pub struct ChiseledBookshelfBlockEntity {
|
||||||
pub position: BlockPos,
|
pub position: BlockPos,
|
||||||
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
||||||
|
|||||||
@ -11,7 +11,6 @@ use std::sync::Arc;
|
|||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use tokio::sync::{Mutex, MutexGuard};
|
use tokio::sync::{Mutex, MutexGuard};
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct DropperBlockEntity {
|
pub struct DropperBlockEntity {
|
||||||
pub position: BlockPos,
|
pub position: BlockPos,
|
||||||
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
||||||
|
|||||||
@ -12,7 +12,6 @@ use crate::world::SimpleWorld;
|
|||||||
|
|
||||||
use super::BlockEntity;
|
use super::BlockEntity;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct EnderChestBlockEntity {
|
pub struct EnderChestBlockEntity {
|
||||||
pub position: BlockPos,
|
pub position: BlockPos,
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,6 @@ use crate::{
|
|||||||
|
|
||||||
use super::{BlockEntity, PropertyDelegate};
|
use super::{BlockEntity, PropertyDelegate};
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct FurnaceBlockEntity {
|
pub struct FurnaceBlockEntity {
|
||||||
pub position: BlockPos,
|
pub position: BlockPos,
|
||||||
pub dirty: AtomicBool,
|
pub dirty: AtomicBool,
|
||||||
|
|||||||
@ -17,7 +17,6 @@ use std::sync::Arc;
|
|||||||
use std::sync::atomic::{AtomicBool, AtomicI32, AtomicI64};
|
use std::sync::atomic::{AtomicBool, AtomicI32, AtomicI64};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct HopperBlockEntity {
|
pub struct HopperBlockEntity {
|
||||||
pub position: BlockPos,
|
pub position: BlockPos,
|
||||||
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
||||||
|
|||||||
@ -24,7 +24,6 @@ use crate::{
|
|||||||
|
|
||||||
use super::BlockEntity;
|
use super::BlockEntity;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ShulkerBoxBlockEntity {
|
pub struct ShulkerBoxBlockEntity {
|
||||||
pub position: BlockPos,
|
pub position: BlockPos,
|
||||||
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
pub items: [Arc<Mutex<ItemStack>>; Self::INVENTORY_SIZE],
|
||||||
|
|||||||
@ -10,7 +10,7 @@ pub use state::RawBlockState;
|
|||||||
|
|
||||||
use crate::BlockStateId;
|
use crate::BlockStateId;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub struct BlockStateCodec {
|
pub struct BlockStateCodec {
|
||||||
/// Block name
|
/// Block name
|
||||||
|
|||||||
@ -40,9 +40,6 @@ const SECTOR_BYTES: usize = 4096;
|
|||||||
// 1.21.10
|
// 1.21.10
|
||||||
pub const WORLD_DATA_VERSION: i32 = 4556;
|
pub const WORLD_DATA_VERSION: i32 = 4556;
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
|
||||||
pub struct AnvilChunkFormat;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Compression {
|
pub enum Compression {
|
||||||
@ -72,7 +69,6 @@ impl<R: Read> Read for CompressionRead<R> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
|
||||||
pub struct AnvilChunkData {
|
pub struct AnvilChunkData {
|
||||||
compression: Option<Compression>,
|
compression: Option<Compression>,
|
||||||
// Length is always the length of this + compression byte (1) so we dont need to save a length
|
// Length is always the length of this + compression byte (1) so we dont need to save a length
|
||||||
|
|||||||
@ -20,7 +20,7 @@ use super::anvil::CHUNK_COUNT;
|
|||||||
/// used as a header and footer described in https://gist.github.com/Aaron2550/5701519671253d4c6190bde6706f9f98
|
/// used as a header and footer described in https://gist.github.com/Aaron2550/5701519671253d4c6190bde6706f9f98
|
||||||
const SIGNATURE: [u8; 8] = u64::to_be_bytes(0xc3ff13183cca9d9a);
|
const SIGNATURE: [u8; 8] = u64::to_be_bytes(0xc3ff13183cca9d9a);
|
||||||
|
|
||||||
#[derive(Default, Clone, Copy)]
|
#[derive(Default, Copy, Clone)]
|
||||||
struct LinearChunkHeader {
|
struct LinearChunkHeader {
|
||||||
size: u32,
|
size: u32,
|
||||||
timestamp: u32,
|
timestamp: u32,
|
||||||
|
|||||||
@ -330,7 +330,7 @@ impl ChunkEntityData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct ChunkSectionNBT {
|
struct ChunkSectionNBT {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
block_states: Option<ChunkSectionBlockStates>,
|
block_states: Option<ChunkSectionBlockStates>,
|
||||||
@ -362,7 +362,7 @@ pub struct PaletteBiomeEntry {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct ChunkSectionBlockStates {
|
pub struct ChunkSectionBlockStates {
|
||||||
#[serde(
|
#[serde(
|
||||||
serialize_with = "nbt_long_array",
|
serialize_with = "nbt_long_array",
|
||||||
@ -444,7 +444,7 @@ impl Default for LightContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
struct ChunkNbt {
|
struct ChunkNbt {
|
||||||
data_version: i32,
|
data_version: i32,
|
||||||
|
|||||||
@ -95,7 +95,7 @@ pub struct ChunkEntityData {
|
|||||||
///
|
///
|
||||||
/// A chunk can be:
|
/// A chunk can be:
|
||||||
/// - Subchunks: 24 separate subchunks are stored.
|
/// - Subchunks: 24 separate subchunks are stored.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ChunkSections {
|
pub struct ChunkSections {
|
||||||
pub sections: Box<[SubChunk]>,
|
pub sections: Box<[SubChunk]>,
|
||||||
pub min_y: i32,
|
pub min_y: i32,
|
||||||
@ -127,13 +127,13 @@ impl ChunkSections {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct SubChunk {
|
pub struct SubChunk {
|
||||||
pub block_states: BlockPalette,
|
pub block_states: BlockPalette,
|
||||||
pub biomes: BiomePalette,
|
pub biomes: BiomePalette,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct ChunkLight {
|
pub struct ChunkLight {
|
||||||
pub sky_light: Box<[LightContainer]>,
|
pub sky_light: Box<[LightContainer]>,
|
||||||
pub block_light: Box<[LightContainer]>,
|
pub block_light: Box<[LightContainer]>,
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use super::format::{ChunkSectionBiomes, ChunkSectionBlockStates, PaletteBiomeEnt
|
|||||||
/// 3d array indexed by y,z,x
|
/// 3d array indexed by y,z,x
|
||||||
type AbstractCube<T, const DIM: usize> = [[[T; DIM]; DIM]; DIM];
|
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> {
|
pub struct HeterogeneousPaletteData<V: Hash + Eq + Copy, const DIM: usize> {
|
||||||
cube: Box<AbstractCube<V, DIM>>,
|
cube: Box<AbstractCube<V, DIM>>,
|
||||||
palette: Vec<V>,
|
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
|
/// 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.
|
/// may distinct registry ids are in the cube.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub enum PalettedContainer<V: Hash + Eq + Copy + Default, const DIM: usize> {
|
pub enum PalettedContainer<V: Hash + Eq + Copy + Default, const DIM: usize> {
|
||||||
Homogeneous(V),
|
Homogeneous(V),
|
||||||
Heterogeneous(Box<HeterogeneousPaletteData<V, DIM>>),
|
Heterogeneous(Box<HeterogeneousPaletteData<V, DIM>>),
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use std::num::NonZeroU8;
|
|||||||
|
|
||||||
use pumpkin_util::math::vector2::Vector2;
|
use pumpkin_util::math::vector2::Vector2;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
pub struct Cylindrical {
|
pub struct Cylindrical {
|
||||||
pub center: Vector2<i32>,
|
pub center: Vector2<i32>,
|
||||||
pub view_distance: NonZeroU8,
|
pub view_distance: NonZeroU8,
|
||||||
|
|||||||
@ -20,8 +20,7 @@ impl AttachedToLogsTreeDecorator {
|
|||||||
&self,
|
&self,
|
||||||
chunk: &mut T,
|
chunk: &mut T,
|
||||||
random: &mut RandomGenerator,
|
random: &mut RandomGenerator,
|
||||||
_root_positions: Vec<BlockPos>,
|
log_positions: &[BlockPos],
|
||||||
log_positions: Vec<BlockPos>,
|
|
||||||
) {
|
) {
|
||||||
// TODO: shuffle
|
// TODO: shuffle
|
||||||
for pos in log_positions {
|
for pos in log_positions {
|
||||||
|
|||||||
@ -53,8 +53,8 @@ impl TreeDecorator {
|
|||||||
&self,
|
&self,
|
||||||
chunk: &mut T,
|
chunk: &mut T,
|
||||||
random: &mut RandomGenerator,
|
random: &mut RandomGenerator,
|
||||||
root_positions: Vec<BlockPos>,
|
root_positions: &[BlockPos],
|
||||||
log_positions: Vec<BlockPos>,
|
log_positions: &[BlockPos],
|
||||||
) {
|
) {
|
||||||
match self {
|
match self {
|
||||||
TreeDecorator::TrunkVine(decorator) => decorator.generate(chunk, random, log_positions),
|
TreeDecorator::TrunkVine(decorator) => decorator.generate(chunk, random, log_positions),
|
||||||
@ -69,25 +69,25 @@ impl TreeDecorator {
|
|||||||
}
|
}
|
||||||
TreeDecorator::AttachedToLeaves(_decorator) => {}
|
TreeDecorator::AttachedToLeaves(_decorator) => {}
|
||||||
TreeDecorator::AttachedToLogs(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(
|
pub(super) fn get_leaf_litter_positions(
|
||||||
root_positions: Vec<BlockPos>,
|
root_positions: &[BlockPos],
|
||||||
log_positions: Vec<BlockPos>,
|
log_positions: &[BlockPos],
|
||||||
) -> Vec<BlockPos> {
|
) -> Vec<BlockPos> {
|
||||||
let mut list = Vec::new();
|
let mut list = Vec::new();
|
||||||
if root_positions.is_empty() {
|
if root_positions.is_empty() {
|
||||||
list.extend_from_slice(&log_positions);
|
list.extend_from_slice(log_positions);
|
||||||
} else if !log_positions.is_empty()
|
} else if !log_positions.is_empty()
|
||||||
&& root_positions.first().unwrap().0.y == log_positions.first().unwrap().0.y
|
&& root_positions.first().unwrap().0.y == log_positions.first().unwrap().0.y
|
||||||
{
|
{
|
||||||
list.extend_from_slice(&log_positions);
|
list.extend_from_slice(log_positions);
|
||||||
list.extend_from_slice(&root_positions);
|
list.extend_from_slice(root_positions);
|
||||||
} else {
|
} else {
|
||||||
list.extend_from_slice(&root_positions);
|
list.extend_from_slice(root_positions);
|
||||||
}
|
}
|
||||||
|
|
||||||
list
|
list
|
||||||
|
|||||||
@ -22,8 +22,8 @@ impl PlaceOnGroundTreeDecorator {
|
|||||||
&self,
|
&self,
|
||||||
chunk: &mut T,
|
chunk: &mut T,
|
||||||
random: &mut RandomGenerator,
|
random: &mut RandomGenerator,
|
||||||
root_positions: Vec<BlockPos>,
|
root_positions: &[BlockPos],
|
||||||
log_positions: Vec<BlockPos>,
|
log_positions: &[BlockPos],
|
||||||
) {
|
) {
|
||||||
let list = TreeDecorator::get_leaf_litter_positions(root_positions, log_positions);
|
let list = TreeDecorator::get_leaf_litter_positions(root_positions, log_positions);
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ impl TrunkVineTreeDecorator {
|
|||||||
&self,
|
&self,
|
||||||
chunk: &mut T,
|
chunk: &mut T,
|
||||||
random: &mut RandomGenerator,
|
random: &mut RandomGenerator,
|
||||||
log_positions: Vec<BlockPos>,
|
log_positions: &[BlockPos],
|
||||||
) {
|
) {
|
||||||
for pos in log_positions {
|
for pos in log_positions {
|
||||||
if random.next_bounded_i32(3) > 0
|
if random.next_bounded_i32(3) > 0
|
||||||
|
|||||||
@ -46,7 +46,7 @@ impl TreeFeature {
|
|||||||
let log_positions = self.generate_main(chunk, min_y, height, feature_name, random, pos);
|
let log_positions = self.generate_main(chunk, min_y, height, feature_name, random, pos);
|
||||||
|
|
||||||
for decorator in &self.decorators {
|
for decorator in &self.decorators {
|
||||||
decorator.generate(chunk, random, Vec::new(), log_positions.clone());
|
decorator.generate(chunk, random, &[], &log_positions);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
use std::fmt::Debug;
|
|
||||||
|
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
use pumpkin_data::noise_router::WrapperType;
|
use pumpkin_data::noise_router::WrapperType;
|
||||||
|
|
||||||
@ -20,13 +18,12 @@ mod test;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_deserializer;
|
mod test_deserializer;
|
||||||
|
|
||||||
pub trait NoisePos: Debug {
|
pub trait NoisePos {
|
||||||
fn x(&self) -> i32;
|
fn x(&self) -> i32;
|
||||||
fn y(&self) -> i32;
|
fn y(&self) -> i32;
|
||||||
fn z(&self) -> i32;
|
fn z(&self) -> i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct UnblendedNoisePos {
|
pub struct UnblendedNoisePos {
|
||||||
x: i32,
|
x: i32,
|
||||||
y: i32,
|
y: i32,
|
||||||
|
|||||||
@ -6,6 +6,7 @@ use pumpkin_data::tag;
|
|||||||
use pumpkin_data::{
|
use pumpkin_data::{
|
||||||
Block, BlockState, block_properties::blocks_movement, chunk::Biome, tag::Taggable,
|
Block, BlockState, block_properties::blocks_movement, chunk::Biome, tag::Taggable,
|
||||||
};
|
};
|
||||||
|
use pumpkin_util::math::block_box::BlockBox;
|
||||||
use pumpkin_util::{
|
use pumpkin_util::{
|
||||||
HeightMap,
|
HeightMap,
|
||||||
math::{position::BlockPos, vector2::Vector2, vector3::Vector3},
|
math::{position::BlockPos, vector2::Vector2, vector3::Vector3},
|
||||||
@ -918,6 +919,7 @@ impl ProtoChunk {
|
|||||||
let population_seed =
|
let population_seed =
|
||||||
Xoroshiro::get_population_seed(random_config.seed, block_pos.0.x, block_pos.0.z);
|
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() {
|
for (_structure, (pos, stype)) in chunk.structure_starts.clone() {
|
||||||
dbg!("generating structure");
|
dbg!("generating structure");
|
||||||
stype.generate(pos.clone(), chunk);
|
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 {
|
fn start_cell_x(&self, horizontal_cell_block_count: u8) -> i32 {
|
||||||
self.start_block_x() / horizontal_cell_block_count as i32
|
self.start_block_x() / horizontal_cell_block_count as i32
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use pumpkin_data::{Block, BlockDirection};
|
use pumpkin_data::{Block, BlockDirection};
|
||||||
use pumpkin_util::{
|
use pumpkin_util::{
|
||||||
HeightMap,
|
HeightMap,
|
||||||
math::{position::BlockPos, vector2::Vector2, vector3::Vector3},
|
math::{block_box::BlockBox, position::BlockPos, vector2::Vector2, vector3::Vector3},
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
@ -22,11 +22,11 @@ impl StructureGenerator for BuriedTreasureGenerator {
|
|||||||
let z = get_center_z(chunk.chunk_pos.y);
|
let z = get_center_z(chunk.chunk_pos.y);
|
||||||
let y = chunk.get_top_y(&HeightMap::OceanFloorWg, &Vector2::new(x, z)) - 1;
|
let y = chunk.get_top_y(&HeightMap::OceanFloorWg, &Vector2::new(x, z)) - 1;
|
||||||
let generator = StructurePiecesCollector {
|
let generator = StructurePiecesCollector {
|
||||||
pieces_positions: vec![BlockPos::new(
|
pieces_positions: vec![BlockBox::from_pos(BlockPos::new(
|
||||||
get_offset_x(chunk.chunk_pos.x, 9),
|
get_offset_x(chunk.chunk_pos.x, 9),
|
||||||
90,
|
90,
|
||||||
get_offset_z(chunk.chunk_pos.y, 9),
|
get_offset_z(chunk.chunk_pos.y, 9),
|
||||||
)],
|
))],
|
||||||
};
|
};
|
||||||
StructurePosition {
|
StructurePosition {
|
||||||
position: BlockPos(Vector3::new(x, y, z)),
|
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(
|
let y = chunk.get_top_y(
|
||||||
&HeightMap::OceanFloorWg,
|
&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 {
|
for _ in y..chunk.bottom_y() as i32 {
|
||||||
let state = chunk.get_block_state(&pos.0);
|
let state = chunk.get_block_state(&pos.0);
|
||||||
let down_raw_state = chunk.get_block_state(&pos.down().0);
|
let down_raw_state = chunk.get_block_state(&pos.down().0);
|
||||||
|
|||||||
@ -1,15 +1,16 @@
|
|||||||
use pumpkin_data::BlockState;
|
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;
|
use crate::ProtoChunk;
|
||||||
|
|
||||||
pub mod buried_treasure;
|
pub mod buried_treasure;
|
||||||
pub mod nether_fortress;
|
pub mod nether_fortress;
|
||||||
|
pub mod swamp_hut;
|
||||||
|
|
||||||
pub trait StructureGenerator {
|
pub trait StructureGenerator {
|
||||||
fn get_structure_position(&self, chunk: &ProtoChunk) -> StructurePosition;
|
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)]
|
#[expect(clippy::too_many_arguments)]
|
||||||
@ -72,5 +73,5 @@ pub struct StructurePosition {
|
|||||||
|
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone, Debug)]
|
||||||
pub struct StructurePiecesCollector {
|
pub struct StructurePiecesCollector {
|
||||||
pub pieces_positions: Vec<BlockPos>,
|
pub pieces_positions: Vec<BlockBox>,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use pumpkin_data::Block;
|
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 serde::Deserialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -29,7 +29,7 @@ impl StructureGenerator for NetherFortressGenerator {
|
|||||||
generator,
|
generator,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn generate(&self, position: BlockPos, chunk: &mut crate::ProtoChunk) {
|
fn generate(&self, position: BlockBox, chunk: &mut crate::ProtoChunk) {
|
||||||
BridgePlatform::generate(&BridgePlatform, position, chunk);
|
BridgePlatform::generate(&BridgePlatform, position, chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ impl StructureGenerator for NetherFortressGenerator {
|
|||||||
pub struct BridgePlatform;
|
pub struct BridgePlatform;
|
||||||
|
|
||||||
impl 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(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, 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);
|
super::fill(1, 2, 1, 5, 2, 7, Block::NETHER_BRICKS.default_state, chunk);
|
||||||
|
|||||||
@ -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!()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,7 +4,6 @@ use pumpkin_nbt::{compound::NbtCompound, tag::NbtTag};
|
|||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Debug,
|
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
sync::Arc,
|
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 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;
|
fn size(&self) -> usize;
|
||||||
|
|
||||||
// --- Asynchronous Methods (Using BlockFuture) ---
|
// --- Asynchronous Methods (Using BlockFuture) ---
|
||||||
|
|||||||
@ -15,7 +15,7 @@ use std::cmp::{max, min};
|
|||||||
|
|
||||||
mod categories;
|
mod categories;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct ItemStack {
|
pub struct ItemStack {
|
||||||
pub item_count: u8,
|
pub item_count: u8,
|
||||||
pub item: &'static Item,
|
pub item: &'static Item,
|
||||||
|
|||||||
@ -52,7 +52,7 @@ impl From<i32> for TickPriority {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ScheduledTick<T> {
|
pub struct ScheduledTick<T> {
|
||||||
pub delay: u8,
|
pub delay: u8,
|
||||||
pub priority: TickPriority,
|
pub priority: TickPriority,
|
||||||
@ -60,7 +60,7 @@ pub struct ScheduledTick<T> {
|
|||||||
pub value: T,
|
pub value: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct OrderedTick<T> {
|
pub struct OrderedTick<T> {
|
||||||
pub priority: TickPriority,
|
pub priority: TickPriority,
|
||||||
pub sub_tick_order: u64,
|
pub sub_tick_order: u64,
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use pumpkin_util::math::position::BlockPos;
|
|||||||
|
|
||||||
use crate::tick::{MAX_TICK_DELAY, OrderedTick, ScheduledTick};
|
use crate::tick::{MAX_TICK_DELAY, OrderedTick, ScheduledTick};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ChunkTickScheduler<T> {
|
pub struct ChunkTickScheduler<T> {
|
||||||
tick_queue: [Vec<OrderedTick<T>>; MAX_TICK_DELAY],
|
tick_queue: [Vec<OrderedTick<T>>; MAX_TICK_DELAY],
|
||||||
queued_ticks: HashSet<(BlockPos, T)>,
|
queued_ticks: HashSet<(BlockPos, T)>,
|
||||||
|
|||||||
@ -43,7 +43,7 @@ impl FireBlock {
|
|||||||
.to_props()
|
.to_props()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|p| p.0 == "waterlogged")
|
.find(|p| p.0 == "waterlogged")
|
||||||
.map(|(_, v)| v == true.to_string())
|
.map(|(_, v)| v == "true")
|
||||||
})
|
})
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
@ -415,7 +415,7 @@ impl BlockBehaviour for FireBlock {
|
|||||||
|
|
||||||
fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> {
|
fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
FireBlockBase::broken(args.world.clone(), *args.position).await;
|
FireBlockBase::broken(args.world, *args.position).await;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -115,7 +115,7 @@ impl FireBlockBase {
|
|||||||
.is_some();
|
.is_some();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn broken(world: Arc<World>, block_pos: BlockPos) {
|
async fn broken(world: &World, block_pos: BlockPos) {
|
||||||
world
|
world
|
||||||
.sync_world_event(WorldEvent::FireExtinguished, block_pos, 0)
|
.sync_world_event(WorldEvent::FireExtinguished, block_pos, 0)
|
||||||
.await;
|
.await;
|
||||||
|
|||||||
@ -41,7 +41,7 @@ impl BlockBehaviour for SoulFireBlock {
|
|||||||
|
|
||||||
fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> {
|
fn broken<'a>(&'a self, args: BrokenArgs<'a>) -> BlockFuture<'a, ()> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
FireBlockBase::broken(args.world.clone(), *args.position).await;
|
FireBlockBase::broken(args.world, *args.position).await;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,7 +69,8 @@ impl<'a> PistonHandler<'a> {
|
|||||||
}
|
}
|
||||||
for block_pos in self.moved_blocks.clone() {
|
for block_pos in self.moved_blocks.clone() {
|
||||||
let block = self.world.get_block(&block_pos).await;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
@ -146,7 +147,7 @@ impl<'a> PistonHandler<'a> {
|
|||||||
let block_pos3 = self.moved_blocks[m];
|
let block_pos3 = self.moved_blocks[m];
|
||||||
let block = self.world.get_block(&block_pos3).await;
|
let block = self.world.get_block(&block_pos3).await;
|
||||||
if Self::is_block_sticky(block)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
@ -193,7 +194,7 @@ impl<'a> PistonHandler<'a> {
|
|||||||
self.moved_blocks.extend(list3);
|
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() {
|
for direction in BlockDirection::all() {
|
||||||
if direction.to_axis() == self.motion_direction.to_axis() {
|
if direction.to_axis() == self.motion_direction.to_axis() {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@ -39,7 +39,7 @@ impl ArgumentConsumer for MsgArgConsumer {
|
|||||||
|
|
||||||
let mut msg = match first_word_opt {
|
let mut msg = match first_word_opt {
|
||||||
Some(word) => word.to_string(),
|
Some(word) => word.to_string(),
|
||||||
None => return Box::pin(async move { None }),
|
None => return Box::pin(async { None }),
|
||||||
};
|
};
|
||||||
|
|
||||||
while let Some(word) = args.pop() {
|
while let Some(word) = args.pop() {
|
||||||
|
|||||||
@ -52,7 +52,6 @@ pub async fn send_c_commands_packet(player: &Arc<Player>, dispatcher: &CommandDi
|
|||||||
player.client.enqueue_packet(&packet).await;
|
player.client.enqueue_packet(&packet).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct ProtoNodeBuilder<'a> {
|
struct ProtoNodeBuilder<'a> {
|
||||||
child_nodes: Vec<Self>,
|
child_nodes: Vec<Self>,
|
||||||
node_type: ProtoNodeType<'a>,
|
node_type: ProtoNodeType<'a>,
|
||||||
|
|||||||
@ -403,9 +403,9 @@ impl CommandDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Register a command with the dispatcher.
|
/// 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 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");
|
let primary_name = names.next().expect("at least one name must be provided");
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ use crate::entity::{ai::goal::GoalFuture, mob::Mob};
|
|||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Default)]
|
|
||||||
pub struct AmbientStandGoal {
|
pub struct AmbientStandGoal {
|
||||||
goal_control: Controls,
|
goal_control: Controls,
|
||||||
cooldown: i32,
|
cooldown: i32,
|
||||||
|
|||||||
@ -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 ;)
|
// We actually only use the first 4 bits ;)
|
||||||
pub struct Controls(u8);
|
pub struct Controls(u8);
|
||||||
|
|
||||||
|
|||||||
@ -2198,7 +2198,7 @@ impl NBTStorage for PlayerInventory {
|
|||||||
equipment_compound.put_component("head", item_compound);
|
equipment_compound.put_component("head", item_compound);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
warn!("Invalid equipment slot for a player {slot:?}");
|
warn!("Invalid equipment slot for a player");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,11 +94,15 @@ impl Context {
|
|||||||
/// # Example
|
/// # 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;
|
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.
|
/// Retrieves a registered service by name and type.
|
||||||
@ -136,21 +140,23 @@ impl Context {
|
|||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// - `tree`: The command tree to register.
|
/// - `tree`: The command tree to register.
|
||||||
/// - `permission`: The permission level required to execute the command.
|
/// - `permission`: The permission level required to execute the command.
|
||||||
pub async fn register_command(
|
pub async fn register_command<P: Into<String>>(
|
||||||
&self,
|
&self,
|
||||||
tree: crate::command::tree::CommandTree,
|
tree: crate::command::tree::CommandTree,
|
||||||
permission_node: &str,
|
permission: P,
|
||||||
) {
|
) {
|
||||||
let plugin_name = self.metadata.name;
|
let plugin_name = self.metadata.name;
|
||||||
let full_permission_node = if permission_node.contains(':') {
|
let permission = permission.into();
|
||||||
permission_node.to_string()
|
|
||||||
|
let full_permission_node = if permission.contains(':') {
|
||||||
|
permission
|
||||||
} else {
|
} else {
|
||||||
format!("{plugin_name}:{permission_node}")
|
format!("{plugin_name}:{permission}")
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut dispatcher_lock = self.server.command_dispatcher.write().await;
|
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() {
|
for world in self.server.worlds.read().await.iter() {
|
||||||
|
|||||||
@ -6,7 +6,6 @@ use crate::plugin::loader::{PluginLoadFuture, PluginUnloadFuture};
|
|||||||
|
|
||||||
use super::{LoaderError, Path, Plugin, PluginLoader, PluginMetadata};
|
use super::{LoaderError, Path, Plugin, PluginLoader, PluginMetadata};
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct NativePluginLoader;
|
pub struct NativePluginLoader;
|
||||||
|
|
||||||
impl PluginLoader for NativePluginLoader {
|
impl PluginLoader for NativePluginLoader {
|
||||||
|
|||||||
@ -817,7 +817,7 @@ impl Server {
|
|||||||
} else if target_selector.get_limit() == 1 {
|
} else if target_selector.get_limit() == 1 {
|
||||||
// If the limit is 1, we just return a random entity
|
// If the limit is 1, we just return a random entity
|
||||||
return if let Some(entity) = iter.choose(&mut rand::rng()) {
|
return if let Some(entity) = iter.choose(&mut rand::rng()) {
|
||||||
vec![entity.clone()]
|
vec![entity]
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
};
|
};
|
||||||
|
|||||||
@ -9,7 +9,6 @@ use crate::entity::player::Player;
|
|||||||
use crate::server::Server;
|
use crate::server::Server;
|
||||||
const NANOSECONDS_PER_SECOND: i64 = 1_000_000_000;
|
const NANOSECONDS_PER_SECOND: i64 = 1_000_000_000;
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ServerTickRateManager {
|
pub struct ServerTickRateManager {
|
||||||
tickrate: AtomicCell<f32>,
|
tickrate: AtomicCell<f32>,
|
||||||
nanoseconds_per_tick: AtomicI64,
|
nanoseconds_per_tick: AtomicI64,
|
||||||
|
|||||||
@ -81,9 +81,8 @@ impl CustomBossbars {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn replace_bossbar(&mut self, resource_location: &str, bossbar_data: CustomBossbar) {
|
pub fn replace_bossbar(&mut self, resource_location: String, bossbar_data: CustomBossbar) {
|
||||||
self.custom_bossbars
|
self.custom_bossbars.insert(resource_location, bossbar_data);
|
||||||
.insert(resource_location.to_string(), bossbar_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|||||||
@ -219,7 +219,7 @@ impl World {
|
|||||||
level_info,
|
level_info,
|
||||||
players: Arc::new(RwLock::new(HashMap::new())),
|
players: Arc::new(RwLock::new(HashMap::new())),
|
||||||
entities: 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)),
|
worldborder: Mutex::new(Worldborder::new(0.0, 0.0, 30_000_000.0, 0, 0, 0)),
|
||||||
level_time: Mutex::new(LevelTime::new()),
|
level_time: Mutex::new(LevelTime::new()),
|
||||||
dimension_type,
|
dimension_type,
|
||||||
@ -594,6 +594,7 @@ impl World {
|
|||||||
// Entity ticks
|
// Entity ticks
|
||||||
for entity in entities_to_tick {
|
for entity in entities_to_tick {
|
||||||
entity.get_entity().age.fetch_add(1, Relaxed);
|
entity.get_entity().age.fetch_add(1, Relaxed);
|
||||||
|
|
||||||
entity.tick(entity.clone(), server).await;
|
entity.tick(entity.clone(), server).await;
|
||||||
for player in self.players.read().await.values() {
|
for player in self.players.read().await.values() {
|
||||||
if player
|
if player
|
||||||
@ -767,7 +768,6 @@ impl World {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// log::debug!("spawning list size {}", spawn_list.len());
|
// log::debug!("spawning list size {}", spawn_list.len());
|
||||||
log::trace!("spawning counter {:?}", spawn_state.mob_category_counts);
|
|
||||||
|
|
||||||
spawning_chunks.shuffle(&mut rng());
|
spawning_chunks.shuffle(&mut rng());
|
||||||
|
|
||||||
|
|||||||
@ -17,13 +17,6 @@ pub struct Scoreboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Scoreboard {
|
impl Scoreboard {
|
||||||
#[must_use]
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
objectives: HashMap::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn add_objective(&mut self, world: &World, objective: ScoreboardObjective<'_>) {
|
pub async fn add_objective(&mut self, world: &World, objective: ScoreboardObjective<'_>) {
|
||||||
if self.objectives.contains_key(objective.name) {
|
if self.objectives.contains_key(objective.name) {
|
||||||
// Maybe make this an error?
|
// Maybe make this an error?
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user