commit 0bd7dc38d298853cb8dba7d3fc17bf87d7a002a7 Author: Wuzzy Date: Sun Oct 14 18:39:46 2018 +0200 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..3174a99 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Slow Eater mod + +Version 1.0.0 + +## Description +After eating something, the player must wait for 5 seconds before eating again. +This mod also adds an eating sound. + +## License (all files) +MIT License diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..c398d74 --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +After eating something, the player must wait for 5 seconds before eating again. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..1c8b501 --- /dev/null +++ b/init.lua @@ -0,0 +1,29 @@ +local EATING_DELAY = 5 -- time in seconds player must wait before being allowed to eat again + +minetest.register_on_item_eat(function(hp_change, replace_with_item, itemstack, user, pointed_thing) + local last_eat_time = user:get_attribute("last_eat_time") + local can_eat = true + if last_eat_time ~= nil then + last_eat_time = tonumber(last_eat_time) + end + if type(last_eat_time) == "number" then + local current_time = minetest.get_gametime() + if current_time - last_eat_time < EATING_DELAY then + can_eat = false + end + end + if can_eat then + user:set_attribute("last_eat_time", minetest.get_gametime()) + local def = itemstack:get_definition() + local eat_sound + if def.sounds and def.sounds.eat then + eat_sound = def.sounds.eat + else + eat_sound = { name = "sloweater_eat_generic", gain = 1 } + end + minetest.sound_play(eat_sound, {pos=user:getpos(), max_hear_distance = 16}) + return nil + else + return itemstack + end +end) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..543fd63 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = sloweater diff --git a/sounds/sloweater_eat_generic.ogg b/sounds/sloweater_eat_generic.ogg new file mode 100644 index 0000000..b6acd07 Binary files /dev/null and b/sounds/sloweater_eat_generic.ogg differ