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