Skip to content

Commit 2ef4dea

Browse files
committed
Add EntityBitMask bitflag for entity metadata bitmask
1 parent 7ec3ad1 commit 2ef4dea

5 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎server/Cargo.toml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ smallvec = "0.6.10"
3737
lazy_static = "1.3.0"
3838
nalgebra-glm = "0.4.0"
3939
derive_deref = "1.1.0"
40-
feather_codegen = { path = "../codegen" }
40+
feather_codegen = { path = "../codegen" }
41+
bitflags = "1.1.0"

‎server/src/entity/metadata.rs‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
//! Definition for entity metadata enum.
22
use feather_core::{EntityMetadata, Slot};
33

4+
bitflags! {
5+
pub struct EntityBitMask: u8 {
6+
const ON_FIRE = 0x01;
7+
const CROUCHED = 0x02;
8+
const SPRITING = 0x08;
9+
const SWIMMING = 0x10;
10+
const INVISIBLE = 0x20;
11+
const GLOWING_EFFECT = 0x40;
12+
const FLYING_WITH_ELYTRA = 0x80;
13+
}
14+
}
15+
416
entity_metadata! {
517
Metadata,
618
Entity {
@@ -21,11 +33,16 @@ mod tests {
2133

2234
#[test]
2335
fn test_basic() {
24-
let mut meta = Metadata::Entity(Entity::new(0, 0, false, false));
36+
let mut meta = Metadata::Entity(Entity::new(
37+
(EntityBitMask::ON_FIRE | EntityBitMask::CROUCHED).bits(),
38+
0,
39+
false,
40+
false,
41+
));
2542

2643
let raw = meta.to_raw_metadata();
2744

28-
assert_eq!(raw.get(0), Some(MetaEntry::Byte(0)));
45+
assert_eq!(raw.get(0), Some(MetaEntry::Byte(0b0000_0011)));
2946
assert_eq!(raw.get(5), Some(MetaEntry::Boolean(false)));
3047
assert_eq!(raw.get(6), None);
3148
}

‎server/src/entity/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ mod types;
1212
pub use broadcast::{EntityBroadcastSystem, EntitySpawnEvent};
1313
pub use component::{EntityComponent, PlayerComponent, VelocityComponent};
1414
pub use destroy::{EntityDestroyBroadcastSystem, EntityDestroyEvent, EntityDestroySystem};
15-
pub use metadata::Metadata;
15+
pub use metadata::{EntityBitMask, Metadata};
1616
pub use movement::{broadcast_entity_movement, EntityMoveBroadcastSystem, EntityMoveEvent};
1717
pub use types::EntityType;

‎server/src/main.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ extern crate lazy_static;
2222
extern crate derive_deref;
2323
#[macro_use]
2424
extern crate feather_codegen;
25+
#[macro_use]
26+
extern crate bitflags;
2527

2628
extern crate nalgebra_glm as glm;
2729

0 commit comments

Comments
 (0)