|
|
|
@ -1034,6 +1034,158 @@ class CacheItemsStates: |
|
|
|
|
self.state() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GrabSuppliesStates: |
|
|
|
|
def idle(self): |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
def init(self): |
|
|
|
|
if self.supplies: |
|
|
|
|
self.state = self.check_supplies |
|
|
|
|
else: |
|
|
|
|
print('Aborting getting supplies, none specified') |
|
|
|
|
self.state = self.cleanup |
|
|
|
|
|
|
|
|
|
def check_supplies(self): |
|
|
|
|
for items, maximum in self.supplies.items(): |
|
|
|
|
print('Checking items:', items) |
|
|
|
|
num_items = self.g.game.count_items(items) |
|
|
|
|
print('Have:', num_items) |
|
|
|
|
|
|
|
|
|
if num_items: |
|
|
|
|
print('Skipping') |
|
|
|
|
continue |
|
|
|
|
else: |
|
|
|
|
self.target_items = items |
|
|
|
|
self.maximum_items = maximum |
|
|
|
|
self.count = 0 |
|
|
|
|
self.state = self.find_barrels |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
print('Aborting, don\'t need any more supplies') |
|
|
|
|
self.state = self.cleanup |
|
|
|
|
|
|
|
|
|
def find_barrels(self): |
|
|
|
|
print('Finding barrels...') |
|
|
|
|
w = self.g.world |
|
|
|
|
p = utils.pint(self.g.pos) |
|
|
|
|
|
|
|
|
|
self.barrels = w.find_blocks_indexed(p, blocks.BARREL_IDS, 100) |
|
|
|
|
print('Found:', self.barrels) |
|
|
|
|
self.state = self.choose_barrel |
|
|
|
|
|
|
|
|
|
def choose_barrel(self): |
|
|
|
|
print('Choosing a barrel...') |
|
|
|
|
w = self.g.world |
|
|
|
|
p = utils.pint(self.g.pos) |
|
|
|
|
c = self.g.chunks |
|
|
|
|
|
|
|
|
|
if not len(self.barrels): |
|
|
|
|
print('No barrels') |
|
|
|
|
self.state = self.cleanup |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
barrel = self.barrels[0] |
|
|
|
|
|
|
|
|
|
tmp = c.get_block_at(*barrel) |
|
|
|
|
c.set_block_at(*barrel, blocks.AIR) |
|
|
|
|
navpath = w.path_to_place(p, barrel) |
|
|
|
|
c.set_block_at(*barrel, tmp) |
|
|
|
|
|
|
|
|
|
print('navpath:', navpath) |
|
|
|
|
|
|
|
|
|
if navpath: |
|
|
|
|
self.g.path = navpath[:-1] |
|
|
|
|
self.opening = self.g.path[-1] |
|
|
|
|
self.area = barrel |
|
|
|
|
self.state = self.going_to_barrel |
|
|
|
|
return |
|
|
|
|
else: |
|
|
|
|
self.barrel.pop(0) |
|
|
|
|
|
|
|
|
|
def going_to_barrel(self): |
|
|
|
|
if utils.pint(self.g.pos) == self.opening: |
|
|
|
|
self.g.look_at = self.area |
|
|
|
|
self.state = self.open_barrel |
|
|
|
|
|
|
|
|
|
def open_barrel(self): |
|
|
|
|
print('Opening barrel') |
|
|
|
|
self.g.game.open_container(self.area) |
|
|
|
|
self.wait_time = 1 |
|
|
|
|
self.state = self.wait |
|
|
|
|
|
|
|
|
|
def wait(self): |
|
|
|
|
# wait for server to send us barrel contents |
|
|
|
|
if self.wait_time > 0: |
|
|
|
|
self.wait_time -= utils.TICK |
|
|
|
|
else: |
|
|
|
|
self.state = self.grab_items |
|
|
|
|
|
|
|
|
|
def grab_items(self): |
|
|
|
|
if self.g.item_lock: return |
|
|
|
|
|
|
|
|
|
w = self.g.window |
|
|
|
|
w_info = mcdata.WINDOWS[w.data.window_type] |
|
|
|
|
w_container_slots = w_info.container |
|
|
|
|
|
|
|
|
|
for slot_num in w_container_slots: |
|
|
|
|
if slot_num not in w.contents: |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
slot = w.contents[slot_num] |
|
|
|
|
|
|
|
|
|
if not slot.present: |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
if slot.item_id not in self.target_items: |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
if self.count >= self.maximum_items: |
|
|
|
|
break |
|
|
|
|
self.count += 1 |
|
|
|
|
|
|
|
|
|
print('Moving', slot) |
|
|
|
|
|
|
|
|
|
self.g.item_lock = True |
|
|
|
|
self.g.game.click_window(slot_num, 0, 1, slot) |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
print('Nothing left to move') |
|
|
|
|
self.state = self.close_barrel |
|
|
|
|
|
|
|
|
|
def close_barrel(self): |
|
|
|
|
print('Closing barrel') |
|
|
|
|
self.g.game.close_window() |
|
|
|
|
self.state = self.cleanup |
|
|
|
|
|
|
|
|
|
def cleanup(self): |
|
|
|
|
self.g.look_at = None |
|
|
|
|
self.state = self.done |
|
|
|
|
|
|
|
|
|
def done(self): |
|
|
|
|
# never gets ran, placeholder |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
def __init__(self, global_state): |
|
|
|
|
self.g = global_state |
|
|
|
|
self.state = self.idle |
|
|
|
|
|
|
|
|
|
self.supplies = {} |
|
|
|
|
self.target_supplies = [] |
|
|
|
|
self.barrels = [] |
|
|
|
|
|
|
|
|
|
self.target_items = None |
|
|
|
|
self.maximum_items = 0 |
|
|
|
|
self.count = 0 |
|
|
|
|
|
|
|
|
|
self.area = None |
|
|
|
|
self.opening = None |
|
|
|
|
self.wait_time = 0 |
|
|
|
|
|
|
|
|
|
def run(self): |
|
|
|
|
self.state() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PlantTreeStates: |
|
|
|
|
def idle(self): |
|
|
|
|
return None |
|
|
|
@ -1558,6 +1710,7 @@ class JobStates: |
|
|
|
|
self.gather_sand_states = GatherSandStates(self.g) |
|
|
|
|
self.sleep_with_bed_states = SleepWithBedStates(self.g) |
|
|
|
|
self.cache_items_states = CacheItemsStates(self.g) |
|
|
|
|
self.grab_supplies_states = GrabSuppliesStates(self.g) |
|
|
|
|
self.find_gapple_states = FindGappleStates(self.g) |
|
|
|
|
self.plant_tree_states = PlantTreeStates(self.g) |
|
|
|
|
self.clear_leaves_states = ClearLeavesStates(self.g) |
|
|
|
@ -1623,6 +1776,7 @@ class JobStates: |
|
|
|
|
|
|
|
|
|
def farm_wood(self): |
|
|
|
|
machines = [ |
|
|
|
|
self.grab_supplies_states, |
|
|
|
|
self.gather_wood_states, |
|
|
|
|
self.clear_leaves_states, |
|
|
|
|
self.plant_tree_states, |
|
|
|
@ -1632,6 +1786,9 @@ class JobStates: |
|
|
|
|
] |
|
|
|
|
self.sleep_with_bed_states.silent = True |
|
|
|
|
self.cache_items_states.silent = True |
|
|
|
|
self.grab_supplies_states.supplies = { |
|
|
|
|
tuple(items.AXE_IDS): 9, |
|
|
|
|
} |
|
|
|
|
return machines |
|
|
|
|
|
|
|
|
|
def farm_wart(self): |
|
|
|
|