mirror of
https://github.com/minetest-mods/i3.git
synced 2025-07-03 09:00:23 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
da91223c4d | |||
408267754c | |||
b4de48370a | |||
477efe56d3 |
38
API.md
38
API.md
@ -21,31 +21,33 @@ i3.new_tab("stuff", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
formspec = function(player, data, fs)
|
formspec = function(player, data, fs)
|
||||||
fs("label[3,1;This is just a test]")
|
fs"label[3,1;This is just a test]"
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- Events handling happens here
|
-- Events handling happens here
|
||||||
fields = function(player, data, fields)
|
fields = function(player, data, fields)
|
||||||
|
if fields.mybutton then
|
||||||
|
do_things()
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
- `player` is an `ObjectRef` to the user.
|
- `player` is an `ObjectRef` to the user.
|
||||||
- `data` are the user data.
|
- `data` are the user data.
|
||||||
- `fs` is the formspec table which is callable with a metamethod. Each call adds a new entry.
|
- `fs` is the formspec table which is callable with a metamethod. Every call adds a new entry.
|
||||||
|
|
||||||
#### `i3.set_fs(player)`
|
#### `i3.set_fs(player)`
|
||||||
|
|
||||||
Updates the current formspec.
|
Update the current formspec.
|
||||||
|
|
||||||
#### `i3.remove_tab(tabname)`
|
#### `i3.remove_tab(tabname)`
|
||||||
|
|
||||||
Deletes a tab by name.
|
Delete a tab by name.
|
||||||
|
|
||||||
#### `i3.get_current_tab(player)`
|
#### `i3.get_current_tab(player)`
|
||||||
|
|
||||||
Returns the current player tab. `player` is an `ObjectRef` to the user.
|
Return the current player tab. `player` is an `ObjectRef` to the user.
|
||||||
|
|
||||||
#### `i3.set_tab(player[, tabname])`
|
#### `i3.set_tab(player[, tabname])`
|
||||||
|
|
||||||
@ -54,7 +56,7 @@ Sets the current tab by name. `player` is an `ObjectRef` to the user.
|
|||||||
|
|
||||||
#### `i3.override_tab(tabname, def)`
|
#### `i3.override_tab(tabname, def)`
|
||||||
|
|
||||||
Overrides a tab by name. `def` is the tab definition like seen in `i3.set_tab`.
|
Override a tab by name. `def` is the tab definition like seen in `i3.set_tab`
|
||||||
|
|
||||||
#### `i3.tabs`
|
#### `i3.tabs`
|
||||||
|
|
||||||
@ -68,9 +70,11 @@ Custom recipes are nonconventional crafts outside the main crafting grid.
|
|||||||
They can be registered in-game dynamically and have a size beyond 3x3 items.
|
They can be registered in-game dynamically and have a size beyond 3x3 items.
|
||||||
|
|
||||||
**Note:** the registration format differs from the default registration format in everything.
|
**Note:** the registration format differs from the default registration format in everything.
|
||||||
The width is automatically calculated depending where you place the commas. Look at the examples attentively.
|
The width is automatically calculated depending where you place the commas.
|
||||||
|
|
||||||
#### Registering a custom crafting type (example)
|
Examples:
|
||||||
|
|
||||||
|
#### Registering a custom crafting type
|
||||||
|
|
||||||
```Lua
|
```Lua
|
||||||
i3.register_craft_type("digging", {
|
i3.register_craft_type("digging", {
|
||||||
@ -79,7 +83,7 @@ i3.register_craft_type("digging", {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Registering a custom crafting recipe (examples)
|
#### Registering a custom crafting recipe
|
||||||
|
|
||||||
```Lua
|
```Lua
|
||||||
i3.register_craft {
|
i3.register_craft {
|
||||||
@ -159,7 +163,7 @@ mode is implemented as a recipe filter.
|
|||||||
|
|
||||||
#### `i3.add_recipe_filter(name, function(recipes, player))`
|
#### `i3.add_recipe_filter(name, function(recipes, player))`
|
||||||
|
|
||||||
Adds a recipe filter with the given `name`. The filter function returns the
|
Add a recipe filter with the given `name`. The filter function returns the
|
||||||
recipes to be displayed, given the available recipes and an `ObjectRef` to the
|
recipes to be displayed, given the available recipes and an `ObjectRef` to the
|
||||||
user. Each recipe is a table of the form returned by
|
user. Each recipe is a table of the form returned by
|
||||||
`minetest.get_craft_recipe`.
|
`minetest.get_craft_recipe`.
|
||||||
@ -181,7 +185,7 @@ end)
|
|||||||
|
|
||||||
#### `i3.set_recipe_filter(name, function(recipe, player))`
|
#### `i3.set_recipe_filter(name, function(recipe, player))`
|
||||||
|
|
||||||
Removes all recipe filters and adds a new one.
|
Remove all recipe filters and add a new one.
|
||||||
|
|
||||||
#### `i3.recipe_filters`
|
#### `i3.recipe_filters`
|
||||||
|
|
||||||
@ -207,7 +211,7 @@ Notes:
|
|||||||
|
|
||||||
#### `i3.add_search_filter(name, function(item, values))`
|
#### `i3.add_search_filter(name, function(item, values))`
|
||||||
|
|
||||||
Adds a search filter.
|
Add a search filter.
|
||||||
The search function must return a boolean value (whether the given item should be listed or not).
|
The search function must return a boolean value (whether the given item should be listed or not).
|
||||||
|
|
||||||
- `name` is the filter name.
|
- `name` is the filter name.
|
||||||
@ -241,7 +245,7 @@ Sorting methods are used to filter the player's main inventory.
|
|||||||
|
|
||||||
#### `i3.add_sorting_method(name, def)`
|
#### `i3.add_sorting_method(name, def)`
|
||||||
|
|
||||||
Adds a player inventory sorting method.
|
Add a player inventory sorting method.
|
||||||
|
|
||||||
- `name` is the method name.
|
- `name` is the method name.
|
||||||
- `def` is the method definition.
|
- `def` is the method definition.
|
||||||
@ -276,7 +280,7 @@ A table containing all sorting methods.
|
|||||||
|
|
||||||
#### `i3.compress(item, def)`
|
#### `i3.compress(item, def)`
|
||||||
|
|
||||||
Adds a new group of items to compress.
|
Add a new group of items to compress.
|
||||||
|
|
||||||
- `item` is the item which represent the group of compressed items.
|
- `item` is the item which represent the group of compressed items.
|
||||||
- `def` is a table specifying the substring replace patterns to be used.
|
- `def` is a table specifying the substring replace patterns to be used.
|
||||||
@ -301,7 +305,7 @@ A map of all compressed item groups, indexed by stereotypes.
|
|||||||
|
|
||||||
#### `i3.hud_notif(name, msg[, img])`
|
#### `i3.hud_notif(name, msg[, img])`
|
||||||
|
|
||||||
Shows a Steam-like HUD notification on the bottom-right corner of the screen (experimental).
|
Show a Steam-like HUD notification on the bottom-right corner of the screen (experimental).
|
||||||
|
|
||||||
- `name` is the player name.
|
- `name` is the player name.
|
||||||
- `msg` is the HUD message to show.
|
- `msg` is the HUD message to show.
|
||||||
@ -309,7 +313,7 @@ Shows a Steam-like HUD notification on the bottom-right corner of the screen (ex
|
|||||||
|
|
||||||
#### `i3.get_recipes(item)`
|
#### `i3.get_recipes(item)`
|
||||||
|
|
||||||
Returns a table of recipes and usages of `item`.
|
Return a table of recipes and usages of `item`.
|
||||||
|
|
||||||
#### `i3.export_url`
|
#### `i3.export_url`
|
||||||
|
|
||||||
|
2
init.lua
2
init.lua
@ -20,7 +20,7 @@ local function lf(path)
|
|||||||
end
|
end
|
||||||
|
|
||||||
i3 = {
|
i3 = {
|
||||||
version = 1113,
|
version = 1115,
|
||||||
data = core.deserialize(storage:get_string"data") or {},
|
data = core.deserialize(storage:get_string"data") or {},
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
|
@ -148,10 +148,6 @@ if core.global_exists"skins" then
|
|||||||
i3.modules.skins = true
|
i3.modules.skins = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if core.global_exists"hb" then
|
|
||||||
i3.modules.hudbars = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if core.global_exists"awards" then
|
if core.global_exists"awards" then
|
||||||
i3.modules.awards = true
|
i3.modules.awards = true
|
||||||
|
|
||||||
|
10
src/hud.lua
10
src/hud.lua
@ -4,6 +4,14 @@ local function init_hud(player)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local data = i3.data[name]
|
local data = i3.data[name]
|
||||||
|
|
||||||
|
local wdesc_y = -90
|
||||||
|
|
||||||
|
if core.global_exists"hb" then
|
||||||
|
wdesc_y -= ceil(hb.hudbars_count / 2) * 5
|
||||||
|
elseif not i3.settings.damage_enabled then
|
||||||
|
wdesc_y += 15
|
||||||
|
end
|
||||||
|
|
||||||
data.hud = {
|
data.hud = {
|
||||||
bg = player:hud_add {
|
bg = player:hud_add {
|
||||||
hud_elem_type = "image",
|
hud_elem_type = "image",
|
||||||
@ -36,7 +44,7 @@ local function init_hud(player)
|
|||||||
wielditem = player:hud_add {
|
wielditem = player:hud_add {
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
position = {x = 0.5, y = 1},
|
position = {x = 0.5, y = 1},
|
||||||
offset = {x = 0, y = -65 - (i3.modules.hudbars and (ceil(hb.hudbars_count / 2) * 25) or 25)},
|
offset = {x = 0, y = wdesc_y},
|
||||||
alignment = {x = 0, y = -1},
|
alignment = {x = 0, y = -1},
|
||||||
number = 0xffffff,
|
number = 0xffffff,
|
||||||
text = "",
|
text = "",
|
||||||
|
Reference in New Issue
Block a user