Aim crop farmers at targets with pitch limit
This commit is contained in:
@@ -6,6 +6,23 @@ from mosfet.jobs.gather_crop import GatherCropStates
|
||||
|
||||
|
||||
class CropBatchTests(unittest.TestCase):
|
||||
def test_navigation_looks_at_the_crop_target(self):
|
||||
crop = (5, 64, 8)
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def path_to_place(_start, _target):
|
||||
return [(1, 64, 1), crop]
|
||||
|
||||
g = Munch(world=FakeWorld(), pos=(1, 64, 1), path=[], look_at=None)
|
||||
state = GatherCropStates(g)
|
||||
state.crop = crop
|
||||
|
||||
state.nav_to_crop()
|
||||
|
||||
self.assertEqual(g.look_at, crop)
|
||||
self.assertEqual(g.path[-1], crop)
|
||||
|
||||
def test_gather_crop_finishes_after_sixteen_successful_replants(self):
|
||||
unripe_wheat = blocks.MCD_BLOCKS['wheat']['minStateId']
|
||||
mature_wheat = blocks.MATURE_WHEAT_ID
|
||||
|
||||
+41
-22
@@ -2,37 +2,56 @@ import unittest
|
||||
|
||||
from munch import Munch
|
||||
|
||||
from mosfet.bot import FARMING_PITCH, pitch_lock_for_job, update_pitch
|
||||
from mosfet.bot import look_direction_from_eye, update_pitch
|
||||
from mosfet.vector import Point3D
|
||||
|
||||
|
||||
class LookDirection:
|
||||
def __init__(self, angle):
|
||||
self.angle = angle
|
||||
|
||||
def length(self):
|
||||
return 2.0
|
||||
|
||||
def normalized(self):
|
||||
return self
|
||||
|
||||
def angleDeg(self, _direction):
|
||||
return self.angle
|
||||
|
||||
|
||||
class TestFarmingPitch(unittest.TestCase):
|
||||
def test_crop_and_wart_farming_lock_pitch(self):
|
||||
def farm_crop():
|
||||
pass
|
||||
def test_aiming_at_a_same_level_crop_uses_eye_height_and_looks_down(self):
|
||||
player = Point3D((0.5, 64.0, 0.5))
|
||||
crop_center = Point3D((1.5, 64.5, 1.5))
|
||||
direction = look_direction_from_eye(player, crop_center)
|
||||
|
||||
def farm_wart():
|
||||
pass
|
||||
|
||||
def sleep():
|
||||
pass
|
||||
|
||||
self.assertEqual(
|
||||
pitch_lock_for_job(Munch(state=farm_crop)), FARMING_PITCH)
|
||||
self.assertEqual(
|
||||
pitch_lock_for_job(Munch(state=farm_wart)), FARMING_PITCH)
|
||||
self.assertIsNone(pitch_lock_for_job(Munch(state=sleep)))
|
||||
self.assertIsNone(pitch_lock_for_job(None))
|
||||
|
||||
def test_pitch_is_held_at_45_despite_look_target_changes(self):
|
||||
self.assertGreater(direction.y, 0)
|
||||
state = Munch(pitch=0.0)
|
||||
for _ in range(5):
|
||||
update_pitch(state, object(), FARMING_PITCH)
|
||||
update_pitch(state, direction)
|
||||
self.assertGreater(state.pitch, 0.0)
|
||||
|
||||
def test_pitch_never_looks_more_than_45_degrees_down(self):
|
||||
state = Munch(pitch=0.0)
|
||||
directly_below = LookDirection(0.0)
|
||||
for _ in range(8):
|
||||
update_pitch(state, directly_below)
|
||||
self.assertEqual(state.pitch, 45.0)
|
||||
|
||||
# Without the farming lock, ordinary look behavior is restored.
|
||||
update_pitch(state, None)
|
||||
def test_pitch_tracks_look_target_instead_of_a_fixed_farming_angle(self):
|
||||
state = Munch(pitch=0.0)
|
||||
direction_to_crop = LookDirection(45.0)
|
||||
for _ in range(5):
|
||||
update_pitch(state, direction_to_crop)
|
||||
self.assertEqual(state.pitch, 45.0)
|
||||
|
||||
# Looking level at another target pulls the pitch back toward zero.
|
||||
update_pitch(state, LookDirection(90.0))
|
||||
self.assertEqual(state.pitch, 35.0)
|
||||
|
||||
update_pitch(state, None)
|
||||
self.assertEqual(state.pitch, 25.0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -120,6 +120,23 @@ class GatherWartTests(unittest.TestCase):
|
||||
state.wait_place()
|
||||
self.assertIs(state.state.__func__, state.cleanup.__func__)
|
||||
|
||||
def test_navigation_looks_at_the_wart_target(self):
|
||||
position = (5, 64, 8)
|
||||
|
||||
class FakeWorld:
|
||||
@staticmethod
|
||||
def path_to_place(_start, _target):
|
||||
return [(1, 64, 1), position]
|
||||
|
||||
g = Munch(world=FakeWorld(), pos=(1, 64, 1), path=[], look_at=None)
|
||||
state = GatherWartStates(g)
|
||||
state.wart = position
|
||||
|
||||
state.nav_to_wart()
|
||||
|
||||
self.assertEqual(g.look_at, position)
|
||||
self.assertEqual(g.path[-1], position)
|
||||
|
||||
def test_unreachable_wart_is_blacklisted_without_undefined_variable(self):
|
||||
position = (5, 64, 8)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user