Merge pull request #1247 from rdbtCVS/t3/fix-q-drop-animation

🤖 Agent: merged after verify passed and the wave 2 integration run on the desktop (main + 16 contributor PRs, tree 71afc562: workspace tests 1887/0, launcher 113, naga translations 0 failures, parity --changed 304/0).
This commit is contained in:
Ludovic Marie
2026-10-22 21:56:24 +02:00
committed by GitHub
4 changed files with 65 additions and 18 deletions
@@ -14,13 +14,22 @@ fn main() {
for count in [0, 1, 4, 64] {
let mut slot = Some(ItemStack::new("minecraft:stone", count));
let mut dropped = 0;
let mut swings = 0;
let mut packets = 0;
for _ in 0..2 {
if let Some(stack) =
take_held_drop(&mut slot, all, mode == GameMode::Spectator)
{
dropped += stack.count;
swings += 1;
}
println!("{} {}", slot.as_ref().map_or(0, |s| s.count), dropped);
if mode != GameMode::Spectator {
packets += 1;
}
println!(
"{} {dropped} {swings} {packets}",
slot.as_ref().map_or(0, |s| s.count),
);
}
}
}
+13 -10
View File
@@ -7,7 +7,7 @@
//! client predicts its own movement; the server stays authoritative for
//! everything else.
use super::{Dim, Game, Mining, Screen};
use horizon_client::first_person::Hand;
use horizon_client::first_person::{Hand, SwingAnimation};
use horizon_client::{
Result,
chunk::{BIOME_STRATEGY, Chunk, Light, MIN_Y, SECTIONS, Section, block_strategy},
@@ -3983,23 +3983,26 @@ impl Game<'_> {
Ok(true)
}
KeyCode::KeyQ => {
if self.spectator() {
return Ok(true);
}
let all = self.keys.contains(&KeyCode::ControlLeft);
// MultiPlayerGameMode.dropItem: predict removal before sending
// the action, then swing only if a nonempty stack was removed.
let dropped = horizon_client::items::take_held_drop(
&mut self.inventory[self.selected],
all,
false,
);
self.send(S::PlayerAction(play::PlayerAction {
action: if all { 4 } else { 5 },
pos: [0; 3],
direction: 0,
sequence: 0,
}));
// Inventory.removeFromSelected (prediction).
let slot = &mut self.inventory[self.selected];
if let Some(s) = slot {
if all || s.count <= 1 {
*slot = None;
} else {
s.count -= 1;
}
if dropped.is_some() {
self.swing_hand(Hand::Main, SwingAnimation::DEFAULT);
}
self.swing_arm();
Ok(true)
}
KeyCode::KeyE => {
@@ -6,9 +6,14 @@ import java.io.PrintWriter;
import net.minecraft.client.*;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.*;
import net.minecraft.world.item.*;
import net.minecraft.world.item.component.SwingAnimation;
import net.minecraft.world.level.GameType;
/** Runs the real key handler through its drop loop; stops before item-use handling. */
@@ -41,16 +46,36 @@ public final class VanillaHeldDropOracle {
}
static final class Actor extends LocalPlayer {
GameType mode;
int swings;
Actor() { super(null, null, null, null, null, null, false, null, null); }
@Override public GameType gameMode() { return mode; }
@Override public boolean isUsingItem() { throw new Done(); }
@Override public boolean swing(InteractionHand hand, SwingAnimation animation, boolean sendPacket) {
if (hand != InteractionHand.MAIN_HAND || !animation.equals(SwingAnimation.DEFAULT) || sendPacket)
throw new AssertionError("unexpected drop swing");
swings++;
return true;
}
}
static final class Connection extends ClientPacketListener {
int drops;
ServerboundPlayerActionPacket.Action expected;
Connection() { super(null, null, null); }
@Override public void send(Packet<?> packet) {
if (packet instanceof ServerboundPlayerActionPacket action) {
if (action.getAction() != expected) throw new AssertionError("unexpected drop action");
drops++;
}
}
}
static final class Controller extends MultiPlayerGameMode {
int dropped;
Controller() { super(null, null); }
// Controlled dispatch boundary: no networking, swings, statistics or item entities.
// Run vanilla's actual prediction, packet dispatch and conditional swing.
@Override public void dropItem(LocalPlayer player, boolean all) {
dropped += player.getInventory().removeFromSelected(all).getCount();
int before = player.getInventory().getSelectedItem().getCount();
super.dropItem(player, all);
dropped += before - player.getInventory().getSelectedItem().getCount();
}
}
public static void main(String[] args) throws Exception {
@@ -81,6 +106,9 @@ public final class VanillaHeldDropOracle {
field(Player.class, "inventory").set(actor, inventory);
field(Minecraft.class, "player").set(client, actor);
var controller = make(Controller.class);
var connection = make(Connection.class);
field(MultiPlayerGameMode.class, "minecraft").set(controller, client);
field(MultiPlayerGameMode.class, "connection").set(controller, connection);
field(Minecraft.class, "gameMode").set(client, controller);
try (var out = new PrintWriter(Files.newBufferedWriter(Path.of(args[0])))) {
for (var mode : GameType.values()) for (boolean all : new boolean[]{false, true}) {
@@ -91,6 +119,10 @@ public final class VanillaHeldDropOracle {
inventory.setSelectedSlot(selected);
inventory.setItem(selected, new ItemStack(Items.STONE, count));
controller.dropped = 0;
actor.swings = 0;
connection.drops = 0;
connection.expected = all ? ServerboundPlayerActionPacket.Action.DROP_ALL_ITEMS
: ServerboundPlayerActionPacket.Action.DROP_ITEM;
// Two consecutive key presses also cover an emptied stack and repeated spectator drops.
for (int press = 0; press < 2; press++) {
((Key) options.keyDrop).clicks = 1;
@@ -100,7 +132,8 @@ public final class VanillaHeldDropOracle {
} catch (InvocationTargetException e) {
if (!(e.getCause() instanceof Done)) throw e;
}
out.println(inventory.getSelectedItem().getCount() + " " + controller.dropped);
out.println(inventory.getSelectedItem().getCount() + " " + controller.dropped
+ " " + actor.swings + " " + connection.drops);
}
}
}
+6 -4
View File
@@ -2,10 +2,12 @@
"""Compare selected-slot drops with Minecraft.handleKeybinds in all four game modes.
The oracle invokes the unmodified native key handler, consuming real drop-key
clicks. Its controlled dropItem callback removes from the real player Inventory;
other keys are idle and execution stops at the following item-use boundary.
clicks, and MultiPlayerGameMode.dropItem's real prediction and swing dispatch.
Other keys are idle and execution stops at the following item-use boundary.
Checks Q/Ctrl+Q, slots 0/8, empty/single/partial/full stacks and repeated drops.
Packet delivery, item entities, swing animation and statistics are outside scope.
Checks swing attempts and drop packet counts, including packets without swings
for empty slots. Packet delivery, animation ticks, item entities and statistics
are outside scope.
"""
import os
import subprocess
@@ -35,7 +37,7 @@ def main():
subprocess.run(['cargo', 'run', '--quiet', '-p', 'horizon-client', '--example',
'held_drop_fixture'], cwd=lab.ROOT, stdout=out, check=True)
matched = base.compare(build / 'vanilla.txt', build / 'rust.txt')
print(f'Held drop parity passed: {matched} selected-stack/drop-count snapshots match vanilla')
print(f'Held drop parity passed: {matched} inventory/drop/swing/packet snapshots match vanilla')
if __name__ == '__main__':