forked from LizzyFleckenstein03/Memeclone
Disable eat delay for cake
This commit is contained in:
parent
16adc1b029
commit
eab0205c2f
|
@ -45,6 +45,7 @@ Please read <http://minecraft.gamepedia.com/Breaking> to learn how digging times
|
|||
* `soil_nether_wart=1`: Nether wart will grow on this
|
||||
* `disable_suffocation=1`: Disables suffocation for full solid cubes (1)
|
||||
* `destroys_items=1`: If an item happens to be *inside* this node, the item will be destroyed
|
||||
* `no_eat_delay=1`: Only for foodstuffs. When eating this, all eating delays are ignored.
|
||||
|
||||
#### Footnotes
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ minetest.register_node("mcl_cake:cake", {
|
|||
fixed = full_cake
|
||||
},
|
||||
stack_max = 1,
|
||||
groups = {handy=1, cake=7, food=2,attached_node=1, dig_by_piston=1},
|
||||
groups = {handy=1, cake=7, food=2,no_eat_delay=1, attached_node=1, dig_by_piston=1},
|
||||
drop = '',
|
||||
on_rightclick = function(pos, node, clicker, itemstack)
|
||||
minetest.do_item_eat(2, ItemStack("mcl_cake:cake_6"), ItemStack("mcl_cake:cake"), clicker, {type="nothing"})
|
||||
|
@ -92,7 +92,7 @@ local register_slice = function(level, nodebox, desc)
|
|||
type = "fixed",
|
||||
fixed = nodebox,
|
||||
},
|
||||
groups = {handy=1, cake=level, food=2,attached_node=1,not_in_creative_inventory=1,dig_by_piston=1},
|
||||
groups = {handy=1, cake=level, food=2,no_eat_delay=1,attached_node=1,not_in_creative_inventory=1,dig_by_piston=1},
|
||||
drop = '',
|
||||
on_rightclick = on_rightclick,
|
||||
sounds = mcl_sounds.node_sound_leaves_defaults(),
|
||||
|
|
|
@ -15,12 +15,15 @@ core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, point
|
|||
|
||||
local name = user:get_player_name()
|
||||
|
||||
-- Allow eating only after a delay of 2 seconds.
|
||||
-- This prevents eating as an excessive speed.
|
||||
-- Yes, os.time() is not a precise timer but it is good enough for our purposes.
|
||||
-- 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
|
||||
|
||||
-- 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
|
||||
-- of the second the player made the first eat.
|
||||
-- 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 (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
|
||||
itemstack = mcl_hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||
for _, callback in pairs(core.registered_on_item_eats) do
|
||||
local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing, old_itemstack)
|
||||
|
|
Loading…
Reference in New Issue