Fix achievements for crafting
This commit is contained in:
parent
046c4ce447
commit
8161cc7cab
@ -1 +1,2 @@
|
|||||||
default
|
default
|
||||||
|
crafting
|
||||||
|
@ -111,7 +111,7 @@ end
|
|||||||
|
|
||||||
-- Interaction callbacks
|
-- Interaction callbacks
|
||||||
|
|
||||||
local function on_craft(itemstack, player, craftgrid, craftinv)
|
local function on_craft(itemstack, player)
|
||||||
for aname, def in pairs(achievements.registered_achievements) do
|
for aname, def in pairs(achievements.registered_achievements) do
|
||||||
if def.craftitem ~= nil then
|
if def.craftitem ~= nil then
|
||||||
if def.craftitem == itemstack:get_name() then
|
if def.craftitem == itemstack:get_name() then
|
||||||
@ -168,10 +168,11 @@ minetest.register_on_shutdown(on_shutdown)
|
|||||||
|
|
||||||
minetest.register_on_newplayer(on_newplayer)
|
minetest.register_on_newplayer(on_newplayer)
|
||||||
|
|
||||||
minetest.register_on_craft(on_craft)
|
|
||||||
minetest.register_on_dignode(on_dig)
|
minetest.register_on_dignode(on_dig)
|
||||||
minetest.register_on_placenode(on_place)
|
minetest.register_on_placenode(on_place)
|
||||||
|
|
||||||
|
crafting.register_on_craft(on_craft)
|
||||||
|
|
||||||
-- Formspecs
|
-- Formspecs
|
||||||
|
|
||||||
local form = default.ui.get_page("default:default")
|
local form = default.ui.get_page("default:default")
|
||||||
|
@ -5,15 +5,26 @@
|
|||||||
|
|
||||||
crafting = {}
|
crafting = {}
|
||||||
|
|
||||||
|
-- Callbacks
|
||||||
|
|
||||||
|
crafting.callbacks = {
|
||||||
|
on_craft = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Array of registered craft recipes
|
||||||
|
|
||||||
crafting.registered_crafts = {}
|
crafting.registered_crafts = {}
|
||||||
|
|
||||||
-- User table of last selected row etc.
|
-- User table of last selected row etc.
|
||||||
|
|
||||||
crafting.userdata = {}
|
crafting.userdata = {}
|
||||||
|
|
||||||
-- Crafting can only take 4 itemstacks as input for sanity/interface reasons
|
-- Crafting can only take 4 itemstacks as input for sanity/interface reasons
|
||||||
|
|
||||||
crafting.max_inputs = 4
|
crafting.max_inputs = 4
|
||||||
|
|
||||||
-- Default crafting definition values
|
-- Default crafting definition values
|
||||||
|
|
||||||
crafting.default_craftdef = {
|
crafting.default_craftdef = {
|
||||||
output = nil,
|
output = nil,
|
||||||
items = {},
|
items = {},
|
||||||
@ -100,7 +111,11 @@ function crafting.get_crafts(filter)
|
|||||||
return results
|
return results
|
||||||
end
|
end
|
||||||
|
|
||||||
function crafting.craft(wanted, wanted_count, output, items)
|
function crafting.register_on_craft(func)
|
||||||
|
table.insert(crafting.callbacks.on_craft, func)
|
||||||
|
end
|
||||||
|
|
||||||
|
function crafting.craft(player, wanted, wanted_count, output, items)
|
||||||
-- `output` can be any ItemStack value
|
-- `output` can be any ItemStack value
|
||||||
-- Duplicate items in `items` should work correctly
|
-- Duplicate items in `items` should work correctly
|
||||||
|
|
||||||
@ -197,6 +212,10 @@ function crafting.craft(wanted, wanted_count, output, items)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for _, func in ipairs(crafting.callbacks.on_craft) do
|
||||||
|
func(output, player)
|
||||||
|
end
|
||||||
|
|
||||||
return {items = items, output = output}
|
return {items = items, output = output}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -324,10 +343,8 @@ local function on_player_receive_fields(player, form_name, fields)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local crafted = crafting.craft(wanted_itemstack,
|
local crafted = crafting.craft(player, wanted_itemstack, count,
|
||||||
count,
|
output_itemstack, inv:get_list("craft_in"))
|
||||||
output_itemstack,
|
|
||||||
inv:get_list("craft_in"))
|
|
||||||
|
|
||||||
if crafted then
|
if crafted then
|
||||||
inv:set_stack("craft_out", 1, "")
|
inv:set_stack("craft_out", 1, "")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user