From b0210af5ca70a5d32e4ac2a48be01b942ebc7733 Mon Sep 17 00:00:00 2001 From: ShrBox Date: Sat, 24 Feb 2024 22:29:28 +0800 Subject: [PATCH] fix: try fix getBlockFromViewVector --- src/legacy/api/EntityAPI.cpp | 21 +++++++++------------ src/legacy/api/PlayerAPI.cpp | 22 ++++++++++------------ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/legacy/api/EntityAPI.cpp b/src/legacy/api/EntityAPI.cpp index d7a3cec9..955eccbc 100644 --- a/src/legacy/api/EntityAPI.cpp +++ b/src/legacy/api/EntityAPI.cpp @@ -1425,18 +1425,15 @@ Local EntityClass::getBlockFromViewVector(const Arguments& args) { } HitResult res = actor->traceRay(maxDistance, false, true); - return Local(); // 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(); - // 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(); + return BlockClass::newBlock(std::move(&bl), &bp, actor->getDimensionId().id); } CATCH("Fail in getBlockFromViewVector!"); } diff --git a/src/legacy/api/PlayerAPI.cpp b/src/legacy/api/PlayerAPI.cpp index cc2d0741..d92178bc 100644 --- a/src/legacy/api/PlayerAPI.cpp +++ b/src/legacy/api/PlayerAPI.cpp @@ -2966,7 +2966,7 @@ Local 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(); @@ -3002,17 +3002,15 @@ Local PlayerClass::getBlockFromViewVector(const Arguments& args) { HitResult res = player->traceRay(maxDistance, false, true); return Local(); - // 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(); - // 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(); + return BlockClass::newBlock(std::move(&bl), &bp, player->getDimensionId().id); } CATCH("Fail in getBlockFromViewVector!"); }