Aim and click beds from grounded openings

This commit is contained in:
Tanner committed 2026-11-18 20:39:47 +00:00
1 parent 838bac6680
commit 37f72d674f
3 files changed
+264 -44

No files matched your search

+58
View File
@@ -1396,6 +1396,64 @@ class Game(LegacyGame):
self.g.connection.write_packet(ClientTickEnd(), force=True)
return True
def aim_angles_to_point(self, point):
"""Return the yaw/pitch needed to look at a world-space point."""
position = self.g.pos
if not hasattr(position, 'x'):
position = vector.Point3D(position)
target = vector.Point3D(point)
yaw_direction = position - target
yaw_direction.y = 0
yaw = self.g.get('yaw', 0.0)
if yaw_direction.length() > 0.6:
yaw = yaw_direction.normalized().signedAngleDeg(
other=bot.YAW_ANGLE_DIR, ref=bot.YAW_ANGLE_REF)
look_direction = bot.look_direction_from_eye(position, target)
pitch = self.g.get('pitch', 0.0)
if look_direction.length() > 0.6:
pitch = (look_direction.normalized().angleDeg(
bot.PITCH_ANGLE_DIR) - 90) * -1
pitch = min(pitch, bot.MAX_DOWNWARD_PITCH)
return yaw, pitch
def aim_at_point(self, point):
"""Aim the movement controller at an exact world-space point."""
point = tuple(float(value) for value in point)
self.g.look_at = tuple(value - 0.5 for value in point)
return self.aim_angles_to_point(point)
def bed_interaction_point(self, position):
"""Return a point and cursor on the bed's actual top collision shape."""
position = tuple(int(value) for value in position)
state_id = self.g.world.block_at(*position)
if state_id not in blocks.BED_IDS:
return None
boxes = blocks.COLLISION_BOXES.get(state_id, ())
centered = [box for box in boxes
if box[0] <= 0.5 <= box[3] and
box[2] <= 0.5 <= box[5]]
if not centered:
return None
box = max(centered, key=lambda candidate: candidate[4])
cursor = (0.5, float(box[4]), 0.5)
point = (position[0] + cursor[0],
position[1] + cursor[1],
position[2] + cursor[2])
return cursor, point
def click_bed(self, position, hand=0, cursor=None):
"""Right-click a bed at its top surface using protocol-777 placement."""
position = tuple(int(value) for value in position)
interaction = self.bed_interaction_point(position)
if interaction is None:
return False
if cursor is None:
cursor = interaction[0]
self.place_block(position, BlockFace.TOP, hand=hand, cursor=cursor)
return True
def place_block(self, location, face, hand=0, cursor_y=None,
sneaking=False, cursor=None):
location = tuple(int(value) for value in location)