@@ -38,14 +38,14 @@ use uuid::Uuid;
3838
3939use crate :: {
4040 protocol:: {
41- datatypes:: { Bounded , VarInt } ,
41+ datatypes:: { Bounded , Slot , VarInt } ,
4242 packets:: {
4343 login:: * ,
4444 play:: {
4545 ConfirmTeleportS , GameEvent , GameEventC , Gamemode , KeepAliveC , LoginPlayC ,
4646 OpenScreenC , PlayerInfoUpdateC , PlayerStatus , SetBorderCenterC , SetBorderSizeC ,
47- SetCenterChunkC , SetPlayerPositionAndRotationS , SetPlayerPositionS ,
48- SetTickingStateC , StepTicksC , SynchronisePositionC , UseItemOnS ,
47+ SetCenterChunkC , SetContainerContentC , SetPlayerPositionAndRotationS ,
48+ SetPlayerPositionS , SetTickingStateC , StepTicksC , SynchronisePositionC , UseItemOnS ,
4949 } ,
5050 } ,
5151 Frame , Packet , PacketState ,
@@ -76,7 +76,7 @@ pub struct Player {
7676
7777 entity : RwLock < Entity > ,
7878
79- next_window_id : AtomicU8 ,
79+ next_window_id : Mutex < u8 > ,
8080 window : RwLock < Option < Window > > ,
8181}
8282
@@ -113,7 +113,7 @@ impl SharedPlayer {
113113
114114 entity : RwLock :: new ( Entity :: default ( ) ) ,
115115
116- next_window_id : AtomicU8 :: new ( 0 ) ,
116+ next_window_id : Mutex :: new ( 1 ) ,
117117 window : RwLock :: new ( None ) ,
118118 } ) )
119119 }
@@ -570,7 +570,15 @@ impl SharedPlayer {
570570 match server. get_container ( x, y, z) {
571571 None => ( ) ,
572572 Some ( container) => {
573- let id = self . 0 . next_window_id . fetch_add ( 1 , Ordering :: Relaxed ) ;
573+ let id = {
574+ let mut next_window_id = self . 0 . next_window_id . lock ( ) . await ;
575+ let id = * next_window_id;
576+ * next_window_id = next_window_id. wrapping_add ( 1 ) ;
577+ if * next_window_id == 0 {
578+ * next_window_id = 1 ;
579+ }
580+ id
581+ } ;
574582
575583 let window = Window {
576584 id,
@@ -580,6 +588,17 @@ impl SharedPlayer {
580588
581589 self . 0 . io . tx ( & OpenScreenC :: from ( & window) ) . await ?;
582590
591+ self . 0
592+ . io
593+ . tx ( & SetContainerContentC {
594+ window_id : id,
595+ // FIXME: track this correctly
596+ state_id : 0 ,
597+ slot_data : container. 0 ,
598+ carried_item : Slot :: default ( ) ,
599+ } )
600+ . await ?;
601+
583602 {
584603 let mut sw = self . 0 . window . write ( ) . await ;
585604 * sw = Some ( window) ;
0 commit comments