improve mcl_bucket API (on_take callback)

This commit is contained in:
AFCMS 2021-05-19 11:14:18 +02:00
parent 067affcabb
commit a9bf923df9
2 changed files with 13 additions and 7 deletions

View File

@ -1,8 +1,7 @@
local S = minetest.get_translator("mcl_buckets")
local modpath = minetest.get_modpath(minetest.get_current_modname())
-- Minetest 0.4 mod: bucket
-- See README.txt for licensing and other information. -- See README.txt for licensing and other information.
local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)
local modpath = minetest.get_modpath(modname)
minetest.register_alias("bucket:bucket_empty", "mcl_buckets:bucket_empty") minetest.register_alias("bucket:bucket_empty", "mcl_buckets:bucket_empty")
minetest.register_alias("bucket:bucket_water", "mcl_buckets:bucket_water") minetest.register_alias("bucket:bucket_water", "mcl_buckets:bucket_water")
@ -51,6 +50,7 @@ function mcl_buckets.register_liquid(def)
mcl_buckets.liquids[def.source_take[i]] = { mcl_buckets.liquids[def.source_take[i]] = {
source_place = def.source_place, source_place = def.source_place,
source_take = def.source_take[i], source_take = def.source_take[i],
on_take = def.on_take,
itemname = def.itemname, itemname = def.itemname,
} }
if type(def.source_place) == "string" then if type(def.source_place) == "string" then
@ -207,9 +207,9 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
-- Fill bucket, but not in Creative Mode -- Fill bucket, but not in Creative Mode
if not minetest.is_creative_enabled(user:get_player_name()) then if not minetest.is_creative_enabled(user:get_player_name()) then
new_bucket = ItemStack({name = liquiddef.itemname}) new_bucket = ItemStack({name = liquiddef.itemname})
if liquiddef.itemname == "mcl_buckets:bucket_lava" and awards and awards.unlock and user and user:is_player() then if liquiddef.on_take then
awards.unlock(user:get_player_name(), "mcl:hotStuff") liquiddef.on_take(user)
end end
end end
minetest.add_node(pointed_thing.under, {name="air"}) minetest.add_node(pointed_thing.under, {name="air"})

View File

@ -1,6 +1,7 @@
local S = minetest.get_translator(minetest.get_current_modname()) local S = minetest.get_translator(minetest.get_current_modname())
local mod_mcl_core = minetest.get_modpath("mcl_core") local mod_mcl_core = minetest.get_modpath("mcl_core")
local mod_mclx_core = minetest.get_modpath("mclx_core") local mod_mclx_core = minetest.get_modpath("mclx_core")
local has_awards = minetest.get_modpath("awards")
local sound_place = function(itemname, pos) local sound_place = function(itemname, pos)
local def = minetest.registered_nodes[itemname] local def = minetest.registered_nodes[itemname]
@ -28,6 +29,11 @@ if mod_mcl_core then
end end
end, end,
source_take = {"mcl_core:lava_source", "mcl_nether:nether_lava_source"}, source_take = {"mcl_core:lava_source", "mcl_nether:nether_lava_source"},
on_take = function(user)
if has_awards and user and user:is_player() then
awards.unlock(user:get_player_name(), "mcl:hotStuff")
end
end,
itemname = "mcl_buckets:bucket_lava", itemname = "mcl_buckets:bucket_lava",
inventory_image = "bucket_lava.png", inventory_image = "bucket_lava.png",
name = S("Lava Bucket"), name = S("Lava Bucket"),