mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add entity events: on_attacked, on_used
This commit is contained in:
parent
a36ffaacd9
commit
50050dbe40
6 changed files with 44 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue