add 'normal' argument to on_use_on_block event

This commit is contained in:
MihailRis 2024-07-29 15:23:04 +03:00
parent 0f26d7c93a
commit d6696b54cb
6 changed files with 12 additions and 13 deletions

View File

@ -51,7 +51,7 @@ function on_use(playerid: int)
Called on RMB click out of a block.
```lua
function on_use_on_block(x: int, y: int, z: int, playerid: int)
function on_use_on_block(x: int, y: int, z: int, playerid: int, normal: vec3)
```
Called on block RMB click. Prevents block **placing-block** placing if returns **true**

View File

@ -51,9 +51,7 @@ function on_use(playerid: int)
Вызывается при нажатии ПКМ не на блок.
```lua
function on_use_on_block(x: int, y: int, z: int, playerid: int)
function on_use_on_block(x: int, y: int, z: int, playerid: int, normal: vec3)
```
Вызывается при нажатии ПКМ на блок. Предотвращает установку блока, прописанного в `placing-block` если возвращает `true`

View File

@ -50,12 +50,12 @@ static debug::Logger logger("engine");
namespace fs = std::filesystem;
void addWorldGenerators() {
static void add_world_generators() {
WorldGenerators::addGenerator<DefaultWorldGenerator>("core:default");
WorldGenerators::addGenerator<FlatWorldGenerator>("core:flat");
}
inline void create_channel(Engine* engine, std::string name, NumberSetting& setting) {
static void create_channel(Engine* engine, std::string name, NumberSetting& setting) {
if (name != "master") {
audio::create_channel(name);
}
@ -114,7 +114,7 @@ Engine::Engine(EngineSettings& settings, SettingsHandler& settingsHandler, Engin
keepAlive(settings.ui.language.observe([=](auto lang) {
setLanguage(lang);
}, true));
addWorldGenerators();
add_world_generators();
scripting::initialize(this);
basePacks = files::read_list(resdir/fs::path("config/builtins.list"));

View File

@ -503,7 +503,7 @@ void PlayerController::updateInteraction() {
bool preventDefault = false;
if (item->rt.funcsset.on_use_on_block) {
preventDefault = scripting::on_item_use_on_block(
player.get(), item, iend.x, iend.y, iend.z
player.get(), item, iend, selection.normal
);
} else if (item->rt.funcsset.on_use) {
preventDefault = scripting::on_item_use(player.get(), item);

View File

@ -277,12 +277,13 @@ bool scripting::on_item_use(Player* player, const ItemDef* item) {
});
}
bool scripting::on_item_use_on_block(Player* player, const ItemDef* item, int x, int y, int z) {
bool scripting::on_item_use_on_block(Player* player, const ItemDef* item, glm::ivec3 ipos, glm::ivec3 normal) {
std::string name = item->name + ".useon";
return lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (auto L) {
lua::pushivec3_stack(L, x, y, z);
return lua::emit_event(lua::get_main_thread(), name, [ipos, normal, player] (auto L) {
lua::pushivec3_stack(L, ipos.x, ipos.y, ipos.z);
lua::pushinteger(L, player->getId());
return 4;
lua::pushivec(L, normal);
return 5;
});
}

View File

@ -71,7 +71,7 @@ namespace scripting {
/// @brief Called on RMB click on block with the item selected
/// @return true if prevents default action
bool on_item_use_on_block(Player* player, const ItemDef* item, int x, int y, int z);
bool on_item_use_on_block(Player* player, const ItemDef* item, glm::ivec3 ipos, glm::ivec3 normal);
/// @brief Called on LMB click on block with the item selected
/// @return true if prevents default action