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
@@ -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