LeviLamina
Loading...
Searching...
No Matches
BlockComponentStorage.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/deps/core/utility/typeid_t.h"
7#include "mc/platform/brstd/flat_map.h"
8#include "mc/platform/brstd/flat_set.h"
9
10// auto generated forward declare list
11// clang-format off
22class OnFallOnTrigger;
24class OnPlacedTrigger;
28class OnStepOnTrigger;
65// clang-format on
66
68public:
69 // BlockComponentStorage inner types declare
70 // clang-format off
71 struct ComponentBase;
72 template<typename T0> struct ComponentInstance;
73 // clang-format on
74
75 // BlockComponentStorage inner types define
77 public:
78 // virtual functions
79 // NOLINTBEGIN
80 virtual ~ComponentBase() = default;
81 // NOLINTEND
82 };
83
86 template <typename T0>
87 struct ComponentInstance : ComponentBase {
88 template <class... A>
89 explicit ComponentInstance(A&&... a) : mValue(::std::forward<A>(a)...) {}
90
91 T0 mValue;
92 };
93
94public:
95 // member variables
96 // NOLINTBEGIN
97 ::ll::TypedStorage<
98 8,
99 48,
102 ::std::unique_ptr<::BlockComponentStorage::ComponentBase>,
103 ::std::less<::Bedrock::typeid_t<void>>,
104 ::std::vector<::Bedrock::typeid_t<void>>,
105 ::std::vector<::std::unique_ptr<::BlockComponentStorage::ComponentBase>>>>
106 mComponents;
107 ::ll::TypedStorage<
108 8,
109 24,
112 ::std::less<::Bedrock::typeid_t<void>>,
113 ::std::vector<::Bedrock::typeid_t<void>>>>
114 mStatelessComponents;
115 ::ll::TypedStorage<1, 1, bool> mAllowModifyingComponents;
116 ::ll::TypedStorage<1, 1, bool> mAllowComponentReplacement;
117 ::ll::TypedStorage<1, 1, bool> mAllowTryGetComponentBeforeFinalization;
118 ::ll::TypedStorage<8, 16, ::std::weak_ptr<::BlockComponentEventSubscriber>> mBlockComponentEventSubscriber;
119 // NOLINTEND
120
121public:
122 // member functions
123 // NOLINTBEGIN
124 MCAPI ::BlockComponentStorage::ComponentBase* _findComponentBase(::Bedrock::typeid_t<void> componentIdToFind) const;
125
127 // NOLINTEND
128
129public:
130 template <class T>
131 [[nodiscard]] bool hasComponent() const {
132 // The game also reads mAllowModifyingComponents at the top of this function and discards
133 // the result; that read has no observable effect, so it is omitted here.
134 auto const& components = mComponents.get();
135 return components.find(::Bedrock::type_id<void, T>()) != components.end();
136 }
137
139 template <class T>
140 [[nodiscard]] T* _findComponentTyped() const {
141 auto* componentBase = _findComponentBase(::Bedrock::type_id<void, T>());
142 return componentBase != nullptr ? reinterpret_cast<T*>(&componentBase[1]) : nullptr;
143 }
144
147 template <class TComponent, class... Args>
148 TComponent* _addStatefulComponent(::Bedrock::typeid_t<void> typeId, Args&&... args) {
149 if (auto* existing = _findComponentBase(typeId)) {
150 // The payload sits immediately after ComponentBase's vtable pointer.
151 auto* component = reinterpret_cast<TComponent*>(&existing[1]);
152 if (mAllowComponentReplacement) {
153 *component = TComponent{::std::forward<Args>(args)...};
154 }
155 return component;
156 }
157
158 auto* instance = new ComponentInstance<TComponent>(::std::forward<Args>(args)...);
159 auto* component = &instance->mValue;
160
161 auto const& keys = mComponents->keys();
162 auto const at =
163 ::std::lower_bound(keys.cbegin(), keys.cend(), typeId, ::std::less<::Bedrock::typeid_t<void>>{});
164 mComponents->emplace_hint(at, typeId, ::std::unique_ptr<ComponentBase>{instance});
165
166 // The game locks the event subscriber here and drops the result; refcounting it is all its
167 // inlined body does.
168 (void)mBlockComponentEventSubscriber.lock();
169
170 return component;
171 }
172
173 inline void allowComponentReplacement() { mAllowComponentReplacement = true; }
174
175public:
176 // destructor thunk
177 // NOLINTBEGIN
178 MCAPI void $dtor();
179 // NOLINTEND
180};
Definition typeid_t.h:36
Definition BlockComponentEventSubscriber.h:10
Definition BlockComponentStorage.h:67
TComponent * _addStatefulComponent(::Bedrock::typeid_t< void > typeId, Args &&... args)
Constructs a component of type TComponent in place and inserts it, or overwrites the existing one whe...
Definition BlockComponentStorage.h:148
T * _findComponentTyped() const
The payload sits immediately after ComponentBase's vtable pointer.
Definition BlockComponentStorage.h:140
Definition BlockConnectionComponent.h:17
Definition BlockCustomComponentsComponent.h:20
Definition BlockDeprecatedR16EventListenerComponent.h:17
Definition BlockEntityFallOnConfigurationComponent.h:5
Definition BlockMultiBlockComponent.h:24
Definition BlockRandomOffsetComponent.h:14
Definition BlockRedstoneConsumerComponent.h:15
Definition BlockTickConfigurationComponent.h:5
Definition BlockTransformationComponent.h:9
Definition OnFallOnTrigger.h:14
Definition OnInteractTrigger.h:14
Definition OnPlacedTrigger.h:14
Definition OnPlayerDestroyedTrigger.h:15
Definition OnPlayerPlacingTrigger.h:14
Definition OnStepOffTrigger.h:14
Definition OnStepOnTrigger.h:14
Definition flat_map.h:15
Definition flat_set.h:10
Definition BlockAmbientSoundComponent.h:14
Definition BlockBlockEntityComponent.h:5
Definition BlockChestObstructionComponent.h:8
Definition BlockCollisionBoxComponent.h:14
Definition BlockComponentStorage.h:76
Definition BlockComponentStorage.h:87
Definition BlockConnectionRuleComponent.h:10
Definition BlockContainerComponent.h:5
Definition BlockCraftingTableComponent.h:5
Definition BlockDestructibleByExplosionComponent.h:5
Definition BlockDestructibleByMiningComponent.h:8
Definition BlockDestructionParticlesComponent.h:13
Definition BlockDisplayNameComponent.h:5
Definition BlockEmbeddedVisualComponent.h:11
Definition BlockFlammableComponent.h:10
Definition BlockFlowerPottableComponent.h:5
Definition BlockFrictionComponent.h:5
Definition BlockGeometryComponent.h:18
Definition BlockInstrumentComponent.h:8
Definition BlockItemVisualComponent.h:11
Definition BlockLeashableComponent.h:9
Definition BlockLightDampeningComponent.h:8
Definition BlockLightEmissionComponent.h:8
Definition BlockLiquidDetectionComponent.h:9
Definition BlockLootComponent.h:5
Definition BlockMapColorComponent.h:9
Definition BlockMaterialInstancesComponent.h:14
Definition BlockMovableComponent.h:9
Definition BlockPlacementFilterComponent.h:12
Definition BlockPrecipitationInteractionsComponent.h:8
Definition BlockQueuedTickingComponent.h:9
Definition BlockRandomTickingComponent.h:9
Definition BlockRedstoneComponent.h:5
Definition BlockRedstoneProducerComponent.h:19
Definition BlockSelectionBoxComponent.h:8
Definition BlockSoundComponent.h:10
Definition BlockSupportComponent.h:13
Definition BlockVoxelShapesCullingComponent.h:10