Skip to content

Commit

Permalink
[LuaMod] 'path()' member added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Apr 3, 2020
1 parent ead5e7d commit 94b959c
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 8 deletions.
10 changes: 10 additions & 0 deletions docs/lua-api-mod.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions mods/creative_inventory/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}

Expand Down Expand Up @@ -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},

Expand Down
File renamed without changes
7 changes: 4 additions & 3 deletions mods/default/blocks/furnace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
--
-- =====================================================================================
--
local modpath = mod:path()

mod:block {
id = "furnace",
Expand Down Expand Up @@ -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},
}

Expand All @@ -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},
}

Expand Down Expand Up @@ -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},
}

Expand Down
3 changes: 2 additions & 1 deletion mods/default/blocks/workbench.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
--
-- =====================================================================================
--
local modpath = mod:path()

mod:block {
id = "workbench",
Expand Down Expand Up @@ -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},
}

Expand Down
4 changes: 3 additions & 1 deletion mods/default/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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},
}

Expand Down
1 change: 1 addition & 0 deletions source/client/graphics/TextureAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion source/server/lua/LuaMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ void LuaMod::commit() {

void LuaMod::initUsertype(sol::state &lua) {
lua.new_usertype<LuaMod>("LuaMod",
sol::constructors<LuaMod(std::string)>(),
"id", &LuaMod::id,
"path", &LuaMod::path,

"block", &LuaMod::registerBlock,
"item", &LuaMod::registerItem,
"crafting_recipe", &LuaMod::registerCraftingRecipe,
Expand Down
2 changes: 2 additions & 0 deletions source/server/lua/LuaMod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 94b959c

Please sign in to comment.