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