forked from MineClone5/MineClone5
Drop food eating limits in Creative Mode
This commit is contained in:
parent
d9b6bae320
commit
9ed83bd196
|
@ -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.")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue