mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
add "include_non_selectable" parameter to blocks raycast
This commit is contained in:
parent
ce769143f8
commit
8f1739c85b
10 changed files with 57 additions and 23 deletions
|
|
@ -476,8 +476,10 @@ static int l_raycast(lua::State* L) {
|
|||
auto start = lua::tovec<3>(L, 1);
|
||||
auto dir = lua::tovec<3>(L, 2);
|
||||
auto maxDistance = lua::tonumber(L, 3);
|
||||
bool includeNonSelectable = false;
|
||||
std::set<blockid_t> filteredBlocks {};
|
||||
if (lua::gettop(L) >= 5) {
|
||||
const int luaStackSize = lua::gettop(L);
|
||||
if (luaStackSize >= 5) {
|
||||
if (lua::istable(L, 5)) {
|
||||
int addLen = lua::objlen(L, 5);
|
||||
for (int i = 0; i < addLen; i++) {
|
||||
|
|
@ -493,6 +495,9 @@ static int l_raycast(lua::State* L) {
|
|||
throw std::runtime_error("table expected for filter");
|
||||
}
|
||||
}
|
||||
if (luaStackSize >= 6) {
|
||||
includeNonSelectable = lua::toboolean(L, 6);
|
||||
}
|
||||
glm::vec3 end;
|
||||
glm::ivec3 normal;
|
||||
glm::ivec3 iend;
|
||||
|
|
@ -504,9 +509,10 @@ static int l_raycast(lua::State* L) {
|
|||
end,
|
||||
normal,
|
||||
iend,
|
||||
filteredBlocks
|
||||
filteredBlocks,
|
||||
includeNonSelectable
|
||||
)) {
|
||||
if (lua::gettop(L) >= 4 && !lua::isnil(L, 4)) {
|
||||
if (luaStackSize >= 4 && !lua::isnil(L, 4)) {
|
||||
lua::pushvalue(L, 4);
|
||||
} else {
|
||||
lua::createtable(L, 0, 5);
|
||||
|
|
|
|||
|
|
@ -141,8 +141,10 @@ static int l_raycast(lua::State* L) {
|
|||
auto dir = lua::tovec<3>(L, 2);
|
||||
auto maxDistance = lua::tonumber(L, 3);
|
||||
auto ignoreEntityId = lua::tointeger(L, 4);
|
||||
bool includeNonSelectable = false;
|
||||
std::set<blockid_t> filteredBlocks {};
|
||||
if (lua::gettop(L) >= 6) {
|
||||
const int luaStackSize = lua::gettop(L);
|
||||
if (luaStackSize >= 6) {
|
||||
if (lua::istable(L, 6)) {
|
||||
int addLen = lua::objlen(L, 6);
|
||||
for (int i = 0; i < addLen; i++) {
|
||||
|
|
@ -158,6 +160,9 @@ static int l_raycast(lua::State* L) {
|
|||
throw std::runtime_error("table expected for filter");
|
||||
}
|
||||
}
|
||||
if (luaStackSize >= 7) {
|
||||
includeNonSelectable = lua::toboolean(L, 6);
|
||||
}
|
||||
|
||||
glm::vec3 end;
|
||||
glm::ivec3 normal;
|
||||
|
|
@ -173,14 +178,15 @@ static int l_raycast(lua::State* L) {
|
|||
end,
|
||||
normal,
|
||||
iend,
|
||||
filteredBlocks
|
||||
filteredBlocks,
|
||||
includeNonSelectable
|
||||
)) {
|
||||
maxDistance = glm::distance(start, end);
|
||||
block = voxel->id;
|
||||
}
|
||||
if (auto ray =
|
||||
level->entities->rayCast(start, dir, maxDistance, ignoreEntityId)) {
|
||||
if (lua::gettop(L) >= 5 && !lua::isnil(L, 5)) {
|
||||
if (luaStackSize >= 5 && !lua::isnil(L, 5)) {
|
||||
lua::pushvalue(L, 5);
|
||||
} else {
|
||||
lua::createtable(L, 0, 6);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue