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