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"
88 template <
typename T0>
91 explicit ComponentInstance(A&&... a) : mValue(::std::forward<A>(a)...) {}
104 ::std::unique_ptr<::BlockComponentStorage::ComponentBase>,
105 ::std::less<::Bedrock::typeid_t<void>>,
106 ::std::vector<::Bedrock::typeid_t<void>>,
107 ::std::vector<::std::unique_ptr<::BlockComponentStorage::ComponentBase>>>>
114 ::std::less<::Bedrock::typeid_t<void>>,
115 ::std::vector<::Bedrock::typeid_t<void>>>>
116 mStatelessComponents;
117 ::ll::TypedStorage<1, 1, bool> mAllowModifyingComponents;
118 ::ll::TypedStorage<1, 1, bool> mAllowComponentReplacement;
119 ::ll::TypedStorage<1, 1, bool> mAllowTryGetComponentBeforeFinalization;
120 ::ll::TypedStorage<8, 16, ::std::weak_ptr<::BlockComponentEventSubscriber>> mBlockComponentEventSubscriber;
133 [[nodiscard]]
bool hasComponent()
const {
136 auto const& components = mComponents.get();
137 return components.find(::Bedrock::type_id<void, T>()) != components.end();
143 auto* componentBase = _findComponentBase(::Bedrock::type_id<void, T>());
144 return componentBase !=
nullptr ?
reinterpret_cast<T*
>(&componentBase[1]) :
nullptr;
149 template <
class TComponent,
class... Args>
151 if (
auto* existing = _findComponentBase(typeId)) {
153 auto* component =
reinterpret_cast<TComponent*
>(&existing[1]);
154 if (mAllowComponentReplacement) {
155 *component = TComponent{::std::forward<Args>(args)...};
161 auto* component = &instance->mValue;
163 auto const& keys = mComponents->keys();
166 mComponents->emplace_hint(at, typeId, ::std::unique_ptr<ComponentBase>{instance});
170 (void)mBlockComponentEventSubscriber.lock();
175 inline void allowComponentReplacement() { mAllowComponentReplacement =
true; }
Definition BlockComponentEventSubscriber.h:10
Definition BlockComponentStorage.h:69
MCAPI ~BlockComponentStorage()
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:150
T * _findComponentTyped() const
The payload sits immediately after ComponentBase's vtable pointer.
Definition BlockComponentStorage.h:142
Definition BlockConnectionComponent.h:17
Definition BlockCustomComponentsComponent.h:21
Definition BlockDeprecatedR16EventListenerComponent.h:17
Definition BlockEntityFallOnConfigurationComponent.h:5
Definition BlockMultiBlockComponent.h:24
Definition BlockNeighborChangeConfigurationComponent.h:5
Definition BlockRandomOffsetComponent.h:14
Definition BlockRedstoneConsumerComponent.h:16
Definition BlockTickConfigurationComponent.h:5
Definition BlockVibrationPropertiesComponent.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:78
Definition BlockComponentStorage.h:89
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