use crate::{ArmorPiece, ArmorSlot, ToolItem};
#[derive(yog_data::Schema, Debug, Clone)]
pub struct FoodDef {
pub nutrition: u32,
pub saturation: f32,
pub can_always_eat: bool,
}
impl FoodDef {
pub fn new(nutrition: u32, saturation: f32) -> Self {
Self {
nutrition,
saturation,
can_always_eat: false,
}
}
pub fn can_always_eat(mut self) -> Self {
self.can_always_eat = true;
self
}
}
#[derive(yog_data::Schema, Debug, Clone)]
pub struct ItemDef {
pub id: String,
pub max_stack: u8,
pub name: Option<String>,
pub tooltip: Option<String>,
pub max_damage: u32,
pub fire_resistant: bool,
pub fuel_ticks: u32,
pub food: Option<FoodDef>,
pub tool: Option<ToolItem>,
pub armor: Option<ArmorPiece>,
pub wearable: Option<ArmorSlot>,
pub hangs: Option<Hangs>,
}
#[derive(yog_data::Schema, Debug, Clone, PartialEq)]
pub struct Hangs {
pub entity: String,
pub size: Option<[u32; 2]>,
}
impl ItemDef {
pub fn new(id: impl Into<String>) -> Self {
Self {
id: id.into(),
max_stack: 64,
name: None,
tooltip: None,
max_damage: 0,
fire_resistant: false,
fuel_ticks: 0,
food: None,
tool: None,
armor: None,
wearable: None,
hangs: None,
}
}
pub fn tool(mut self, kind: impl Into<String>, material: impl Into<String>) -> Self {
self.tool = Some(ToolItem {
kind: kind.into(),
material: material.into(),
attack_damage: None,
attack_speed: None,
});
self
}
pub fn tool_attack(mut self, damage: Option<f32>, speed: Option<f32>) -> Self {
if let Some(t) = &mut self.tool {
t.attack_damage = damage;
t.attack_speed = speed;
}
self
}
pub fn armor(mut self, slot: ArmorSlot, material: impl Into<String>) -> Self {
self.armor = Some(ArmorPiece {
slot,
material: material.into(),
});
self
}
pub fn wearable(mut self, slot: ArmorSlot) -> Self {
self.wearable = Some(slot);
self
}
pub fn hangs(mut self, entity: impl Into<String>, size: Option<[u32; 2]>) -> Self {
self.hangs = Some(Hangs {
entity: entity.into(),
size,
});
self
}
pub fn max_stack(mut self, n: u8) -> Self {
self.max_stack = n;
self
}
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
pub fn tooltip(mut self, tooltip: impl Into<String>) -> Self {
self.tooltip = Some(tooltip.into());
self
}
pub fn max_damage(mut self, durability: u32) -> Self {
self.max_damage = durability;
self
}
pub fn fire_resistant(mut self) -> Self {
self.fire_resistant = true;
self
}
pub fn fuel(mut self, ticks: u32) -> Self {
self.fuel_ticks = ticks;
self
}
pub fn food(mut self, food: FoodDef) -> Self {
self.food = Some(food);
self
}
}