From a9bf923df9cf228d5bce4a9d7027de7d4e9d8fed Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 19 May 2021 11:14:18 +0200 Subject: [PATCH] improve mcl_bucket API (on_take callback) --- mods/ITEMS/mcl_buckets/init.lua | 14 +++++++------- mods/ITEMS/mcl_buckets/register.lua | 6 ++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 0ba68b7231..7e67eee8e2 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -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. +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_water", "mcl_buckets:bucket_water") @@ -51,6 +50,7 @@ function mcl_buckets.register_liquid(def) mcl_buckets.liquids[def.source_take[i]] = { source_place = def.source_place, source_take = def.source_take[i], + on_take = def.on_take, itemname = def.itemname, } 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 if not minetest.is_creative_enabled(user:get_player_name()) then 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 - awards.unlock(user:get_player_name(), "mcl:hotStuff") - end + if liquiddef.on_take then + liquiddef.on_take(user) + end end minetest.add_node(pointed_thing.under, {name="air"}) diff --git a/mods/ITEMS/mcl_buckets/register.lua b/mods/ITEMS/mcl_buckets/register.lua index b5d86ac0e8..43156716c1 100644 --- a/mods/ITEMS/mcl_buckets/register.lua +++ b/mods/ITEMS/mcl_buckets/register.lua @@ -1,6 +1,7 @@ local S = minetest.get_translator(minetest.get_current_modname()) local mod_mcl_core = minetest.get_modpath("mcl_core") local mod_mclx_core = minetest.get_modpath("mclx_core") +local has_awards = minetest.get_modpath("awards") local sound_place = function(itemname, pos) local def = minetest.registered_nodes[itemname] @@ -28,6 +29,11 @@ if mod_mcl_core then end end, 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", inventory_image = "bucket_lava.png", name = S("Lava Bucket"),