also add contributors to /pumpkin command Co-Authored-By: Fyor <90567841+fyordev@users.noreply.github.com> Co-Authored-By: MartV0 <34748938+martv0@users.noreply.github.com> Co-Authored-By: FabseGP <fabsegp@fabseman.space>
60 lines
1.3 KiB
Rust
60 lines
1.3 KiB
Rust
use std::{collections::HashMap, sync::Arc};
|
|
|
|
use pumpkin_data::data_component_impl::EquipmentSlot;
|
|
use pumpkin_world::item::ItemStack;
|
|
use tokio::sync::Mutex;
|
|
|
|
// EntityEquipment.java
|
|
#[derive(Clone)]
|
|
pub struct EntityEquipment {
|
|
pub equipment: HashMap<EquipmentSlot, Arc<Mutex<ItemStack>>>,
|
|
}
|
|
|
|
impl Default for EntityEquipment {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
impl EntityEquipment {
|
|
#[must_use]
|
|
pub fn new() -> Self {
|
|
Self {
|
|
equipment: HashMap::new(),
|
|
}
|
|
}
|
|
|
|
pub async fn put(&mut self, slot: &EquipmentSlot, stack: ItemStack) -> ItemStack {
|
|
self.equipment
|
|
.insert(slot.clone(), Arc::new(Mutex::new(stack)))
|
|
.unwrap_or(Arc::new(Mutex::new(ItemStack::EMPTY.clone())))
|
|
.lock()
|
|
.await
|
|
.clone()
|
|
}
|
|
|
|
#[must_use]
|
|
pub fn get(&self, slot: &EquipmentSlot) -> Arc<Mutex<ItemStack>> {
|
|
self.equipment
|
|
.get(slot)
|
|
.cloned()
|
|
.unwrap_or(Arc::new(Mutex::new(ItemStack::EMPTY.clone())))
|
|
}
|
|
|
|
pub async fn is_empty(&self) -> bool {
|
|
for stack in self.equipment.values() {
|
|
if !stack.lock().await.is_empty() {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
true
|
|
}
|
|
|
|
pub fn clear(&mut self) {
|
|
self.equipment.clear();
|
|
}
|
|
|
|
// TODO: tick
|
|
}
|