From 4026b410f49dd43e0ef092cba5bfd01ae4d3586e Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 24 Apr 2021 22:34:25 +0000 Subject: [PATCH] Set sand origin when command is given --- main.py | 2 ++ mosfet/commands.py | 4 ++++ mosfet/jobs/gather_sand.py | 10 ++++++---- mosfet/jobs/sleep_with_bed.py | 2 +- mosfet/protocol/managers.py | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 2eb152e..33e3149 100644 --- a/main.py +++ b/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(): diff --git a/mosfet/commands.py b/mosfet/commands.py index bf0d5a8..17fa8ca 100644 --- a/mosfet/commands.py +++ b/mosfet/commands.py @@ -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': diff --git a/mosfet/jobs/gather_sand.py b/mosfet/jobs/gather_sand.py index 59b418c..7059822 100644 --- a/mosfet/jobs/gather_sand.py +++ b/mosfet/jobs/gather_sand.py @@ -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 diff --git a/mosfet/jobs/sleep_with_bed.py b/mosfet/jobs/sleep_with_bed.py index 8d33a0c..b4ae799 100644 --- a/mosfet/jobs/sleep_with_bed.py +++ b/mosfet/jobs/sleep_with_bed.py @@ -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: diff --git a/mosfet/protocol/managers.py b/mosfet/protocol/managers.py index fa1ed3e..1a26130 100644 --- a/mosfet/protocol/managers.py +++ b/mosfet/protocol/managers.py @@ -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?