Skip to content

Commit b2940fe

Browse files
committed
Bugfix sending gamemodes
- Make sure to check if the gamemode is explicitly defined
1 parent 9d07add commit b2940fe

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

mcidle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def init():
8282
if not args.username or not args.password:
8383
print("Can't re-auth user because no user or password provided!", flush=True)
8484
return
85-
print("Username or password wrong, waiting 30 seconds before reconnecting..")
85+
print("Username or password wrong, waiting 15 seconds before reconnecting..")
8686
time.sleep(15)
8787

8888
if __name__ == '__main__':

src/networking/packet_handler/clientbound/login_handler.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@ def join_world(self):
115115
# Send their last held item
116116
self.connection.send_packet_raw(HeldItemChangeClientbound(Slot=self.mc_connection.game_state.held_item_slot))
117117

118-
# Send their current gamemode
119-
if self.mc_connection.game_state.gamemode:
118+
# Send their current gamemode if it's defined
119+
if self.mc_connection.game_state.gamemode is not None:
120+
print("Sent gamemode", self.mc_connection.game_state.gamemode, flush=True)
120121
self.connection.send_packet_raw(GameState(Reason=3,\
121122
Value=self.mc_connection.game_state.gamemode))
123+
else:
124+
print("Gamemode not present", flush=True)
122125
# Send their inventory
123126
self.connection.send_single_packet_dict(self.mc_connection.game_state.main_inventory)
124127

src/networking/packet_handler/packet_processor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def process_packet(self, packet):
9797
elif packet.id == GameStateP.id:
9898
game_state = GameStateP().read(packet.packet_buffer)
9999
if game_state.Reason == 3: # Change Gamemode
100+
print("Set gamemode to ", game_state.Value, flush=True)
100101
self.game_state.gamemode = game_state.Value
101102
elif packet.id == SetSlot.id:
102103
set_slot = SetSlot().read(packet.packet_buffer)
@@ -109,11 +110,12 @@ def process_packet(self, packet):
109110
# In case the gamemode is changed through a respawn packet
110111
respawn = Respawn().read(packet.packet_buffer)
111112
self.game_state.gamemode = respawn.Gamemode
113+
print("Set gamemode to", respawn.Gamemode, flush=True)
112114
elif packet.id == UpdateHealth.id:
113115
update_health = UpdateHealth().read(packet.packet_buffer)
114116
self.game_state.update_health = update_health
115117
# Respawn the player if they're dead..
116-
print(update_health, flush=True)
118+
print("Health: %s" % update_health.Health, flush=True)
117119
if update_health.Health == 0:
118120
print("Client died, respawning", flush=True)
119121
return ClientStatus(ActionID=0)

0 commit comments

Comments
 (0)