diff --git a/docs/lua-api-mod.md b/docs/lua-api-mod.md index f567a74c..64adbddb 100644 --- a/docs/lua-api-mod.md +++ b/docs/lua-api-mod.md @@ -54,6 +54,16 @@ mod:smelting_recipe { ## Functions +### `id` + +Returns the string ID of the mod. + +### `path` + +Returns the path of the mod, relative to current working directory. + +## Registration functions + ### `block` Defines a block from a table, see [this page](lua-api-block.md) for more information. diff --git a/mods/creative_inventory/init.lua b/mods/creative_inventory/init.lua index 43fdc72d..99122356 100644 --- a/mods/creative_inventory/init.lua +++ b/mods/creative_inventory/init.lua @@ -43,7 +43,7 @@ function show_creative_window(client, screen_width, screen_height, gui_scale) name = "img_background", pos = {x = 0, y = 0}, - texture = "mods/default/textures/gui/creative_window.png", + texture = mod:path() .. "/textures/gui/creative_window.png", clip = {x = 0, y = 0, width = 195, height = 136}, } @@ -76,7 +76,7 @@ function show_creative_window(client, screen_width, screen_height, gui_scale) name = "scroll_bar", pos = {x = 175, y = 18}, - texture = "mods/default/textures/gui/tabs.png", + texture = mod:path() .. "/textures/gui/tabs.png", clip = {x = 232, y = 0, width = 12, height = 15}, clip_selected = {x = 244, y = 0, width = 12, height = 15}, diff --git a/mods/default/textures/gui/creative_window.png b/mods/creative_inventory/textures/gui/creative_window.png similarity index 100% rename from mods/default/textures/gui/creative_window.png rename to mods/creative_inventory/textures/gui/creative_window.png diff --git a/mods/default/textures/gui/tabs.png b/mods/creative_inventory/textures/gui/tabs.png similarity index 100% rename from mods/default/textures/gui/tabs.png rename to mods/creative_inventory/textures/gui/tabs.png diff --git a/mods/default/blocks/furnace.lua b/mods/default/blocks/furnace.lua index 3b8812ee..117e46ca 100644 --- a/mods/default/blocks/furnace.lua +++ b/mods/default/blocks/furnace.lua @@ -24,6 +24,7 @@ -- -- ===================================================================================== -- +local modpath = mod:path() mod:block { id = "furnace", @@ -53,7 +54,7 @@ mod:block { meta = "item_progress", max_value = 200, - texture = "mods/default/textures/gui/furnace.png", + texture = modpath .. "/textures/gui/furnace.png", clip = {x = 176, y = 14, width = 24, height = 17}, } @@ -68,7 +69,7 @@ mod:block { meta = "ticks_remaining", max_meta = "current_burn_time", - texture = "mods/default/textures/gui/furnace.png", + texture = modpath .. "/textures/gui/furnace.png", clip = {x = 176, y = 0, width = 14, height = 14}, } @@ -161,7 +162,7 @@ mod:block { name = "img_background", pos = {x = 0, y = 0}, - texture = "mods/default/textures/gui/furnace.png", + texture = modpath .. "/textures/gui/furnace.png", clip = {x = 0, y = 0, width = 176, height = 166}, } diff --git a/mods/default/blocks/workbench.lua b/mods/default/blocks/workbench.lua index 3dd6141f..4f4b609f 100644 --- a/mods/default/blocks/workbench.lua +++ b/mods/default/blocks/workbench.lua @@ -24,6 +24,7 @@ -- -- ===================================================================================== -- +local modpath = mod:path() mod:block { id = "workbench", @@ -91,7 +92,7 @@ mod:block { name = "img_background", pos = {x = 0, y = 0}, - texture = "mods/default/textures/gui/workbench.png", + texture = modpath .. "/textures/gui/workbench.png", clip = {x = 0, y = 0, width = 176, height = 166}, } diff --git a/mods/default/init.lua b/mods/default/init.lua index cd80075a..e571050e 100644 --- a/mods/default/init.lua +++ b/mods/default/init.lua @@ -71,6 +71,8 @@ function init(player) player_inv:add_stack("default:diamond", 64); end +local modpath = mod:path() + function show_inventory(client, screen_width, screen_height, gui_scale) local gui = LuaGUI.new() @@ -81,7 +83,7 @@ function show_inventory(client, screen_width, screen_height, gui_scale) name = "img_background", pos = {x = 0, y = 0}, - texture = "mods/default/textures/gui/inventory.png", + texture = modpath .. "/textures/gui/inventory.png", clip = {x = 0, y = 0, width = 176, height = 166}, } diff --git a/source/client/graphics/TextureAtlas.cpp b/source/client/graphics/TextureAtlas.cpp index 65d55166..3669413b 100644 --- a/source/client/graphics/TextureAtlas.cpp +++ b/source/client/graphics/TextureAtlas.cpp @@ -122,6 +122,7 @@ void TextureAtlas::loadFromRegistry(const std::string &texturePack) { if (!texturePack.empty() && !gk::Filesystem::fileExists("texturepacks/" + texturePack)) throw EXCEPTION("Texture pack '" + texturePack +"' doesn't exist"); + // FIXME: Undefined texture should be created from current texture size if (texturePack.empty()) addFile("mods/default/textures/blocks/", "undefined.png"); else diff --git a/source/server/lua/LuaMod.cpp b/source/server/lua/LuaMod.cpp index 73e12bd8..4bdd8c09 100644 --- a/source/server/lua/LuaMod.cpp +++ b/source/server/lua/LuaMod.cpp @@ -52,8 +52,9 @@ void LuaMod::commit() { void LuaMod::initUsertype(sol::state &lua) { lua.new_usertype("LuaMod", - sol::constructors(), "id", &LuaMod::id, + "path", &LuaMod::path, + "block", &LuaMod::registerBlock, "item", &LuaMod::registerItem, "crafting_recipe", &LuaMod::registerCraftingRecipe, diff --git a/source/server/lua/LuaMod.hpp b/source/server/lua/LuaMod.hpp index eb17a53d..c100f767 100644 --- a/source/server/lua/LuaMod.hpp +++ b/source/server/lua/LuaMod.hpp @@ -48,6 +48,8 @@ class LuaMod { const std::string &id() const { return m_id; } + std::string path() const { return "mods/" + m_id; } + static void initUsertype(sol::state &lua); private: