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::{
client::play::{
CSetContainerContent, CSetContainerProperty, CSetContainerSlot, CSetCursorItem,
CSetPlayerInventory,
CSetPlayerInventory, CSetSelectedSlot,
},
codec::item_stack_seralizer::OptionalItemStackHash,
server::play::SlotActionType,
@ -50,6 +50,7 @@ pub trait InventoryPlayer: Send + Sync {
async fn enqueue_cursor_packet(&self, packet: &CSetCursorItem);
async fn enqueue_property_packet(&self, packet: &CSetContainerProperty);
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) {

View File

@ -39,9 +39,9 @@ use pumpkin_protocol::client::play::{
CEntityAnimation, CEntityPositionSync, CGameEvent, CKeepAlive, COpenScreen, CParticle,
CPlayDisconnect, CPlayerAbilities, CPlayerInfoUpdate, CPlayerPosition, CPlayerSpawnPosition,
CRespawn, CSetContainerContent, CSetContainerProperty, CSetContainerSlot, CSetCursorItem,
CSetExperience, CSetHealth, CSetPlayerInventory, CSoundEffect, CStopSound, CSubtitle,
CSystemChatMessage, CTitleText, CUnloadChunk, CUpdateMobEffect, CUpdateTime, GameEvent,
MetaDataType, Metadata, PlayerAction, PlayerInfoFlags, PreviousMessage,
CSetExperience, CSetHealth, CSetPlayerInventory, CSetSelectedSlot, CSoundEffect, CStopSound,
CSubtitle, CSystemChatMessage, CTitleText, CUnloadChunk, CUpdateMobEffect, CUpdateTime,
GameEvent, MetaDataType, Metadata, PlayerAction, PlayerInfoFlags, PreviousMessage,
};
use pumpkin_protocol::codec::identifier::Identifier;
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) {
// Read selected hotbar slot
self.set_selected_slot(nbt.get_int("SelectedItemSlot").unwrap_or(0) as u8);
// Process inventory list
if let Some(inventory_list) = nbt.get_list("Inventory") {
for tag in inventory_list {
@ -2452,4 +2451,8 @@ impl InventoryPlayer for Player {
async fn enqueue_slot_set_packet(&self, packet: &CSetPlayerInventory) {
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 pumpkin_config::{BASIC_CONFIG, advanced_config};
use pumpkin_inventory::screen_handler::InventoryPlayer;
use pumpkin_macros::send_cancellable;
use pumpkin_protocol::client::login::CEncryptionRequest;
use pumpkin_protocol::client::play::CChangeDifficulty;
use pumpkin_protocol::client::play::CSetSelectedSlot;
use pumpkin_protocol::{ClientPacket, client::config::CPluginMessage};
use pumpkin_registry::{DimensionType, Registry};
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()))
} else {
None