11from src .networking .packets .serverbound import KeepAlive as KeepAliveServerbound , TeleportConfirm , ClientStatus
22from src .networking .packets .clientbound import ChunkData , UnloadChunk , SpawnEntity , \
33 DestroyEntities , KeepAlive , ChatMessage , PlayerPositionAndLook , TimeUpdate , \
4- HeldItemChange , SetSlot , PlayerListItem , PlayerAbilities , Respawn , UpdateHealth
4+ HeldItemChange , SetSlot , PlayerListItem , PlayerAbilities , Respawn , UpdateHealth , JoinGame
55
66from src .networking .packets .clientbound import GameState as GameStateP
77
@@ -67,6 +67,16 @@ def chunk_load(self, packet):
6767
6868 def process_packet (self , packet ):
6969 with self .game_state .state_lock :
70+ if packet .id == Respawn .id :
71+ # In case the gamemode is changed through a respawn packet
72+ respawn = Respawn ().read (packet .packet_buffer )
73+ self .game_state .gamemode = respawn .Gamemode
74+ print ("Set gamemode to" , respawn .Gamemode , flush = True )
75+ if packet .id == JoinGame .id :
76+ join_game = JoinGame ().read (packet .packet_buffer )
77+ self .game_state .gamemode = join_game .Gamemode & 3 # Bit 4 (0x8) is the hardcore flaga
78+ print ("Set gamemode to" , self .game_state .gamemode , "JoinGame" , flush = True )
79+
7080 if packet .id in self .game_state .join_ids :
7181 self .game_state .packet_log [packet .id ] = packet
7282 elif packet .id == ChunkData .id : # ChunkData
@@ -111,11 +121,6 @@ def process_packet(self, packet):
111121 self .player_list (packet )
112122 elif packet .id == PlayerAbilities .id :
113123 self .game_state .abilities = PlayerAbilities ().read (packet .packet_buffer )
114- elif packet .id == Respawn .id :
115- # In case the gamemode is changed through a respawn packet
116- respawn = Respawn ().read (packet .packet_buffer )
117- self .game_state .gamemode = respawn .Gamemode
118- print ("Set gamemode to" , respawn .Gamemode , flush = True )
119124 elif packet .id == UpdateHealth .id :
120125 update_health = UpdateHealth ().read (packet .packet_buffer )
121126 self .game_state .update_health = update_health
@@ -125,4 +130,5 @@ def process_packet(self, packet):
125130 print ("Client died, respawning" , flush = True )
126131 return ClientStatus (ActionID = 0 )
127132
133+
128134 return None
0 commit comments