Botcraft 1.21.4
Loading...
Searching...
No Matches
Window.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <shared_mutex>
5
7
10
11namespace Botcraft
12{
13 class Window
14 {
15 public:
16 static constexpr short PLAYER_INVENTORY_INDEX = 0;
17
18 static constexpr short INVENTORY_CRAFTING_OUTPUT_INDEX = 0;
19 static constexpr short INVENTORY_CRAFTING_INPUT_START = 1;
20 static constexpr short INVENTORY_ARMOR_START = 5;
21 static constexpr short INVENTORY_HEAD_ARMOR = INVENTORY_ARMOR_START + 0;
22 static constexpr short INVENTORY_CHEST_ARMOR = INVENTORY_ARMOR_START + 1;
23 static constexpr short INVENTORY_LEGS_ARMOR = INVENTORY_ARMOR_START + 2;
24 static constexpr short INVENTORY_FEET_ARMOR = INVENTORY_ARMOR_START + 3;
25 static constexpr short INVENTORY_STORAGE_START = 9;
26 static constexpr short INVENTORY_HOTBAR_START = 36;
27 static constexpr short INVENTORY_OFFHAND_INDEX = 45;
28
30
31 void Init();
32
33 ProtocolCraft::Slot GetSlot(const short index) const;
34 std::map<short, ProtocolCraft::Slot> GetSlots() const;
35 /// @brief Get a read-only locked version of all the slots
36 /// @return Basically an object you can use as a std::map<short, ProtocolCraft::Slot>*.
37 /// **ALL UPDATE OF THIS INVENTORY WILL BE BLOCKED WHILE THIS OBJECT IS ALIVE**, make sure it goes out of scope
38 /// as soon as you don't need it. You can use GetSlots instead to get a copy without blocking future updates
40 InventoryType GetType() const;
41 void SetSlot(const short index, const ProtocolCraft::Slot& slot);
42 void SetContent(const std::vector<ProtocolCraft::Slot>& slots_);
43#if PROTOCOL_VERSION < 755 /* < 1.17 */
44 /// @brief Return a unique transaction id and increment it for next time
45 /// @return The transaction id to use for next transaction
46 int GetNextTransactionId();
47#elif PROTOCOL_VERSION > 755 /* > 1.17 */
48 int GetStateId() const;
49 void SetStateId(const int state_id_);
50#endif
51 short GetFirstPlayerInventorySlot() const;
52
53 private:
54 mutable std::shared_mutex window_mutex;
55
56 std::map<short, ProtocolCraft::Slot> slots;
58
59#if PROTOCOL_VERSION < 755 /* < 1.17 */
60 // TODO, need mutex to make this thread-safe?
61 int next_transaction_id;
62#elif PROTOCOL_VERSION > 755 /* > 1.17 */
64#endif
65 };
66} // Botcraft
Mutex protected reference, will be locked until destroyed.
short GetFirstPlayerInventorySlot() const
Definition Window.cpp:87
static constexpr short INVENTORY_HOTBAR_START
Definition Window.hpp:26
static constexpr short INVENTORY_HEAD_ARMOR
Definition Window.hpp:21
void SetContent(const std::vector< ProtocolCraft::Slot > &slots_)
Definition Window.cpp:58
static constexpr short INVENTORY_LEGS_ARMOR
Definition Window.hpp:23
std::map< short, ProtocolCraft::Slot > GetSlots() const
Definition Window.cpp:35
static constexpr short INVENTORY_CRAFTING_INPUT_START
Definition Window.hpp:19
const InventoryType type
Definition Window.hpp:57
void SetSlot(const short index, const ProtocolCraft::Slot &slot)
Definition Window.cpp:52
int GetStateId() const
Definition Window.cpp:74
static constexpr short INVENTORY_ARMOR_START
Definition Window.hpp:20
void SetStateId(const int state_id_)
Definition Window.cpp:80
ProtocolCraft::Slot GetSlot(const short index) const
Definition Window.cpp:24
std::shared_mutex window_mutex
Definition Window.hpp:54
std::map< short, ProtocolCraft::Slot > slots
Definition Window.hpp:56
InventoryType GetType() const
Definition Window.cpp:46
static constexpr short INVENTORY_CRAFTING_OUTPUT_INDEX
Definition Window.hpp:18
static constexpr short INVENTORY_STORAGE_START
Definition Window.hpp:25
Utilities::ScopeLockedWrapper< const std::map< short, ProtocolCraft::Slot >, std::shared_mutex, std::shared_lock > GetLockedSlots() const
Get a read-only locked version of all the slots.
Definition Window.cpp:41
static constexpr short PLAYER_INVENTORY_INDEX
Definition Window.hpp:16
static constexpr short INVENTORY_OFFHAND_INDEX
Definition Window.hpp:27
static constexpr short INVENTORY_CHEST_ARMOR
Definition Window.hpp:22
static constexpr short INVENTORY_FEET_ARMOR
Definition Window.hpp:24
InventoryType
Definition Enums.hpp:217