3#include "mc/_HeaderOutputPredefine.h"
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"
86 template <
typename T0>
89 explicit ComponentInstance(A&&... a) : mValue(::std::forward<A>(a)...) {}
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>>>>
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;
131 [[nodiscard]]
bool hasComponent()
const {
134 auto const& components = mComponents.get();
135 return components.find(::Bedrock::type_id<void, T>()) != components.end();
141 auto* componentBase = _findComponentBase(::Bedrock::type_id<void, T>());
142 return componentBase !=
nullptr ?
reinterpret_cast<T*
>(&componentBase[1]) :
nullptr;
147 template <
class TComponent,
class... Args>
149 if (
auto* existing = _findComponentBase(typeId)) {
151 auto* component =
reinterpret_cast<TComponent*
>(&existing[1]);
152 if (mAllowComponentReplacement) {
153 *component = TComponent{::std::forward<Args>(args)...};
159 auto* component = &instance->mValue;
161 auto const& keys = mComponents->keys();
164 mComponents->emplace_hint(at, typeId, ::std::unique_ptr<ComponentBase>{instance});
168 (void)mBlockComponentEventSubscriber.lock();
173 inline void allowComponentReplacement() { mAllowComponentReplacement =
true; }
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 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 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