Cache after sleep near labeled chests

This commit is contained in:
Tanner
2026-11-08 17:08:12 +00:00
parent 930f4f3868
commit c79ee932a3
6 changed files with 166 additions and 10 deletions
+29 -1
View File
@@ -3,7 +3,7 @@ import time
import importlib
import random
from itertools import count
from math import floor
from math import ceil, floor
from minecraft.networking.types import BlockFace
@@ -19,6 +19,27 @@ class CacheItemsStates:
def idle(self):
return None
def _has_compatible_labeled_chest_near(self, bed, distance=16):
world = self.g.get('world')
if world is None:
return False
keep_slots = self._needed_inventory_slots_to_keep()
for chest in world.find_labeled_chests(bed, distance):
positions = chest.get('positions') or (chest['position'],)
if min(utils.phyp(bed, position) for position in positions) > distance:
continue
item_ids = chest['item_ids']
for slot, item in self.g.inv.items():
if (not 9 <= slot <= 44 or not item.present or
item.item_id not in item_ids or
item.item_id in items.WANTED_ITEMS):
continue
if (item.item_id in items.NEEDED_ITEMS and
slot in keep_slots):
continue
return True
return False
def init(self):
self.skip_inventory_slots = set()
self.skip_items = []
@@ -30,8 +51,15 @@ class CacheItemsStates:
self.container_item_ids = None
num_stacks = self.g.game.count_inventory_slots()
has_override = 'minimum' in self.__dict__
minimum = self.__dict__.pop(
'minimum', self.g.get('minimum_cache_slots', 27))
post_sleep_bed = self.g.pop('post_sleep_cache_bed', None)
if (not has_override and post_sleep_bed is not None and
self._has_compatible_labeled_chest_near(post_sleep_bed)):
minimum = ceil(minimum / 2)
print('Lowering cache threshold after sleep near a compatible chest:',
minimum)
print('Inventory amount:', num_stacks)
if num_stacks == 0:
self.state = self.cleanup
+4 -8
View File
@@ -105,9 +105,10 @@ class GatherCropStates:
crop, section_size = self._select_crop(candidates, crop_types, p)
if crop is None:
print('No good crops left; retrying after a short wait.')
self.retry_after = time.monotonic() + 15.0
self.state = self.wait_for_crops
print('No good crops left; running maintenance after {} harvests'.format(
self.completed_crops))
self.completed_crops = 0
self.state = self.cleanup
return
print('Found crop:', crop,
@@ -116,10 +117,6 @@ class GatherCropStates:
self.type_id = w.block_at(*crop)
self.state = self.nav_to_crop
def wait_for_crops(self):
if time.monotonic() >= self.retry_after:
self.state = self.find_new_crop
def nav_to_crop(self):
w = self.g.world
p = utils.pint(self.g.pos)
@@ -251,7 +248,6 @@ class GatherCropStates:
self.seed_deadline = None
self.seed_wait_logged = False
self.active_section_anchor = None
self.retry_after = 0.0
self.bad_crops = []
self.completed_crops = 0
+3
View File
@@ -21,6 +21,7 @@ class SleepWithBedStates:
return None
def init(self):
self.sleep_confirmed = False
self.my_bed = False
self.area = None
self.opening = None
@@ -371,6 +372,8 @@ class SleepWithBedStates:
return
self.g.look_at = None
self.g.path = []
if self.sleep_confirmed and self.area is not None:
self.g.post_sleep_cache_bed = tuple(self.area)
self.my_bed = False
self.force_new_bed = False
self.state = self.done