From 9ed83bd1961260cf5b391cda8f702550804104ea Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 5 Feb 2019 21:51:40 +0100 Subject: [PATCH] Drop food eating limits in Creative Mode --- mods/HELP/mcl_doc_basics/init.lua | 3 ++- mods/ITEMS/mcl_cake/init.lua | 6 +++--- mods/ITEMS/mcl_end/chorus_plant.lua | 2 +- mods/ITEMS/mcl_mobitems/init.lua | 2 +- mods/PLAYER/mcl_hunger/hunger.lua | 17 ++++++++++++----- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/mods/HELP/mcl_doc_basics/init.lua b/mods/HELP/mcl_doc_basics/init.lua index 3e367d6aef..f4980bfe11 100644 --- a/mods/HELP/mcl_doc_basics/init.lua +++ b/mods/HELP/mcl_doc_basics/init.lua @@ -770,8 +770,9 @@ S("• Creative inventory is available to obtain most items easily").."\n".. S("• Hand breaks all default blocks instantly").."\n".. S("• Greatly increased hand pointing range").."\n".. S("• Mined blocks don't drop items").."\n".. +S("• Items don't get used up").."\n".. S("• Tools don't wear off").."\n".. -S("• Bows have infinite arrows").."\n".. +S("• You can eat food whenever you want").."\n".. S("• You can always use the minimap").."\n\n".. S("Damage is not affected by Creative Mode, it needs to be disabled seperately.") diff --git a/mods/ITEMS/mcl_cake/init.lua b/mods/ITEMS/mcl_cake/init.lua index fdc110154d..75542fb936 100644 --- a/mods/ITEMS/mcl_cake/init.lua +++ b/mods/ITEMS/mcl_cake/init.lua @@ -51,7 +51,7 @@ minetest.register_node("mcl_cake:cake", { on_rightclick = function(pos, node, clicker, itemstack) local newcake = minetest.do_item_eat(2, ItemStack("mcl_cake:cake_6"), ItemStack("mcl_cake:cake"), clicker, {type="nothing"}) -- Check if we were allowed to eat - if newcake:get_name() ~= "mcl_cake:cake" then + if newcake:get_name() ~= "mcl_cake:cake" or minetest.settings:get_bool("creative_mode") == true then minetest.add_node(pos,{type="node",name="mcl_cake:cake_6",param2=0}) end end, @@ -71,7 +71,7 @@ local register_slice = function(level, nodebox, desc) on_rightclick = function(pos, node, clicker, itemstack) local newcake = minetest.do_item_eat(2, ItemStack(after_eat), ItemStack(this), clicker, {type="nothing"}) -- Check if we were allowed to eat - if newcake:get_name() ~= this then + if newcake:get_name() ~= this or minetest.settings:get_bool("creative_mode") == true then minetest.add_node(pos,{type="node",name=after_eat,param2=0}) end end @@ -80,7 +80,7 @@ local register_slice = function(level, nodebox, desc) on_rightclick = function(pos, node, clicker, itemstack) local newcake = minetest.do_item_eat(2, ItemStack("mcl:cake:cake 0"), ItemStack("mcl_cake:cake_1"), clicker, {type="nothing"}) -- Check if we were allowed to eat - if newcake:get_name() ~= this then + if newcake:get_name() ~= this or minetest.settings:get_bool("creative_mode") == true then minetest.remove_node(pos) core.check_for_falling(pos) end diff --git a/mods/ITEMS/mcl_end/chorus_plant.lua b/mods/ITEMS/mcl_end/chorus_plant.lua index 882971f19f..9793862e4d 100644 --- a/mods/ITEMS/mcl_end/chorus_plant.lua +++ b/mods/ITEMS/mcl_end/chorus_plant.lua @@ -339,7 +339,7 @@ local eat_chorus_fruit = function(itemstack, player, pointed_thing) local count = itemstack:get_count() local new_itemstack = minetest.do_item_eat(0, nil, itemstack, player, pointed_thing) local new_count = new_itemstack:get_count() - if count ~= new_count or new_itemstack:get_name() ~= "mcl_end:chorus_fruit" then + if count ~= new_count or new_itemstack:get_name() ~= "mcl_end:chorus_fruit" or (minetest.settings:get_bool("creative_mode") == true) then random_teleport(player) end return new_itemstack diff --git a/mods/ITEMS/mcl_mobitems/init.lua b/mods/ITEMS/mcl_mobitems/init.lua index d2c4f2b154..86fe54d1ea 100644 --- a/mods/ITEMS/mcl_mobitems/init.lua +++ b/mods/ITEMS/mcl_mobitems/init.lua @@ -135,7 +135,7 @@ minetest.register_craftitem("mcl_mobitems:cooked_rabbit", { local drink_milk = function(itemstack, player, pointed_thing) local bucket = minetest.do_item_eat(0, "mcl_buckets:bucket_empty", itemstack, player, pointed_thing) -- Check if we were allowed to drink this (eat delay check) - if bucket:get_name() ~= "mcl_mobitems:milk_bucket" and mcl_hunger.active then + if (bucket:get_name() ~= "mcl_mobitems:milk_bucket" and mcl_hunger.active) or minetest.settings:get_bool("creative_mode") == true then mcl_hunger.stop_poison(player) end return bucket diff --git a/mods/PLAYER/mcl_hunger/hunger.lua b/mods/PLAYER/mcl_hunger/hunger.lua index 508b8b9fc4..461c5f675d 100644 --- a/mods/PLAYER/mcl_hunger/hunger.lua +++ b/mods/PLAYER/mcl_hunger/hunger.lua @@ -15,8 +15,10 @@ minetest.do_item_eat = function(hp_change, replace_with_item, itemstack, user, p local name = user:get_player_name() + local creative = minetest.settings:get_bool("creative_mode") == true + -- Special foodstuffs like the cake may disable the eating delay - local no_eat_delay = minetest.get_item_group(itemstack:get_name(), "no_eat_delay") == 1 + local no_eat_delay = creative or (minetest.get_item_group(itemstack:get_name(), "no_eat_delay") == 1) -- Allow eating only after a delay of 2 seconds. This prevents eating as an excessive speed. -- FIXME: time() is not a precise timer, so the actual delay may be +- 1 second, depending on which fraction @@ -24,7 +26,7 @@ minetest.do_item_eat = function(hp_change, replace_with_item, itemstack, user, p -- FIXME: In singleplayer, there's a cheat to circumvent this, simply by pausing the game between eats. -- This is because os.time() obviously does not care about the pause. A fix needs a different timer mechanism. if no_eat_delay or (mcl_hunger.last_eat[name] < 0) or (os.difftime(os.time(), mcl_hunger.last_eat[name]) >= 2) then - local can_eat_when_full = minetest.get_item_group(itemstack:get_name(), "can_eat_when_full") == 1 + local can_eat_when_full = creative or minetest.get_item_group(itemstack:get_name(), "can_eat_when_full") == 1 -- Don't allow eating when player has full hunger bar (some exceptional items apply) if can_eat_when_full or (mcl_hunger.get_hunger(user) < 20) then itemstack = mcl_hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing) @@ -136,8 +138,11 @@ local poisonrandomizer = PseudoRandom(os.time()) function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poison, exhaust, poisonchance, sound) return function(itemstack, user, pointed_thing) local itemname = itemstack:get_name() - - if itemstack:take_item() ~= nil and user ~= nil then + local creative = minetest.settings:get_bool("creative_mode") == true + if itemstack:peek_item() ~= nil and user ~= nil then + if not creative then + itemstack:take_item() + end local name = user:get_player_name() local hp = user:get_hp() @@ -242,7 +247,9 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poiso end --sound:eat - itemstack:add_item(replace_with_item) + if not creative then + itemstack:add_item(replace_with_item) + end end return itemstack end