From 3291fcb054c8a55687847b7e574c428cbba3195a Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 20 May 2017 17:45:04 +0200 Subject: [PATCH] Add saturation value to food items --- mods/ITEMS/mcl_cake/depends.txt | 1 + mods/ITEMS/mcl_cake/init.lua | 2 ++ mods/ITEMS/mcl_core/craftitems.lua | 2 ++ mods/ITEMS/mcl_end/init.lua | 1 + mods/ITEMS/mcl_farming/beetroot.lua | 2 ++ mods/ITEMS/mcl_farming/carrots.lua | 2 ++ mods/ITEMS/mcl_farming/melon.lua | 1 + mods/ITEMS/mcl_farming/potatoes.lua | 3 +++ mods/ITEMS/mcl_farming/pumpkin.lua | 1 + mods/ITEMS/mcl_farming/wheat.lua | 2 ++ mods/ITEMS/mcl_fishing/init.lua | 6 ++++++ mods/ITEMS/mcl_mobitems/init.lua | 13 +++++++++++++ mods/PLAYER/mcl_hunger/hunger.lua | 10 +++++++--- mods/PLAYER/mcl_hunger/init.lua | 2 ++ 14 files changed, 45 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_cake/depends.txt b/mods/ITEMS/mcl_cake/depends.txt index 91d2c38207..e09b019949 100644 --- a/mods/ITEMS/mcl_cake/depends.txt +++ b/mods/ITEMS/mcl_cake/depends.txt @@ -1,5 +1,6 @@ mcl_core mcl_sounds +mcl_hunger bucket mcl_farming mcl_mobitems diff --git a/mods/ITEMS/mcl_cake/init.lua b/mods/ITEMS/mcl_cake/init.lua index d6f2696411..635abb7517 100644 --- a/mods/ITEMS/mcl_cake/init.lua +++ b/mods/ITEMS/mcl_cake/init.lua @@ -55,6 +55,7 @@ minetest.register_node("mcl_cake:cake", { sounds = mcl_sounds.node_sound_leaves_defaults(), _food_particles = false, + _mcl_saturation = 0.4, _mcl_blast_resistance = 2.5, _mcl_hardness = 0.5, }) @@ -96,6 +97,7 @@ local register_slice = function(level, nodebox, desc) sounds = mcl_sounds.node_sound_leaves_defaults(), _food_particles = false, + _mcl_saturation = 0.4, _mcl_blast_resistance = 2.5, _mcl_hardness = 0.5, }) diff --git a/mods/ITEMS/mcl_core/craftitems.lua b/mods/ITEMS/mcl_core/craftitems.lua index a71b002adc..8d5bc3bc78 100644 --- a/mods/ITEMS/mcl_core/craftitems.lua +++ b/mods/ITEMS/mcl_core/craftitems.lua @@ -139,6 +139,7 @@ minetest.register_craftitem("mcl_core:apple", { on_place = minetest.item_eat(4), on_secondary_use = minetest.item_eat(4), groups = { food = 2, eatable = 4 }, + _mcl_saturation = 2.4, }) minetest.register_craftitem("mcl_core:apple_gold", { @@ -150,4 +151,5 @@ minetest.register_craftitem("mcl_core:apple_gold", { on_place = minetest.item_eat(8), on_secondary_use = minetest.item_eat(8), groups = { food = 2, eatable = 8 }, + _mcl_saturation = 9.6, }) diff --git a/mods/ITEMS/mcl_end/init.lua b/mods/ITEMS/mcl_end/init.lua index 4b35bfa3ec..bdfda56356 100644 --- a/mods/ITEMS/mcl_end/init.lua +++ b/mods/ITEMS/mcl_end/init.lua @@ -257,6 +257,7 @@ minetest.register_craftitem("mcl_end:chorus_fruit", { on_place = minetest.item_eat(4), on_secondary_use = minetest.item_eat(4), groups = { food = 2, eatable = 4 }, + _mcl_saturation = 2.4, stack_max = 64, }) diff --git a/mods/ITEMS/mcl_farming/beetroot.lua b/mods/ITEMS/mcl_farming/beetroot.lua index cc5eb1a86e..90e20bba7d 100644 --- a/mods/ITEMS/mcl_farming/beetroot.lua +++ b/mods/ITEMS/mcl_farming/beetroot.lua @@ -125,6 +125,7 @@ minetest.register_craftitem("mcl_farming:beetroot_item", { on_place = minetest.item_eat(1), on_secondary_use = minetest.item_eat(1), groups = { food = 2, eatable = 1 }, + _mcl_saturation = 1.2, }) minetest.register_craftitem("mcl_farming:beetroot_soup", { @@ -136,6 +137,7 @@ minetest.register_craftitem("mcl_farming:beetroot_soup", { on_place = minetest.item_eat(6, "mcl_core:bowl"), on_secondary_use = minetest.item_eat(6, "mcl_core:bowl"), groups = { food = 3, eatable = 6 }, + _mcl_saturation = 7.2, }) minetest.register_craft({ diff --git a/mods/ITEMS/mcl_farming/carrots.lua b/mods/ITEMS/mcl_farming/carrots.lua index 01006e0df0..d3de0fc132 100644 --- a/mods/ITEMS/mcl_farming/carrots.lua +++ b/mods/ITEMS/mcl_farming/carrots.lua @@ -84,6 +84,7 @@ minetest.register_craftitem("mcl_farming:carrot_item", { _doc_items_usagehelp = "Hold it in your hand and rightclick to eat it. Place it on top of farmland to plant the carrot. It grows in sunlight and grows faster on hydrated farmland. Rightclick an animal to feed it.", inventory_image = "farming_carrot.png", groups = { food = 2, eatable = 3 }, + _mcl_saturation = 3.6, on_secondary_use = minetest.item_eat(3), on_place = function(itemstack, placer, pointed_thing) local new = mcl_farming:place_seed(itemstack, placer, pointed_thing, "mcl_farming:carrot_1") @@ -102,6 +103,7 @@ minetest.register_craftitem("mcl_farming:carrot_item_gold", { on_place = minetest.item_eat(6), on_secondary_use = minetest.item_eat(6), groups = { brewitem = 1, food = 2, eatable = 6 }, + _mcl_saturation = 14.4, }) minetest.register_craft({ diff --git a/mods/ITEMS/mcl_farming/melon.lua b/mods/ITEMS/mcl_farming/melon.lua index 33ba069e44..4fae9c8eb5 100644 --- a/mods/ITEMS/mcl_farming/melon.lua +++ b/mods/ITEMS/mcl_farming/melon.lua @@ -114,6 +114,7 @@ minetest.register_craftitem("mcl_farming:melon_item", { on_place = minetest.item_eat(2), on_secondary_use = minetest.item_eat(2), groups = { food = 2, eatable = 2 }, + _mcl_saturation = 1.2, }) minetest.register_craft({ diff --git a/mods/ITEMS/mcl_farming/potatoes.lua b/mods/ITEMS/mcl_farming/potatoes.lua index ccb63d40e4..349ec7b944 100644 --- a/mods/ITEMS/mcl_farming/potatoes.lua +++ b/mods/ITEMS/mcl_farming/potatoes.lua @@ -85,6 +85,7 @@ minetest.register_craftitem("mcl_farming:potato_item", { _doc_items_usagehelp = "Hold it in your hand and rightclick to eat it. Place it on top of farmland to plant it. It grows in sunlight and grows faster on hydrated farmland. Rightclick an animal to feed it.", inventory_image = "farming_potato.png", groups = { food = 2, eatable = 1 }, + _mcl_saturation = 0.6, stack_max = 64, on_secondary_use = minetest.item_eat(1), on_place = function(itemstack, placer, pointed_thing) @@ -105,6 +106,7 @@ minetest.register_craftitem("mcl_farming:potato_item_baked", { on_place = minetest.item_eat(6), on_secondary_use = minetest.item_eat(6), groups = { food = 2, eatable = 6 }, + _mcl_saturation = 6.0, }) minetest.register_craftitem("mcl_farming:potato_item_poison", { @@ -117,6 +119,7 @@ minetest.register_craftitem("mcl_farming:potato_item_poison", { on_place = minetest.item_eat(0), on_secondary_use = minetest.item_eat(0), groups = { food = 2, eatable = 0 }, + _mcl_saturation = 1.2, }) minetest.register_craft({ diff --git a/mods/ITEMS/mcl_farming/pumpkin.lua b/mods/ITEMS/mcl_farming/pumpkin.lua index b0b886c385..1237844d10 100644 --- a/mods/ITEMS/mcl_farming/pumpkin.lua +++ b/mods/ITEMS/mcl_farming/pumpkin.lua @@ -131,6 +131,7 @@ minetest.register_craftitem("mcl_farming:pumpkin_pie", { on_place = minetest.item_eat(8), on_secondary_use = minetest.item_eat(8), groups = { food = 2, eatable = 8 }, + _mcl_saturation = 4.8, }) minetest.register_craft({ diff --git a/mods/ITEMS/mcl_farming/wheat.lua b/mods/ITEMS/mcl_farming/wheat.lua index ed58b62712..05467a4abc 100644 --- a/mods/ITEMS/mcl_farming/wheat.lua +++ b/mods/ITEMS/mcl_farming/wheat.lua @@ -112,6 +112,7 @@ minetest.register_craftitem("mcl_farming:cookie", { _doc_items_longdesc = "This is a food item which can be eaten for 2 hunger points.", inventory_image = "farming_cookie.png", groups = {food=2, eatable=2}, + _mcl_saturation = 0.4, on_place = minetest.item_eat(2), on_secondary_use = minetest.item_eat(2), }) @@ -122,6 +123,7 @@ minetest.register_craftitem("mcl_farming:bread", { _doc_items_longdesc = "This is a food item which can be eaten for 5 hunger points.", inventory_image = "farming_bread.png", groups = {food=2, eatable=5}, + _mcl_saturation = 6.0, on_place = minetest.item_eat(5), on_secondary_use = minetest.item_eat(5), }) diff --git a/mods/ITEMS/mcl_fishing/init.lua b/mods/ITEMS/mcl_fishing/init.lua index ebfbbcb441..78069694c8 100644 --- a/mods/ITEMS/mcl_fishing/init.lua +++ b/mods/ITEMS/mcl_fishing/init.lua @@ -127,6 +127,7 @@ minetest.register_craftitem("mcl_fishing:fish_raw", { on_secondary_use = minetest.item_eat(2), stack_max = 64, groups = { food=2, eatable = 2 }, + _mcl_saturation = 0.4, }) minetest.register_craftitem("mcl_fishing:fish_cooked", { @@ -137,6 +138,7 @@ minetest.register_craftitem("mcl_fishing:fish_cooked", { on_secondary_use = minetest.item_eat(5), stack_max = 64, groups = { food=2, eatable=5 }, + _mcl_saturation = 9.6, }) minetest.register_craft({ @@ -155,6 +157,7 @@ minetest.register_craftitem("mcl_fishing:salmon_raw", { on_secondary_use = minetest.item_eat(2), stack_max = 64, groups = { food=2, eatable = 2 }, + _mcl_saturation = 0.4, }) minetest.register_craftitem("mcl_fishing:salmon_cooked", { @@ -165,6 +168,7 @@ minetest.register_craftitem("mcl_fishing:salmon_cooked", { on_secondary_use = minetest.item_eat(6), stack_max = 64, groups = { food=2, eatable=6 }, + _mcl_saturation = 9.6, }) minetest.register_craft({ @@ -183,6 +187,7 @@ minetest.register_craftitem("mcl_fishing:clownfish_raw", { on_secondary_use = minetest.item_eat(1), stack_max = 64, groups = { food=2, eatable = 1 }, + _mcl_saturation = 0.2, }) -- Pufferfish @@ -195,5 +200,6 @@ minetest.register_craftitem("mcl_fishing:pufferfish_raw", { on_secondary_use = minetest.item_eat(1), stack_max = 64, groups = { food=2, eatable=1 }, + _mcl_saturation = 0.2, }) diff --git a/mods/ITEMS/mcl_mobitems/init.lua b/mods/ITEMS/mcl_mobitems/init.lua index 5d54b17ea1..115c233ba9 100644 --- a/mods/ITEMS/mcl_mobitems/init.lua +++ b/mods/ITEMS/mcl_mobitems/init.lua @@ -8,6 +8,7 @@ minetest.register_craftitem("mcl_mobitems:rotten_flesh", { on_place = minetest.item_eat(4), on_secondary_use = minetest.item_eat(4), groups = { food = 2, eatable = 4 }, + _mcl_saturation = 0.8, stack_max = 64, }) @@ -19,6 +20,7 @@ minetest.register_craftitem("mcl_mobitems:mutton", { on_place = minetest.item_eat(2), on_secondary_use = minetest.item_eat(2), groups = { food = 2, eatable = 2 }, + _mcl_saturation = 1.2, stack_max = 64, }) @@ -30,6 +32,7 @@ minetest.register_craftitem("mcl_mobitems:cooked_mutton", { on_place = minetest.item_eat(6), on_secondary_use = minetest.item_eat(6), groups = { food = 2, eatable = 6 }, + _mcl_saturation = 9.6, stack_max = 64, }) @@ -41,6 +44,7 @@ minetest.register_craftitem("mcl_mobitems:beef", { on_place = minetest.item_eat(3), on_secondary_use = minetest.item_eat(3), groups = { food = 2, eatable = 3 }, + _mcl_saturation = 1.8, stack_max = 64, }) @@ -52,6 +56,7 @@ minetest.register_craftitem("mcl_mobitems:cooked_beef", { on_place = minetest.item_eat(8), on_secondary_use = minetest.item_eat(8), groups = { food = 2, eatable = 8 }, + _mcl_saturation = 12.8, stack_max = 64, }) @@ -63,6 +68,7 @@ minetest.register_craftitem("mcl_mobitems:chicken", { on_place = minetest.item_eat(2), on_secondary_use = minetest.item_eat(2), groups = { food = 2, eatable = 2 }, + _mcl_saturation = 1.2, stack_max = 64, }) @@ -74,6 +80,7 @@ minetest.register_craftitem("mcl_mobitems:cooked_chicken", { on_place = minetest.item_eat(6), on_secondary_use = minetest.item_eat(6), groups = { food = 2, eatable = 6 }, + _mcl_saturation = 7.2, stack_max = 64, }) @@ -85,6 +92,7 @@ minetest.register_craftitem("mcl_mobitems:porkchop", { on_place = minetest.item_eat(3), on_secondary_use = minetest.item_eat(3), groups = { food = 2, eatable = 3 }, + _mcl_saturation = 1.8, stack_max = 64, }) @@ -96,6 +104,7 @@ minetest.register_craftitem("mcl_mobitems:cooked_porkchop", { on_place = minetest.item_eat(8), on_secondary_use = minetest.item_eat(8), groups = { food = 2, eatable = 8 }, + _mcl_saturation = 12.8, stack_max = 64, }) @@ -107,6 +116,7 @@ minetest.register_craftitem("mcl_mobitems:rabbit", { on_place = minetest.item_eat(3), on_secondary_use = minetest.item_eat(3), groups = { food = 2, eatable = 3 }, + _mcl_saturation = 1.8, stack_max = 64, }) @@ -118,6 +128,7 @@ minetest.register_craftitem("mcl_mobitems:cooked_rabbit", { on_place = minetest.item_eat(5), on_secondary_use = minetest.item_eat(5), groups = { food = 2, eatable = 5 }, + _mcl_saturation = 6.0, stack_max = 64, }) @@ -142,6 +153,7 @@ minetest.register_craftitem("mcl_mobitems:spider_eye", { on_place = minetest.item_eat(2), on_secondary_use = minetest.item_eat(2), groups = { food = 2, eatable = 2 }, + _mcl_saturation = 3.2, stack_max = 64, }) @@ -261,6 +273,7 @@ minetest.register_craftitem("mcl_mobitems:rabbit_stew", { on_place = minetest.item_eat(10, "mcl_core:bowl"), on_secondary_use = minetest.item_eat(10, "mcl_core:bowl"), groups = { food = 3, eatable = 10 }, + _mcl_saturation = 6.0, }) minetest.register_craftitem("mcl_mobitems:shulker_shell", { diff --git a/mods/PLAYER/mcl_hunger/hunger.lua b/mods/PLAYER/mcl_hunger/hunger.lua index f6c4802211..b7d76e4dd0 100644 --- a/mods/PLAYER/mcl_hunger/hunger.lua +++ b/mods/PLAYER/mcl_hunger/hunger.lua @@ -146,10 +146,14 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisen, heal, sou mcl_hunger.hunger[name] = h mcl_hunger.set_hunger_raw(user) end - -- Dummy saturation (= hunger change) - -- TODO: Use food's actual saturation value + -- Add saturation (must be defined in item table) if hunger_change then - mcl_hunger.saturate(name, hunger_change) + local saturation = minetest.registered_items[itemname]._mcl_saturation + if not saturation then + saturation = 0.0 + minetest.log("warning", "[mcl_hunger] No saturation defined for item “"..itemname.."”!") + end + mcl_hunger.saturate(name, saturation) end -- Poison if poisen then diff --git a/mods/PLAYER/mcl_hunger/init.lua b/mods/PLAYER/mcl_hunger/init.lua index cff1254c3e..184ddbb0fe 100644 --- a/mods/PLAYER/mcl_hunger/init.lua +++ b/mods/PLAYER/mcl_hunger/init.lua @@ -214,6 +214,8 @@ minetest.register_globalstep(function(dtime) if controls.up or controls.down or controls.left or controls.right then -- TODO: Add exhaustion for moving in water end + -- Jumping + -- FIXME: This is quite hacky and doesn't check if the player is actually jumping if controls.jump then mcl_hunger.exhaust(name, mcl_hunger.EXHAUST_JUMP) end