Set sand origin when command is given
This commit is contained in:
		
							
								
								
									
										2
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.py
									
									
									
									
									
								
							@@ -20,6 +20,7 @@ g.name = None
 | 
			
		||||
g.mcdata = False
 | 
			
		||||
g.pos = False
 | 
			
		||||
g.dimension = None
 | 
			
		||||
g.item_lock = False
 | 
			
		||||
g.inv = {}
 | 
			
		||||
g.objects = {}
 | 
			
		||||
g.mobs = {}
 | 
			
		||||
@@ -32,6 +33,7 @@ g.holding = 0
 | 
			
		||||
g.afk = False
 | 
			
		||||
g.health = 20
 | 
			
		||||
g.food = 20
 | 
			
		||||
g.sand_origin = None
 | 
			
		||||
 | 
			
		||||
@app.route('/')
 | 
			
		||||
def hello_world():
 | 
			
		||||
 
 | 
			
		||||
@@ -268,6 +268,8 @@ class Commands:
 | 
			
		||||
                        self.g.job.state = self.g.job.gather_wood
 | 
			
		||||
                        reply = 'ok'
 | 
			
		||||
                    elif data == 'sand':
 | 
			
		||||
                        if not self.g.sand_origin or not self.g.chunks.check_loaded(self.g.sand_origin):
 | 
			
		||||
                            self.g.sand_origin = utils.pint(self.g.pos)
 | 
			
		||||
                        self.g.job.state = self.g.job.gather_sand
 | 
			
		||||
                        reply = 'ok'
 | 
			
		||||
 | 
			
		||||
@@ -288,6 +290,8 @@ class Commands:
 | 
			
		||||
                        self.g.job.state = self.g.job.farm_wood
 | 
			
		||||
                        reply = 'ok'
 | 
			
		||||
                    elif data == 'sand':
 | 
			
		||||
                        if not self.g.sand_origin or not self.g.chunks.check_loaded(self.g.sand_origin):
 | 
			
		||||
                            self.g.sand_origin = utils.pint(self.g.pos)
 | 
			
		||||
                        self.g.job.state = self.g.job.farm_sand
 | 
			
		||||
                        reply = 'ok'
 | 
			
		||||
                    elif data == 'wart':
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,9 @@ class GatherSandStates:
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
    def init(self):
 | 
			
		||||
        if not self.g.sand_origin or not self.g.chunks.check_loaded(self.g.sand_origin):
 | 
			
		||||
            self.g.sand_origin = utils.pint(self.g.pos)
 | 
			
		||||
 | 
			
		||||
        self.state = self.select_shovel
 | 
			
		||||
 | 
			
		||||
    def select_shovel(self):
 | 
			
		||||
@@ -36,10 +39,11 @@ class GatherSandStates:
 | 
			
		||||
    def find_new_slice(self):
 | 
			
		||||
        print('Finding new slice...')
 | 
			
		||||
        w = self.g.world
 | 
			
		||||
        origin = self.g.sand_origin
 | 
			
		||||
 | 
			
		||||
        print('using origin', self.origin)
 | 
			
		||||
        print('using origin', self.g.sand_origin)
 | 
			
		||||
        start = time.time()
 | 
			
		||||
        self.prev_layer, s = w.find_sand_slice(self.origin, 200, 10, self.bad_slices, self.prev_layer)
 | 
			
		||||
        self.prev_layer, s = w.find_sand_slice(self.g.sand_origin, 200, 10, self.bad_slices, self.prev_layer)
 | 
			
		||||
        print('Found slice:', s, 'in', time.time() - start, 'seconds')
 | 
			
		||||
 | 
			
		||||
        if s:
 | 
			
		||||
@@ -117,8 +121,6 @@ class GatherSandStates:
 | 
			
		||||
        self.g = global_state
 | 
			
		||||
        self.state = self.idle
 | 
			
		||||
 | 
			
		||||
        self.origin = utils.pint(self.g.pos)
 | 
			
		||||
        self.origin = (2019, 64, 238)
 | 
			
		||||
        self.slice = None
 | 
			
		||||
        self.bad_slices = []
 | 
			
		||||
        self.prev_layer = 0
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@ class SleepWithBedStates:
 | 
			
		||||
        w = self.g.world
 | 
			
		||||
        p = utils.pint(self.g.pos)
 | 
			
		||||
 | 
			
		||||
        result = w.find_blocks_indexed(p, blocks.BED_IDS)
 | 
			
		||||
        result = w.find_blocks_indexed(p, blocks.BED_IDS, 80)
 | 
			
		||||
 | 
			
		||||
        self.beds = []
 | 
			
		||||
        for bed in result:
 | 
			
		||||
 
 | 
			
		||||
@@ -116,7 +116,7 @@ class ChunksManager:
 | 
			
		||||
        if not c: return None
 | 
			
		||||
        c.set_block_at(x%16, y%16, z%16, block)
 | 
			
		||||
 | 
			
		||||
    def check_loaded(self, position, steps):
 | 
			
		||||
    def check_loaded(self, position, steps=1):
 | 
			
		||||
        x, y, z = utils.pint(position)
 | 
			
		||||
        player_chunk = (x//16, 1, z//16)
 | 
			
		||||
        for i in range(steps): # TODO: base off render_distance?
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user