add 'normal' argument to on_use_on_block event
This commit is contained in:
parent
0f26d7c93a
commit
d6696b54cb
@ -51,7 +51,7 @@ function on_use(playerid: int)
|
|||||||
Called on RMB click out of a block.
|
Called on RMB click out of a block.
|
||||||
|
|
||||||
```lua
|
```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**
|
Called on block RMB click. Prevents block **placing-block** placing if returns **true**
|
||||||
|
|||||||
@ -51,9 +51,7 @@ function on_use(playerid: int)
|
|||||||
Вызывается при нажатии ПКМ не на блок.
|
Вызывается при нажатии ПКМ не на блок.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
function on_use_on_block(x: int, y: int, z: int, playerid: int, normal: vec3)
|
||||||
function on_use_on_block(x: int, y: int, z: int, playerid: int)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Вызывается при нажатии ПКМ на блок. Предотвращает установку блока, прописанного в `placing-block` если возвращает `true`
|
Вызывается при нажатии ПКМ на блок. Предотвращает установку блока, прописанного в `placing-block` если возвращает `true`
|
||||||
|
|||||||
@ -50,12 +50,12 @@ static debug::Logger logger("engine");
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
void addWorldGenerators() {
|
static void add_world_generators() {
|
||||||
WorldGenerators::addGenerator<DefaultWorldGenerator>("core:default");
|
WorldGenerators::addGenerator<DefaultWorldGenerator>("core:default");
|
||||||
WorldGenerators::addGenerator<FlatWorldGenerator>("core:flat");
|
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") {
|
if (name != "master") {
|
||||||
audio::create_channel(name);
|
audio::create_channel(name);
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ Engine::Engine(EngineSettings& settings, SettingsHandler& settingsHandler, Engin
|
|||||||
keepAlive(settings.ui.language.observe([=](auto lang) {
|
keepAlive(settings.ui.language.observe([=](auto lang) {
|
||||||
setLanguage(lang);
|
setLanguage(lang);
|
||||||
}, true));
|
}, true));
|
||||||
addWorldGenerators();
|
add_world_generators();
|
||||||
|
|
||||||
scripting::initialize(this);
|
scripting::initialize(this);
|
||||||
basePacks = files::read_list(resdir/fs::path("config/builtins.list"));
|
basePacks = files::read_list(resdir/fs::path("config/builtins.list"));
|
||||||
|
|||||||
@ -503,7 +503,7 @@ void PlayerController::updateInteraction() {
|
|||||||
bool preventDefault = false;
|
bool preventDefault = false;
|
||||||
if (item->rt.funcsset.on_use_on_block) {
|
if (item->rt.funcsset.on_use_on_block) {
|
||||||
preventDefault = scripting::on_item_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) {
|
} else if (item->rt.funcsset.on_use) {
|
||||||
preventDefault = scripting::on_item_use(player.get(), item);
|
preventDefault = scripting::on_item_use(player.get(), item);
|
||||||
|
|||||||
@ -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";
|
std::string name = item->name + ".useon";
|
||||||
return lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (auto L) {
|
return lua::emit_event(lua::get_main_thread(), name, [ipos, normal, player] (auto L) {
|
||||||
lua::pushivec3_stack(L, x, y, z);
|
lua::pushivec3_stack(L, ipos.x, ipos.y, ipos.z);
|
||||||
lua::pushinteger(L, player->getId());
|
lua::pushinteger(L, player->getId());
|
||||||
return 4;
|
lua::pushivec(L, normal);
|
||||||
|
return 5;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -71,7 +71,7 @@ namespace scripting {
|
|||||||
|
|
||||||
/// @brief Called on RMB click on block with the item selected
|
/// @brief Called on RMB click on block with the item selected
|
||||||
/// @return true if prevents default action
|
/// @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
|
/// @brief Called on LMB click on block with the item selected
|
||||||
/// @return true if prevents default action
|
/// @return true if prevents default action
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user