diff --git a/docs/lua-api-core.md b/docs/lua-api-core.md index f70e02341..b2adb78dc 100644 --- a/docs/lua-api-core.md +++ b/docs/lua-api-core.md @@ -22,6 +22,10 @@ openminer:add_listener(EventType.OnBlockPlaced, function(pos, player, world, cli server:send_chat_message(0, "Block placed at " .. pos.x .. ";" .. pos.y .. ";" .. pos.z .. " by Client" .. player:client_id(), client); end) +openminer:add_listener(EventType.OnBlockDigged, function(pos, player, world, client, server) + server:send_chat_message(0, "Block digged at " .. pos.x .. ";" .. pos.y .. ";" .. pos.z .. " by Client" .. player:client_id(), client); +end) + openminer:add_listener(EventType.OnBlockActivated, function(pos, block, player, world, client, server) if block:string_id() == "default:portal" then server:send_chat_message(0, "Swoosh! Changing dimension...", client); @@ -32,5 +36,6 @@ end) Possible events: - `OnBlockPlaced`: `funcion(pos, player, world, client, server)` +- `OnBlockDigged`: `funcion(pos, player, world, client, server)` - `OnBlockActivated`: `function(pos, block, player, world, client, server)` diff --git a/mods/default/init.lua b/mods/default/init.lua index e571050ec..6d49cb48e 100644 --- a/mods/default/init.lua +++ b/mods/default/init.lua @@ -38,6 +38,10 @@ dofile("dimensions.lua") -- server:send_chat_message(0, "Block placed at " .. pos.x .. ";" .. pos.y .. ";" .. pos.z .. " by Client" .. player:client_id(), client); -- end) +-- openminer:add_listener(EventType.OnBlockDigged, function(pos, player, world, client, server) +-- server:send_chat_message(0, "Block digged at " .. pos.x .. ";" .. pos.y .. ";" .. pos.z .. " by Client" .. player:client_id(), client); +-- end) + openminer:add_listener(EventType.OnBlockActivated, function(pos, block, player, world, client, server) if block:string_id() == "default:portal" then server:send_chat_message(0, "Swoosh! Changing dimension...", client); diff --git a/source/server/lua/LuaCore.cpp b/source/server/lua/LuaCore.cpp index b14b17d6f..63ac18761 100644 --- a/source/server/lua/LuaCore.cpp +++ b/source/server/lua/LuaCore.cpp @@ -36,6 +36,7 @@ void LuaCore::addListener(LuaEventType eventType, const sol::function &listener) void LuaCore::initUsertype(sol::state &lua) { lua["EventType"] = lua.create_table_with( "OnBlockPlaced", LuaEventType::OnBlockPlaced, + "OnBlockDigged", LuaEventType::OnBlockDigged, "OnBlockActivated", LuaEventType::OnBlockActivated ); diff --git a/source/server/lua/LuaCore.hpp b/source/server/lua/LuaCore.hpp index c0ee13e1a..7e4736a2b 100644 --- a/source/server/lua/LuaCore.hpp +++ b/source/server/lua/LuaCore.hpp @@ -37,6 +37,7 @@ class ServerModLoader; enum class LuaEventType { OnBlockPlaced, + OnBlockDigged, OnBlockActivated }; diff --git a/source/server/network/ServerCommandHandler.cpp b/source/server/network/ServerCommandHandler.cpp index 46ed261b3..82cca8ab4 100644 --- a/source/server/network/ServerCommandHandler.cpp +++ b/source/server/network/ServerCommandHandler.cpp @@ -285,6 +285,8 @@ void ServerCommandHandler::setupCallbacks() { world.onBlockDigged(x, y, z, Registry::getInstance().getBlock(world.getBlock(x, y, z)), *player); world.setBlock(x, y, z, 0); + m_scriptEngine.luaCore().onEvent(LuaEventType::OnBlockDigged, glm::ivec3{x, y, z}, *player, world, client, *this); + sf::Packet answer; answer << Network::Command::BlockUpdate << x << y << z << u32(0); m_server.sendToAllClients(answer);