diff --git a/common/src/comp/inventory/item.rs b/common/src/comp/inventory/item.rs index 3cb7578a4a..9e984b28c9 100644 --- a/common/src/comp/inventory/item.rs +++ b/common/src/comp/inventory/item.rs @@ -1,4 +1,4 @@ -use specs::Component; +use specs::{Component, FlaggedStorage}; use specs_idvs::IDVStorage; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -62,5 +62,5 @@ impl Default for Item { } impl Component for Item { - type Storage = IDVStorage; + type Storage = FlaggedStorage>; } diff --git a/common/src/comp/mod.rs b/common/src/comp/mod.rs index 20ec83c0d6..65ce76c53f 100644 --- a/common/src/comp/mod.rs +++ b/common/src/comp/mod.rs @@ -20,7 +20,7 @@ pub use controller::Controller; pub use inputs::{ Attacking, CanBuild, Gliding, Jumping, MoveDir, OnGround, Respawning, Rolling, Wielding, }; -pub use inventory::{item, Inventory, InventoryUpdate}; +pub use inventory::{item, Inventory, InventoryUpdate, Item}; pub use last::Last; pub use phys::{ForceUpdate, Ori, Pos, Vel}; pub use player::Player; diff --git a/common/src/msg/ecs_packet.rs b/common/src/msg/ecs_packet.rs index b2f3d8bbbe..56bf63c68a 100644 --- a/common/src/msg/ecs_packet.rs +++ b/common/src/msg/ecs_packet.rs @@ -25,6 +25,7 @@ sphynx::sum_type! { CanBuild(comp::CanBuild), Stats(comp::Stats), LightEmitter(comp::LightEmitter), + Item(comp::Item), } } // Automatically derive From for EcsCompPhantom @@ -40,6 +41,7 @@ sphynx::sum_type! { CanBuild(PhantomData), Stats(PhantomData), LightEmitter(PhantomData), + Item(PhantomData), } } impl sphynx::CompPacket for EcsCompPacket { diff --git a/common/src/state.rs b/common/src/state.rs index 8934f484e3..ee8bcb7d2e 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -131,6 +131,7 @@ impl State { ecs.register_synced::(); ecs.register_synced::(); ecs.register_synced::(); + ecs.register_synced::(); // Register components send from clients -> server ecs.register::(); diff --git a/server/src/lib.rs b/server/src/lib.rs index c064818dc2..f0dd5e70ac 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -419,6 +419,7 @@ impl Server { let mut disconnected_clients = Vec::new(); let mut requested_chunks = Vec::new(); let mut modified_blocks = Vec::new(); + let mut dropped_items = Vec::new(); self.clients.remove_if(|entity, client| { let mut disconnect = false; @@ -499,12 +500,19 @@ impl Server { state.write_component(entity, comp::InventoryUpdate); } ClientMsg::DropInventorySlot(x) => { - state + let item = state .ecs() .write_storage::() .get_mut(entity) - .map(|inv| inv.remove(x)); // TODO: Spawn an item drop entity + .and_then(|inv| inv.remove(x)); + state.write_component(entity, comp::InventoryUpdate); + + if let (Some(pos), Some(item)) = + (state.ecs().read_storage::().get(entity), item) + { + dropped_items.push((*pos, item)); + } } ClientMsg::Character { name, body } => match client.client_state { // Become Registered first. @@ -682,6 +690,12 @@ impl Server { self.state.set_block(pos, block); } + for (pos, item) in dropped_items { + self.create_object(pos, comp::object::Body::Crate) + .with(item) + .build(); + } + Ok(frontend_events) }