Skip to content

Commit

Permalink
fix: avoid constructing Block
Browse files Browse the repository at this point in the history
  • Loading branch information
futrime committed Jan 22, 2024
1 parent a6f3e22 commit 54ec0c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/api/BlockAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Local<Object> BlockClass::newBlock(Block const* p, BlockPos const* pos, int dim)
}

Local<Object> BlockClass::newBlock(BlockPos const* pos, int dim) {
Block bl = ll::service::getLevel()->getDimension(dim)->getBlockSourceFromMainChunkSource().getBlock(*pos);
auto& bl = ll::service::getLevel()->getDimension(dim)->getBlockSourceFromMainChunkSource().getBlock(*pos);
return BlockClass::newBlock(&bl, pos, dim);
}

Expand All @@ -98,7 +98,7 @@ Local<Object> BlockClass::newBlock(Block const* p, BlockPos const* pos, BlockSou

Local<Object> BlockClass::newBlock(IntVec4 pos) {
BlockPos bp = {(float)pos.x, (float)pos.y, (float)pos.z};
Block bl = ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource().getBlock(bp);
auto& bl = ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource().getBlock(bp);
return BlockClass::newBlock(&bl, &bp, pos.dim);
}

Expand Down Expand Up @@ -337,7 +337,7 @@ Local<Value> BlockClass::getBlockState(const Arguments& args) {

Local<Value> BlockClass::hasContainer(const Arguments& args) {
try {
Block bl = ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource().getBlock(
auto& bl = ll::service::getLevel()->getDimension(pos.dim)->getBlockSourceFromMainChunkSource().getBlock(
pos.getBlockPos()
);
return Boolean::newBoolean(bl.isContainerBlock());
Expand Down
2 changes: 1 addition & 1 deletion src/api/BlockEntityAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Local<Value> BlockEntityClass::setNbt(const Arguments& args) {
Local<Value> BlockEntityClass::getBlock(const Arguments& args) {
try {
BlockPos bp = blockEntity->getPosition();
Block bl = ll::service::getLevel()->getDimension(dim)->getBlockSourceFromMainChunkSource().getBlock(bp);
auto& bl = ll::service::getLevel()->getDimension(dim)->getBlockSourceFromMainChunkSource().getBlock(bp);
return BlockClass::newBlock(&bl, &bp, dim);
}
CATCH("Fail in getBlock!")
Expand Down

0 comments on commit 54ec0c6

Please sign in to comment.