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