diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index 53d3adde18..8a0ba0f5cf 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -804,14 +804,14 @@ impl Item { .any(|tag| matches!(tag, ItemTag::SalvageInto(_))) } - // Attempts to salvage an item, returning the salvaged items if salvageable, - // else the original item is not Theoretically supports returning multiple - // items, only returns one per tag in the item for now + // Attempts to salvage an item by consuming it, returns the salvaged items if + // salvageable, else the original item pub fn try_salvage(self) -> Result, Item> { if !self.is_salvageable() { return Err(self); } + // Creates one item for every salvage tag in the target item let salvaged_items: Vec<_> = self .item_def .tags diff --git a/common/src/recipe.rs b/common/src/recipe.rs index 2ceea34c11..a5398ff034 100644 --- a/common/src/recipe.rs +++ b/common/src/recipe.rs @@ -37,6 +37,11 @@ impl Recipe { let mut recipe_inputs = Vec::new(); let mut unsatisfied_requirements = Vec::new(); + // Checks each input against a slot in the inventory. If the slot contains an + // item that fulfills the need of the input, takes from the inventory up to the + // quantity needed for the crafting input. If the item either cannot be used, or + // there is insufficient quantity, adds input and number of materials needed to + // unsatisfied requirements. self.inputs .iter() .enumerate() @@ -65,10 +70,12 @@ impl Recipe { } }); + // If there are no unsatisfied requirements, create the items produced by the + // recipe in the necessary quantity, else insert the ingredients back into the + // inventory if unsatisfied_requirements.is_empty() { let (item_def, quantity) = &self.output; - let crafted_item = - Item::new_from_item_def(Arc::clone(item_def), &[], ability_map, msm); + let crafted_item = Item::new_from_item_def(Arc::clone(item_def), &[], ability_map, msm); let mut crafted_items = Vec::with_capacity(*quantity as usize); for _ in 0..*quantity { crafted_items.push(crafted_item.duplicate(ability_map, msm)); diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index d3b8c4c627..3fa3a07bb0 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -647,24 +647,6 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Craft), ); } - - // Drop the item if there wasn't enough space - // if let Some(Some((item, amount))) = craft_result { - // let ability_map = &state.ecs().read_resource::(); - // let msm = - // state.ecs().read_resource::(); - // for _ in 0..amount { - // dropped_items.push(( - // state - // .read_component_copied::(entity) - // .unwrap_or_default(), - // state - // .read_component_copied::(entity) - // .unwrap_or_default(), - // item.duplicate(ability_map, &msm), - // )); - // } - // } }, comp::InventoryManip::Sort => { inventory.sort();