mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-11-29 22:03:42 +01:00
commit
7757eb72fd
78
init.lua
78
init.lua
@ -56,13 +56,13 @@ local function table_merge(t, t2)
|
||||
return t
|
||||
end
|
||||
|
||||
local function table_clean(t)
|
||||
local function clean_items(items)
|
||||
local hash, ct = {}, {}
|
||||
for i = 1, #t do
|
||||
local v = t[i]
|
||||
if not hash[v] then
|
||||
ct[#ct + 1] = v
|
||||
hash[v] = true
|
||||
for i = 1, #items do
|
||||
local item = items[i]
|
||||
if not hash[item] and reg_items[item] then
|
||||
ct[#ct + 1] = item
|
||||
hash[item] = true
|
||||
end
|
||||
end
|
||||
|
||||
@ -410,9 +410,6 @@ local function make_formspec(name)
|
||||
fs[#fs + 1] = [[
|
||||
no_prepend[]
|
||||
background[1,1;1,1;craftguide_bg.png;true]
|
||||
image_button[2.4,0.12;0.8,0.8;craftguide_search_icon.png;search;]
|
||||
image_button[3.05,0.12;0.8,0.8;craftguide_clear_icon.png;clear;]
|
||||
field_close_on_enter[filter;false]
|
||||
]]
|
||||
|
||||
fs[#fs + 1] = "tooltip[size_inc;" .. S("Increase window size") .. "]"
|
||||
@ -424,6 +421,12 @@ local function make_formspec(name)
|
||||
",0.12;0.8,0.8;craftguide_zoomout_icon.png;size_dec;]"
|
||||
end
|
||||
|
||||
fs[#fs + 1] = [[
|
||||
image_button[2.4,0.12;0.8,0.8;craftguide_search_icon.png;search;]
|
||||
image_button[3.05,0.12;0.8,0.8;craftguide_clear_icon.png;clear;]
|
||||
field_close_on_enter[filter;false]
|
||||
]]
|
||||
|
||||
fs[#fs + 1] = "tooltip[search;" .. S("Search") .. "]"
|
||||
fs[#fs + 1] = "tooltip[clear;" .. S("Reset") .. "]"
|
||||
fs[#fs + 1] = "tooltip[prev;" .. S("Previous page") .. "]"
|
||||
@ -587,7 +590,7 @@ local function item_in_inv(item, inv_items)
|
||||
end
|
||||
end
|
||||
|
||||
local function init_data(player, name)
|
||||
local function init_data(name)
|
||||
player_data[name] = {
|
||||
filter = "",
|
||||
pagenum = 1,
|
||||
@ -725,6 +728,18 @@ local function on_receive_fields(player, fields)
|
||||
end
|
||||
end
|
||||
|
||||
mt.register_on_mods_loaded(get_init_items)
|
||||
|
||||
mt.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
init_data(name)
|
||||
end)
|
||||
|
||||
mt.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
player_data[name] = nil
|
||||
end)
|
||||
|
||||
if sfinv_only then
|
||||
sfinv.register_page("craftguide:craftguide", {
|
||||
title = "Craft Guide",
|
||||
@ -737,10 +752,9 @@ if sfinv_only then
|
||||
end,
|
||||
|
||||
on_enter = function(self, player, context)
|
||||
if next(recipe_filters) then
|
||||
local name = player:get_player_name()
|
||||
local data = player_data[name]
|
||||
|
||||
if next(recipe_filters) then
|
||||
data.items_raw = get_filtered_items(player)
|
||||
search(data)
|
||||
end
|
||||
@ -759,9 +773,9 @@ else
|
||||
|
||||
local function on_use(user)
|
||||
local name = user:get_player_name()
|
||||
local data = player_data[name]
|
||||
|
||||
if next(recipe_filters) then
|
||||
local data = player_data[name]
|
||||
data.items_raw = get_filtered_items(user)
|
||||
search(data)
|
||||
end
|
||||
@ -809,8 +823,9 @@ else
|
||||
|
||||
mt.register_craft({
|
||||
output = "craftguide:book",
|
||||
type = "shapeless",
|
||||
recipe = {"default:book"}
|
||||
recipe = {
|
||||
{"default:book"}
|
||||
}
|
||||
})
|
||||
|
||||
mt.register_craft({
|
||||
@ -821,8 +836,9 @@ else
|
||||
|
||||
mt.register_craft({
|
||||
output = "craftguide:sign",
|
||||
type = "shapeless",
|
||||
recipe = {"default:sign_wall_wood"}
|
||||
recipe = {
|
||||
{"default:sign_wall_wood"}
|
||||
}
|
||||
})
|
||||
|
||||
mt.register_craft({
|
||||
@ -843,18 +859,6 @@ else
|
||||
end
|
||||
end
|
||||
|
||||
mt.register_on_mods_loaded(get_init_items)
|
||||
|
||||
mt.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
init_data(player, name)
|
||||
end)
|
||||
|
||||
mt.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
player_data[name] = nil
|
||||
end)
|
||||
|
||||
if progressive_mode then
|
||||
local function recipe_in_inv(recipe, inv_items)
|
||||
for _, item in pairs(recipe.items) do
|
||||
@ -870,7 +874,7 @@ if progressive_mode then
|
||||
local name = player:get_player_name()
|
||||
local discovered = player_data[name].inv_items
|
||||
local inv_items = get_inv_items(player)
|
||||
discovered = table_clean(table_merge(discovered, inv_items))
|
||||
discovered = clean_items(table_merge(discovered, inv_items))
|
||||
|
||||
if #discovered == 0 then
|
||||
return {}
|
||||
@ -910,8 +914,9 @@ if progressive_mode then
|
||||
save_meta(players[i])
|
||||
end
|
||||
end)
|
||||
else
|
||||
mt.register_chatcommand("craft", {
|
||||
end
|
||||
|
||||
mt.register_chatcommand("craft", {
|
||||
description = S("Show recipe(s) of the pointed node"),
|
||||
func = function(name)
|
||||
local player = mt.get_player_by_name(name)
|
||||
@ -941,7 +946,11 @@ else
|
||||
local recipes = recipes_cache[node_name]
|
||||
local is_fuel = fuel_cache[node_name]
|
||||
|
||||
if not recipes then
|
||||
if recipes then
|
||||
recipes = apply_recipe_filters(recipes, player)
|
||||
end
|
||||
|
||||
if not recipes or #recipes == 0 then
|
||||
if is_fuel then
|
||||
recipes = get_item_usages(node_name)
|
||||
if #recipes > 0 then
|
||||
@ -959,8 +968,7 @@ else
|
||||
|
||||
return true, show_fs(player, name)
|
||||
end,
|
||||
})
|
||||
end
|
||||
})
|
||||
|
||||
--[[ Custom recipes (>3x3) test code
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user