Skip to content

Commit 1ad208c

Browse files
committed
feat(tag): update game items when break blocks
1 parent 5400609 commit 1ad208c

File tree

3 files changed

+18
-39
lines changed

3 files changed

+18
-39
lines changed

crates/hyperion/src/egress/sync_entity_state.rs

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,49 +40,27 @@ impl Module for EntityStateSyncModule {
4040
.singleton()
4141
.multi_threaded()
4242
.kind::<flecs::pipeline::OnStore>()
43-
.run(|mut table| {
44-
while table.next() {
45-
let world = table.world();
46-
47-
unsafe {
48-
const _: () = assert!(size_of::<Xp>() == size_of::<u16>());
49-
const _: () = assert!(align_of::<Xp>() == align_of::<u16>());
50-
51-
let compose = table.field_unchecked::<Compose>(0);
52-
let compose = compose.first().unwrap();
53-
54-
let net = table.field_unchecked::<NetworkStreamRef>(1);
55-
let net = net.get(..).unwrap();
56-
57-
let mut prev_xp = table.field_unchecked::<Xp>(2);
58-
let prev_xp = prev_xp.get_mut(..).unwrap();
59-
60-
let mut xp = table.field_unchecked::<Xp>(3);
61-
let xp = xp.get_mut(..).unwrap();
62-
63-
for (idx, (prev, current)) in itertools::zip_eq(prev_xp, xp).enumerate() {
64-
if prev == current {
65-
continue;
66-
}
43+
.each_entity(|entity, (compose, net, prev, current)| {
44+
let world = entity.world();
45+
if prev == current {
46+
return;
47+
}
6748

68-
let net = net.get(idx).unwrap();
49+
entity.modified::<Xp>();
6950

70-
let visual = current.get_visual();
51+
let visual = current.get_visual();
7152

72-
let packet = play::ExperienceBarUpdateS2c {
73-
bar: visual.prop,
74-
level: VarInt(i32::from(visual.level)),
75-
total_xp: VarInt::default(),
76-
};
53+
let packet = play::ExperienceBarUpdateS2c {
54+
bar: visual.prop,
55+
level: VarInt(i32::from(visual.level)),
56+
total_xp: VarInt::default(),
57+
};
7758

78-
compose
79-
.unicast(&packet, *net, SystemId(100), &world)
80-
.unwrap();
59+
compose
60+
.unicast(&packet, *net, SystemId(100), &world)
61+
.unwrap();
8162

82-
*prev = *current;
83-
}
84-
}
85-
}
63+
*prev = *current;
8664
});
8765

8866
system!("entity_metadata_sync", world, &Compose($), &mut MetadataChanges)

crates/hyperion/src/simulation/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ impl Module for SimModule {
556556

557557
world.set(prefabs);
558558

559-
world.component::<Xp>();
559+
world.component::<Xp>().meta();
560560

561561
world.component::<PlayerSkin>();
562562
world.component::<Command>();

events/tag/src/module/level.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl Module for LevelModule {
3939
.filter()
4040
.each_entity(
4141
|entity, (xp, upgraded_to, rank, team, main_block_count, inventory)| {
42+
println!("update");
4243
let new_level = xp.get_visual().level;
4344
let world = entity.world();
4445
let level_diff = new_level - upgraded_to.value;

0 commit comments

Comments
 (0)