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