Confirm crop seed selection before planting

This commit is contained in:
Tanner committed 2026-11-10 00:52:26 +00:00
1 parent 1a7bdb2be4
commit 46b0657bcf
4 files changed
+105 -21

No files matched your search

+54 -13
View File
@@ -372,6 +372,7 @@ class GatherCropStates:
self.crop_profile['seed_started_at'] = now
self.seed_deadline = now + 8.0
self.seed_wait_logged = False
self.seed_hand_wait_logged = False
self.state = self.select_seed
elif time.time() > self.break_deadline:
print('Crop break timed out at {}: expected state {}, server still has {}'.format(
@@ -380,6 +381,20 @@ class GatherCropStates:
self.bad_crops.append(self.crop)
self.state = self.find_new_crop
def _held_item_snapshot(self):
hand = int(self.g.get('holding_hand', 0) or 0)
slot = (45 if hand == 1 else
36 + int(self.g.get('holding_slot', 0) or 0))
item = (self.g.get('inv', {}) or {}).get(slot)
item_id = (item.item_id if item and
getattr(item, 'present', False) else None)
return hand, slot, item_id
def _seed_is_in_selected_hand(self):
hand, _slot, slot_item_id = self._held_item_snapshot()
return (self.g.get('holding') == self.target_seed and
slot_item_id == self.target_seed and hand in (0, 1))
def select_seed(self):
self._finish_crop_travel()
crop_seeds = {
@@ -397,15 +412,13 @@ class GatherCropStates:
self.state = self.find_new_crop
return
if self.target_seed == self.g.get('holding'):
if self.crop_profile:
self.crop_profile['seed'] = (
time.monotonic() -
self.crop_profile.pop('seed_started_at', time.monotonic()))
self.seed_deadline = None
self.state = self.place_crop
elif self.g.game.select_item([self.target_seed]):
self.seed_deadline = None
hand, slot, slot_item_id = self._held_item_snapshot()
print('Selecting crop seed: target={}, local held={}, hand={}, '
'slot={}, slot item={}'.format(
self.target_seed, self.g.get('holding'), hand, slot,
slot_item_id))
if self.g.game.select_item([self.target_seed], force=True):
print('Crop seed selection sent; awaiting matching held-slot state')
self.state = self.wait_select
else:
if (self.seed_deadline is not None and
@@ -422,8 +435,24 @@ class GatherCropStates:
def wait_select(self):
self._finish_crop_travel()
if self.target_seed != self.g.holding:
if not self._seed_is_in_selected_hand():
if not getattr(self, 'seed_hand_wait_logged', False):
hand, slot, slot_item_id = self._held_item_snapshot()
print('Waiting for seed in selected hand: target={}, held={}, '
'hand={}, slot={}, slot item={}'.format(
self.target_seed, self.g.get('holding'), hand,
slot, slot_item_id))
self.seed_hand_wait_logged = True
if (self.seed_deadline is not None and
time.monotonic() > self.seed_deadline):
print('Seed did not reach the selected hand; skipping',
self.crop)
self.bad_crops.append(self.crop)
self.seed_deadline = None
self.state = self.find_new_crop
return
self.seed_deadline = None
self.seed_hand_wait_logged = False
if self.crop_profile:
self.crop_profile['seed'] = (
time.monotonic() -
@@ -432,6 +461,13 @@ class GatherCropStates:
def place_crop(self):
self._finish_crop_travel()
if not self._seed_is_in_selected_hand():
print('Seed is no longer in the selected hand; reselecting',
self.target_seed)
self.seed_deadline = time.monotonic() + 8.0
self.seed_hand_wait_logged = False
self.state = self.select_seed
return
position = self.g.get('pos')
if position is not None and utils.pint(position) != self.crop:
return
@@ -443,12 +479,16 @@ class GatherCropStates:
# Keep the existing path moving until the support face is
# within reach and visible.
return
hand, slot, slot_item_id = self._held_item_snapshot()
if self.crop_profile:
self.crop_profile['plant_started_at'] = time.monotonic()
self.place_deadline = time.time() + 3.0
self.g.game.place_block(
p, BlockFace.TOP, hand=self.g.get('holding_hand', 0))
print('Placed crop')
print('Sending crop placement: crop={}, held={}, hand={}, '
'slot={}, slot item={}, position={}'.format(
self.crop, self.g.get('holding'), hand, slot,
slot_item_id, tuple(position) if position is not None else None))
self.g.game.place_block(p, BlockFace.TOP, hand=hand)
print('Crop use sent; awaiting replant confirmation')
self.state = self.wait_place
def wait_place(self):
@@ -506,6 +546,7 @@ class GatherCropStates:
self.target_seed = None
self.seed_deadline = None
self.seed_wait_logged = False
self.seed_hand_wait_logged = False
self.active_section_anchor = None
self.active_section_maturity = (0, 0)
self.active_section_positions = None