A guest draws a bow, and lets go to shoot

A client of a server sent the bow's use but never started using the item
itself, so letting go of the button sent no RELEASE_USE_ITEM: the server
kept the guest drawing and never shot. BowItem.use runs on the client too
(startUsingItem, with an arrow or in creative), and Minecraft.handleKeybinds
releases the item in use once the button is up.

The guest now draws on its own side as well (held until the button lets go
or another slot is picked), so the server shoots when it lets go.

lan_e2e: `arrows` passes both ways now (the guest's arrow hurts the host);
the `pvp` and `arrows` checks allow the victim natural regeneration while
pvp is off (it healed 19.3 -> 20 and failed the exact check).

Fixes #484

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-21 23:14:06 +02:00
parent 5763854b0d
commit ceff635615
2 changed files with 22 additions and 5 deletions
+19 -3
View File
@@ -3336,6 +3336,16 @@ impl Game<'_> {
// MultiPlayerGameMode.useItem runs the use here too: food starts
// being eaten (Consumable.startConsuming).
self.with_hand(hand, |g| g.start_eating(&info));
// BowItem.use: startUsingItem here too (with an arrow, or in creative), so that letting
// go sends RELEASE_USE_ITEM (Minecraft.handleKeybinds) and the server shoots.
if &*held.item == "minecraft:bow" {
self.with_hand(hand, |g| {
if g.using.is_none() && (g.creative || g.projectile_slot("minecraft:bow").is_some())
{
g.using = Some((g.held_slot(), 0));
}
});
}
item_has_use(&info)
}
@@ -3351,14 +3361,20 @@ impl Game<'_> {
}
self.remote_use_item(Hand::Off);
}
/// `LivingEntity.updatingUsingItem` for a consumable on a server client: the
/// eating animation and its crumbs. The server eats it and sends the
/// stack, the hunger and the sounds.
/// `LivingEntity.updatingUsingItem` on a server client: a drawn bow, and a
/// consumable's eating animation and its crumbs. The server eats it and
/// sends the stack, the hunger and the sounds.
fn remote_tick_using(&mut self) {
let Some((slot, ticks)) = self.using else {
return;
};
let stack = self.stack_in(slot).cloned();
// A drawn bow: held until the button lets go (or another slot is picked).
if stack.as_ref().is_some_and(|s| &*s.item == "minecraft:bow") {
self.using = (slot == self.selected || slot == super::shield::OFFHAND_SLOT)
.then_some((slot, ticks + 1));
return;
}
let consumable = stack
.as_ref()
.and_then(|s| self.res.items().get(&s.item))
+3 -2
View File
@@ -608,7 +608,8 @@ def check_pvp(host, guest, out):
host('command', command='team remove parity_allies')
assert hits['guest hits host'][1] < hits['guest hits host'][0], f'the guest did not hurt the host: {hits}'
assert hits['host hits guest'][1] < hits['host hits guest'][0], f'the host did not hurt the guest: {hits}'
assert hits['pvp off'][1] == hits['pvp off'][0], f'pvp off still hurts: {hits}'
# Natural regeneration may heal the victim meanwhile.
assert hits['pvp off'][1] >= hits['pvp off'][0], f'pvp off still hurts: {hits}'
for name in ('guest hits teammate', 'host hits teammate'):
assert hits[name][1] == hits[name][0], f'friendly fire off still hurts ({name}): {hits}'
return hits
@@ -643,7 +644,7 @@ def check_arrows(host, guest, out):
g('command', command='clear @s')
assert hits['guest shoots host'][1] < hits['guest shoots host'][0], f"the guest's arrow did not hurt the host: {hits}"
assert hits['host shoots guest'][1] < hits['host shoots guest'][0], f"the host's arrow did not hurt the guest: {hits}"
assert hits['pvp off'][1] == hits['pvp off'][0], f'pvp off, an arrow still hurts: {hits}'
assert hits['pvp off'][1] >= hits['pvp off'][0], f'pvp off, an arrow still hurts: {hits}'
return hits