Aim crop farmers at targets with pitch limit

This commit is contained in:
Tanner
2026-11-07 17:35:32 +00:00
parent 95f4aa4821
commit a019b54396
6 changed files with 89 additions and 37 deletions
+12 -13
View File
@@ -57,26 +57,25 @@ PITCH_ANGLE_DIR = vector.Vector3D((0, 1, 0))
YAW_ANGLE_DIR = vector.Vector3D((0, 0, -1))
YAW_ANGLE_REF = vector.Vector3D((0, 1, 0))
YAW_LOOK_AHEAD = 4
FARMING_PITCH = 45.0
PLAYER_EYE_HEIGHT = 1.62
MAX_DOWNWARD_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) in ('farm_crop', 'farm_wart')
else None)
def look_direction_from_eye(position, target):
eye = vector.Point3D((position.x, position.y + PLAYER_EYE_HEIGHT,
position.z))
return eye - target
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:
def update_pitch(g, look_at_d):
if 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
target_pitch = min(target_pitch, MAX_DOWNWARD_PITCH)
g.pitch += utils.cap(target_pitch - g.pitch, 10)
@@ -239,12 +238,12 @@ def tick(global_state):
else:
look_at = None
pitch_lock = pitch_lock_for_job(g.get('job'))
if look_at:
look_at.x += 0.5
look_at.y += 0.5
look_at.z += 0.5
look_at_d = p - look_at
update_pitch(g, look_at_d, pitch_lock)
update_pitch(g, look_direction_from_eye(p, look_at))
# remove vertical component for yaw calculation
look_at_d.y = 0
@@ -255,7 +254,7 @@ def tick(global_state):
target_yaw_d = (target_yaw_d + 180) % 360 - 180
g.yaw += utils.cap(target_yaw_d, 30)
else:
update_pitch(g, None, pitch_lock)
update_pitch(g, None)
from minecraft.networking.modern import (
ClientTickEnd, PlayerPositionRotation,