diff --git a/mods/ITEMS/mcl_honey/init.lua b/mods/ITEMS/mcl_honey/init.lua index a870e7c08..01690ffdb 100644 --- a/mods/ITEMS/mcl_honey/init.lua +++ b/mods/ITEMS/mcl_honey/init.lua @@ -68,18 +68,80 @@ minetest.register_node("mcl_honey:honeycomb_block", { }) -- Honey +-- rewirtten mobitems' drink_milk_delayed for honey + +local function drink_honey_delayed(itemstack, player, pointed_thing) + if pointed_thing.type == "node" then + local node = minetest.get_node(pointed_thing.under) + if player and not player:get_player_control().sneak then + if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, player, itemstack) or itemstack + end + end + elseif pointed_thing.type == "object" then + return itemstack + end + + local function drink_honey(itemstack, player, pointed_thing) + -- Check if we were allowed to drink this (eat delay check) + if mcl_hunger.active and ( + player:get_inventory():get_stack("main", player:get_wield_index(), itemstack) == "mcl_honey:honey_bottle" or + minetest.is_creative_enabled(player:get_player_name()) + ) then + -- mcl_hunger.stop_poison(player) + end + mcl_potions.clear_effect(player, "poison") + end + + -- Wrapper for handling mcl_hunger delayed eating + local name = player:get_player_name() + local hunger_internal = mcl_hunger.eat_internal[name] + hunger_internal._custom_itemstack = itemstack -- Used as comparison to make sure the custom wrapper executes only when the same item is eaten + hunger_internal._custom_var = { + itemstack = itemstack, + player = player, + pointed_thing = pointed_thing, + } + hunger_internal._custom_func = drink_honey + hunger_internal._custom_wrapper = function(name) + local hunger_internal2 = mcl_hunger.eat_internal[name] + hunger_internal2._custom_func( + hunger_internal2._custom_var.itemstack, + hunger_internal2._custom_var.player, + hunger_internal2._custom_var.pointed_thing + ) + end + + minetest.do_item_eat(0, "mcl_potions:glass_bottle", itemstack, player, pointed_thing) +end + +-- Register the honey bottle item minetest.register_craftitem("mcl_honey:honey_bottle", { - description = S("Honey Bottle"), - _doc_items_longdesc = S("Honey Bottle is used to craft honey blocks and to restore hunger points."), - _doc_items_usagehelp = S("Drinking will restore 6 hunger points. Can also be used to craft honey blocks."), - inventory_image = "mcl_honey_honey_bottle.png", - groups = { craftitem = 1, food = 3, eatable = 6, can_eat_when_full = 1 }, - on_place = minetest.item_eat(6, "mcl_potions:glass_bottle"), - on_secondary_use = minetest.item_eat(6, "mcl_potions:glass_bottle"), - _mcl_saturation = 1.2, - stack_max = 16, + description = S("Honey Bottle"), + docitems_longdesc = S("Honey Bottle is used to craft honey blocks and to restore hunger points. It also stops poisoning"), + docitems_usagehelp = S("Drinking will restore 6 hunger points and stop poison. Can also be used to craft honey blocks."), + inventory_image = "mcl_honey_honey_bottle.png", + groups = { craftitem = 1, food = 3, eatable = 6, can_eat_when_full = 1 }, + on_place = drink_honey_delayed, + on_secondary_use = drink_honey_delayed, + mclsaturation = 1.2, + stack_max = 16, }) +-- Register the honey bottle item +minetest.register_craftitem("mcl_honey:honey_bottle", { + description = S("Honey Bottle"), + docitems_longdesc = S("Honey Bottle is used to craft honey blocks and to restore hunger points. It also stops poisoning"), + docitems_usagehelp = S("Drinking will restore 6 hunger points and stop poison. Can also be used to craft honey blocks."), + inventory_image = "mcl_honey_honey_bottle.png", + groups = { craftitem = 1, food = 3, eatable = 6, can_eat_when_full = 1 }, + on_place = drink_honey_delayed, + on_secondary_use = drink_honey_delayed, + mclsaturation = 1.2, + stack_max = 16, +}) + + minetest.register_node("mcl_honey:honey_block", { description = S("Honey Block"), _doc_items_longdesc = S("Honey Block. Used as a decoration and in redstone. Is sticky on some sides."),