From 6409d35f9e60f56b21cbbb53a4ce7dbdea5a634f Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 25 Sep 2019 23:04:18 +0100 Subject: [PATCH] Added flower and grass items --- common/src/comp/inventory/item.rs | 47 ++++++++++++++++++++++++++++--- common/src/terrain/block.rs | 10 +++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/common/src/comp/inventory/item.rs b/common/src/comp/inventory/item.rs index d83095d2ca..108efc4795 100644 --- a/common/src/comp/inventory/item.rs +++ b/common/src/comp/inventory/item.rs @@ -94,6 +94,21 @@ impl Consumable { } } +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub enum Ingredient { + Flower, + Grass, +} + +impl Ingredient { + pub fn name(&self) -> &'static str { + match self { + Ingredient::Flower => "flower", + Ingredient::Grass => "grass", + } + } +} + #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Debug { Boost, @@ -114,7 +129,9 @@ pub enum Item { kind: Consumable, effect: Effect, }, - Ingredient, + Ingredient { + kind: Ingredient, + }, Debug(Debug), } @@ -123,8 +140,8 @@ impl Item { match self { Item::Tool { kind, .. } => kind.name(), Item::Armor { kind, .. } => kind.name(), - Item::Consumable { .. } => "", - Item::Ingredient => "", + Item::Consumable { kind, .. } => kind.name(), + Item::Ingredient { kind } => kind.name(), Item::Debug(_) => "Debugging item", } } @@ -134,7 +151,7 @@ impl Item { Item::Tool { .. } => "tool", Item::Armor { .. } => "armour", Item::Consumable { .. } => "consumable", - Item::Ingredient => "ingredient", + Item::Ingredient { .. } => "ingredient", Item::Debug(_) => "debug", } } @@ -148,6 +165,16 @@ impl Item { BlockKind::Apple => Some(Self::apple()), BlockKind::Mushroom => Some(Self::mushroom()), BlockKind::Velorite => Some(Self::velorite()), + BlockKind::BlueFlower => Some(Self::flower()), + BlockKind::PinkFlower => Some(Self::flower()), + BlockKind::PurpleFlower => Some(Self::flower()), + BlockKind::RedFlower => Some(Self::flower()), + BlockKind::WhiteFlower => Some(Self::flower()), + BlockKind::YellowFlower => Some(Self::flower()), + BlockKind::Sunflower => Some(Self::flower()), + BlockKind::LongGrass => Some(Self::grass()), + BlockKind::MediumGrass => Some(Self::grass()), + BlockKind::ShortGrass => Some(Self::grass()), _ => None, } } @@ -174,6 +201,18 @@ impl Item { effect: Effect::Xp(250), } } + + pub fn flower() -> Self { + Item::Ingredient { + kind: Ingredient::Flower, + } + } + + pub fn grass() -> Self { + Item::Ingredient { + kind: Ingredient::Grass, + } + } } impl Default for Item { diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index 3184b9ebd8..77bb2c8768 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -131,6 +131,16 @@ impl BlockKind { pub fn is_collectible(&self) -> bool { match self { + BlockKind::BlueFlower => true, + BlockKind::PinkFlower => true, + BlockKind::PurpleFlower => true, + BlockKind::RedFlower => true, + BlockKind::WhiteFlower => true, + BlockKind::YellowFlower => true, + BlockKind::Sunflower => true, + BlockKind::LongGrass => true, + BlockKind::MediumGrass => true, + BlockKind::ShortGrass => true, BlockKind::Apple => true, BlockKind::Mushroom => true, BlockKind::Velorite => true,