add entity events: on_attacked, on_used

This commit is contained in:
MihailRis
2024-07-16 14:04:05 +03:00
parent a36ffaacd9
commit 50050dbe40
6 changed files with 44 additions and 0 deletions
+17
View File
@@ -449,6 +449,20 @@ void PlayerController::processRightClick(Block* def, Block* target) {
}
}
void PlayerController::updateEntityInteraction(entityid_t eid, bool lclick, bool rclick) {
auto entityOpt = level->entities->get(eid);
if (!entityOpt.has_value()) {
return;
}
auto entity = entityOpt.value();
if (lclick) {
scripting::on_attacked(entity, player.get(), player->getEntity());
}
if (rclick) {
scripting::on_entity_used(entity, player.get());
}
}
void PlayerController::updateInteraction() {
auto indices = level->content->getIndices();
auto chunks = level->chunks.get();
@@ -468,6 +482,9 @@ void PlayerController::updateInteraction() {
if (rclick && item->rt.funcsset.on_use) {
scripting::on_item_use(player.get(), item);
}
if (selection.entity) {
updateEntityInteraction(selection.entity, lclick, rclick);
}
return;
}