mirror of
https://github.com/minetest-mods/craftguide.git
synced 2025-07-06 18:10:31 +02:00
Rename and refactor get_fields
This commit is contained in:
122
init.lua
122
init.lua
@ -654,18 +654,7 @@ end
|
|||||||
|
|
||||||
mt.register_on_mods_loaded(get_init_items)
|
mt.register_on_mods_loaded(get_init_items)
|
||||||
|
|
||||||
local function get_fields(player, ...)
|
local function on_receive_fields(player, fields)
|
||||||
local args, formname, fields = {...}
|
|
||||||
if sfinv_only then
|
|
||||||
fields = args[1]
|
|
||||||
else
|
|
||||||
formname, fields = args[1], args[2]
|
|
||||||
end
|
|
||||||
|
|
||||||
if not sfinv_only and formname ~= "craftguide" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local data = player_data[player_name]
|
local data = player_data[player_name]
|
||||||
|
|
||||||
@ -716,63 +705,68 @@ local function get_fields(player, ...)
|
|||||||
data.iX = data.iX - (fields.size_dec and 1 or -1)
|
data.iX = data.iX - (fields.size_dec and 1 or -1)
|
||||||
show_fs(player, player_name)
|
show_fs(player, player_name)
|
||||||
|
|
||||||
else for item in pairs(fields) do
|
else
|
||||||
if item:find(":") then
|
local item
|
||||||
if item:sub(-4) == "_inv" then
|
for field in pairs(fields) do
|
||||||
item = item:sub(1,-5)
|
if field:find(":") then
|
||||||
|
item = field
|
||||||
|
break
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local is_fuel = get_fueltime(item) > 0
|
if not item then
|
||||||
local recipes = get_recipes(item)
|
return
|
||||||
|
elseif item:sub(-4) == "_inv" then
|
||||||
|
item = item:sub(1,-5)
|
||||||
|
end
|
||||||
|
|
||||||
|
local is_fuel = get_fueltime(item) > 0
|
||||||
|
local recipes = get_recipes(item)
|
||||||
|
if progressive_mode then
|
||||||
|
recipes = apply_progressive_filters(recipes, player)
|
||||||
|
end
|
||||||
|
|
||||||
|
local no_recipes = not next(recipes)
|
||||||
|
if no_recipes and (progressive_mode or not is_fuel) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if item ~= data.input then
|
||||||
|
data.show_usage = nil
|
||||||
|
else
|
||||||
|
data.show_usage = not data.show_usage
|
||||||
|
end
|
||||||
|
|
||||||
|
if not progressive_mode and is_fuel and no_recipes then
|
||||||
|
data.show_usage = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if data.show_usage then
|
||||||
|
data.usages = get_item_usages(item)
|
||||||
|
|
||||||
|
if is_fuel then
|
||||||
|
data.usages[#data.usages + 1] = {
|
||||||
|
width = 1,
|
||||||
|
type = "normal",
|
||||||
|
items = {item},
|
||||||
|
output = "BURN",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
if progressive_mode then
|
if progressive_mode then
|
||||||
recipes = apply_progressive_filters(recipes, player)
|
data.usages = apply_progressive_filters(data.usages, player)
|
||||||
end
|
end
|
||||||
|
|
||||||
local no_recipes = not next(recipes)
|
if not next(data.usages) then
|
||||||
if no_recipes and (progressive_mode or not is_fuel) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if item ~= data.input then
|
|
||||||
data.show_usage = nil
|
data.show_usage = nil
|
||||||
else
|
|
||||||
data.show_usage = not data.show_usage
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not progressive_mode and is_fuel and no_recipes then
|
|
||||||
data.show_usage = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if data.show_usage then
|
|
||||||
data.usages = get_item_usages(item)
|
|
||||||
|
|
||||||
if is_fuel then
|
|
||||||
data.usages[#data.usages + 1] = {
|
|
||||||
width = 1,
|
|
||||||
type = "normal",
|
|
||||||
items = {item},
|
|
||||||
output = "BURN",
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
if progressive_mode and next(data.usages) then
|
|
||||||
data.usages =
|
|
||||||
apply_progressive_filters(data.usages, player)
|
|
||||||
end
|
|
||||||
|
|
||||||
if not next(data.usages) then
|
|
||||||
data.show_usage = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
data.input = item
|
|
||||||
data.recipes_item = recipes
|
|
||||||
data.rnum = 1
|
|
||||||
|
|
||||||
show_fs(player, player_name)
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
data.input = item
|
||||||
|
data.recipes_item = recipes
|
||||||
|
data.rnum = 1
|
||||||
|
|
||||||
|
show_fs(player, player_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -798,11 +792,15 @@ if sfinv_only then
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
on_player_receive_fields = function(self, player, context, fields)
|
on_player_receive_fields = function(self, player, context, fields)
|
||||||
get_fields(player, fields)
|
on_receive_fields(player, fields)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
mt.register_on_player_receive_fields(get_fields)
|
mt.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
if formname == "craftguide" then
|
||||||
|
on_receive_fields(player, fields)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
local function on_use(user)
|
local function on_use(user)
|
||||||
local player_name = user:get_player_name()
|
local player_name = user:get_player_name()
|
||||||
|
Reference in New Issue
Block a user