Implement item cachine for 26.3
This commit is contained in:
+46
-20
@@ -13,7 +13,6 @@ from mosfet import utils
|
||||
from mosfet import path
|
||||
from mosfet.info import blocks
|
||||
from mosfet.info import items
|
||||
from mosfet.info import mcdata
|
||||
from mosfet.info import mobs
|
||||
|
||||
class CacheItemsStates:
|
||||
@@ -25,8 +24,12 @@ class CacheItemsStates:
|
||||
self.skip_items = []
|
||||
|
||||
num_stacks = self.g.game.count_inventory_slots()
|
||||
minimum = getattr(
|
||||
self, 'minimum', self.g.get('minimum_cache_slots', 27))
|
||||
print('Inventory amount:', num_stacks)
|
||||
if num_stacks >= self.g.minimum_cache_slots:
|
||||
if num_stacks == 0:
|
||||
self.state = self.cleanup
|
||||
elif num_stacks >= minimum:
|
||||
self.state = self.find_trapped_chests
|
||||
else:
|
||||
print('Aborting caching, not full')
|
||||
@@ -53,23 +56,30 @@ class CacheItemsStates:
|
||||
return
|
||||
|
||||
chest = self.trapped_chests[0]
|
||||
self.area = chest
|
||||
|
||||
navpath = w.path_to_place_faked(p, chest)
|
||||
print('navpath:', navpath)
|
||||
for opening in w.find_cache_openings(chest):
|
||||
navpath = w.path_to_place(p, opening)
|
||||
if navpath:
|
||||
print('navpath to trapped chest:', navpath)
|
||||
self.opening = opening
|
||||
self.g.path = navpath
|
||||
self.state = self.going_to_trapped_chest
|
||||
return
|
||||
|
||||
if navpath:
|
||||
self.g.path = navpath[:-1]
|
||||
self.opening = self.g.path[-1]
|
||||
self.area = chest
|
||||
self.state = self.going_to_trapped_chest
|
||||
return
|
||||
else:
|
||||
self.trapped_chests.pop(0)
|
||||
time.sleep(0.1)
|
||||
self.trapped_chests.pop(0)
|
||||
time.sleep(0.1)
|
||||
|
||||
def going_to_trapped_chest(self):
|
||||
if utils.pint(self.g.pos) == self.opening:
|
||||
self.g.look_at = self.area
|
||||
self.wait_time = 0.5
|
||||
self.state = self.turn_to_trapped_chest
|
||||
|
||||
def turn_to_trapped_chest(self):
|
||||
self.g.look_at = self.area
|
||||
self.wait_time -= utils.TICK
|
||||
if self.wait_time <= 0:
|
||||
self.state = self.open_chest
|
||||
|
||||
def select_chest(self):
|
||||
@@ -84,7 +94,7 @@ class CacheItemsStates:
|
||||
w = self.g.world
|
||||
p = utils.pint(self.g.pos)
|
||||
|
||||
for area in w.find_cache_areas(p, 100):
|
||||
for area in w.find_cache_areas(p, 16):
|
||||
print('Found area:', area)
|
||||
if area not in self.bad_areas:
|
||||
break
|
||||
@@ -112,10 +122,18 @@ class CacheItemsStates:
|
||||
def going_to_area(self):
|
||||
if utils.pint(self.g.pos) == self.opening:
|
||||
self.g.look_at = self.area
|
||||
self.wait_time = 0.5
|
||||
self.state = self.turn_to_cache_spot
|
||||
|
||||
def turn_to_cache_spot(self):
|
||||
self.g.look_at = self.area
|
||||
self.wait_time -= utils.TICK
|
||||
if self.wait_time <= 0:
|
||||
self.state = self.place_chest
|
||||
|
||||
def place_chest(self):
|
||||
self.g.game.place_block(self.area, BlockFace.TOP)
|
||||
support = utils.padd(self.area, path.BLOCK_BELOW)
|
||||
self.g.game.place_block(support, BlockFace.TOP)
|
||||
self.state = self.open_chest
|
||||
|
||||
def open_chest(self):
|
||||
@@ -139,14 +157,19 @@ class CacheItemsStates:
|
||||
print('Didnt get a window, aborting')
|
||||
self.state = self.cleanup
|
||||
return
|
||||
if w.data.window_type != mcdata.SINGLE_CHEST:
|
||||
print('Got wrong window, aborting')
|
||||
if not w.container_slots:
|
||||
print('Chest contents have not arrived, aborting')
|
||||
self.g.game.close_window()
|
||||
self.state = self.cleanup
|
||||
return
|
||||
if w.container_slots not in (27, 54):
|
||||
print('Got non-chest window, aborting')
|
||||
self.g.game.close_window()
|
||||
self.state = self.cleanup
|
||||
return
|
||||
|
||||
w_info = mcdata.WINDOWS[w.data.window_type]
|
||||
w_inventory_slots = w_info.inventory
|
||||
w_container_slots = w_info.container
|
||||
w_container_slots = range(w.container_slots)
|
||||
w_inventory_slots = range(w.container_slots, len(w.contents))
|
||||
|
||||
used_slots = self.g.game.count_window_slots()
|
||||
print('used:', used_slots, 'total:', len(w_container_slots))
|
||||
@@ -204,6 +227,9 @@ class CacheItemsStates:
|
||||
def cleanup(self):
|
||||
self.g.look_at = None
|
||||
self.state = self.done
|
||||
if (self.g.get('job') and
|
||||
getattr(self.g.job.state, '__name__', None) == 'cache_items'):
|
||||
self.g.job.state = self.g.job.idle
|
||||
|
||||
def done(self):
|
||||
# never gets ran, placeholder
|
||||
|
||||
Reference in New Issue
Block a user