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/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;
27class HashedString;
28class HitResult;
31class ItemActor;
32class ItemInstance;
33class ItemStackBase;
35class Player;
36class Random;
37class RenderParams;
38class 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 static optional_ref<Block const> tryGetFromRegistry(std::string_view name);
57 LLNDAPI static optional_ref<Block const> tryGetFromRegistry(std::string_view name, ushort legacyData);
58 LLNDAPI static optional_ref<Block const> tryGetFromRegistry(std::string_view name, BlockStatesType const& states);
59
60 LLNDAPI bool isAir() const;
61
62 [[nodiscard]] BlockType const& getBlockType() const { return *mBlockType; }
63
64 [[nodiscard]] std::string const& getTypeName() const { return getBlockType().getTypeName(); }
65
66 [[nodiscard]] unsigned short getBlockItemId() const { return getBlockType().mID->mValue; }
67
68 [[nodiscard]] ushort getData() const { return mData; }
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
92public:
93 // member variables
94 // NOLINTBEGIN
95 ::ll::TypedStorage<8, 104, ::BlockComponentStorage> mComponents;
96 ::ll::TypedStorage<2, 2, ushort const> mData;
97 ::ll::TypedStorage<8, 8, ::gsl::not_null<::BlockType*>> mBlockType;
98 ::ll::TypedStorage<4, 8, ::CachedComponentData> mCachedComponentData;
99 ::ll::TypedStorage<8, 96, ::BlockComponentDirectData> mDirectData;
100 ::ll::TypedStorage<8, 24, ::std::vector<::HashedString>> mTags;
101 ::ll::TypedStorage<8, 24, ::CompoundTag> mSerializationId;
102 ::ll::TypedStorage<8, 8, uint64> mSerializationIdHash;
103 ::ll::TypedStorage<4, 4, uint> mSerializationIdHashForNetwork;
104 ::ll::TypedStorage<4, 4, uint> mNetworkId;
105 ::ll::TypedStorage<1, 1, bool> mHasRuntimeId;
106 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::IClientBlockData>> mClientData;
107 // NOLINTEND
108
109public:
110 // prevent constructor by default
111 Block();
112
113public:
114 // virtual functions
115 // NOLINTBEGIN
116 virtual ~Block() = default;
117 // NOLINTEND
118
119public:
120 // member functions
121 // NOLINTBEGIN
122 MCAPI Block(ushort data, ::gsl::not_null<::BlockType*> oldBlock);
123
124 MCAPI Block(ushort data, ::gsl::not_null<::BlockType*> oldBlock, ::CompoundTag serId, uint const& runId);
125
126 MCAPI_C void _playAmbientSounds(::BlockAnimateTickData const& tickData) const;
127
128 MCAPI void _removeFromTickingQueues(::BlockSource& region, ::BlockPos const& pos) const;
129
130 MCAPI ::ItemInstance asItemInstance(::BlockSource& region, ::BlockPos const& position, bool withData) const;
131
132 MCAPI bool breaksFallingBlocks(::BaseGameVersion version) const;
133
134 MCAPI ::std::string buildDescriptionName() const;
135
136 MCAPI void buildSerializationId(uint latestUpdaterVersion);
137
138 MCAPI bool canConnect(::Block const& connectionBlock, uchar toOther) const;
139
140 MCAPI ::HitResult clip(::BlockPos const& pos, ::Vec3 const& A, ::Vec3 const& B, ::AABB const& aabb) 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 MCAPI bool executeTrigger(::DefinitionTrigger const& trigger, ::RenderParams& params) const;
172
173 MCAPI_C void forEachState(::brstd::function_ref<bool(::BlockState const&, int)> callback) const;
174
175 MCAPI bool getCollisionShape(
176 ::AABB& outAABB,
177 ::IConstBlockSource const& region,
178 ::BlockPos const& pos,
180 ) const;
181
182 MCAPI_C ::BlockType::HorizontalDirectionBits
183 getConnectedDirections(::BlockPos const& pos, ::BlockSource& region) const;
184
185 MCAPI_C ::std::string getCraftingLabelText() const;
186
187 MCAPI ::std::string getDescriptionId() const;
188
189 MCAPI_C ::VoxelShapes::VoxelShape const* getOcclusionFaceShape(uchar face) const;
190
191 MCAPI_C ::AABB const&
192 getOutline(::IConstBlockSource const& region, ::BlockPos const& pos, ::AABB& bufferValue) const;
193
194 MCAPI_S ::Vec3 getRandomOffset(::BlockPos const& pos) const;
195
196 MCAPI_C bool getSecondPart(::BlockSource const& region, ::BlockPos const& pos, ::BlockPos& out) const;
197
198 MCAPI ::Block const& getStateFromLegacyData(ushort data) const;
199
200 MCAPI bool hasState(::HashedString const& name) const;
201
202 MCAPI bool hasState(::BlockState const& stateType) const;
203
204 MCAPI bool hasTag(::HashedString const& tagName) const;
205
206 MCAPI_C bool isCraftingBlock() const;
207
208 MCAPI_C bool isInteractiveBlock() const;
209
210 MCAPI bool isPartialBlock(::BlockSource const& region, ::BlockPos const& pos) const;
211
212 MCAPI bool isPreservingMediumWhenPlaced(::Block const& medium) const;
213
214 MCAPI bool isSolidBlockingBlockAndNotSignalSource() const;
215
216 MCAPI bool isTopPartialBlock(::BlockSource const& region, ::BlockPos const& pos) const;
217
218 MCAPI bool mayPlace(::BlockSource& region, ::BlockPos const& pos, uchar face) const;
219
220 MCAPI void neighborChanged(::BlockSource& region, ::BlockPos const& pos, ::BlockPos const& neighborPos) const;
221
222 MCAPI void onFallOn(::BlockSource& region, ::BlockPos const& pos, ::Actor& entity, float fallDistance) const;
223
224 MCAPI void onPlace(::BlockSource& region, ::BlockPos const& pos, ::Block const& previousBlock) const;
225
226 MCAPI void onStateChange(::BlockSource& region, ::BlockPos const& pos, ::Block const& previousBlock) const;
227
228 MCAPI void onStepOff(::Actor& entity, ::BlockPos const& pos) const;
229
230 MCAPI void onStepOn(::Actor& entity, ::BlockPos const& pos) const;
231
232 MCAPI void playerDestroy(::Player& player, ::BlockPos const& pos) const;
233
234 MCAPI ::ItemActor*
235 popResource(::BlockSource& region, ::BlockPos const& pos, ::ItemInstance const& itemInstance) const;
236
237 MCAPI void queuedTick(::BlockSource& region, ::BlockPos const& pos, ::Random& random) const;
238
239 MCAPI void randomTick(::BlockSource& region, ::BlockPos const& pos, ::Random& random) const;
240
241 MCAPI bool shouldRandomTick() const;
242
243 MCAPI ::std::string toDebugString() const;
244
245 MCAPI bool use(::Player& player, ::BlockPos const& pos, uchar face, ::std::optional<::Vec3> hit) const;
246 // NOLINTEND
247
248public:
249 // static variables
250 // NOLINTBEGIN
251 MCAPI static ::std::string const& BLOCK_DESCRIPTION_PREFIX();
252 // NOLINTEND
253
254public:
255 // constructor thunks
256 // NOLINTBEGIN
257 MCAPI void* $ctor(ushort data, ::gsl::not_null<::BlockType*> oldBlock);
258
259 MCAPI void* $ctor(ushort data, ::gsl::not_null<::BlockType*> oldBlock, ::CompoundTag serId, uint const& runId);
260 // NOLINTEND
261
262public:
263 // vftables
264 // NOLINTBEGIN
265 MCAPI static void** $vftable();
266 // NOLINTEND
267};
Definition AABB.h:18
Definition Actor.h:105
Definition BaseGameVersion.h:8
Definition BlockPos.h:19
Definition BlockSource.h:68
Definition BlockState.h:13
Definition BlockType.h:84
Definition CompoundTag.h:23
Definition DefinitionTrigger.h:15
Definition GetCollisionShapeInterface.h:13
Definition HashedString.h:5
Definition HitResult.h:17
Definition IClientBlockData.h:13
Definition IConstBlockSource.h:25
Definition ItemActor.h:29
Definition ItemInstance.h:15
Definition ItemStackBase.h:44
Definition NeighborBlockDirections.h:14
Definition Player.h:125
Definition Random.h:10
Definition RenderParams.h:30
Definition Vec3.h:10
Definition VoxelShape.h:18
Definition function_ref.h:60
Definition optional_ref.h:10
Definition BlockAnimateTickData.h:14