Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
feat: add SubChunkBrightnessStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Jul 14, 2023
1 parent 1126f3e commit c9c1c8f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
10 changes: 3 additions & 7 deletions LiteLoader/include/llapi/mc/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,21 @@ class Block {

LIAPI std::string getTypeName() const;
LIAPI int getId() const;
inline unsigned short getTileData(){
inline unsigned short getTileData() const {
return static_cast<unsigned short>(getVariant());
}

/**
* @brief Obtain a copy of the NBT associated with this block. To obtain a reference to the original instance, use block->getSerializationId().
*/
LIAPI std::unique_ptr<CompoundTag> getNbt();
LIAPI std::unique_ptr<CompoundTag> getNbt() const;
[[deprecated("DO NOT USE THIS")]]
LIAPI bool setNbt(CompoundTag* nbt);

inline unsigned short getData() const {
return dAccess<unsigned short, 8>(this);
}

[[deprecated("Use MCAPI getLegacyBlock() instead.")]]
inline class BlockLegacy const* getLegacyBlockPtr() const {
return reinterpret_cast<class BlockLegacy const*>(&this->getLegacyBlock());
}

inline bool operator==(class Block const& block) const {
class BlockLegacy const* p1 = &this->getLegacyBlock();
class BlockLegacy const* p2 = &block.getLegacyBlock();
Expand Down
22 changes: 21 additions & 1 deletion LiteLoader/include/llapi/mc/SubChunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
#define BEFORE_EXTRA
// Include Headers or Declare Types Here

class SubChunkBrightnessStorage {
public:
struct LightPair {
unsigned char blockLight : 4;
unsigned char skyLight : 4;
};
std::array<unsigned char,2048> mLightValues;
};

#undef BEFORE_EXTRA

/**
Expand All @@ -20,7 +29,18 @@ struct SubChunk {

#define AFTER_EXTRA
// Add Member There
enum class SubChunkState;
public:
enum class SubChunkState : int {
Invalid =-1,
Normal = 0,
IsLightingSystemSubChunk = 1,
NeedsRequest = 2,
ReceivedResponseFromServer = 3,
ProcessingSubChunk = 4,
WaitingForCacheResponse = 5,
ProcessedSubChunk = 6,
RequestFinished = 7,
};
#undef AFTER_EXTRA
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_SUBCHUNK
public:
Expand Down
4 changes: 2 additions & 2 deletions LiteLoader/src/llapi/mc/BlockAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ int Block::getId() const {
return getLegacyBlock().getBlockItemId();
}

std::unique_ptr<CompoundTag> Block::getNbt() {
return CompoundTag::fromBlock(this);
std::unique_ptr<CompoundTag> Block::getNbt() const {
return getSerializationId().clone();
}

bool Block::setNbt(CompoundTag* nbt) {
Expand Down
14 changes: 1 addition & 13 deletions ScriptEngine/src/api/BlockAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,7 @@ Local<Value> BlockClass::getNbt(const Arguments& args) {
}

Local<Value> BlockClass::setNbt(const Arguments& args) {
CHECK_ARGS_COUNT(args, 1);

try {
auto nbt = NbtCompoundClass::extract(args[0]);
if (!nbt)
return Local<Value>(); // Null

// update Pre Data
Level::setBlock(pos.getBlockPos(), pos.dim, Block::create(nbt));
preloadData(pos.getBlockPos(), pos.getDimensionId());
return Boolean::newBoolean(true);
}
CATCH("Fail in setNbt!")
return Boolean::newBoolean(false);
}

Local<Value> BlockClass::getBlockState(const Arguments& args) {
Expand Down
2 changes: 1 addition & 1 deletion ScriptEngine/src/api/RemoteCallAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Local<Value> _extractValue(Actor* v) {
return EntityClass::newEntity(v);
};
Local<Value> _extractValue(Block* v) {
return BlockClass::newBlock(const_cast<Block*>(v), BlockPos::ZERO, -1);
return BlockClass::newBlock(v, BlockPos::ZERO, -1);
};
Local<Value> _extractValue(BlockActor* const& v) {
return BlockEntityClass::newBlockEntity(v, -1);
Expand Down

0 comments on commit c9c1c8f

Please sign in to comment.