Skip to content

Commit

Permalink
add new usage
Browse files Browse the repository at this point in the history
  • Loading branch information
suprohub committed Jan 1, 2025
1 parent c692423 commit da9c45a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
17 changes: 17 additions & 0 deletions pumpkin-world/src/item/item_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub struct ItemComponents {
pub attribute_modifiers: Option<AttributeModifiers>,
#[serde(rename = "minecraft:food")]
pub food: Option<Food>,
#[serde(rename = "minecraft:equippable")]
pub equippable: Option<Equippable>,
}

#[derive(Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -86,6 +88,21 @@ pub struct Food {
pub can_always_eat: Option<bool>,
}

#[derive(Deserialize, Clone, Debug)]
pub struct Equippable {
pub slot: ArmorSlot,
pub equip_sound: String,
pub asset_id: String,
}

#[derive(Deserialize, Clone, Copy, Debug)]
pub enum ArmorSlot {
Head,
Chest,
Legs,
Feet,
}

#[derive(Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum Operation {
Expand Down
21 changes: 16 additions & 5 deletions pumpkin/src/net/packet/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,12 +950,23 @@ impl Player {

log::debug!("Player eated food: {:?}", food);
}));
} else {
log::error!(
"An item was used ({}), but the use is not implemented yet",
ITEMS_REGISTRY_NAME_BY_ID.get(&item.id).unwrap()
);
return Ok(());
}

if let Some(equippable) = &item.components.equippable {
let mut inventory = self.inventory().lock().await;
let slot = equippable.slot as usize + 5;

if inventory.get_slot(slot)?.is_none() {
*inventory.get_slot(slot)? = inventory.held_item_mut().take();
}
return Ok(());
}

log::error!(
"An item was used ({}), but the use is not implemented yet",
ITEMS_REGISTRY_NAME_BY_ID.get(&item.id).unwrap()
);
Ok(())
}

Expand Down

0 comments on commit da9c45a

Please sign in to comment.