fix integer raycast filters & add simple raycast test

This commit is contained in:
MihailRis 2026-07-17 00:23:16 +03:00
parent f6e1f23c84
commit 39a4236553
4 changed files with 85 additions and 9 deletions

View file

@ -230,10 +230,14 @@ static void load_blocks_filter(lua::State* L, int idx, std::set<blockid_t>& dst)
int count = lua::objlen(L, idx);
for (int i = 0; i < count; i++) {
lua::rawgeti(L, i + 1, idx);
auto blockName = std::string(lua::tostring(L, -1));
const Block* block = content->blocks.find(blockName);
if (block != nullptr) {
dst.insert(block->rt.id);
if (lua::isnumber(L, -1)) {
dst.insert(lua::touinteger(L, -1));
} else {
auto blockName = std::string(lua::tostring(L, -1));
const Block* block = content->blocks.find(blockName);
if (block != nullptr) {
dst.insert(block->rt.id);
}
}
lua::pop(L);
}
@ -243,10 +247,14 @@ static void load_entities_filter(lua::State* L, int idx, std::set<entitydefid_t>
int count = lua::objlen(L, idx);
for (int i = 0; i < count; i++) {
lua::rawgeti(L, i + 1, idx);
auto entityName = std::string(lua::tostring(L, -1));
const EntityDef* entity = content->entities.find(entityName);
if (entity != nullptr) {
dst.insert(entity->rt.id);
if (lua::isnumber(L, -1)) {
dst.insert(lua::touinteger(L, -1));
} else {
auto entityName = std::string(lua::tostring(L, -1));
const EntityDef* entity = content->entities.find(entityName);
if (entity != nullptr) {
dst.insert(entity->rt.id);
}
}
lua::pop(L);
}

View file

@ -269,7 +269,7 @@ static inline voxel* raycast_blocks(
const auto& def = blocks.require(voxel->id);
if (voxel->id != BLOCK_AIR &&
(def.selectable || includeNonSelectable) &&
(filter == nullptr || (filter->find(def.rt.id) == filter->end()) ==
((filter == nullptr || filter->find(def.rt.id) == filter->end()) ==
settings.blocksFilterExcludeMode)) {
end = start + t * dir;
iend = {ix, iy, iz};