From 2de04daa491ed9721f2f58bc0c35da4f76c78c7a Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Wed, 11 Mar 2020 23:50:21 +0100 Subject: [PATCH] [ScriptEngine] Lots of functions exposed to Lua. --- server/source/core/ServerApplication.cpp | 6 ++--- server/source/lua/ScriptEngine.cpp | 30 ++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/server/source/core/ServerApplication.cpp b/server/source/core/ServerApplication.cpp index 915b4876b..74f42152c 100644 --- a/server/source/core/ServerApplication.cpp +++ b/server/source/core/ServerApplication.cpp @@ -42,6 +42,9 @@ void ServerApplication::init() { if (m_argumentParser.getArgument("port").isFound) m_port = std::stoi(m_argumentParser.getArgument("port").parameter); + m_server.init(m_port); + m_server.setRunning(true); + Registry::setInstance(m_registry); // The id "_:air" is used in CraftingRecipe, update it there if it changes @@ -50,9 +53,6 @@ void ServerApplication::init() { loadMods(); - m_server.init(m_port); - m_server.setRunning(true); - m_serverCommandHandler.setupCallbacks(); m_worldController.setServer(m_serverCommandHandler); diff --git a/server/source/lua/ScriptEngine.cpp b/server/source/lua/ScriptEngine.cpp index d6e998646..f9d624f3f 100644 --- a/server/source/lua/ScriptEngine.cpp +++ b/server/source/lua/ScriptEngine.cpp @@ -51,16 +51,33 @@ void ScriptEngine::init() { void ScriptEngine::initUsertypes() { m_lua.new_usertype("Registry", + "get_block", &Registry::getBlock, + "get_item", &Registry::getItem, + "get_sky", &Registry::getSky, + "get_tree", &Registry::getTree, + "get_biome", &Registry::getBiome, "get_recipe", &Registry::getRecipe, + "get_block_from_string", &Registry::getBlockFromStringID, + "get_item_from_string", &Registry::getItemFromStringID, + "get_sky_from_string", &Registry::getSkyFromStringID, + "get_tree_from_string", &Registry::getTreeFromStringID, + "get_biome_from_string", &Registry::getBiomeFromStringID, + "blocks", &Registry::blocks, - "items", &Registry::items + "items", &Registry::items, + "trees", &Registry::trees, + "biomes", &Registry::biomes, + "dimensions", &Registry::dimensions ); m_lua.new_usertype("World", "get_block", &World::getBlock, + "set_block", &World::setBlock, + "get_data", &World::getData, "set_data", &World::setData, + "get_block_data", &World::getBlockData, "add_block_data", &World::addBlockData ); @@ -71,7 +88,11 @@ void ScriptEngine::initUsertypes() { m_lua.new_usertype("Chunk", "get_block", &Chunk::getBlock, + "set_block", &Chunk::setBlock, + "get_data", &Chunk::getData, + "set_data", &Chunk::setData, + "get_block_data", &Chunk::getBlockData, "add_block_data", &Chunk::addBlockData ); @@ -83,7 +104,12 @@ void ScriptEngine::initUsertypes() { ); m_lua.new_usertype("Block", - "string_id", &Block::stringID + "id", &Block::id, + "data", &Block::data, + "string_id", &Block::stringID, + "label", &Block::label, + "mod_name", &Block::modName, + "is_opaque", &Block::isOpaque ); m_lua.new_usertype("ServerBlock",