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

#include <InventoryManager.hpp>

Inheritance diagram for Botcraft::InventoryManager:
ProtocolCraft::Handler ProtocolCraft::GenericHandler< Message, AllMessages >

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 msg
 
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 &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundContainerSetContentPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundOpenScreenPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundSetHeldSlotPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundMerchantOffersPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundContainerClosePacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundSetCursorItemPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundSetPlayerInventoryPacket &msg) 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 37 of file InventoryManager.hpp.

Constructor & Destructor Documentation

◆ InventoryManager()

Botcraft::InventoryManager::InventoryManager ( )

Member Function Documentation

◆ AddInventory()

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

Definition at line 218 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 460 of file InventoryManager.cpp.

References ApplyTransactionImpl(), and inventory_manager_mutex.

◆ ApplyTransactionImpl()

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

Definition at line 442 of file InventoryManager.cpp.

References cursor, inventories, and Botcraft::InventoryTransaction::msg.

Referenced by ApplyTransaction().

◆ EraseInventory()

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

◆ GetAvailableMerchantOffers()

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

Definition at line 467 of file InventoryManager.cpp.

References available_trades, and inventory_manager_mutex.

◆ GetCursor()

Slot Botcraft::InventoryManager::GetCursor ( ) const

Definition at line 234 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 61 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 56 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 45 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 msg)
overrideprivatevirtual

Definition at line 626 of file InventoryManager.cpp.

References EraseInventory().

◆ Handle() [2/8]

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

Definition at line 518 of file InventoryManager.cpp.

References GetWindow(), and SetStateId().

◆ Handle() [3/8]

◆ Handle() [4/8]

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

◆ Handle() [5/8]

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

◆ Handle() [6/8]

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

◆ Handle() [7/8]

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

Definition at line 570 of file InventoryManager.cpp.

◆ Handle() [8/8]

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

Definition at line 638 of file InventoryManager.cpp.

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

◆ IncrementMerchantOfferUse()

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

Definition at line 473 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 msg

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

Definition at line 246 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 240 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 228 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 19 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 206 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 118 of file InventoryManager.hpp.

Referenced by EraseInventory(), and Handle().


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