Throw designated items at signs during caching
This commit is contained in:
1 parent
46b0657bcf
commit
ce3be28d0c
4 files changed
+469
-2
No files matched your search
@@ -30,6 +30,140 @@ class CacheItemsTests(unittest.TestCase):
|
||||
'Found 11 labeled chests; found 0 trapped chests: []',
|
||||
output.getvalue())
|
||||
|
||||
def test_throw_signs_are_checked_before_cache_containers(self):
|
||||
directive = {
|
||||
'position': (2, 64, 0), 'side': 'front',
|
||||
'item_name': 'seeds', 'item_ids': {items.WHEAT_SEEDS_ID},
|
||||
}
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def find_throw_signs(_center, _bot_name, _distance):
|
||||
return [directive]
|
||||
|
||||
@staticmethod
|
||||
def find_labeled_chests(*_args):
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def find_blocks_indexed(*_args):
|
||||
return []
|
||||
|
||||
state = CacheItemsStates(Munch(
|
||||
world=FakeWorld(), pos=(0, 64, 0), name='mosfet1'))
|
||||
|
||||
state.find_trapped_chests()
|
||||
|
||||
self.assertIs(state.state.__func__, state.choose_throw_sign.__func__)
|
||||
self.assertEqual(state.throw_signs, [directive])
|
||||
|
||||
def test_throw_sign_does_not_bypass_cache_inventory_threshold(self):
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def find_throw_signs(*_args):
|
||||
raise AssertionError('throw signs are checked only at threshold')
|
||||
|
||||
class FakeGame:
|
||||
@staticmethod
|
||||
def count_inventory_slots():
|
||||
return 1
|
||||
|
||||
state = CacheItemsStates(Munch(
|
||||
world=FakeWorld(), pos=(0, 64, 0), name='mosfet2',
|
||||
game=FakeGame(), inv={
|
||||
9: Munch(present=True, item_id=items.WHEAT_SEEDS_ID,
|
||||
item_count=12),
|
||||
}, minimum_cache_slots=27))
|
||||
|
||||
state.init()
|
||||
|
||||
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
||||
|
||||
def test_throw_sign_throws_target_item_at_cache_threshold(self):
|
||||
position = (2, 64, 0)
|
||||
opening = (1, 64, 0)
|
||||
seed = Munch(present=True, item_id=items.WHEAT_SEEDS_ID,
|
||||
item_count=12)
|
||||
dropped = []
|
||||
g = Munch(
|
||||
name='mosfet2', pos=(0, 64, 0), inv={9: seed},
|
||||
item_lock=False, drop_waiting=None, path=[], look_at=None,
|
||||
minimum_cache_slots=27,
|
||||
)
|
||||
directive = {
|
||||
'position': position, 'side': 'front', 'item_name': 'seeds',
|
||||
'item_ids': items.storage_item_ids_for_label('seeds'),
|
||||
}
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def find_throw_signs(_center, bot_name, _distance):
|
||||
self.assertEqual(bot_name, 'mosfet2')
|
||||
return [directive]
|
||||
|
||||
@staticmethod
|
||||
def find_throw_openings(sign, center, radius):
|
||||
self.assertEqual(sign, directive)
|
||||
self.assertEqual(radius, 3)
|
||||
return [{'position': opening, 'alignment': 1.0}]
|
||||
|
||||
@staticmethod
|
||||
def find_labeled_chests(*_args):
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def find_blocks_indexed(*_args):
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def path_to_place(start, target):
|
||||
return [start, target]
|
||||
|
||||
class FakeGame:
|
||||
@staticmethod
|
||||
def count_inventory_slots():
|
||||
return 27
|
||||
|
||||
@staticmethod
|
||||
def drop_inventory_slot(slot, whole_stack=True):
|
||||
dropped.append((slot, whole_stack))
|
||||
g.drop_waiting = {'slot': slot}
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def select_item(_item_ids):
|
||||
return False
|
||||
|
||||
g.world = FakeWorld()
|
||||
g.game = FakeGame()
|
||||
state = CacheItemsStates(g)
|
||||
|
||||
state.init()
|
||||
self.assertIs(state.state.__func__, state.find_trapped_chests.__func__)
|
||||
state.find_trapped_chests()
|
||||
self.assertIs(state.state.__func__, state.choose_throw_sign.__func__)
|
||||
state.choose_throw_sign()
|
||||
self.assertEqual(state.opening, opening)
|
||||
g.pos = opening
|
||||
state.going_to_throw_sign()
|
||||
self.assertEqual(g.look_at, position)
|
||||
state.wait_time = 0
|
||||
state.turn_to_throw_sign()
|
||||
state.throw_items()
|
||||
self.assertEqual(dropped, [(9, True)])
|
||||
self.assertIs(state.state.__func__, state.wait_for_throw.__func__)
|
||||
|
||||
g.drop_waiting = None
|
||||
g.inv[9] = Munch(present=False, item_id=0, item_count=0)
|
||||
state.wait_for_throw()
|
||||
state.throw_items()
|
||||
self.assertIs(state.state.__func__, state.choose_throw_sign.__func__)
|
||||
state.choose_throw_sign()
|
||||
self.assertIs(state.state.__func__, state.choose_trapped_chest.__func__)
|
||||
state.choose_trapped_chest()
|
||||
state.select_chest()
|
||||
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
||||
|
||||
def test_wanted_single_stack_is_not_considered_transferable(self):
|
||||
wanted_id = items.WHEAT_SEEDS_ID
|
||||
old_wanted = items.WANTED_ITEMS
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import unittest
|
||||
from munch import Munch
|
||||
|
||||
from mosfet.info import blocks, items
|
||||
from mosfet.world import World
|
||||
|
||||
|
||||
def wall_sign_state(facing):
|
||||
name = 'oak_wall_sign'
|
||||
data = blocks.MCD_BLOCKS[name]
|
||||
return next(
|
||||
state_id for state_id in range(data['minStateId'], data['maxStateId'] + 1)
|
||||
if blocks.PROPS[state_id].get('facing') == facing and
|
||||
blocks.PROPS[state_id].get('waterlogged') == 'false'
|
||||
)
|
||||
|
||||
|
||||
class FakeChunks:
|
||||
def __init__(self, block_entities=None, states=None):
|
||||
self.block_entities = block_entities or {}
|
||||
self.states = states or {}
|
||||
|
||||
def get_block_at(self, *position):
|
||||
return self.states.get(tuple(position), blocks.AIR)
|
||||
|
||||
|
||||
class ThrowSignTests(unittest.TestCase):
|
||||
def test_throw_directives_support_group_bot_and_item_categories(self):
|
||||
group_sign = (0, 64, 0)
|
||||
individual_sign = (4, 64, 0)
|
||||
chunks = FakeChunks(
|
||||
block_entities={
|
||||
group_sign: {'data': {
|
||||
'front_text': {'messages': [
|
||||
'mosfet', 'throw seeds', '', '',
|
||||
]},
|
||||
'back_text': {'messages': [
|
||||
'mosfet3 throw bread', '', '', '',
|
||||
]},
|
||||
}},
|
||||
individual_sign: {'data': {'front_text': {'messages': [
|
||||
'mosfet2 throw wheat_seeds', '', '', '',
|
||||
]}}},
|
||||
},
|
||||
states={
|
||||
group_sign: wall_sign_state('north'),
|
||||
individual_sign: wall_sign_state('west'),
|
||||
})
|
||||
world = World(Munch(chunks=chunks))
|
||||
|
||||
bot2 = world.find_throw_signs((0, 64, 0), 'mosfet2', 10)
|
||||
self.assertEqual(len(bot2), 2)
|
||||
group = next(sign for sign in bot2 if sign['position'] == group_sign)
|
||||
individual = next(sign for sign in bot2
|
||||
if sign['position'] == individual_sign)
|
||||
self.assertEqual(group['item_ids'],
|
||||
items.storage_item_ids_for_label('seeds'))
|
||||
self.assertEqual(individual['item_ids'],
|
||||
{items.WHEAT_SEEDS_ID})
|
||||
self.assertEqual(group['normal'], (0.0, 0.0, -1.0))
|
||||
self.assertEqual(individual['normal'], (-1.0, 0.0, 0.0))
|
||||
|
||||
bot1 = world.find_throw_signs((0, 64, 0), 'mosfet1', 10)
|
||||
self.assertEqual([sign['position'] for sign in bot1], [group_sign])
|
||||
|
||||
def test_back_text_uses_back_face_normal(self):
|
||||
position = (0, 64, 0)
|
||||
world = World(Munch(chunks=FakeChunks(
|
||||
block_entities={position: {'data': {
|
||||
'front_text': {'messages': ['front', '', '', '']},
|
||||
'back_text': {'messages': [
|
||||
'mosfet2 throw seeds', '', '', '',
|
||||
]},
|
||||
}}},
|
||||
states={position: wall_sign_state('north')})))
|
||||
|
||||
directive = world.find_throw_signs(position, 'mosfet2', 3)[0]
|
||||
|
||||
self.assertEqual(directive['side'], 'back')
|
||||
self.assertEqual(directive['normal'], (0.0, 0.0, 1.0))
|
||||
|
||||
def test_throw_openings_prefer_text_face_and_skip_chute_holes(self):
|
||||
sign_pos = (0, 64, 0)
|
||||
states = {sign_pos: wall_sign_state('north')}
|
||||
for x in range(-4, 5):
|
||||
for z in range(-4, 5):
|
||||
states[(x, 63, z)] = blocks.STONE
|
||||
# The closest point on the sign's text-facing side is a drop chute.
|
||||
states[(0, 63, -1)] = blocks.AIR
|
||||
directive = {
|
||||
'position': sign_pos,
|
||||
'side': 'front',
|
||||
'normal': (0.0, 0.0, -1.0),
|
||||
}
|
||||
world = World(Munch(chunks=FakeChunks(states=states)))
|
||||
|
||||
openings = world.find_throw_openings(
|
||||
directive, center=(2, 64, 0), radius=3)
|
||||
|
||||
self.assertTrue(openings)
|
||||
self.assertNotIn((0, 64, -1), {
|
||||
tuple(opening['position']) for opening in openings
|
||||
})
|
||||
self.assertLessEqual(max(opening['distance'] for opening in openings), 3)
|
||||
self.assertGreater(openings[0]['alignment'], 0.9)
|
||||
self.assertEqual(tuple(openings[0]['position']), (0, 64, -2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user