Merge pull request #999 from ludovic111/fix/guest-use-item-on
🤖 Agent: merged after verify passed. A remote player's item used on a block is used once (a snowball thrown at the ground flew 2× main hand / 3× off hand); part of #484.
This commit is contained in:
@@ -451,6 +451,15 @@ struct Hit {
|
||||
face: [i32; 3],
|
||||
point: [f64; 3],
|
||||
}
|
||||
/// A guest's right click comes as one packet per hand and part
|
||||
/// (`Minecraft.startUseItem`): `ServerGamePacketListenerImpl.handleUseItemOn`
|
||||
/// does the block's and `ItemStack.useOn`'s part, `handleUseItem` the
|
||||
/// item's own (`Item.use`). Running both for either would use the item twice.
|
||||
#[derive(Clone, Copy)]
|
||||
enum GuestUse {
|
||||
OnBlock(Hand),
|
||||
Item(Hand),
|
||||
}
|
||||
|
||||
/// The client world as seen by the vanilla block-behaviour library.
|
||||
struct GameLevel<'w> {
|
||||
@@ -1354,9 +1363,8 @@ struct Game<'a> {
|
||||
saved_for_exit: bool,
|
||||
/// The block a guest is acting on (game/lan_actions.rs).
|
||||
forced_hit: Option<Hit>,
|
||||
/// A guest's `ServerboundUseItemPacket`: the held item alone, no block
|
||||
/// or entity (`ServerGamePacketListenerImpl.handleUseItem`).
|
||||
lan_item_only: bool,
|
||||
/// The part of a right click a guest's packet asks for (game/lan_actions.rs).
|
||||
guest_use: Option<GuestUse>,
|
||||
/// Level events of this tick for the guests, and the guest acting now.
|
||||
lan_events: Vec<(i32, [i32; 3], i32, Option<u32>)>,
|
||||
/// Block events (position, b0, b1, state) and entity events (id, event,
|
||||
@@ -2889,13 +2897,18 @@ impl Game<'_> {
|
||||
return Ok(None);
|
||||
}
|
||||
// A carrot or warped fungus on a stick boosts the ridden pig or strider.
|
||||
if self.riding.is_some()
|
||||
// A guest's use packets name one hand and touch no entity: the client
|
||||
// sends one per hand and part of its click, and Interact for entities.
|
||||
let guest = self.guest_use;
|
||||
let on_block = matches!(guest, Some(GuestUse::OnBlock(_)));
|
||||
if !on_block
|
||||
&& self.riding.is_some()
|
||||
&& let Some(item) = self.held().map(|s| s.item.clone())
|
||||
&& self.use_steering_stick(&item)
|
||||
{
|
||||
return Ok(Some(Hand::Main));
|
||||
}
|
||||
if !self.lan_item_only
|
||||
if guest.is_none()
|
||||
&& (self.interact_frame()
|
||||
|| self.interact_armor_stand()
|
||||
|| self.interact_boat()
|
||||
@@ -2906,12 +2919,16 @@ impl Game<'_> {
|
||||
return Ok(Some(Hand::Main));
|
||||
}
|
||||
// An EntityHitResult may fall through to Item.use, never to useItemOn.
|
||||
let block_hit = if self.lan_item_only || self.entity_targeted() {
|
||||
let block_hit = if matches!(guest, Some(GuestUse::Item(_))) || self.entity_targeted() {
|
||||
None
|
||||
} else {
|
||||
self.pick()
|
||||
};
|
||||
for hand in Hand::BOTH {
|
||||
let hands = match guest {
|
||||
Some(GuestUse::OnBlock(hand) | GuestUse::Item(hand)) => vec![hand],
|
||||
None => Hand::BOTH.to_vec(),
|
||||
};
|
||||
for hand in hands {
|
||||
if self.with_hand(hand, |game| game.use_hand(block_hit.as_ref()))? {
|
||||
return Ok(Some(hand));
|
||||
}
|
||||
@@ -2971,17 +2988,7 @@ impl Game<'_> {
|
||||
[-1, 0, 0] => Direction::West,
|
||||
_ => Direction::East,
|
||||
};
|
||||
let player = PlayerContext {
|
||||
yaw: self.yaw,
|
||||
pitch: self.pitch,
|
||||
may_build: self.may_build(),
|
||||
can_eat: self.creative
|
||||
|| self
|
||||
.player
|
||||
.as_ref()
|
||||
.is_some_and(|p| p.health.food.food < 20),
|
||||
game_master: self.can_use_game_master_blocks(),
|
||||
};
|
||||
let player = self.use_context();
|
||||
let at = Vec3::new(hit.point[0], hit.point[1], hit.point[2]);
|
||||
let item = held.as_ref().map(|s| s.item.to_string());
|
||||
let result = self.with_level(|b, level, ticks| {
|
||||
@@ -3011,6 +3018,10 @@ impl Game<'_> {
|
||||
if block_hit.is_some() && (self.use_bone_meal(&stack)? || self.ignite_tnt(&stack)?) {
|
||||
return Ok(true);
|
||||
}
|
||||
// A guest's UseItemOn stops at ItemStack.useOn: what Item.use does
|
||||
// (throw, drink, eat, raise, equip) waits for its UseItem.
|
||||
let on_block = matches!(self.guest_use, Some(GuestUse::OnBlock(_)));
|
||||
let spawn_egg = stack.item.ends_with("_spawn_egg");
|
||||
use horizon_client::first_person::UseResult;
|
||||
let swings = self.swings_started;
|
||||
match self.use_tool(&stack, block_hit.is_some())? {
|
||||
@@ -3023,30 +3034,33 @@ impl Game<'_> {
|
||||
UseResult::Fail => return Ok(true),
|
||||
UseResult::Pass => {}
|
||||
}
|
||||
if self.use_potion_item(&stack)?
|
||||
|| ((block_hit.is_some() || !stack.item.ends_with("_spawn_egg"))
|
||||
if (!on_block && self.use_potion_item(&stack)?)
|
||||
|| ((block_hit.is_some() || !spawn_egg)
|
||||
&& (!on_block || spawn_egg)
|
||||
&& self.throw_item(&stack)?)
|
||||
{
|
||||
return Ok(true);
|
||||
}
|
||||
if self.raise_shield(self.held_slot())
|
||||
|| self.use_fishing_rod(&stack)
|
||||
if !on_block
|
||||
&& (self.raise_shield(self.held_slot())
|
||||
|| self.use_fishing_rod(&stack)
|
||||
|| self.use_crossbow(&stack)
|
||||
|| self.use_trident(&stack)
|
||||
|| self.boost_firework(&stack)
|
||||
|| self.use_empty_map(&stack)
|
||||
|| self.use_book(&stack)
|
||||
// Block items (heads, carved pumpkins) aimed at a block are
|
||||
// placed first (useItemOn before useItem).
|
||||
|| (!(info.block.is_some() && block_hit.is_some()) && self.equip_from_hand(&stack))
|
||||
|| self.use_book(&stack)
|
||||
// Block items (heads, carved pumpkins) aimed at a block are
|
||||
// placed first (useItemOn before useItem).
|
||||
|| (!(info.block.is_some() && block_hit.is_some())
|
||||
&& self.equip_from_hand(&stack)))
|
||||
{
|
||||
return Ok(true);
|
||||
}
|
||||
if &*stack.item == "minecraft:spyglass" {
|
||||
if !on_block && &*stack.item == "minecraft:spyglass" {
|
||||
self.use_spyglass();
|
||||
return Ok(true);
|
||||
}
|
||||
if &*stack.item == "minecraft:bow" {
|
||||
if !on_block && &*stack.item == "minecraft:bow" {
|
||||
if self.using.is_none()
|
||||
&& (self.creative || self.projectile_slot("minecraft:bow").is_some())
|
||||
{
|
||||
@@ -3055,11 +3069,11 @@ impl Game<'_> {
|
||||
return Ok(true);
|
||||
}
|
||||
// Block foods attempt placement before starting consumption.
|
||||
if !(info.block.is_some() && block_hit.is_some()) && self.start_eating(&info) {
|
||||
if !on_block && !(info.block.is_some() && block_hit.is_some()) && self.start_eating(&info) {
|
||||
return Ok(true);
|
||||
}
|
||||
// BoatItem.use also performs its own fluid/block raycast.
|
||||
if self.place_boat(&stack) {
|
||||
if !on_block && self.place_boat(&stack) {
|
||||
return Ok(true);
|
||||
}
|
||||
if let Some(hit) = block_hit
|
||||
@@ -3083,7 +3097,7 @@ impl Game<'_> {
|
||||
}
|
||||
if !self.may_build() {
|
||||
// ItemStack.useOn passes in adventure mode; useItem eats.
|
||||
return Ok(self.start_eating(&info));
|
||||
return Ok(!on_block && self.start_eating(&info));
|
||||
}
|
||||
let face = match hit.face {
|
||||
[0, 1, 0] => Direction::Up,
|
||||
@@ -3160,6 +3174,20 @@ impl Game<'_> {
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
/// The player as a block's `useItemOn` / `useWithoutItem` sees them.
|
||||
fn use_context(&self) -> PlayerContext {
|
||||
PlayerContext {
|
||||
yaw: self.yaw,
|
||||
pitch: self.pitch,
|
||||
may_build: self.may_build(),
|
||||
can_eat: self.creative
|
||||
|| self
|
||||
.player
|
||||
.as_ref()
|
||||
.is_some_and(|p| p.health.food.food < 20),
|
||||
game_master: self.can_use_game_master_blocks(),
|
||||
}
|
||||
}
|
||||
/// `Consumable.startConsuming` for a held consumable: food needs
|
||||
/// `Player.canEat` (`Consumable.canConsume`), anything else is always
|
||||
/// consumed. The right click is held for `consume_seconds`.
|
||||
@@ -7626,6 +7654,13 @@ impl Game<'_> {
|
||||
{
|
||||
return Ok(UseResult::Success { swing: true });
|
||||
}
|
||||
// BucketItem has no useOn: a guest's UseItemOn leaves it to UseItem.
|
||||
let bucket = horizon_client::items::bucket_contents(&stack.item);
|
||||
if matches!(self.guest_use, Some(GuestUse::OnBlock(_)))
|
||||
&& (item == "bucket" || bucket.is_some())
|
||||
{
|
||||
return Ok(UseResult::Pass);
|
||||
}
|
||||
if item == "bucket" {
|
||||
// getPlayerPOVHitResult(SOURCE_ONLY): powder snow's outline before
|
||||
// a fluid source behind it.
|
||||
@@ -7684,7 +7719,6 @@ impl Game<'_> {
|
||||
return Ok(UseResult::Success { swing: true });
|
||||
}
|
||||
// BucketItem.use has its own ray, even when the crosshair hits an entity.
|
||||
let bucket = horizon_client::items::bucket_contents(&stack.item);
|
||||
if !allow_block_actions && bucket.is_none() {
|
||||
return Ok(UseResult::Pass);
|
||||
}
|
||||
@@ -10969,7 +11003,7 @@ impl<'a> Game<'a> {
|
||||
text_selection: Default::default(),
|
||||
saved_for_exit: false,
|
||||
forced_hit: None,
|
||||
lan_item_only: false,
|
||||
guest_use: None,
|
||||
lan_events: Vec::new(),
|
||||
lan_block_events: Vec::new(),
|
||||
lan_entity_events: Vec::new(),
|
||||
|
||||
@@ -243,6 +243,10 @@ impl Game<'_> {
|
||||
(state.name == "minecraft:end_portal_frame").then(|| (hit, state.clone()))
|
||||
});
|
||||
let Some((hit, state)) = target else {
|
||||
// EnderEyeItem.useOn passes off a frame: a guest's UseItem throws it.
|
||||
if matches!(self.guest_use, Some(super::GuestUse::OnBlock(_))) {
|
||||
return Ok(false);
|
||||
}
|
||||
// EnderEyeItem.use: throw the eye towards the nearest stronghold.
|
||||
self.throw_ender_eye();
|
||||
return Ok(true);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//! blocks, attacking and the commands all behave exactly as they do for the
|
||||
//! host, and every world change they cause reaches all players through the
|
||||
//! block log, the level events and the entity tracker.
|
||||
use super::{Game, Hit, Mining, Screen, lan::LanHost};
|
||||
use super::{Game, GuestUse, Hit, Mining, Screen, lan::LanHost};
|
||||
use horizon_client::{
|
||||
command::vanilla,
|
||||
containers::BlockEntity,
|
||||
@@ -774,11 +774,14 @@ impl Game<'_> {
|
||||
f64::from(p.pos[2]) + f64::from(p.cursor[2]),
|
||||
],
|
||||
};
|
||||
let hand = if p.hand == 1 { Hand::Off } else { Hand::Main };
|
||||
let swung = self.as_guest(host, conn, |g| {
|
||||
g.forced_hit = Some(hit);
|
||||
g.guest_use = Some(GuestUse::OnBlock(hand));
|
||||
let swings = g.swings_started;
|
||||
let _ = g.use_item();
|
||||
g.forced_hit = None;
|
||||
g.guest_use = None;
|
||||
g.swings_started != swings
|
||||
});
|
||||
self.lan_swing_back(host, conn, swung);
|
||||
@@ -797,14 +800,17 @@ impl Game<'_> {
|
||||
if spectator {
|
||||
return;
|
||||
}
|
||||
// handleUseItem: the client's rotation, then the item alone. What it
|
||||
// looked at a moment ago (a block, a mob) is UseItemOn's or Interact's.
|
||||
// handleUseItem: the client's rotation (absSnapRotationTo, which
|
||||
// sends nothing back), then the item alone. What it looked at a
|
||||
// moment ago (a block, a mob) is UseItemOn's or Interact's.
|
||||
let hand = if p.hand == 1 { Hand::Off } else { Hand::Main };
|
||||
let g = &mut host.hub.guests[gi];
|
||||
(g.yaw, g.pitch) = (p.yaw, p.pitch);
|
||||
let swung = self.as_guest(host, conn, |g| {
|
||||
(g.yaw, g.pitch) = (p.yaw, p.pitch);
|
||||
g.lan_item_only = true;
|
||||
g.guest_use = Some(GuestUse::Item(hand));
|
||||
let swings = g.swings_started;
|
||||
let _ = g.use_item();
|
||||
g.lan_item_only = false;
|
||||
g.guest_use = None;
|
||||
g.swings_started != swings
|
||||
});
|
||||
self.lan_swing_back(host, conn, swung);
|
||||
|
||||
@@ -7,6 +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::{
|
||||
Result,
|
||||
chunk::{BIOME_STRATEGY, Chunk, Light, MIN_Y, SECTIONS, Section, block_strategy},
|
||||
@@ -1687,7 +1688,6 @@ impl Game<'_> {
|
||||
// ClientPacketListener.handleSwingAnimation: the entity swings
|
||||
// (LivingEntity.swing, which a swing in its first half ignores).
|
||||
C::SwingAnimation(p) => {
|
||||
use horizon_client::first_person::Hand;
|
||||
let hand = if p.hand == 1 { Hand::Off } else { Hand::Main };
|
||||
let animation = horizon_client::first_person::SwingAnimation {
|
||||
kind: p.kind.clamp(0, 255) as u8,
|
||||
@@ -3215,12 +3215,16 @@ impl Game<'_> {
|
||||
false
|
||||
}
|
||||
|
||||
fn remote_use_block(&mut self) -> bool {
|
||||
let held_block = self
|
||||
.held()
|
||||
/// MultiPlayerGameMode.useItemOn for `hand`: whether the click ends there
|
||||
/// (the block reacts, or a block item is placed).
|
||||
fn remote_use_block(&mut self, hand: Hand) -> bool {
|
||||
let held = self.with_hand(hand, |g| g.held().cloned());
|
||||
let held_block = held
|
||||
.as_ref()
|
||||
.and_then(|h| self.res.items().get(&h.item))
|
||||
.is_some_and(|i| i.block.is_some());
|
||||
if let Some(hit) = self.pick() {
|
||||
let reacts = hand == Hand::Main && self.remote_block_reacts(&hit, held.as_ref());
|
||||
let seq = self.next_sequence();
|
||||
let cursor = [
|
||||
(hit.point[0] - f64::from(hit.pos[0])) as f32,
|
||||
@@ -3228,7 +3232,7 @@ impl Game<'_> {
|
||||
(hit.point[2] - f64::from(hit.pos[2])) as f32,
|
||||
];
|
||||
self.send(S::UseItemOn(play::UseItemOn {
|
||||
hand: 0,
|
||||
hand: hand_id(hand),
|
||||
pos: hit.pos,
|
||||
face: i32::from(face_direction(hit.face)),
|
||||
cursor,
|
||||
@@ -3247,28 +3251,85 @@ impl Game<'_> {
|
||||
r.placing = Some((target, ticks));
|
||||
}
|
||||
if held_block {
|
||||
self.swing_arm();
|
||||
self.with_hand(hand, Game::swing_arm);
|
||||
return true;
|
||||
}
|
||||
return reacts;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn remote_use_item(&mut self) {
|
||||
if let Some(held) = self.held().cloned() {
|
||||
let seq = self.next_sequence();
|
||||
self.send(S::UseItem(play::UseItem {
|
||||
hand: 0,
|
||||
sequence: seq,
|
||||
yaw: self.yaw,
|
||||
pitch: self.pitch,
|
||||
}));
|
||||
// MultiPlayerGameMode.useItem runs the use here too: food starts
|
||||
// being eaten (Consumable.startConsuming).
|
||||
if let Some(info) = self.res.items().get(&held.item).cloned() {
|
||||
self.start_eating(&info);
|
||||
}
|
||||
/// Whether the block hit takes a main-hand right click with `held`
|
||||
/// (`BlockState.useItemOn`, then `useWithoutItem`): a door, a button, a
|
||||
/// container. Vanilla's client runs it on its own level first; this runs
|
||||
/// it on a copy that keeps no change.
|
||||
fn remote_block_reacts(&self, hit: &super::Hit, held: Option<&ItemStack>) -> bool {
|
||||
// Player.isSecondaryUseActive with something in either hand.
|
||||
let hands_full = self.stack_in(self.selected).is_some() || self.offhand.is_some();
|
||||
if self.keys.contains(&KeyCode::ShiftLeft) && hands_full {
|
||||
return false;
|
||||
}
|
||||
use horizon_core::geometry::Direction;
|
||||
let face = match hit.face {
|
||||
[0, 1, 0] => Direction::Up,
|
||||
[0, -1, 0] => Direction::Down,
|
||||
[0, 0, -1] => Direction::North,
|
||||
[0, 0, 1] => Direction::South,
|
||||
[-1, 0, 0] => Direction::West,
|
||||
_ => Direction::East,
|
||||
};
|
||||
let mut level = DryLevel {
|
||||
world: &self.world,
|
||||
changed: HashMap::new(),
|
||||
random: horizon_core::random::LegacyRandom::new(0),
|
||||
};
|
||||
self.res
|
||||
.behaviours()
|
||||
.use_item_on(
|
||||
&mut level,
|
||||
&mut horizon_world::level::Ticks::default(),
|
||||
horizon_core::position::BlockPos::new(hit.pos[0], hit.pos[1], hit.pos[2]),
|
||||
face,
|
||||
horizon_core::geometry::Vec3::new(hit.point[0], hit.point[1], hit.point[2]),
|
||||
self.use_context(),
|
||||
held.map(|s| &*s.item),
|
||||
)
|
||||
.consumes_action()
|
||||
}
|
||||
|
||||
/// MultiPlayerGameMode.useItem for `hand`, if it holds something: whether
|
||||
/// the click ends there, as far as this client can tell (`item_has_use`).
|
||||
fn remote_use_item(&mut self, hand: Hand) -> bool {
|
||||
let Some(held) = self.with_hand(hand, |g| g.held().cloned()) else {
|
||||
return false;
|
||||
};
|
||||
let seq = self.next_sequence();
|
||||
self.send(S::UseItem(play::UseItem {
|
||||
hand: hand_id(hand),
|
||||
sequence: seq,
|
||||
yaw: self.yaw,
|
||||
pitch: self.pitch,
|
||||
}));
|
||||
let Some(info) = self.res.items().get(&held.item).cloned() else {
|
||||
return false;
|
||||
};
|
||||
// MultiPlayerGameMode.useItem runs the use here too: food starts
|
||||
// being eaten (Consumable.startConsuming).
|
||||
self.with_hand(hand, |g| g.start_eating(&info));
|
||||
item_has_use(&info)
|
||||
}
|
||||
|
||||
/// The rest of Minecraft.startUseItem once the main hand's target passed:
|
||||
/// the main hand's item, then the off hand's turn (its block, its item).
|
||||
/// The server does each packet's part with that packet's hand only.
|
||||
fn remote_use_hands(&mut self) {
|
||||
if self.remote_use_item(Hand::Main) {
|
||||
return;
|
||||
}
|
||||
if !self.entity_targeted() && self.remote_use_block(Hand::Off) {
|
||||
return;
|
||||
}
|
||||
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
|
||||
@@ -4122,6 +4183,92 @@ pub(super) fn input_ordinal(input: Input) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// The client's world for a guess at what a click does: reads go to the
|
||||
/// world, writes stay here and are dropped.
|
||||
struct DryLevel<'w> {
|
||||
world: &'w horizon_client::world::World,
|
||||
changed: HashMap<horizon_core::position::BlockPos, BlockStateId>,
|
||||
random: horizon_core::random::LegacyRandom,
|
||||
}
|
||||
|
||||
impl horizon_world::level::LevelAccess for DryLevel<'_> {
|
||||
fn block_state(&self, pos: horizon_core::position::BlockPos) -> BlockStateId {
|
||||
self.changed
|
||||
.get(&pos)
|
||||
.copied()
|
||||
.unwrap_or_else(|| self.world.block(pos.x, pos.y, pos.z))
|
||||
}
|
||||
fn set_raw(
|
||||
&mut self,
|
||||
pos: horizon_core::position::BlockPos,
|
||||
state: BlockStateId,
|
||||
) -> Option<BlockStateId> {
|
||||
let previous = self.block_state(pos);
|
||||
self.changed.insert(pos, state);
|
||||
Some(previous)
|
||||
}
|
||||
fn is_loaded(&self, pos: horizon_core::position::BlockPos) -> bool {
|
||||
self.world.loaded(pos.x, pos.z)
|
||||
}
|
||||
fn random(&mut self) -> &mut horizon_core::random::LegacyRandom {
|
||||
&mut self.random
|
||||
}
|
||||
fn game_time(&self) -> i64 {
|
||||
self.world.game_time
|
||||
}
|
||||
}
|
||||
|
||||
/// `InteractionHand` on the wire.
|
||||
fn hand_id(hand: Hand) -> i32 {
|
||||
match hand {
|
||||
Hand::Main => 0,
|
||||
Hand::Off => 1,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `Item.use` usually acts on this item (eats, drinks, equips, raises,
|
||||
/// throws, shoots, fills or places), which ends `Minecraft.startUseItem` at
|
||||
/// its hand. Tools and materials pass, and the off hand gets its turn. The
|
||||
/// server decides; this is the client's guess of whether to go on.
|
||||
fn item_has_use(info: &horizon_client::items::ItemInfo) -> bool {
|
||||
let id = info.id.trim_start_matches("minecraft:");
|
||||
info.consumable.is_some()
|
||||
|| info.equip_slot.is_some()
|
||||
|| info.blocks_attacks.is_some()
|
||||
|| horizon_client::items::bucket_contents(&info.id).is_some()
|
||||
|| id.ends_with("_boat")
|
||||
|| id.ends_with("_raft")
|
||||
|| id.ends_with("_bundle")
|
||||
|| matches!(
|
||||
id,
|
||||
"bow"
|
||||
| "crossbow"
|
||||
| "trident"
|
||||
| "spyglass"
|
||||
| "fishing_rod"
|
||||
| "snowball"
|
||||
| "egg"
|
||||
| "blue_egg"
|
||||
| "brown_egg"
|
||||
| "ender_pearl"
|
||||
| "ender_eye"
|
||||
| "wind_charge"
|
||||
| "splash_potion"
|
||||
| "lingering_potion"
|
||||
| "experience_bottle"
|
||||
| "bucket"
|
||||
| "glass_bottle"
|
||||
| "map"
|
||||
| "writable_book"
|
||||
| "written_book"
|
||||
| "goat_horn"
|
||||
| "bundle"
|
||||
| "brush"
|
||||
| "carrot_on_a_stick"
|
||||
| "warped_fungus_on_a_stick"
|
||||
)
|
||||
}
|
||||
|
||||
/// The view distance a client asks for: its render distance, which Horizon
|
||||
/// lets go past vanilla's 32 (a vanilla server still caps it at its own).
|
||||
fn client_view_distance(render_distance: i32) -> i8 {
|
||||
@@ -4137,10 +4284,10 @@ impl horizon_client::interaction_input::TargetUseWorld for RemoteUseWorld<'_, '_
|
||||
self.0.remote_use_entity()
|
||||
}
|
||||
fn use_block(&mut self) -> bool {
|
||||
self.0.remote_use_block()
|
||||
self.0.remote_use_block(Hand::Main)
|
||||
}
|
||||
fn use_item(&mut self) {
|
||||
self.0.remote_use_item();
|
||||
self.0.remote_use_hands();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -462,6 +462,8 @@ public final class VanillaProtocolClient {
|
||||
net.minecraft.core.BlockPos furnace = null;
|
||||
int furnaceWindow = -1;
|
||||
int furnaceState = 0;
|
||||
// Snowballs the server spawned since the last right click.
|
||||
int snowballs = 0;
|
||||
// The villager the server's console summoned beside the spawn.
|
||||
int villager = -1;
|
||||
net.minecraft.world.phys.Vec3 villagerAt = null;
|
||||
@@ -561,6 +563,9 @@ public final class VanillaProtocolClient {
|
||||
+ p.chatType().targetName().map(VanillaProtocolClient::json));
|
||||
} else if (packet instanceof ClientboundDisguisedChatPacket p && step > 0 && step < 5 + REPLIES.length) {
|
||||
record("play-chat", "disguised " + json(p.message()) + " " + p.chatType().chatType().getRegisteredName());
|
||||
} else if (packet instanceof net.minecraft.network.protocol.game.ClientboundAddEntityPacket p
|
||||
&& p.getType() == net.minecraft.world.entity.EntityTypes.SNOWBALL) {
|
||||
snowballs++;
|
||||
} else if (packet instanceof net.minecraft.network.protocol.game.ClientboundAddEntityPacket p
|
||||
&& p.getType() == net.minecraft.world.entity.EntityTypes.VILLAGER) {
|
||||
villager = p.getId();
|
||||
@@ -709,6 +714,37 @@ public final class VanillaProtocolClient {
|
||||
} else if (step == 11 + REPLIES.length && now - stepAt > 1500) {
|
||||
send(new net.minecraft.network.protocol.game.ServerboundContainerClosePacket(furnaceWindow));
|
||||
record("play-furnace", "closed");
|
||||
step++;
|
||||
stepAt = now;
|
||||
} else if (step == 12 + REPLIES.length && now - stepAt > 1500) {
|
||||
// Once the furnace is closed on the server too: the slot change isn't the furnace menu's.
|
||||
send(new ServerboundChatCommandPacket("item replace entity @s weapon.mainhand with minecraft:snowball 16"));
|
||||
step++;
|
||||
stepAt = now;
|
||||
} else if (step == 13 + REPLIES.length && now - stepAt > 1500) {
|
||||
// A right click on the ground with a snowball, as the 26.3 client sends it
|
||||
// (Minecraft.startUseItem): the block's part, which passes, then the item's.
|
||||
useOn(respawnAt, net.minecraft.world.InteractionHand.MAIN_HAND, 2);
|
||||
use(position, net.minecraft.world.InteractionHand.MAIN_HAND, 3);
|
||||
snowballs = 0;
|
||||
step++;
|
||||
stepAt = now;
|
||||
} else if (step == 14 + REPLIES.length && now - stepAt > 2000) {
|
||||
record("play-use", "main hand on a block: " + snowballs + " snowball(s)");
|
||||
send(new ServerboundChatCommandPacket("item replace entity @s weapon.mainhand with minecraft:air"));
|
||||
send(new ServerboundChatCommandPacket("item replace entity @s weapon.offhand with minecraft:snowball 16"));
|
||||
step++;
|
||||
stepAt = now;
|
||||
} else if (step == 15 + REPLIES.length && now - stepAt > 1500) {
|
||||
// An empty main hand: its block part only (no item to use), then the off hand's two.
|
||||
useOn(respawnAt, net.minecraft.world.InteractionHand.MAIN_HAND, 4);
|
||||
useOn(respawnAt, net.minecraft.world.InteractionHand.OFF_HAND, 5);
|
||||
use(position, net.minecraft.world.InteractionHand.OFF_HAND, 6);
|
||||
snowballs = 0;
|
||||
step++;
|
||||
stepAt = now;
|
||||
} else if (step == 16 + REPLIES.length && now - stepAt > 2000) {
|
||||
record("play-use", "off hand on a block: " + snowballs + " snowball(s)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -734,6 +770,19 @@ public final class VanillaProtocolClient {
|
||||
return type + (run > 1 && !type.equals("minecraft:remove_entities") ? " x" + run : "");
|
||||
}
|
||||
|
||||
/** ServerboundUseItemOnPacket on the top of the block under the player. */
|
||||
private void useOn(PositionMoveRotation at, net.minecraft.world.InteractionHand hand, int sequence) throws Exception {
|
||||
net.minecraft.core.BlockPos ground = net.minecraft.core.BlockPos.containing(at.position()).below();
|
||||
send(new net.minecraft.network.protocol.game.ServerboundUseItemOnPacket(hand,
|
||||
new net.minecraft.world.phys.BlockHitResult(net.minecraft.world.phys.Vec3.atCenterOf(ground).add(0.0, 0.5, 0.0),
|
||||
net.minecraft.core.Direction.UP, ground, false), sequence));
|
||||
}
|
||||
|
||||
/** ServerboundUseItemPacket, looking where the player looks. */
|
||||
private void use(PositionMoveRotation at, net.minecraft.world.InteractionHand hand, int sequence) throws Exception {
|
||||
send(new net.minecraft.network.protocol.game.ServerboundUseItemPacket(hand, sequence, at.yRot(), at.xRot()));
|
||||
}
|
||||
|
||||
/**
|
||||
* A packet after the respawn request, as compared: entity ids and periodic or streamed
|
||||
* packets (time, keep-alive, chunk data and light, whose batching follows each server's
|
||||
|
||||
@@ -16,7 +16,8 @@ LevelLoadTracker waits: until the "level chunks load start" event and the
|
||||
chunk under the player), sets a furnace
|
||||
beside itself, gives itself raw iron and coal, sets and asks its own score
|
||||
(`@s`), opens the furnace, shift-clicks
|
||||
the ore and the coal in and the ingot out, and leaves. The
|
||||
the ore and the coal in and the ingot out, right-clicks the ground with a
|
||||
snowball in the main hand, then in the off hand, and leaves. The
|
||||
console then runs `list` and `say` and `stop`. Compared, all of them
|
||||
exactly:
|
||||
|
||||
@@ -37,6 +38,9 @@ exactly:
|
||||
player respawned (guests' death messages aren't Horizon's yet: left out);
|
||||
- the furnace menu: its type and title, its contents, the slots each
|
||||
shift-click changes and its lit and cooking totals;
|
||||
- the snowballs each right click throws: one, though the client sends the
|
||||
block's part and the item's of each hand as separate packets
|
||||
(handleUseItemOn, handleUseItem);
|
||||
- the console lines about the player (an operator's command feedback, which
|
||||
vanilla broadcasts to the console, included), the chat, `list`, `say` and
|
||||
`stop`;
|
||||
|
||||
Reference in New Issue
Block a user