Merge pull request #2644 from kacpherek/fix/remote-break-item-change
🤖 Agent: Proven in union R1 (branch union/cg19-r1, main + 83 of kacpherek's PRs): the 98 harnesses it can affect, clippy -D warnings, tests, lan_e2e in-frame and on the server thread.
This commit is contained in:
@@ -144,6 +144,11 @@ impl Game<'_> {
|
||||
let harvest = !facts.requires_tool || self.res.items().correct_for_drops(held, &facts.name);
|
||||
speed / facts.hardness / if harvest { 30.0 } else { 100.0 }
|
||||
}
|
||||
/// A key for the main-hand stack (`destroyingItem`): its item and components.
|
||||
pub(super) fn main_hand_key(&self) -> String {
|
||||
self.held()
|
||||
.map_or(String::new(), |s| format!("{} {:?}", s.item, s.extra))
|
||||
}
|
||||
/// Whether an attack would hit an entity rather than the block behind
|
||||
/// it: the crosshair's `EntityHitResult`.
|
||||
pub(super) fn entity_targeted(&self) -> bool {
|
||||
@@ -503,9 +508,7 @@ impl HandWorld for GameHands<'_, '_> {
|
||||
true
|
||||
}
|
||||
fn main_hand_key(&mut self) -> String {
|
||||
self.game
|
||||
.held()
|
||||
.map_or(String::new(), |s| format!("{} {:?}", s.item, s.extra))
|
||||
self.game.main_hand_key()
|
||||
}
|
||||
fn destroy_stage(&mut self, _: [i32; 3], _: Option<i32>) {}
|
||||
fn swing(&mut self, hand: Hand, animation: SwingAnimation) {
|
||||
|
||||
@@ -194,6 +194,8 @@ pub(super) struct Remote {
|
||||
/// The local player's profile name: its score holder and team member.
|
||||
pub(super) profile_name: String,
|
||||
destroying: Option<([i32; 3], u8, f32)>,
|
||||
/// `MultiPlayerGameMode.destroyingItem`: the held item key the break began with.
|
||||
destroying_item: String,
|
||||
destroy_delay: u32,
|
||||
input: horizon_client::interaction_input::InteractionInput,
|
||||
/// Keys whose presses send a packet (swap hands, drop, a mount's
|
||||
@@ -494,6 +496,7 @@ impl Game<'_> {
|
||||
profile: 0,
|
||||
profile_name: String::new(),
|
||||
destroying: None,
|
||||
destroying_item: String::new(),
|
||||
destroy_delay: 0,
|
||||
input: Default::default(),
|
||||
pending_keys: Vec::new(),
|
||||
@@ -4152,6 +4155,8 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// `MultiPlayerGameMode.stopDestroyBlock`: aborts the break and starts
|
||||
/// the attack strength again.
|
||||
pub(super) fn stop_remote_mining(&mut self) {
|
||||
if let Some((pos, _, _)) = self.remote.as_mut().and_then(|r| r.destroying.take()) {
|
||||
self.send(S::PlayerAction(play::PlayerAction {
|
||||
@@ -4160,6 +4165,7 @@ impl Game<'_> {
|
||||
direction: 0,
|
||||
sequence: 0,
|
||||
}));
|
||||
self.reset_attack_strength();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4213,11 +4219,11 @@ impl Game<'_> {
|
||||
} else {
|
||||
self.destroy_progress(hit.pos)
|
||||
};
|
||||
let same = self
|
||||
.remote
|
||||
.as_ref()
|
||||
.and_then(|r| r.destroying)
|
||||
.is_some_and(|(p, _, _)| p == hit.pos);
|
||||
// sameDestroyTarget: the same block and still the item the break began with.
|
||||
let held = self.main_hand_key();
|
||||
let same = self.remote.as_ref().is_some_and(|r| {
|
||||
r.destroying.is_some_and(|(p, _, _)| p == hit.pos) && r.destroying_item == held
|
||||
});
|
||||
if start && same {
|
||||
return;
|
||||
}
|
||||
@@ -4244,6 +4250,7 @@ impl Game<'_> {
|
||||
}
|
||||
if let Some(r) = self.remote.as_mut() {
|
||||
r.destroying = Some((hit.pos, face, 0.0));
|
||||
r.destroying_item = held;
|
||||
}
|
||||
// startDestroyBlock plays the first hit and crack itself; the
|
||||
// server's level events 2019 and 2020 do the rest.
|
||||
|
||||
@@ -26,7 +26,7 @@ class RemoteMiningTests(unittest.TestCase):
|
||||
struct Hit { pos: [i32; 3], face: u8 }
|
||||
struct Mining { pos: [i32; 3], progress: f32, ticks: u32 }
|
||||
#[derive(Default)]
|
||||
struct Remote { destroy_delay: u32, destroying: Option<([i32; 3], u8, f32)> }
|
||||
struct Remote { destroy_delay: u32, destroying: Option<([i32; 3], u8, f32)>, destroying_item: String }
|
||||
struct Ground { on_ground: bool }
|
||||
struct Player { ground: Ground }
|
||||
#[derive(Clone)]
|
||||
@@ -70,6 +70,8 @@ struct Game {
|
||||
hit: Hit, sequence: i32, packets: Vec<play::PlayerAction>,
|
||||
}
|
||||
impl Game {
|
||||
fn main_hand_key(&self) -> String { String::new() }
|
||||
fn reset_attack_strength(&mut self) {}
|
||||
fn new(hardness: f32, speed: f32, creative: bool) -> Self {
|
||||
Self {
|
||||
remote: Some(Remote::default()), mining: None, creative,
|
||||
|
||||
Reference in New Issue
Block a user