forked from feather-rs/feather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
69 lines (60 loc) · 2.06 KB
/
lib.rs
File metadata and controls
69 lines (60 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! Dealing with entities, including associated components and events.
//! Submodules here are implementations of specific entities, such as items,
//! block entities, monsters, etc. Player entities are handled in `crate::player`,
//! not here.
#[macro_use]
extern crate feather_core;
mod broadcasters;
pub mod drops;
mod fall_damage;
mod inventory;
mod mob;
mod object;
pub mod particle;
pub use self::inventory::InventoryExt;
pub use broadcasters::*;
pub use drops::on_block_break_drop_loot;
pub use fall_damage::update_blocks_fallen;
pub use mob::*;
pub use object::falling_block::{on_entity_land_remove_falling_block, spawn_falling_blocks};
pub use object::item::{item_collect, on_item_drop_spawn_item_entity};
pub use object::*;
extern crate nalgebra_glm as glm;
use feather_core::util::Position;
use feather_server_types::{NetworkId, PreviousPosition, PreviousVelocity, Velocity};
use fecs::{EntityBuilder, IntoQuery, Read, World, Write};
use std::sync::atomic::{AtomicI32, Ordering};
/// Entity ID counter, used to create new entity IDs.
pub static ENTITY_ID_COUNTER: AtomicI32 = AtomicI32::new(0);
#[fecs::system]
pub fn previous_position_velocity_reset(world: &mut World) {
<(Read<Position>, Write<PreviousPosition>)>::query().par_for_each_mut(
world.inner_mut(),
|(pos, mut previous_pos)| {
previous_pos.0 = *pos;
},
);
<(Read<Velocity>, Write<PreviousVelocity>)>::query().par_for_each_mut(
world.inner_mut(),
|(vel, mut previous_vel)| {
previous_vel.0 = vel.0;
},
);
}
/// Inserts the base components for an entity into an `EntityBuilder`.
///
/// This currently includes:
/// * Velocity (0) and PreviousVelocity
/// * Entity ID for the protocol
pub fn base() -> EntityBuilder {
let id = new_id();
EntityBuilder::new()
.with(NetworkId(id))
.with(Velocity::default())
.with(PreviousVelocity::default())
.with(PreviousPosition(position!(0.0, 0.0, 0.0)))
}
/// Returns a new entity ID.
pub fn new_id() -> i32 {
ENTITY_ID_COUNTER.fetch_add(1, Ordering::Relaxed)
}