forked from minetest-mods/unified_inventory
Merge remote-tracking branch 'github/master'
This commit is contained in:
commit
4c4fb3ba88
41
api.lua
41
api.lua
@ -152,6 +152,10 @@ minetest.after(0.01, function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for _, callback in ipairs(ui.initialized_callbacks) do
|
||||||
|
callback()
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
@ -212,10 +216,15 @@ function ui.register_craft(options)
|
|||||||
if options.type == "normal" and options.width == 0 then
|
if options.type == "normal" and options.width == 0 then
|
||||||
options = { type = "shapeless", items = options.items, output = options.output, width = 0 }
|
options = { type = "shapeless", items = options.items, output = options.output, width = 0 }
|
||||||
end
|
end
|
||||||
if not ui.crafts_for.recipe[itemstack:get_name()] then
|
local item_name = itemstack:get_name()
|
||||||
ui.crafts_for.recipe[itemstack:get_name()] = {}
|
if not ui.crafts_for.recipe[item_name] then
|
||||||
|
ui.crafts_for.recipe[item_name] = {}
|
||||||
|
end
|
||||||
|
table.insert(ui.crafts_for.recipe[item_name],options)
|
||||||
|
|
||||||
|
for _, callback in ipairs(ui.craft_registered_callbacks) do
|
||||||
|
callback(item_name, options)
|
||||||
end
|
end
|
||||||
table.insert(ui.crafts_for.recipe[itemstack:get_name()],options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -309,6 +318,32 @@ function ui.register_button(name, def)
|
|||||||
table.insert(ui.buttons, def)
|
table.insert(ui.buttons, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ui.register_on_initialized(callback)
|
||||||
|
if type(callback) ~= "function" then
|
||||||
|
error(("Initialized callback must be a function, %s given."):format(type(callback)))
|
||||||
|
end
|
||||||
|
table.insert(ui.initialized_callbacks, callback)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ui.register_on_craft_registered(callback)
|
||||||
|
if type(callback) ~= "function" then
|
||||||
|
error(("Craft registered callback must be a function, %s given."):format(type(callback)))
|
||||||
|
end
|
||||||
|
table.insert(ui.craft_registered_callbacks, callback)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ui.get_recipe_list(output)
|
||||||
|
return ui.crafts_for.recipe[output]
|
||||||
|
end
|
||||||
|
|
||||||
|
function ui.get_registered_outputs()
|
||||||
|
local outputs = {}
|
||||||
|
for item_name, _ in pairs(ui.crafts_for.recipe) do
|
||||||
|
table.insert(outputs, item_name)
|
||||||
|
end
|
||||||
|
return outputs
|
||||||
|
end
|
||||||
|
|
||||||
function ui.is_creative(playername)
|
function ui.is_creative(playername)
|
||||||
return minetest.check_player_privs(playername, {creative=true})
|
return minetest.check_player_privs(playername, {creative=true})
|
||||||
or minetest.settings:get_bool("creative_mode")
|
or minetest.settings:get_bool("creative_mode")
|
||||||
|
@ -24,8 +24,7 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
unified_inventory.alternate[player_name] = 1
|
unified_inventory.alternate[player_name] = 1
|
||||||
unified_inventory.current_item[player_name] = nil
|
unified_inventory.current_item[player_name] = nil
|
||||||
unified_inventory.current_craft_direction[player_name] = "recipe"
|
unified_inventory.current_craft_direction[player_name] = "recipe"
|
||||||
unified_inventory.set_inventory_formspec(player,
|
unified_inventory.set_inventory_formspec(player, unified_inventory.default)
|
||||||
unified_inventory.default)
|
|
||||||
|
|
||||||
-- Refill slot
|
-- Refill slot
|
||||||
local refill = minetest.create_detached_inventory(player_name.."refill", {
|
local refill = minetest.create_detached_inventory(player_name.."refill", {
|
||||||
|
@ -20,6 +20,64 @@ Grouped by use-case, afterwards sorted alphabetically.
|
|||||||
* Checks whether creative is enabled or the player has `creative`
|
* Checks whether creative is enabled or the player has `creative`
|
||||||
|
|
||||||
|
|
||||||
|
Callbacks
|
||||||
|
---------
|
||||||
|
|
||||||
|
Register a callback that will be run whenever a craft is registered via unified_inventory.register_craft:
|
||||||
|
|
||||||
|
unified_inventory.register_on_craft_registered(
|
||||||
|
function (item_name, options)
|
||||||
|
-- item_name (string): name of the output item, equivalent to `ItemStack:get_name()`
|
||||||
|
-- options (table): definition table of crafts registered by `unified_inventory.register_craft`
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
Register a callback that will be run after all mods have loaded and after the unified_inventory mod has initialised all its internal structures:
|
||||||
|
|
||||||
|
unified_inventory.register_on_initialized(callback)
|
||||||
|
-- The callback is passed no arguments
|
||||||
|
|
||||||
|
|
||||||
|
Accessing Data
|
||||||
|
--------------
|
||||||
|
|
||||||
|
These methods should be used instead of accessing the unified_inventory data structures directly - this will ensure your code survives any potential restructuring of the mod.
|
||||||
|
|
||||||
|
Get a list of recipes for a particular output item:
|
||||||
|
|
||||||
|
unified_inventory.get_recipe_list(output_item)
|
||||||
|
|
||||||
|
Returns a list of tables, each holding a recipe definition, like:
|
||||||
|
{
|
||||||
|
{
|
||||||
|
type = "normal",
|
||||||
|
items = { "default:stick", "default:stick", "default:stick", "default:stick" },
|
||||||
|
output = "default:wood",
|
||||||
|
width = 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "shapeless",
|
||||||
|
items = { "default:tree" },
|
||||||
|
output = "default:wood 4",
|
||||||
|
width = 0
|
||||||
|
},
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
Get a list of all the output items crafts have been registered for:
|
||||||
|
|
||||||
|
unified_inventory.get_registered_outputs()
|
||||||
|
|
||||||
|
Returns a list of item names, like:
|
||||||
|
{
|
||||||
|
"default:stone",
|
||||||
|
"default:chest",
|
||||||
|
"default:brick",
|
||||||
|
"doors:door_wood",
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Pages
|
Pages
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
2
init.lua
2
init.lua
@ -24,6 +24,8 @@ unified_inventory = {
|
|||||||
filtered_items_list = {},
|
filtered_items_list = {},
|
||||||
pages = {},
|
pages = {},
|
||||||
buttons = {},
|
buttons = {},
|
||||||
|
initialized_callbacks = {},
|
||||||
|
craft_registered_callbacks = {},
|
||||||
|
|
||||||
-- Homepos stuff
|
-- Homepos stuff
|
||||||
home_pos = {},
|
home_pos = {},
|
||||||
|
@ -380,6 +380,5 @@ function ui.apply_filter(player, filter, search_dir)
|
|||||||
ui.current_index[player_name] = 1
|
ui.current_index[player_name] = 1
|
||||||
ui.activefilter[player_name] = filter
|
ui.activefilter[player_name] = filter
|
||||||
ui.active_search_direction[player_name] = search_dir
|
ui.active_search_direction[player_name] = search_dir
|
||||||
ui.set_inventory_formspec(player,
|
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
||||||
ui.current_page[player_name])
|
|
||||||
end
|
end
|
||||||
|
@ -330,8 +330,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- waypoints_temp must be initialized before the general unified_inventory
|
||||||
minetest.register_on_joinplayer(function(player)
|
-- joinplayer callback is run for updating the inventory
|
||||||
|
table.insert(minetest.registered_on_joinplayers, 1, function(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local waypoints = get_waypoint_data(player)
|
local waypoints = get_waypoint_data(player)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user