Skip to content

Commit

Permalink
fix: try fix getBlockFromViewVector
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Feb 24, 2024
1 parent 2fc2472 commit b0210af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
21 changes: 9 additions & 12 deletions src/legacy/api/EntityAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,18 +1425,15 @@ Local<Value> EntityClass::getBlockFromViewVector(const Arguments& args) {
}
HitResult res = actor->traceRay(maxDistance, false, true);

return Local<Value>(); // Temporary solution
// TODO: Fix this, block cannot be constructed.
// Block bl;
// BlockPos bp;
// if (includeLiquid && res.mIsHitLiquid) {
// bp = res.mLiquidPos;
// } else {
// bp = res.mBlockPos;
// }
// actor->getDimensionBlockSource().getBlock(bp);
// if (bl.isEmpty()) return Local<Value>();
// return BlockClass::newBlock(std::move(&bl), &bp, actor->getDimensionId().id);
BlockPos bp;
if (includeLiquid && res.mIsHitLiquid) {
bp = res.mLiquidPos;
} else {
bp = res.mBlockPos;
}
Block const& bl = actor->getDimensionBlockSource().getBlock(bp);
if (bl.isEmpty()) return Local<Value>();
return BlockClass::newBlock(std::move(&bl), &bp, actor->getDimensionId().id);
}
CATCH("Fail in getBlockFromViewVector!");
}
Expand Down
22 changes: 10 additions & 12 deletions src/legacy/api/PlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2966,7 +2966,7 @@ Local<Value> PlayerClass::getEntityFromViewVector(const Arguments& args) {
CHECK_ARG_TYPE(args[0], ValueKind::kNumber);
maxDistance = args[0].asNumber().toFloat();
}
HitResult result = player->traceRay(maxDistance);
HitResult result = player->traceRay(maxDistance, true, false);
Actor* entity = result.getEntity();
if (entity) return EntityClass::newEntity(entity);
return Local<Value>();
Expand Down Expand Up @@ -3002,17 +3002,15 @@ Local<Value> PlayerClass::getBlockFromViewVector(const Arguments& args) {
HitResult res = player->traceRay(maxDistance, false, true);

return Local<Value>();
// TODO
// Block bl;
// BlockPos bp;
// if (includeLiquid && res.mIsHitLiquid) {
// bp = res.mLiquidPos;
// } else {
// bp = res.mBlockPos;
// }
// player->getDimensionBlockSource().getBlock(bp);
// if (bl.isEmpty()) return Local<Value>();
// return BlockClass::newBlock(std::move(&bl), &bp, player->getDimensionId().id);
BlockPos bp;
if (includeLiquid && res.mIsHitLiquid) {
bp = res.mLiquidPos;
} else {
bp = res.mBlockPos;
}
Block const& bl = player->getDimensionBlockSource().getBlock(bp);
if (bl.isEmpty()) return Local<Value>();
return BlockClass::newBlock(std::move(&bl), &bp, player->getDimensionId().id);
}
CATCH("Fail in getBlockFromViewVector!");
}
Expand Down

0 comments on commit b0210af

Please sign in to comment.