Cache after sleep near labeled chests
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user