LeviLamina
Loading...
Searching...
No Matches
SubChunk.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/platform/threading/SpinLockImpl.h"
7#include "mc/world/level/block/chunk_volume/SubVolumeViewOf.h"
8#include "mc/world/level/chunk/DirtyTicksCounter.h"
9#include "mc/world/level/chunk/SubChunkBrightnessStorage.h"
10#include "mc/world/level/chunk/SubChunkStorage.h"
11#include "mc/world/level/chunk/sub_chunk_storage_unit/PruneType.h"
12
13// auto generated forward declare list
14// clang-format off
15class Block;
16class BlockPalette;
17class BlockPos;
18class BlockVolume;
19class IDataInput;
20class IDataOutput;
22class SubChunkPos;
24// clang-format on
25
26struct SubChunk {
27public:
28 // SubChunk inner types define
29 enum class BlockLayer : uchar {
30 Standard = 0,
31 Extra = 1,
32 Count = 2,
33 };
34
35 enum class SubChunkState : int {
36 Invalid = -1,
37 Normal = 0,
38 IsLightingSystemSubChunk = 1,
39 NeedsRequest = 2,
40 ReceivedResponseFromServer = 3,
41 ProcessingSubChunk = 4,
42 WaitingForCacheResponse = 5,
43 ProcessedSubChunk = 6,
44 RequestFinished = 7,
45 };
46
47 using Layer = uchar;
48
49public:
50 // member variables
51 // NOLINTBEGIN
52 ::ll::TypedStorage<4, 8, ::DirtyTicksCounter> mDirtyTicksCounter;
53 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::SubChunkBrightnessStorage>> mSkyLight;
54 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::SubChunkBrightnessStorage>> mBlockLight;
55 ::ll::TypedStorage<4, 4, ::SubChunk::SubChunkState> mSubChunkState;
56 ::ll::TypedStorage<1, 1, bool> mHasMaxSkyLight;
57 ::ll::TypedStorage<1, 1, bool> mNeedsInitLighting;
58 ::ll::TypedStorage<1, 1, bool> mNeedsClientLighting;
59 ::ll::TypedStorage<8, 16, ::std::unique_ptr<::SubChunkStorage<::Block>>[2]> mBlocks;
60 ::ll::TypedStorage<8, 16, ::SubChunkStorage<::Block>* [2]> mBlocksReadPtr;
61 ::ll::TypedStorage<8, 24, ::SpinLockImpl> mWriteLock;
62 ::ll::TypedStorage<8, 8, uint64> mHash;
63 ::ll::TypedStorage<1, 1, bool> mHashDirty;
64 ::ll::TypedStorage<1, 1, schar> mAbsoluteIndex;
65 ::ll::TypedStorage<1, 1, bool> mIsReplacementSubChunk;
66 ::ll::TypedStorage<1, 1, uchar> mRenderChunkTrackingVersionNumber;
67 ::ll::TypedStorage<1, 1, bool> mIsInitialized;
68 // NOLINTEND
69
70public:
71 [[nodiscard]] bool isUniform(::Block const& block) const {
72 if (!mBlocksReadPtr[0]->isUniform(block)) {
73 return false;
74 }
75 // The extra layer is optional; a subchunk with only a standard layer is uniform whenever that layer is.
76 if (mBlocksReadPtr[1] != nullptr) {
77 return mBlocksReadPtr[1]->isUniform(block);
78 }
79 return true;
80 }
81
82public:
83 // prevent constructor by default
84 SubChunk& operator=(SubChunk const&);
85 SubChunk(SubChunk const&);
86 SubChunk();
87
88public:
89 // member functions
90 // NOLINTBEGIN
91 MCAPI SubChunk(::SubChunk&& rhs);
92
93 MCAPI SubChunk(::Block const* initBlock, bool maxSkyLight, bool maxLight, schar absoluteIndex);
94
95#ifdef LL_PLAT_C
96 MCAPI void _createBlockLightStorage();
97
98 MCAPI void _createSkyLightStorage();
99#endif
100
101#ifdef LL_PLAT_S
102 MCAPI void _resetLight(bool maxSkyLight, bool maxLight);
103#endif
104
105 MCAPI void _setBlock(uchar layer, ushort index, ::Block const& block);
106
107 MCAPI void deserialize(
108 ::IDataInput& stream,
109 ::BlockPalette const& palette,
110 ::SubChunkPos const& subChunkPos,
111 ::std::optional<::DeserializationChanges*> deserializationChanges
112 );
113
114 MCAPI void fetchBlocks(
115 ::BlockPos const& subChunkOrigin,
116 ::BlockPos const& volumeOrigin,
117 short dimensionMinHeight,
118 ::BlockVolume& volume
119 ) const;
120
121#ifdef LL_PLAT_C
122 MCAPI bool isPlaceHolderSubChunk() const;
123#endif
124
125 MCAPI ::SubChunk& operator=(::SubChunk&& rhs);
126
127 MCAPI void prune(::SubChunkStorageUnit::PruneType pruneType);
128
129 MCAPI ::std::string recalculateHashAndSerialize(bool network);
130
131 MCAPI void reset(::Block const* resetBlock, bool maxSkyLight, bool fullyLit);
132
133 MCAPI void serialize(::IDataOutput& stream, bool network) const;
134
135#ifdef LL_PLAT_S
136 MCAPI void setBlockLight(ushort index, uchar lightValue);
137#endif
138
139 MCAPI void setBlocksToUniform(::Block const& initBlock, bool maxSkyLight, bool fullyLit);
140
141 MCAPI void setFromBlockVolume(
142 ::BlockVolume const& box,
143 short height,
145 );
146
147#ifdef LL_PLAT_C
148 MCAPI void setLight(ushort idx, ::SubChunkBrightnessStorage::LightPair pair);
149#endif
150
151#ifdef LL_PLAT_S
152 MCAPI void setSkyLight(ushort index, uchar lightValue);
153#endif
154
155 MCAPI ~SubChunk();
156 // NOLINTEND
157
158public:
159 // constructor thunks
160 // NOLINTBEGIN
161 MCAPI void* $ctor(::SubChunk&& rhs);
162
163 MCAPI void* $ctor(::Block const* initBlock, bool maxSkyLight, bool maxLight, schar absoluteIndex);
164 // NOLINTEND
165
166public:
167 // destructor thunk
168 // NOLINTBEGIN
169 MCAPI void $dtor();
170 // NOLINTEND
171};
Definition BlockPalette.h:18
Definition BlockPos.h:17
Definition BlockVolume.h:14
Definition Block.h:41
Definition SubVolumeViewOf.h:8
Definition IDataInput.h:8
Definition IDataOutput.h:5
Definition SubChunkBrightnessStorage.h:5
Definition SubChunkPos.h:5
Definition DeserializationChanges.h:14
Definition SubChunkBrightnessStorage.h:13