Lock farming pitch downward

This commit is contained in:
Tanner
2026-11-04 20:12:12 +00:00
parent 7d4f045100
commit b9d43c7c37
2 changed files with 56 additions and 8 deletions
+23 -8
View File
@@ -57,6 +57,26 @@ PITCH_ANGLE_DIR = vector.Vector3D((0, 1, 0))
YAW_ANGLE_DIR = vector.Vector3D((0, 0, -1)) YAW_ANGLE_DIR = vector.Vector3D((0, 0, -1))
YAW_ANGLE_REF = vector.Vector3D((0, 1, 0)) YAW_ANGLE_REF = vector.Vector3D((0, 1, 0))
YAW_LOOK_AHEAD = 4 YAW_LOOK_AHEAD = 4
FARMING_PITCH = 45.0
def pitch_lock_for_job(job_state):
state = getattr(job_state, 'state', None) if job_state else None
return (FARMING_PITCH if getattr(state, '__name__', None) == 'farm_crop'
else None)
def update_pitch(g, look_at_d, fixed_pitch=None):
if fixed_pitch is not None:
target_pitch = fixed_pitch
elif look_at_d is None:
target_pitch = 0.0
elif look_at_d.length() > 0.6:
target_pitch = look_at_d.normalized().angleDeg(PITCH_ANGLE_DIR)
target_pitch = (target_pitch - 90) * -1
else:
return
g.pitch += utils.cap(target_pitch - g.pitch, 10)
def missing_movement_chunks(g): def missing_movement_chunks(g):
@@ -218,16 +238,12 @@ def tick(global_state):
else: else:
look_at = None look_at = None
pitch_lock = pitch_lock_for_job(g.get('job'))
if look_at: if look_at:
look_at.x += 0.5 look_at.x += 0.5
look_at.z += 0.5 look_at.z += 0.5
look_at_d = p - look_at look_at_d = p - look_at
update_pitch(g, look_at_d, pitch_lock)
if look_at_d.length() > 0.6:
target_pitch = look_at_d.normalized().angleDeg(PITCH_ANGLE_DIR)
target_pitch = (target_pitch - 90) * -1
target_pitch_d = target_pitch - g.pitch
g.pitch += utils.cap(target_pitch_d, 10)
# remove vertical component for yaw calculation # remove vertical component for yaw calculation
look_at_d.y = 0 look_at_d.y = 0
@@ -238,8 +254,7 @@ def tick(global_state):
target_yaw_d = (target_yaw_d + 180) % 360 - 180 target_yaw_d = (target_yaw_d + 180) % 360 - 180
g.yaw += utils.cap(target_yaw_d, 30) g.yaw += utils.cap(target_yaw_d, 30)
else: else:
target_pitch_d = 0 - g.pitch update_pitch(g, None, pitch_lock)
g.pitch += utils.cap(target_pitch_d, 10)
from minecraft.networking.modern import ( from minecraft.networking.modern import (
ClientTickEnd, PlayerPositionRotation, ClientTickEnd, PlayerPositionRotation,
+33
View File
@@ -0,0 +1,33 @@
import unittest
from munch import Munch
from mosfet.bot import FARMING_PITCH, pitch_lock_for_job, update_pitch
class TestFarmingPitch(unittest.TestCase):
def test_only_crop_farming_locks_pitch(self):
def farm_crop():
pass
def sleep():
pass
self.assertEqual(
pitch_lock_for_job(Munch(state=farm_crop)), 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):
state = Munch(pitch=0.0)
for _ in range(5):
update_pitch(state, object(), FARMING_PITCH)
self.assertEqual(state.pitch, 45.0)
# Without the farming lock, ordinary look behavior is restored.
update_pitch(state, None)
self.assertEqual(state.pitch, 35.0)
if __name__ == '__main__':
unittest.main()