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