This commit is contained in:
Alexander Medvedev 2025-06-13 17:30:37 +02:00
commit 8e128f1b30
3 changed files with 15 additions and 5 deletions

View File

@ -6,7 +6,7 @@ use pumpkin_data::screen::WindowType;
use pumpkin_protocol::{ use pumpkin_protocol::{
client::play::{ client::play::{
CSetContainerContent, CSetContainerProperty, CSetContainerSlot, CSetCursorItem, CSetContainerContent, CSetContainerProperty, CSetContainerSlot, CSetCursorItem,
CSetPlayerInventory, CSetPlayerInventory, CSetSelectedSlot,
}, },
codec::item_stack_seralizer::OptionalItemStackHash, codec::item_stack_seralizer::OptionalItemStackHash,
server::play::SlotActionType, server::play::SlotActionType,
@ -50,6 +50,7 @@ pub trait InventoryPlayer: Send + Sync {
async fn enqueue_cursor_packet(&self, packet: &CSetCursorItem); async fn enqueue_cursor_packet(&self, packet: &CSetCursorItem);
async fn enqueue_property_packet(&self, packet: &CSetContainerProperty); async fn enqueue_property_packet(&self, packet: &CSetContainerProperty);
async fn enqueue_slot_set_packet(&self, packet: &CSetPlayerInventory); async fn enqueue_slot_set_packet(&self, packet: &CSetPlayerInventory);
async fn enqueue_set_held_item_packet(&self, packet: &CSetSelectedSlot);
} }
pub async fn offer_or_drop_stack(player: &dyn InventoryPlayer, stack: ItemStack) { pub async fn offer_or_drop_stack(player: &dyn InventoryPlayer, stack: ItemStack) {

View File

@ -39,9 +39,9 @@ use pumpkin_protocol::client::play::{
CEntityAnimation, CEntityPositionSync, CGameEvent, CKeepAlive, COpenScreen, CParticle, CEntityAnimation, CEntityPositionSync, CGameEvent, CKeepAlive, COpenScreen, CParticle,
CPlayDisconnect, CPlayerAbilities, CPlayerInfoUpdate, CPlayerPosition, CPlayerSpawnPosition, CPlayDisconnect, CPlayerAbilities, CPlayerInfoUpdate, CPlayerPosition, CPlayerSpawnPosition,
CRespawn, CSetContainerContent, CSetContainerProperty, CSetContainerSlot, CSetCursorItem, CRespawn, CSetContainerContent, CSetContainerProperty, CSetContainerSlot, CSetCursorItem,
CSetExperience, CSetHealth, CSetPlayerInventory, CSoundEffect, CStopSound, CSubtitle, CSetExperience, CSetHealth, CSetPlayerInventory, CSetSelectedSlot, CSoundEffect, CStopSound,
CSystemChatMessage, CTitleText, CUnloadChunk, CUpdateMobEffect, CUpdateTime, GameEvent, CSubtitle, CSystemChatMessage, CTitleText, CUnloadChunk, CUpdateMobEffect, CUpdateTime,
MetaDataType, Metadata, PlayerAction, PlayerInfoFlags, PreviousMessage, GameEvent, MetaDataType, Metadata, PlayerAction, PlayerInfoFlags, PreviousMessage,
}; };
use pumpkin_protocol::codec::identifier::Identifier; use pumpkin_protocol::codec::identifier::Identifier;
use pumpkin_protocol::codec::var_int::VarInt; use pumpkin_protocol::codec::var_int::VarInt;
@ -1919,7 +1919,6 @@ impl NBTStorage for PlayerInventory {
async fn read_nbt_non_mut(&self, nbt: &mut NbtCompound) { async fn read_nbt_non_mut(&self, nbt: &mut NbtCompound) {
// Read selected hotbar slot // Read selected hotbar slot
self.set_selected_slot(nbt.get_int("SelectedItemSlot").unwrap_or(0) as u8); self.set_selected_slot(nbt.get_int("SelectedItemSlot").unwrap_or(0) as u8);
// Process inventory list // Process inventory list
if let Some(inventory_list) = nbt.get_list("Inventory") { if let Some(inventory_list) = nbt.get_list("Inventory") {
for tag in inventory_list { for tag in inventory_list {
@ -2452,4 +2451,8 @@ impl InventoryPlayer for Player {
async fn enqueue_slot_set_packet(&self, packet: &CSetPlayerInventory) { async fn enqueue_slot_set_packet(&self, packet: &CSetPlayerInventory) {
self.client.enqueue_packet(packet).await; self.client.enqueue_packet(packet).await;
} }
async fn enqueue_set_held_item_packet(&self, packet: &CSetSelectedSlot) {
self.client.enqueue_packet(packet).await;
}
} }

View File

@ -16,9 +16,11 @@ use connection_cache::{CachedBranding, CachedStatus};
use key_store::KeyStore; use key_store::KeyStore;
use pumpkin_config::{BASIC_CONFIG, advanced_config}; use pumpkin_config::{BASIC_CONFIG, advanced_config};
use pumpkin_inventory::screen_handler::InventoryPlayer;
use pumpkin_macros::send_cancellable; use pumpkin_macros::send_cancellable;
use pumpkin_protocol::client::login::CEncryptionRequest; use pumpkin_protocol::client::login::CEncryptionRequest;
use pumpkin_protocol::client::play::CChangeDifficulty; use pumpkin_protocol::client::play::CChangeDifficulty;
use pumpkin_protocol::client::play::CSetSelectedSlot;
use pumpkin_protocol::{ClientPacket, client::config::CPluginMessage}; use pumpkin_protocol::{ClientPacket, client::config::CPluginMessage};
use pumpkin_registry::{DimensionType, Registry}; use pumpkin_registry::{DimensionType, Registry};
use pumpkin_util::Difficulty; use pumpkin_util::Difficulty;
@ -322,6 +324,10 @@ impl Server {
} }
} }
player.enqueue_set_held_item_packet(&CSetSelectedSlot::new(
player.get_inventory().get_selected_slot() as i8,
)).await;
Some((player, world.clone())) Some((player, world.clone()))
} else { } else {
None None