diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fca9e4e09..0a48e155e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bamboo collectibles now spawn near rivers - Chest sprites can longer be exploded - Smoke varies by temperature, humidity, time of day and house +- Added loot ownership for drops from mining ### Changed diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index c08cbca453..e374f8f8f5 100644 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -8,8 +8,9 @@ use common::{ agent::{AgentEvent, Sound, SoundKind}, dialogue::Subject, inventory::slot::EquipSlot, + loot_owner::LootOwnerKind, tool::ToolKind, - Inventory, Pos, SkillGroupKind, + Inventory, LootOwner, Pos, SkillGroupKind, }, consts::{MAX_MOUNT_RANGE, SOUND_TRAVEL_DIST_PER_VOLUME}, event::EventBus, @@ -169,6 +170,8 @@ pub fn handle_mine_block( if let Some(block) = block.filter(|b| b.mine_tool().map_or(false, |t| Some(t) == tool)) { // Drop item if one is recoverable from the block if let Some(mut item) = comp::Item::try_reclaim_from_block(block) { + let maybe_uid = state.ecs().uid_from_entity(entity); + if let Some(mut skillset) = state .ecs() .write_storage::() @@ -176,7 +179,7 @@ pub fn handle_mine_block( { if let (Some(tool), Some(uid), Some(exp_reward)) = ( tool, - state.ecs().uid_from_entity(entity), + maybe_uid, item.item_definition_id() .itemdef_id() .and_then(|id| RESOURCE_EXPERIENCE_MANIFEST.read().0.get(id).copied()), @@ -232,10 +235,15 @@ pub fn handle_mine_block( let _ = item.increase_amount(1); } } - state + let item_drop = state .create_item_drop(Default::default(), item) - .with(comp::Pos(pos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0))) - .build(); + .with(comp::Pos(pos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0))); + if let Some(uid) = maybe_uid { + item_drop.with(LootOwner::new(LootOwnerKind::Player(uid))) + } else { + item_drop + } + .build(); } state.set_block(pos, block.into_vacant());