Skip to content
LeviMC
English
AutoLightDark
LeviLamina
Loading...
Searching...
No Matches
Block.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4#include "mc/world/level/block/BlockProperty.h"
5#include "mc/world/level/block/BlockType.h"
6
7// auto generated inclusion list
8#include "mc/deps/core/utility/optional_ref.h"
9#include "mc/deps/nbt/CompoundTag.h"
10#include "mc/world/item/HandSlot.h"
11#include "mc/world/level/ShapeType.h"
12#include "mc/world/level/block/BlockSupportType.h"
13#include "mc/world/level/block/CachedComponentData.h"
14#include "mc/world/level/block/components/BlockComponentDirectData.h"
15#include "mc/world/level/block/components/BlockComponentStorage.h"
16#include "mc/world/level/block/components/ConnectionID.h"
17
18// auto generated forward declare list
19// clang-format off
20class AABB;
21class Actor;
22class BaseGameVersion;
24class BlockPos;
25class BlockSource;
26class BlockState;
27class BlockType;
29class HashedString;
30class HitResult;
31class IRandom;
32class ItemInstance;
33class ItemStackBase;
34class Player;
35class Random;
36class Vec3;
40// clang-format on
41
42class Block {
43public:
44 using BlockStateValueType = std::variant<int, float, bool, std::string>;
45 using BlockStatesType = std::vector<std::pair<std::string, BlockStateValueType>>;
46
47 LLNDAPI static optional_ref<Block const> tryGetFromRegistry(uint runtimeID);
48 LLNDAPI static optional_ref<Block const> tryGetFromRegistry(uint legacyBlockID, ushort legacyData);
49 LLNDAPI static optional_ref<Block const> tryGetFromRegistry(HashedString const& name);
50 LLNDAPI static optional_ref<Block const> tryGetFromRegistry(HashedString const& name, ushort legacyData);
51 LLNDAPI static optional_ref<Block const>
52 tryGetFromRegistry(HashedString const& name, BlockStatesType const& states);
53 LLNDAPI static optional_ref<Block const> tryGetFromRegistry(CompoundTag const& nbt);
54
55 LLNDAPI bool isAir() const;
56 [[nodiscard]] inline bool hasProperty(BlockProperty type) const {
57 return static_cast<uint64>(type) & static_cast<uint64>(mBlockType->mProperties);
58 }
59
60 [[nodiscard]] BlockType const& getBlockType() const { return *mBlockType; }
61
62 [[nodiscard]] std::string const& getTypeName() const { return getBlockType().getTypeName(); }
63
64 [[nodiscard]] unsigned short getBlockItemId() const { return getBlockType().mID->mValue; }
65
66 [[nodiscard]] ushort getData() const { return mData; }
67
68 [[nodiscard]] Material const& getMaterial() const { return getBlockType().mMaterial; }
69
70 template <typename T>
71 std::optional<T> getState(uint64 id) const {
72 return mBlockType->getState<T>(id, mData);
73 }
74
75 template <typename T>
76 std::optional<T> getState(BlockState const& state) const {
77 return mBlockType->getState<T>(state, mData);
78 }
79
80 template <typename T>
81 optional_ref<Block const> setState(uint64 id, T value) const {
82 return mBlockType->trySetState(id, value, mData);
83 }
84
85 template <typename T>
86 optional_ref<Block const> setState(BlockState const& state, T value) const {
87 return mBlockType->trySetState(state, value, mData);
88 }
89
90 bool operator==(Block const& other) const { return mSerializationIdHash == other.mSerializationIdHash; }
91
92 template <typename T>
93 MCAPI T const* tryGetComponent() const;
94
97 mCachedComponentData->mEmissiveBrightness->mValue = mBlockType->getEmissiveBrightness(*this).mValue;
98 mCachedComponentData->mIsSolid = _isSolid();
99 mCachedComponentData->mOcclusionType = _getBlockOcclusionType();
100 }
101
103 LLNDAPI BlockOcclusionType _getBlockOcclusionType() const;
104
105public:
106 // member variables
107 // NOLINTBEGIN
108 ::ll::TypedStorage<8, 96, ::BlockComponentStorage> mComponents;
109 ::ll::TypedStorage<8, 8, ::gsl::not_null<::BlockType*>> mBlockType;
110 ::ll::TypedStorage<4, 8, ::CachedComponentData> mCachedComponentData;
111 ::ll::TypedStorage<8, 96, ::BlockComponentDirectData> mDirectData;
112 ::ll::TypedStorage<8, 24, ::std::vector<::HashedString>> mTags;
113 ::ll::TypedStorage<8, 24, ::CompoundTag> mSerializationId;
114 ::ll::TypedStorage<8, 8, uint64> mSerializationIdHash;
115 ::ll::TypedStorage<4, 4, uint> mSerializationIdHashForNetwork;
116 ::ll::TypedStorage<4, 4, uint> mNetworkId;
117 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::IClientBlockData>> mClientData;
118 ::ll::TypedStorage<2, 2, ushort const> mData;
119 ::ll::TypedStorage<1, 1, bool> mHasRuntimeId;
120 // NOLINTEND
121
122public:
123 // prevent constructor by default
124 Block();
125
126public:
127 // virtual functions
128 // NOLINTBEGIN
129 virtual ~Block() = default;
130 // NOLINTEND
131
132public:
133 // member functions
134 // NOLINTBEGIN
135 MCNAPI Block(ushort data, ::gsl::not_null<::BlockType*> oldBlock);
136
137 MCNAPI Block(ushort data, ::gsl::not_null<::BlockType*> oldBlock, ::CompoundTag serId, uint const& runId);
138
139 MCAPI bool _isSolid() const;
140
141#ifdef LL_PLAT_C
142 MCNAPI void _playAmbientSounds(::BlockAnimateTickData const& tickData) const;
143#endif
144
146 ::BlockSource& region,
147 ::BlockPos const& pos,
148 ::Random& random,
149 bool placingBlock
150 ) const;
151
152 MCAPI void _removeFromTickingQueues(::BlockSource& region, ::BlockPos const& pos) const;
153
154 MCNAPI ::Block& addTag(::HashedString const& tag);
155
156 MCAPI ::ItemInstance asItemInstance(::BlockSource& region, ::BlockPos const& position, bool withData) const;
157
158 MCAPI bool breaksFallingBlocks(::BaseGameVersion version) const;
159
160 MCNAPI ::std::string buildDescriptionId() const;
161
162 MCAPI ::std::string buildDescriptionName() const;
163
164 MCNAPI void buildSerializationId(uint latestUpdaterVersion);
165
166 MCNAPI bool canConnect(::Block const& connectionBlock, uchar toOther) const;
167
168 MCAPI bool canProvideFullSupport(uchar face) const;
169
170 MCAPI bool canProvideSupport(uchar face, ::BlockSupportType type) const;
171
172 MCAPI bool canSurvive(::BlockSource& region, ::BlockPos const& pos) const;
173
174 MCNAPI ::HitResult clip(::BlockPos const& pos, ::Vec3 const& A, ::Vec3 const& B, ::AABB const& aabb) const;
175
176 MCAPI ::HitResult clip(
177 ::BlockSource const& region,
178 ::BlockPos const& pos,
179 ::Vec3 const& A,
180 ::Vec3 const& B,
181 ::ShapeType shapeType,
183 ) const;
184
185 MCAPI uint computeRawSerializationIdHashForNetwork() const;
186
187 MCAPI ::Block const& copyState(::Block const& fromBlock, ::BlockState const& state) const;
188
189 MCNAPI void executeItemEvent(
190 ::ItemStackBase& item,
191 ::std::string const& eventName,
192 ::BlockSource& region,
193 ::BlockPos const& pos,
194 ::Actor& actor,
195 ::HandSlot handSlot
196 ) const;
197
198 MCAPI void finalizeBlockComponentStorage();
199
200 MCNAPI ::std::optional<::ConnectionID> getConnectionID() const;
201
202#ifdef LL_PLAT_C
203 MCNAPI ::std::string getCraftingLabelText() const;
204#endif
205
206 MCAPI ::std::string getDescriptionId() const;
207
208 MCAPI float getDestroySpeed(::ItemStackBase const& item) const;
209
210 MCAPI ::std::string getDisplayName() const;
211
212 MCAPI bool hasTag(::HashedString const& tagName) const;
213
214 MCAPI bool isCropBlock() const;
215
216 MCNAPI bool isPartialBlock(::BlockSource const& region, ::BlockPos const& pos) const;
217
218 MCNAPI bool isPreservingMediumWhenPlaced(::Block const& medium) const;
219
220 MCNAPI bool isTopPartialBlock(::BlockSource const& region, ::BlockPos const& pos) const;
221
222 MCAPI ::Block const& keepStates(::std::vector<::BlockState const*> const& statesToKeep) const;
223
224 MCAPI bool mayPlace(::BlockSource& region, ::BlockPos const& pos, uchar face, ::Actor const* placer) const;
225
226 MCAPI void neighborChanged(::BlockSource& region, ::BlockPos const& pos, ::BlockPos const& neighborPos) const;
227
228 MCNAPI void onActorEvent(::BlockPos const& pos, ::std::string const& eventName, ::Actor& sourceEntity) const;
229
230 MCNAPI void
231 onActorInternalEvent(::BlockPos const& pos, ::std::string const& eventName, ::Actor& sourceEntity) const;
232
233 MCNAPI void onRemove(::BlockSource& region, ::BlockPos const& pos) const;
234
235 MCAPI void onStateChange(
236 ::BlockSource& region,
237 ::BlockPos const& pos,
238 ::Block const& previousBlock,
239 ::BlockChangeContext const& changeSourceContext
240 ) const;
241
242 MCAPI void playerDestroy(::Player& player, ::BlockPos const& pos) const;
243
244 MCAPI void queuedTick(::BlockSource& region, ::BlockPos const& pos, ::Random& random) const;
245
246 MCAPI void randomTick(::BlockSource& region, ::BlockPos const& pos, ::Random& random) const;
247
248 MCAPI void spawnResources(
249 ::BlockSource& region,
250 ::BlockPos const& pos,
251 ::IRandom& random,
252 ::ResourceDropsContext const& resourceDropsContext,
253 ::Actor const* actorContext
254 ) const;
255
256 MCAPI ::std::string toDebugString() const;
257
258 MCAPI bool
259 use(::Player& player, ::BlockPos const& pos, uchar face, ::HandSlot handSlot, ::std::optional<::Vec3> hit) const;
260 // NOLINTEND
261
262public:
263 // static variables
264 // NOLINTBEGIN
265 MCAPI static ::std::string const& BLOCK_DESCRIPTION_PREFIX();
266 // NOLINTEND
267
268public:
269 // constructor thunks
270 // NOLINTBEGIN
271 MCNAPI void* $ctor(ushort data, ::gsl::not_null<::BlockType*> oldBlock);
272
273 MCNAPI void* $ctor(ushort data, ::gsl::not_null<::BlockType*> oldBlock, ::CompoundTag serId, uint const& runId);
274 // NOLINTEND
275
276public:
277 // vftables
278 // NOLINTBEGIN
279 MCNAPI static void** $vftable();
280 // NOLINTEND
281};
Definition AABB.h:18
Definition Actor.h:116
Definition BaseGameVersion.h:8
Definition BlockChangeContext.h:11
Definition BlockPos.h:14
Definition BlockSource.h:72
Definition BlockState.h:14
Definition BlockType.h:79
MCAPI Block(ushort data, ::gsl::not_null<::BlockType * > oldBlock)
void cacheComponentData()
Refreshes the data cached on this block state from its components and block type.
Definition Block.h:96
MCAPI void onRemove(::BlockSource &region, ::BlockPos const &pos) const
MCAPI bool isTopPartialBlock(::BlockSource const &region, ::BlockPos const &pos) const
MCAPI void executeItemEvent(::ItemStackBase &item, ::std::string const &eventName, ::BlockSource &region, ::BlockPos const &pos, ::Actor &actor, ::HandSlot handSlot) const
MCAPI bool canConnect(::Block const &connectionBlock, uchar toOther) const
MCAPI ::std::optional<::ConnectionID > getConnectionID() const
MCAPI void onActorEvent(::BlockPos const &pos, ::std::string const &eventName, ::Actor &sourceEntity) const
MCAPI void _queueForTickBasedOnComponentConfiguration(::BlockSource &region, ::BlockPos const &pos, ::Random &random, bool placingBlock) const
MCAPI void buildSerializationId(uint latestUpdaterVersion)
MCAPI::std::string buildDescriptionId() const
MCAPI Block(ushort data, ::gsl::not_null<::BlockType * > oldBlock, ::CompoundTag serId, uint const &runId)
MCAPI void * $ctor(ushort data, ::gsl::not_null<::BlockType * > oldBlock, ::CompoundTag serId, uint const &runId)
MCAPI void onActorInternalEvent(::BlockPos const &pos, ::std::string const &eventName, ::Actor &sourceEntity) const
MCAPI void * $ctor(ushort data, ::gsl::not_null<::BlockType * > oldBlock)
MCAPI bool isPartialBlock(::BlockSource const &region, ::BlockPos const &pos) const
MCAPI::Block & addTag(::HashedString const &tag)
LLNDAPI BlockOcclusionType _getBlockOcclusionType() const
The block type properties and material are inspected in order of decreasing priority.
MCAPI bool isPreservingMediumWhenPlaced(::Block const &medium) const
MCAPI::HitResult clip(::BlockPos const &pos, ::Vec3 const &A, ::Vec3 const &B, ::AABB const &aabb) const
static MCAPI void ** $vftable()
Definition CompoundTag.h:18
Definition GetCollisionShapeInterface.h:13
Definition HashedString.h:5
Definition HitResult.h:18
Definition IClientBlockData.h:5
Definition IRandom.h:10
Definition ItemInstance.h:15
Definition ItemStackBase.h:45
Definition Material.h:8
Definition Player.h:131
Definition Random.h:10
Definition Vec3.h:10
Definition optional_ref.h:10
Definition BlockAnimateTickData.h:14
Definition ResourceDropsContext.h:16