add entity events: on_attacked, on_used
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user