mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-29 14:01:07 +01:00
Drop food eating limits in Creative Mode
This commit is contained in:
parent
d9b6bae320
commit
9ed83bd196
5 changed files with 19 additions and 11 deletions
|
@ -770,8 +770,9 @@ S("• Creative inventory is available to obtain most items easily").."\n"..
|
||||||
S("• Hand breaks all default blocks instantly").."\n"..
|
S("• Hand breaks all default blocks instantly").."\n"..
|
||||||
S("• Greatly increased hand pointing range").."\n"..
|
S("• Greatly increased hand pointing range").."\n"..
|
||||||
S("• Mined blocks don't drop items").."\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("• 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("• You can always use the minimap").."\n\n"..
|
||||||
|
|
||||||
S("Damage is not affected by Creative Mode, it needs to be disabled seperately.")
|
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)
|
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"})
|
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
|
-- 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})
|
minetest.add_node(pos,{type="node",name="mcl_cake:cake_6",param2=0})
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -71,7 +71,7 @@ local register_slice = function(level, nodebox, desc)
|
||||||
on_rightclick = function(pos, node, clicker, itemstack)
|
on_rightclick = function(pos, node, clicker, itemstack)
|
||||||
local newcake = minetest.do_item_eat(2, ItemStack(after_eat), ItemStack(this), clicker, {type="nothing"})
|
local newcake = minetest.do_item_eat(2, ItemStack(after_eat), ItemStack(this), clicker, {type="nothing"})
|
||||||
-- Check if we were allowed to eat
|
-- 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})
|
minetest.add_node(pos,{type="node",name=after_eat,param2=0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -80,7 +80,7 @@ local register_slice = function(level, nodebox, desc)
|
||||||
on_rightclick = function(pos, node, clicker, itemstack)
|
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"})
|
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
|
-- 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)
|
minetest.remove_node(pos)
|
||||||
core.check_for_falling(pos)
|
core.check_for_falling(pos)
|
||||||
end
|
end
|
||||||
|
|
|
@ -339,7 +339,7 @@ local eat_chorus_fruit = function(itemstack, player, pointed_thing)
|
||||||
local count = itemstack:get_count()
|
local count = itemstack:get_count()
|
||||||
local new_itemstack = minetest.do_item_eat(0, nil, itemstack, player, pointed_thing)
|
local new_itemstack = minetest.do_item_eat(0, nil, itemstack, player, pointed_thing)
|
||||||
local new_count = new_itemstack:get_count()
|
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)
|
random_teleport(player)
|
||||||
end
|
end
|
||||||
return new_itemstack
|
return new_itemstack
|
||||||
|
|
|
@ -135,7 +135,7 @@ minetest.register_craftitem("mcl_mobitems:cooked_rabbit", {
|
||||||
local drink_milk = function(itemstack, player, pointed_thing)
|
local drink_milk = function(itemstack, player, pointed_thing)
|
||||||
local bucket = minetest.do_item_eat(0, "mcl_buckets:bucket_empty", 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)
|
-- 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)
|
mcl_hunger.stop_poison(player)
|
||||||
end
|
end
|
||||||
return bucket
|
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 name = user:get_player_name()
|
||||||
|
|
||||||
|
local creative = minetest.settings:get_bool("creative_mode") == true
|
||||||
|
|
||||||
-- Special foodstuffs like the cake may disable the eating delay
|
-- 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.
|
-- 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
|
-- 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.
|
-- 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.
|
-- 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
|
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)
|
-- 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
|
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)
|
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)
|
function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poison, exhaust, poisonchance, sound)
|
||||||
return function(itemstack, user, pointed_thing)
|
return function(itemstack, user, pointed_thing)
|
||||||
local itemname = itemstack:get_name()
|
local itemname = itemstack:get_name()
|
||||||
|
local creative = minetest.settings:get_bool("creative_mode") == true
|
||||||
if itemstack:take_item() ~= nil and user ~= nil then
|
if itemstack:peek_item() ~= nil and user ~= nil then
|
||||||
|
if not creative then
|
||||||
|
itemstack:take_item()
|
||||||
|
end
|
||||||
local name = user:get_player_name()
|
local name = user:get_player_name()
|
||||||
local hp = user:get_hp()
|
local hp = user:get_hp()
|
||||||
|
|
||||||
|
@ -242,7 +247,9 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poiso
|
||||||
end
|
end
|
||||||
|
|
||||||
--sound:eat
|
--sound:eat
|
||||||
itemstack:add_item(replace_with_item)
|
if not creative then
|
||||||
|
itemstack:add_item(replace_with_item)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue