Fix bugs and pause on zzz

This commit is contained in:
Tanner Collin 2020-12-18 04:15:09 +00:00
parent d108d7c817
commit cdd71d2610
4 changed files with 21 additions and 18 deletions

6
bot.py
View File

@ -101,6 +101,10 @@ def tick(global_state):
target.x += 0.5 target.x += 0.5
target.z += 0.5 target.z += 0.5
if g.afk_timeout > 0:
target = None
g.afk_timeout -= utils.TICK
if target: if target:
d = p - target d = p - target
@ -205,7 +209,7 @@ def init(global_state):
g.job = jobs.JobStates(g) g.job = jobs.JobStates(g)
g.chopped_tree = False g.chopped_tree = False
g.queue_afk = False g.afk_timeout = 0
g.filling = False g.filling = False

11
game.py
View File

@ -578,12 +578,8 @@ class Game:
if command == 'zzz': if command == 'zzz':
if not self.g.afk and self.g.dimension == 'overworld': if not self.g.afk and self.g.dimension == 'overworld':
if self.g.path:
travel_time = int(len(self.g.path) * 0.4) + 2
reply = 'gimme ' + str(travel_time) + ' secs, moving'
self.g.queue_afk = True
else:
reply = '/afk' reply = '/afk'
self.g.afk_timeout = 5.0
if command == 'tree': if command == 'tree':
pos = utils.pint(self.g.pos) pos = utils.pint(self.g.pos)
@ -1101,8 +1097,3 @@ class Game:
if not self.g.path: if not self.g.path:
self.g.correction_count = 0 self.g.correction_count = 0
if self.g.queue_afk:
self.g.chat.send('/afk')
self.g.queue_afk = False

View File

@ -82,5 +82,5 @@ POTATO_ID = get_id('potato')
WHEAT_SEEDS_ID = get_id('wheat_seeds') WHEAT_SEEDS_ID = get_id('wheat_seeds')
BEETROOT_SEEDS_ID = get_id('beetroot_seeds') BEETROOT_SEEDS_ID = get_id('beetroot_seeds')
NEEDED_ITEMS = BED_IDS | set([CHEST_ID]) NEEDED_ITEMS = BED_IDS | SHOVEL_IDS | AXE_IDS | set([CHEST_ID])
WANTED_ITEMS = SAPLING_IDS | set([NETHERWART_ID, CARROT_ID, POTATO_ID, WHEAT_SEEDS_ID, BEETROOT_SEEDS_ID]) WANTED_ITEMS = SAPLING_IDS | set([NETHERWART_ID, CARROT_ID, POTATO_ID, WHEAT_SEEDS_ID, BEETROOT_SEEDS_ID])

18
jobs.py
View File

@ -364,6 +364,10 @@ class GatherWoodStates:
def init(self): def init(self):
self.g.chopped_tree = False self.g.chopped_tree = False
self.state = self.select_axe
def select_axe(self):
self.g.game.select_item(items.AXE_IDS)
self.state = self.find_new_tree self.state = self.find_new_tree
def find_new_tree(self): def find_new_tree(self):
@ -647,7 +651,7 @@ class GrabSandStates:
w = self.g.world w = self.g.world
p = utils.pint(self.g.pos) p = utils.pint(self.g.pos)
sand = w.find_objects(items.SAND_ID) sand = w.find_objects([items.SAND_ID])
if not sand: if not sand:
print('No sand objects found, aborting') print('No sand objects found, aborting')
@ -771,7 +775,7 @@ class SleepWithBedStates:
self.state = self.use_bed self.state = self.use_bed
def use_bed(self): def use_bed(self):
if self.g.time >= 12542: if self.g.time > 12550:
print('Sleeping') print('Sleeping')
self.g.game.place_block(self.area, BlockFace.TOP) self.g.game.place_block(self.area, BlockFace.TOP)
if not self.silent: if not self.silent:
@ -798,7 +802,7 @@ class SleepWithBedStates:
def collect_bed(self): def collect_bed(self):
if not self.g.breaking: if not self.g.breaking:
self.g.path = [utils.padd(self.area, utils.spiral(n)) for n in range(9)] self.g.path = [utils.padd(self.area, utils.spiral(n)) for n in range(9)]
self.wait_time = 4 self.wait_time = 2
self.state = self.wait self.state = self.wait
def wait(self): def wait(self):
@ -1101,7 +1105,7 @@ class GrabSuppliesStates:
self.state = self.going_to_barrel self.state = self.going_to_barrel
return return
else: else:
self.barrel.pop(0) self.barrels.pop(0)
def going_to_barrel(self): def going_to_barrel(self):
if utils.pint(self.g.pos) == self.opening: if utils.pint(self.g.pos) == self.opening:
@ -1140,7 +1144,7 @@ class GrabSuppliesStates:
if slot.item_id not in self.target_items: if slot.item_id not in self.target_items:
continue continue
if self.count >= self.maximum_items: if self.maximum_items and self.count >= self.maximum_items:
break break
self.count += 1 self.count += 1
@ -1743,6 +1747,7 @@ class JobStates:
def farm_sand(self): def farm_sand(self):
machines = [ machines = [
self.grab_supplies_states,
self.check_threats_states, self.check_threats_states,
self.gather_sand_states, self.gather_sand_states,
self.grab_sand_states, self.grab_sand_states,
@ -1751,6 +1756,9 @@ class JobStates:
] ]
self.sleep_with_bed_states.silent = True self.sleep_with_bed_states.silent = True
self.cache_items_states.silent = True self.cache_items_states.silent = True
self.grab_supplies_states.supplies = {
tuple(items.SHOVEL_IDS): 9
}
return machines return machines
def cache_items(self): def cache_items(self):