mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-31 08:22:33 +00:00
fix: some bugs
This commit is contained in:
4
pumpkin-codegen/Cargo.lock
generated
4
pumpkin-codegen/Cargo.lock
generated
@@ -905,9 +905,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.50.0"
|
||||
version = "1.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d"
|
||||
checksum = "2bd1c4c0fc4a7ab90fc15ef6daaa3ec3b893f004f915f2392557ed23237820cd"
|
||||
dependencies = [
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
@@ -381,9 +381,7 @@ impl ToTokens for MaterialConditionStruct {
|
||||
"floor" => quote!(
|
||||
pumpkin_util::math::vertical_surface_type::VerticalSurfaceType::Floor
|
||||
),
|
||||
_ => quote!(
|
||||
pumpkin_util::math::vertical_surface_type::VerticalSurfaceType::Floor
|
||||
),
|
||||
_ => quote!(panic!("Unknown surface type")),
|
||||
};
|
||||
|
||||
tokens.extend(quote!(
|
||||
|
||||
@@ -13,8 +13,7 @@ use crate::loot::LootTableStruct;
|
||||
pub struct EntityType {
|
||||
/// Numeric registry ID for this entity type.
|
||||
pub id: u16,
|
||||
/// Base maximum health points, if defined.
|
||||
pub max_health: Option<f32>,
|
||||
pub attributes: Option<Vec<BTreeMap<String, f64>>>,
|
||||
/// Whether this entity can be attacked by players or other entities.
|
||||
pub attackable: Option<bool>,
|
||||
/// Whether this entity is classified as a mob (affects spawning mechanics).
|
||||
@@ -85,11 +84,18 @@ impl ToTokens for NamedEntityType<'_> {
|
||||
let entity = self.1;
|
||||
let id = LitInt::new(&entity.id.to_string(), proc_macro2::Span::call_site());
|
||||
|
||||
let max_health = if let Some(mh) = entity.max_health {
|
||||
quote! { Some(#mh) }
|
||||
} else {
|
||||
quote! { None }
|
||||
};
|
||||
let attribute_tokens = entity.attributes.as_ref().map(|vec| {
|
||||
vec.iter().map(|map| {
|
||||
let (key, value) = map.iter().next().unwrap();
|
||||
let key = key.strip_prefix("minecraft:").unwrap_or(key);
|
||||
// Replace dots with underscores and uppercase for Enum naming (e.g. generic.max_health -> GENERIC_MAX_HEALTH)
|
||||
let enum_variant = format_ident!("{}", key.replace('.', "_").to_uppercase());
|
||||
|
||||
quote! { (Attributes::#enum_variant, #value) }
|
||||
}).collect::<Vec<_>>()
|
||||
}).unwrap_or_default();
|
||||
|
||||
let attributes_field = quote! { &[#(#attribute_tokens),*] };
|
||||
|
||||
let attackable = if let Some(a) = entity.attackable {
|
||||
quote! { Some(#a) }
|
||||
@@ -160,7 +166,7 @@ impl ToTokens for NamedEntityType<'_> {
|
||||
tokens.extend(quote! {
|
||||
EntityType {
|
||||
id: #id,
|
||||
max_health: #max_health,
|
||||
attributes: #attributes_field,
|
||||
attackable: #attackable,
|
||||
mob: #mob,
|
||||
saveable: #saveable,
|
||||
@@ -213,6 +219,7 @@ pub fn build() -> TokenStream {
|
||||
use crate::data_component_impl::IDSetContent;
|
||||
use crate::tag::Taggable;
|
||||
use crate::tag::RegistryKey;
|
||||
use crate::attributes::Attributes;
|
||||
use pumpkin_util::loot_table::*;
|
||||
use pumpkin_util::HeightMap;
|
||||
use std::hash::Hash;
|
||||
@@ -220,7 +227,7 @@ pub fn build() -> TokenStream {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EntityType {
|
||||
pub id: u16,
|
||||
pub max_health: Option<f32>,
|
||||
pub attributes: &'static [(Attributes, f64)],
|
||||
pub attackable: Option<bool>,
|
||||
pub mob: bool,
|
||||
pub saveable: bool,
|
||||
|
||||
@@ -126,8 +126,7 @@ fn value_to_placement_modifier(v: &Value) -> TokenStream {
|
||||
quote! { PlacementModifier::FixedPlacement(vec![#(#positions),*]) }
|
||||
}
|
||||
"minecraft:heightmap" => {
|
||||
let heightmap =
|
||||
value_to_height_map(v["heightmap"].as_str().unwrap_or("MOTION_BLOCKING"));
|
||||
let heightmap = value_to_height_map(v["heightmap"].as_str().unwrap());
|
||||
quote! {
|
||||
PlacementModifier::Heightmap(HeightmapPlacementModifier {
|
||||
heightmap: #heightmap,
|
||||
|
||||
Reference in New Issue
Block a user