add 'blocking' entity property

This commit is contained in:
MihailRis 2024-07-10 04:56:02 +03:00
parent 60f4f33180
commit e0358fe2db
6 changed files with 19 additions and 4 deletions

View File

@ -6,5 +6,6 @@
"sensors": [
["aabb", -0.2, -0.2, -0.2, 0.2, 0.2, 0.2],
["radius", 1.6]
]
],
"blocking": false
}

View File

@ -348,6 +348,7 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& name, const fs
}
root->str("skeleton-name", def.skeletonName);
root->flag("blocking", def.blocking);
}
void ContentLoader::loadEntity(EntityDef& def, const std::string& full, const std::string& name) {

View File

@ -405,9 +405,10 @@ void PlayerController::processRightClick(Block* def, Block* target) {
}
blockid_t chosenBlock = def->rt.id;
auto hitbox = player->getHitbox();
if (hitbox && def->obstacle && level->physics->isBlockInside(
coord.x, coord.y, coord.z, def,state, hitbox)) {
AABB blockAABB(coord, coord+1);
bool blocked = level->entities->hasBlockingInside(blockAABB);
if (def->obstacle && blocked) {
return;
}
auto vox = chunks->get(coord);

View File

@ -404,6 +404,16 @@ void Entities::render(Assets* assets, ModelBatch& batch, const Frustum& frustum,
}
}
bool Entities::hasBlockingInside(AABB aabb) {
auto view = registry.view<EntityId, Transform>();
for (auto [entity, eid, transform] : view.each()) {
if (eid.def.blocking && aabb.contains(transform.pos)) {
return true;
}
}
return false;
}
std::vector<Entity> Entities::getAllInside(AABB aabb) {
std::vector<Entity> collected;
auto view = registry.view<Transform>();

View File

@ -188,6 +188,7 @@ public:
void loadEntity(const dynamic::Map_sptr& map);
void loadEntity(const dynamic::Map_sptr& map, Entity entity);
void onSave(const Entity& entity);
bool hasBlockingInside(AABB aabb);
std::vector<Entity> getAllInside(AABB aabb);
void despawn(entityid_t id);
dynamic::Value serialize(const Entity& entity);

View File

@ -24,6 +24,7 @@ struct EntityDef {
std::vector<std::pair<size_t, AABB>> boxSensors {};
std::vector<std::pair<size_t, float>> radialSensors {};
std::string skeletonName = name;
bool blocking = true;
struct {
bool enabled = true;