LeviLamina
Loading...
Searching...
No Matches
Container.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4#include "mc/safety/RedactableString.h"
5#include "mc/world/ContainerIterator.h"
6#include "mc/world/ContainerOwner.h"
7
8// auto generated inclusion list
9#include "mc/deps/core/utility/pub_sub/Connector.h"
10#include "mc/deps/core/utility/pub_sub/Publisher.h"
11#include "mc/deps/shared_types/legacy/ContainerType.h"
12#include "mc/platform/brstd/copyable_function.h"
13#include "mc/platform/brstd/function_ref.h"
14#include "mc/safety/RedactableString.h"
15#include "mc/util/BidirectionalUnorderedMap.h"
16#include "mc/world/ContainerCloseListener.h"
17#include "mc/world/ContainerContentChangeListener.h"
18#include "mc/world/ContainerOwner.h"
19#include "mc/world/ContainerSizeChangeListener.h"
20#include "mc/world/TypedRuntimeId.h"
21
22// auto generated forward declare list
23// clang-format off
24class Actor;
25class BlockSource;
26class CompoundTag;
27class ItemDescriptor;
28class ItemStack;
29class Random;
30class Vec3;
32namespace Bedrock::PubSub::ThreadModel { struct SingleThreaded; }
33// clang-format on
34
35class Container {
36public:
37 // Container inner types declare
38 // clang-format off
39 struct PublisherWrapper;
40 // clang-format on
41
42 // Container inner types define
44 public:
45 // member variables
46 // NOLINTBEGIN
47 ::ll::
49 mPublisher;
50 // NOLINTEND
51 };
52
53 using ItemStackNetIdChangedCallback = ::std::function<void(int, ::ItemStack const&)>;
54
55public:
56 [[nodiscard]] std::string const& getTypeName() const { return containerTypeMap().at(mContainerType); }
57
58 LLNDAPI optional_ref<ItemStack> getItemNonConst(int index);
59
60 [[nodiscard]] ItemStack& operator[](int index) { return this->getItemNonConst(index); }
61
62 [[nodiscard]] ItemStack const& operator[](int index) const { return this->getItem(index); }
63
64 using TransactionContext =
65 ::brstd::copyable_function<void(::Container&, int, ::ItemStack const&, ::ItemStack const&)>;
66
67public:
68 using Iterator = ContainerIterator<Container>;
69 using ConstIterator = ContainerIterator<Container const>;
70
71 using ReverseIterator = std::reverse_iterator<Iterator>;
72 using ConstReverseIterator = std::reverse_iterator<ConstIterator>;
73
74 [[nodiscard]] constexpr Iterator begin() noexcept { return {this, 0}; }
75 [[nodiscard]] constexpr ConstIterator cbegin() const noexcept { return {this, 0}; }
76 [[nodiscard]] constexpr Iterator end() noexcept { return {this, getContainerSize()}; }
77 [[nodiscard]] constexpr ConstIterator cend() const noexcept { return {this, getContainerSize()}; }
78
79 [[nodiscard]] constexpr ReverseIterator rbegin() noexcept { return ReverseIterator{end()}; }
80 [[nodiscard]] constexpr ConstReverseIterator crbegin() const noexcept { return ConstReverseIterator{cend()}; }
81 [[nodiscard]] constexpr ReverseIterator rend() noexcept { return ReverseIterator{begin()}; }
82 [[nodiscard]] constexpr ConstReverseIterator crend() const noexcept { return ConstReverseIterator{cbegin()}; }
83
84public:
85 // member variables
86 // NOLINTBEGIN
87 ::SharedTypes::Legacy::ContainerType mContainerType;
88 ::SharedTypes::Legacy::ContainerType mGameplayContainerType;
89 ::std::unordered_set<::ContainerContentChangeListener*> mContentChangeListeners;
90 ::std::unordered_set<::ContainerSizeChangeListener*> mSizeChangeListeners;
91 ::std::unordered_set<::ContainerCloseListener*> mCloseListeners;
92 ::Container::PublisherWrapper mRemovedPublisher;
93 ::std::deque<TransactionContext> mTransactionContextStack;
94 ::Bedrock::Safety::RedactableString mName;
95 bool mCustomName;
96 ::ContainerOwner mContainerOwner;
97 ::ContainerRuntimeId mContainerRuntimeId;
98 // NOLINTEND
99
100public:
101 // prevent constructor by default
102 Container();
103
104public:
105 // virtual functions
106 // NOLINTBEGIN
107 virtual ~Container();
108
109 virtual void init();
110
111 virtual void serverInitItemStackIds(
112 int containerSlot,
113 int count,
114 ::std::function<void(int, ::ItemStack const&)> onNetIdChanged
115 ) = 0;
116
117 virtual void addContentChangeListener(::ContainerContentChangeListener* listener);
118
119 virtual void removeContentChangeListener(::ContainerContentChangeListener* listener);
120
121 virtual ::Bedrock::PubSub::Connector<void()>* getContainerRemovedConnector();
122
123 virtual bool hasRemovedSubscribers() const;
124
125 virtual ::ItemStack const& getItem(int slot) const = 0;
126
127 virtual bool hasRoomForItem(::ItemStack const& item) const;
128
129 virtual bool addItem(::ItemStack& item);
130
131 virtual bool addItemWithForceBalance(::ItemStack& item);
132
133 virtual bool addItemToFirstEmptySlot(::ItemStack const& item);
134
135 virtual void setItem(int slot, ::ItemStack const& item) = 0;
136
137 virtual void setItemWithForceBalance(int slot, ::ItemStack const& item, bool forceBalanced);
138
139 virtual void removeItem(int slot, int count);
140
141 virtual void removeAllItems();
142
143 virtual void removeAllItemsWithForceBalance();
144
145 virtual void containerRemoved();
146
147 virtual void dropSlotContent(::BlockSource& region, ::Vec3 const& pos, bool randomizeDrop, int slot);
148
149 virtual void dropContents(::BlockSource& region, ::Vec3 const& pos, bool randomizeDrop);
150
151 virtual int getContainerSize() const = 0;
152
153 virtual int getMaxStackSize() const = 0;
154
155 virtual void startOpen(::Actor& actor) = 0;
156
157 virtual void stopOpen(::Actor& actor);
158
159 virtual ::std::vector<::ItemStack> getSlotCopies() const;
160
161 virtual ::std::vector<::ItemStack const*> const getSlots() const;
162
163 virtual int getEmptySlotsCount() const;
164
165 virtual int getItemCount(::ItemStack const& compare) const;
166
167 virtual int firstEmptySlot() const;
168
169 virtual int firstItem() const;
170
171 virtual int findFirstSlotForItem(::ItemStack const& item) const;
172
173 virtual int reverseFindFirstSlotForItem(::ItemStack const& item) const;
174
175 virtual bool canPushInItem(int slot, int face, ::ItemStack const& item) const;
176
177 virtual bool canPullOutItem(int slot, int face, ::ItemStack const& item) const;
178
179 virtual void setContainerChanged(int slot);
180
181 virtual void setContainerMoved();
182
183 virtual void setCustomName(::Bedrock::Safety::RedactableString const& name);
184
185 virtual bool hasCustomName() const;
186
187 virtual void readAdditionalSaveData(::CompoundTag const& tag);
188
189 virtual void addAdditionalSaveData(::CompoundTag& tag);
190
191 virtual void initializeContainerContents(::BlockSource& region);
192
193 virtual bool isEmpty() const;
194
195 virtual bool isSlotDisabled(int slot) const;
196 // NOLINTEND
197
198public:
199 // member functions
200 // NOLINTBEGIN
201 MCAPI Container(::Container const&);
202
203 MCAPI explicit Container(::SharedTypes::Legacy::ContainerType type);
204
205 MCAPI Container(::SharedTypes::Legacy::ContainerType type, ::std::string const& name, bool customName);
206
207#ifdef LL_PLAT_C
208 MCAPI Container(
209 ::SharedTypes::Legacy::ContainerType type,
210 ::Bedrock::Safety::RedactableString const& name,
211 bool customName
212 );
213#endif
214
215 MCAPI void
216 _dropSlotContent(::BlockSource& region, ::Random& random, ::Vec3 const& pos, bool randomizeDrop, int slot);
217
218 MCAPI void
219 _serverInitId(int slot, ::ItemStack& item, ::std::function<void(int, ::ItemStack const&)> onNetIdChanged);
220
221 MCAPI void createTransactionContext(
222 ::brstd::copyable_function<void(::Container&, int, ::ItemStack const&, ::ItemStack const&)> callback,
223 ::brstd::function_ref<void()> execute
224 );
225
226 MCAPI int getItemCount(::ItemDescriptor const& descriptor) const;
227
228 MCAPI int getRedstoneSignalFromContainer(::BlockSource& region);
229
230 MCAPI ::Container& operator=(::Container const&);
231
232 MCAPI void serverInitItemStackIdsAll(::std::function<void(int, ::ItemStack const&)> onNetIdChanged);
233 // NOLINTEND
234
235public:
236 // static functions
237 // NOLINTBEGIN
238 MCAPI static ::SharedTypes::Legacy::ContainerType getContainerTypeId(::std::string const& name);
239 // NOLINTEND
240
241public:
242 // static variables
243 // NOLINTBEGIN
244 MCAPI static ::BidirectionalUnorderedMap<::SharedTypes::Legacy::ContainerType, ::std::string> const&
245 containerTypeMap();
246 // NOLINTEND
247
248public:
249 // constructor thunks
250 // NOLINTBEGIN
251 MCAPI void* $ctor(::Container const&);
252
253 MCAPI void* $ctor(::SharedTypes::Legacy::ContainerType type);
254
255 MCAPI void* $ctor(::SharedTypes::Legacy::ContainerType type, ::std::string const& name, bool customName);
256
257#ifdef LL_PLAT_C
258 MCAPI void*
259 $ctor(::SharedTypes::Legacy::ContainerType type, ::Bedrock::Safety::RedactableString const& name, bool customName);
260#endif
261 // NOLINTEND
262
263public:
264 // destructor thunk
265 // NOLINTBEGIN
266 MCAPI void $dtor();
267 // NOLINTEND
268
269public:
270 // virtual function thunks
271 // NOLINTBEGIN
272 MCFOLD void $init();
273
274 MCAPI void $addContentChangeListener(::ContainerContentChangeListener* listener);
275
276 MCAPI void $removeContentChangeListener(::ContainerContentChangeListener* listener);
277
278 MCAPI ::Bedrock::PubSub::Connector<void()>* $getContainerRemovedConnector();
279
280 MCAPI bool $hasRemovedSubscribers() const;
281
282 MCAPI bool $hasRoomForItem(::ItemStack const& item) const;
283
284 MCAPI bool $addItem(::ItemStack& item);
285
286 MCAPI bool $addItemWithForceBalance(::ItemStack& item);
287
288 MCAPI bool $addItemToFirstEmptySlot(::ItemStack const& item);
289
290 MCFOLD void $setItemWithForceBalance(int slot, ::ItemStack const& item, bool forceBalanced);
291
292 MCAPI void $removeItem(int slot, int count);
293
294 MCAPI void $removeAllItems();
295
296 MCAPI void $removeAllItemsWithForceBalance();
297
298 MCAPI void $containerRemoved();
299
300 MCAPI void $dropSlotContent(::BlockSource& region, ::Vec3 const& pos, bool randomizeDrop, int slot);
301
302 MCAPI void $dropContents(::BlockSource& region, ::Vec3 const& pos, bool randomizeDrop);
303
304 MCAPI void $stopOpen(::Actor& actor);
305
306 MCAPI ::std::vector<::ItemStack> $getSlotCopies() const;
307
308 MCAPI ::std::vector<::ItemStack const*> const $getSlots() const;
309
310 MCAPI int $getEmptySlotsCount() const;
311
312 MCAPI int $getItemCount(::ItemStack const& compare) const;
313
314 MCAPI int $firstEmptySlot() const;
315
316 MCAPI int $firstItem() const;
317
318 MCAPI int $findFirstSlotForItem(::ItemStack const& item) const;
319
320 MCAPI int $reverseFindFirstSlotForItem(::ItemStack const& item) const;
321
322 MCFOLD bool $canPushInItem(int slot, int face, ::ItemStack const& item) const;
323
324 MCFOLD bool $canPullOutItem(int slot, int face, ::ItemStack const& item) const;
325
326 MCAPI void $setContainerChanged(int slot);
327
328 MCAPI void $setContainerMoved();
329
330 MCAPI void $setCustomName(::Bedrock::Safety::RedactableString const& name);
331
332 MCAPI bool $hasCustomName() const;
333
334 MCAPI void $readAdditionalSaveData(::CompoundTag const& tag);
335
336 MCAPI void $addAdditionalSaveData(::CompoundTag& tag);
337
338 MCFOLD void $initializeContainerContents(::BlockSource& region);
339
340 MCAPI bool $isEmpty() const;
341
342 MCFOLD bool $isSlotDisabled(int slot) const;
343
344
345 // NOLINTEND
346
347public:
348 // vftables
349 // NOLINTBEGIN
350 MCAPI static void** $vftable();
351 // NOLINTEND
352};
Definition Actor.h:113
Definition Publisher.h:25
Definition BlockSource.h:71
Definition CompoundTag.h:18
Definition ItemDescriptor.h:25
Definition ItemStack.h:26
Definition Random.h:10
Definition Vec3.h:10
Definition optional_ref.h:10
Definition ContainerRuntimeIdTag.h:5
Definition Container.h:43