add 'blocking' entity property
This commit is contained in:
@@ -6,5 +6,6 @@
|
|||||||
"sensors": [
|
"sensors": [
|
||||||
["aabb", -0.2, -0.2, -0.2, 0.2, 0.2, 0.2],
|
["aabb", -0.2, -0.2, -0.2, 0.2, 0.2, 0.2],
|
||||||
["radius", 1.6]
|
["radius", 1.6]
|
||||||
]
|
],
|
||||||
|
"blocking": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -348,6 +348,7 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& name, const fs
|
|||||||
}
|
}
|
||||||
|
|
||||||
root->str("skeleton-name", def.skeletonName);
|
root->str("skeleton-name", def.skeletonName);
|
||||||
|
root->flag("blocking", def.blocking);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::loadEntity(EntityDef& def, const std::string& full, const std::string& name) {
|
void ContentLoader::loadEntity(EntityDef& def, const std::string& full, const std::string& name) {
|
||||||
|
|||||||
@@ -405,9 +405,10 @@ void PlayerController::processRightClick(Block* def, Block* target) {
|
|||||||
}
|
}
|
||||||
blockid_t chosenBlock = def->rt.id;
|
blockid_t chosenBlock = def->rt.id;
|
||||||
|
|
||||||
auto hitbox = player->getHitbox();
|
AABB blockAABB(coord, coord+1);
|
||||||
if (hitbox && def->obstacle && level->physics->isBlockInside(
|
bool blocked = level->entities->hasBlockingInside(blockAABB);
|
||||||
coord.x, coord.y, coord.z, def,state, hitbox)) {
|
|
||||||
|
if (def->obstacle && blocked) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto vox = chunks->get(coord);
|
auto vox = chunks->get(coord);
|
||||||
|
|||||||
@@ -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> Entities::getAllInside(AABB aabb) {
|
||||||
std::vector<Entity> collected;
|
std::vector<Entity> collected;
|
||||||
auto view = registry.view<Transform>();
|
auto view = registry.view<Transform>();
|
||||||
|
|||||||
@@ -188,6 +188,7 @@ public:
|
|||||||
void loadEntity(const dynamic::Map_sptr& map);
|
void loadEntity(const dynamic::Map_sptr& map);
|
||||||
void loadEntity(const dynamic::Map_sptr& map, Entity entity);
|
void loadEntity(const dynamic::Map_sptr& map, Entity entity);
|
||||||
void onSave(const Entity& entity);
|
void onSave(const Entity& entity);
|
||||||
|
bool hasBlockingInside(AABB aabb);
|
||||||
std::vector<Entity> getAllInside(AABB aabb);
|
std::vector<Entity> getAllInside(AABB aabb);
|
||||||
void despawn(entityid_t id);
|
void despawn(entityid_t id);
|
||||||
dynamic::Value serialize(const Entity& entity);
|
dynamic::Value serialize(const Entity& entity);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ struct EntityDef {
|
|||||||
std::vector<std::pair<size_t, AABB>> boxSensors {};
|
std::vector<std::pair<size_t, AABB>> boxSensors {};
|
||||||
std::vector<std::pair<size_t, float>> radialSensors {};
|
std::vector<std::pair<size_t, float>> radialSensors {};
|
||||||
std::string skeletonName = name;
|
std::string skeletonName = name;
|
||||||
|
bool blocking = true;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user