mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added item drops
This commit is contained in:
parent
b3cae2f3dd
commit
995090d2d4
@ -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<Self>;
|
||||
type Storage = FlaggedStorage<Self, IDVStorage<Self>>;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -25,6 +25,7 @@ sphynx::sum_type! {
|
||||
CanBuild(comp::CanBuild),
|
||||
Stats(comp::Stats),
|
||||
LightEmitter(comp::LightEmitter),
|
||||
Item(comp::Item),
|
||||
}
|
||||
}
|
||||
// Automatically derive From<T> for EcsCompPhantom
|
||||
@ -40,6 +41,7 @@ sphynx::sum_type! {
|
||||
CanBuild(PhantomData<comp::CanBuild>),
|
||||
Stats(PhantomData<comp::Stats>),
|
||||
LightEmitter(PhantomData<comp::LightEmitter>),
|
||||
Item(PhantomData<comp::Item>),
|
||||
}
|
||||
}
|
||||
impl sphynx::CompPacket for EcsCompPacket {
|
||||
|
@ -131,6 +131,7 @@ impl State {
|
||||
ecs.register_synced::<comp::Stats>();
|
||||
ecs.register_synced::<comp::CanBuild>();
|
||||
ecs.register_synced::<comp::LightEmitter>();
|
||||
ecs.register_synced::<comp::Item>();
|
||||
|
||||
// Register components send from clients -> server
|
||||
ecs.register::<comp::Controller>();
|
||||
|
@ -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::<comp::Inventory>()
|
||||
.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::<comp::Pos>().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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user