Display when the bot is loading chunks
This commit is contained in:
		
							
								
								
									
										14
									
								
								bot.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								bot.py
									
									
									
									
									
								
							@@ -55,10 +55,18 @@ def tick(global_state):
 | 
				
			|||||||
    target = None
 | 
					    target = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # make sure current chunks are loaded for physics
 | 
					    # make sure current chunks are loaded for physics
 | 
				
			||||||
    if not g.chunks.check_loaded(p, 9):
 | 
					    if not g.chunks.check_loaded(p, 288):
 | 
				
			||||||
 | 
					        if not g.chunks.loading:
 | 
				
			||||||
 | 
					            print('Loading chunks', end='', flush=True)
 | 
				
			||||||
 | 
					            g.chunks.loading = True
 | 
				
			||||||
        packet = serverbound.play.PositionAndLookPacket(x=p.x, feet_y=p.y, z=p.z, pitch=0, yaw=0, on_ground=True)
 | 
					        packet = serverbound.play.PositionAndLookPacket(x=p.x, feet_y=p.y, z=p.z, pitch=0, yaw=0, on_ground=True)
 | 
				
			||||||
        g.connection.write_packet(packet, force=True)
 | 
					        g.connection.write_packet(packet, force=True)
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        if g.chunks.loading:
 | 
				
			||||||
 | 
					            print()
 | 
				
			||||||
 | 
					            print('Chunks loaded.')
 | 
				
			||||||
 | 
					        g.chunks.loading = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    g.chunks.unload_chunks(p)
 | 
					    g.chunks.unload_chunks(p)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -246,10 +254,6 @@ def bot(global_state):
 | 
				
			|||||||
            time.sleep(utils.TICK)
 | 
					            time.sleep(utils.TICK)
 | 
				
			||||||
        print('Player loaded.')
 | 
					        print('Player loaded.')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while not g.chunks.check_loaded(g.pos, 288):
 | 
					 | 
				
			||||||
            time.sleep(utils.TICK)
 | 
					 | 
				
			||||||
        print('Chunks loaded.')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        init(g)
 | 
					        init(g)
 | 
				
			||||||
        g.game.close_window()
 | 
					        g.game.close_window()
 | 
				
			||||||
        print('Initialized.')
 | 
					        print('Initialized.')
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,6 +44,7 @@ class ChunksManager:
 | 
				
			|||||||
        self.chunks = {}
 | 
					        self.chunks = {}
 | 
				
			||||||
        self.biomes = {}
 | 
					        self.biomes = {}
 | 
				
			||||||
        self.index = {}
 | 
					        self.index = {}
 | 
				
			||||||
 | 
					        self.loading = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def handle_block(self, block_packet):
 | 
					    def handle_block(self, block_packet):
 | 
				
			||||||
        self.set_block_at(block_packet.location.x, block_packet.location.y, block_packet.location.z, block_packet.block_state_id)
 | 
					        self.set_block_at(block_packet.location.x, block_packet.location.y, block_packet.location.z, block_packet.block_state_id)
 | 
				
			||||||
@@ -74,6 +75,8 @@ class ChunksManager:
 | 
				
			|||||||
                        self.index[item_id].append(coords)
 | 
					                        self.index[item_id].append(coords)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.biomes[(chunk_packet.x, None, chunk_packet.z)] = chunk_packet.biomes # FIXME
 | 
					        self.biomes[(chunk_packet.x, None, chunk_packet.z)] = chunk_packet.biomes # FIXME
 | 
				
			||||||
 | 
					        if self.loading:
 | 
				
			||||||
 | 
					            print('.', end='', flush=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def register(self, connection):
 | 
					    def register(self, connection):
 | 
				
			||||||
        connection.register_packet_listener(self.handle_block, clientbound.play.BlockChangePacket)
 | 
					        connection.register_packet_listener(self.handle_block, clientbound.play.BlockChangePacket)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user