Botcraft 1.21.5
Loading...
Searching...
No Matches
Botcraft::InventoryManager Class Reference

#include <InventoryManager.hpp>

Inheritance diagram for Botcraft::InventoryManager:
ProtocolCraft::Handler ProtocolCraft::GenericHandler< Packet, AllPackets >

Public Member Functions

 InventoryManager ()
 
std::shared_ptr< WindowGetWindow (const short window_id) const
 
short GetFirstOpenedWindowId () const
 
std::shared_ptr< WindowGetPlayerInventory () const
 
short GetIndexHotbarSelected () const
 
ProtocolCraft::Slot GetHotbarSelected () const
 
ProtocolCraft::Slot GetOffHand () const
 
ProtocolCraft::Slot GetCursor () const
 
void EraseInventory (const short window_id)
 
InventoryTransaction PrepareTransaction (const std::shared_ptr< ProtocolCraft::ServerboundContainerClickPacket > &transaction)
 "think" about the changes made by this transaction, filling in the necessary values in the packet
 
void ApplyTransaction (const InventoryTransaction &transaction)
 Apply a given transaction to a container.
 
std::vector< ProtocolCraft::MerchantOfferGetAvailableMerchantOffers () const
 
void IncrementMerchantOfferUse (const int index)
 

Private Member Functions

void SetHotbarSelected (const short index)
 
void SetCursor (const ProtocolCraft::Slot &c)
 
void AddInventory (const short window_id, const InventoryType window_type)
 
void SetSlot (const short window_id, const short index, const ProtocolCraft::Slot &slot)
 
void SynchronizeContainerPlayerInventory (const short window_id)
 
void SetStateId (const short window_id, const int state_id)
 
virtual void Handle (ProtocolCraft::ClientboundContainerSetSlotPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundContainerSetContentPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundOpenScreenPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundSetHeldSlotPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundMerchantOffersPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundContainerClosePacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundSetCursorItemPacket &packet) override
 
virtual void Handle (ProtocolCraft::ClientboundSetPlayerInventoryPacket &packet) override
 
void ApplyTransactionImpl (const InventoryTransaction &transaction)
 

Private Attributes

std::shared_mutex inventory_manager_mutex
 
std::map< short, std::shared_ptr< Window > > inventories
 
short index_hotbar_selected
 
ProtocolCraft::Slot cursor
 
int trading_container_id
 
std::vector< ProtocolCraft::MerchantOfferavailable_trades
 

Detailed Description

Definition at line 39 of file InventoryManager.hpp.

Constructor & Destructor Documentation

◆ InventoryManager()

Member Function Documentation

◆ AddInventory()

void Botcraft::InventoryManager::AddInventory ( const short  window_id,
const InventoryType  window_type 
)
private

Definition at line 221 of file InventoryManager.cpp.

References inventories, and inventory_manager_mutex.

Referenced by Handle().

◆ ApplyTransaction()

void Botcraft::InventoryManager::ApplyTransaction ( const InventoryTransaction transaction)

Apply a given transaction to a container.

Parameters
transactionThe transaction to apply

Definition at line 475 of file InventoryManager.cpp.

References ApplyTransactionImpl(), and inventory_manager_mutex.

◆ ApplyTransactionImpl()

void Botcraft::InventoryManager::ApplyTransactionImpl ( const InventoryTransaction transaction)
private

◆ EraseInventory()

void Botcraft::InventoryManager::EraseInventory ( const short  window_id)

◆ GetAvailableMerchantOffers()

std::vector< MerchantOffer > Botcraft::InventoryManager::GetAvailableMerchantOffers ( ) const

Definition at line 482 of file InventoryManager.cpp.

References available_trades, and inventory_manager_mutex.

◆ GetCursor()

Slot Botcraft::InventoryManager::GetCursor ( ) const

Definition at line 237 of file InventoryManager.cpp.

References cursor, and inventory_manager_mutex.

◆ GetFirstOpenedWindowId()

short Botcraft::InventoryManager::GetFirstOpenedWindowId ( ) const

◆ GetHotbarSelected()

Slot Botcraft::InventoryManager::GetHotbarSelected ( ) const

◆ GetIndexHotbarSelected()

short Botcraft::InventoryManager::GetIndexHotbarSelected ( ) const

Definition at line 64 of file InventoryManager.cpp.

References index_hotbar_selected, and inventory_manager_mutex.

◆ GetOffHand()

Slot Botcraft::InventoryManager::GetOffHand ( ) const

◆ GetPlayerInventory()

std::shared_ptr< Window > Botcraft::InventoryManager::GetPlayerInventory ( ) const

Definition at line 59 of file InventoryManager.cpp.

References GetWindow(), and Botcraft::Window::PLAYER_INVENTORY_INDEX.

Referenced by GetHotbarSelected(), and GetOffHand().

◆ GetWindow()

std::shared_ptr< Window > Botcraft::InventoryManager::GetWindow ( const short  window_id) const

Definition at line 48 of file InventoryManager.cpp.

References inventories, and inventory_manager_mutex.

Referenced by GetPlayerInventory(), Handle(), and PrepareTransaction().

◆ Handle() [1/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundContainerClosePacket packet)
overrideprivatevirtual

Definition at line 641 of file InventoryManager.cpp.

References EraseInventory().

◆ Handle() [2/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundContainerSetContentPacket packet)
overrideprivatevirtual

Definition at line 533 of file InventoryManager.cpp.

References GetWindow(), and SetStateId().

◆ Handle() [3/8]

◆ Handle() [4/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundMerchantOffersPacket packet)
overrideprivatevirtual

◆ Handle() [5/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundOpenScreenPacket packet)
overrideprivatevirtual

◆ Handle() [6/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundSetCursorItemPacket packet)
overrideprivatevirtual

◆ Handle() [7/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundSetHeldSlotPacket packet)
overrideprivatevirtual

Definition at line 585 of file InventoryManager.cpp.

◆ Handle() [8/8]

void Botcraft::InventoryManager::Handle ( ProtocolCraft::ClientboundSetPlayerInventoryPacket packet)
overrideprivatevirtual

Definition at line 653 of file InventoryManager.cpp.

References Botcraft::Window::PLAYER_INVENTORY_INDEX, and SetSlot().

◆ IncrementMerchantOfferUse()

void Botcraft::InventoryManager::IncrementMerchantOfferUse ( const int  index)

Definition at line 488 of file InventoryManager.cpp.

References available_trades, inventory_manager_mutex, and LOG_WARNING.

◆ PrepareTransaction()

InventoryTransaction Botcraft::InventoryManager::PrepareTransaction ( const std::shared_ptr< ProtocolCraft::ServerboundContainerClickPacket > &  transaction)

"think" about the changes made by this transaction, filling in the necessary values in the packet

Parameters
transactionThe transaction to update with the modifications
Returns
An InventoryTransaction with various info, depending on the version

Definition at line 249 of file InventoryManager.cpp.

References Botcraft::Crafting, cursor, Botcraft::AssetsManager::getInstance(), GetWindow(), inventory_manager_mutex, ProtocolCraft::Slot::IsEmptySlot(), Botcraft::AssetsManager::Items(), LOG_ERROR, Botcraft::PlayerInventory, and ProtocolCraft::Slot::SameItem().

◆ SetCursor()

void Botcraft::InventoryManager::SetCursor ( const ProtocolCraft::Slot c)
private

Definition at line 243 of file InventoryManager.cpp.

References cursor, and inventory_manager_mutex.

Referenced by Handle().

◆ SetHotbarSelected()

void Botcraft::InventoryManager::SetHotbarSelected ( const short  index)
private

Definition at line 231 of file InventoryManager.cpp.

References index_hotbar_selected, and inventory_manager_mutex.

◆ SetSlot()

void Botcraft::InventoryManager::SetSlot ( const short  window_id,
const short  index,
const ProtocolCraft::Slot slot 
)
private

Definition at line 22 of file InventoryManager.cpp.

References inventories, inventory_manager_mutex, and LOG_WARNING.

Referenced by Handle(), Handle(), and Handle().

◆ SetStateId()

void Botcraft::InventoryManager::SetStateId ( const short  window_id,
const int  state_id 
)
private

Definition at line 209 of file InventoryManager.cpp.

References inventories, and inventory_manager_mutex.

Referenced by Handle(), and Handle().

◆ SynchronizeContainerPlayerInventory()

void Botcraft::InventoryManager::SynchronizeContainerPlayerInventory ( const short  window_id)
private

Member Data Documentation

◆ available_trades

std::vector<ProtocolCraft::MerchantOffer> Botcraft::InventoryManager::available_trades
private

◆ cursor

ProtocolCraft::Slot Botcraft::InventoryManager::cursor
private

◆ index_hotbar_selected

short Botcraft::InventoryManager::index_hotbar_selected
private

◆ inventories

std::map<short, std::shared_ptr<Window> > Botcraft::InventoryManager::inventories
private

◆ inventory_manager_mutex

◆ trading_container_id

int Botcraft::InventoryManager::trading_container_id
private

Definition at line 120 of file InventoryManager.hpp.

Referenced by EraseInventory(), Handle(), and InventoryManager().


The documentation for this class was generated from the following files: