From e0358fe2db990220defbd37ecb82aeb0ec2a2a4c Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 10 Jul 2024 04:56:02 +0300 Subject: [PATCH] add 'blocking' entity property --- res/content/base/entities/drop.json | 3 ++- src/content/ContentLoader.cpp | 1 + src/logic/PlayerController.cpp | 7 ++++--- src/objects/Entities.cpp | 10 ++++++++++ src/objects/Entities.hpp | 1 + src/objects/EntityDef.hpp | 1 + 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/res/content/base/entities/drop.json b/res/content/base/entities/drop.json index b40e11f0..3df0c513 100644 --- a/res/content/base/entities/drop.json +++ b/res/content/base/entities/drop.json @@ -6,5 +6,6 @@ "sensors": [ ["aabb", -0.2, -0.2, -0.2, 0.2, 0.2, 0.2], ["radius", 1.6] - ] + ], + "blocking": false } diff --git a/src/content/ContentLoader.cpp b/src/content/ContentLoader.cpp index dac39bc4..cdfec691 100644 --- a/src/content/ContentLoader.cpp +++ b/src/content/ContentLoader.cpp @@ -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) { diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index 4cbb77a2..f46ad02d 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -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); diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index 1812d52b..d9e80e9d 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -404,6 +404,16 @@ void Entities::render(Assets* assets, ModelBatch& batch, const Frustum& frustum, } } +bool Entities::hasBlockingInside(AABB aabb) { + auto view = registry.view(); + for (auto [entity, eid, transform] : view.each()) { + if (eid.def.blocking && aabb.contains(transform.pos)) { + return true; + } + } + return false; +} + std::vector Entities::getAllInside(AABB aabb) { std::vector collected; auto view = registry.view(); diff --git a/src/objects/Entities.hpp b/src/objects/Entities.hpp index b2611d93..731866e0 100644 --- a/src/objects/Entities.hpp +++ b/src/objects/Entities.hpp @@ -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 getAllInside(AABB aabb); void despawn(entityid_t id); dynamic::Value serialize(const Entity& entity); diff --git a/src/objects/EntityDef.hpp b/src/objects/EntityDef.hpp index 3cc015ff..3f731547 100644 --- a/src/objects/EntityDef.hpp +++ b/src/objects/EntityDef.hpp @@ -24,6 +24,7 @@ struct EntityDef { std::vector> boxSensors {}; std::vector> radialSensors {}; std::string skeletonName = name; + bool blocking = true; struct { bool enabled = true;