add helper function for {eatable}

This commit is contained in:
tenplus1 2024-07-26 17:23:29 +01:00
parent 71431a298d
commit 191d4acb90
2 changed files with 28 additions and 4 deletions

View File

@ -14,7 +14,7 @@ local S = wine.S
-- blue agave
minetest.register_node("wine:blue_agave", {
description = S("Blue Agave") .. " (♥2)",
description = S("Blue Agave"),
drawtype = "plantlike",
visual_scale = 0.8,
tiles = {"wine_blue_agave.png"},
@ -28,7 +28,7 @@ minetest.register_node("wine:blue_agave", {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, 0.3, 0.2}
},
groups = {snappy = 3, attached_node = 1, plant = 1, eatable = 2},
groups = {snappy = 3, attached_node = 1, plant = 1},
sounds = snd_l,
on_use = minetest.item_eat(2),
@ -73,6 +73,7 @@ minetest.register_node("wine:blue_agave", {
end
})
wine.add_eatable("wine:blue_agave", 2)
-- blue agave into cyan dye
if minetest.get_modpath("mcl_dye") then

View File

@ -69,13 +69,34 @@ function wine:add_item(list)
end
end
-- helper function
local mod_tt_base = minetest.get_modpath("tt_base")
function wine.add_eatable(item, hp)
local def = minetest.registered_items[item]
if def then
local grps = def.groups or {}
grps.eatable = hp ; grps.flammable = 2
if mod_tt_base == nil then
def.description = def.description .. " (♥" .. hp .. ")"
end
minetest.override_item(item, {description = def.description, groups = grps})
end
end
-- add drink with bottle
function wine:add_drink(name, desc, has_bottle, num_hunger, num_thirst, alcoholic)
-- glass
minetest.register_node("wine:glass_" .. name, {
description = S("Glass of " .. desc) .. " (♥" .. num_hunger .. ")",
description = S("Glass of " .. desc),
drawtype = "plantlike",
visual_scale = 0.5,
tiles = {"wine_" .. name .. "_glass.png"},
@ -90,7 +111,7 @@ function wine:add_drink(name, desc, has_bottle, num_hunger, num_thirst, alcoholi
fixed = {-0.15, -0.5, -0.15, 0.15, 0, 0.15}
},
groups = {
vessel = 1, dig_immediate = 3, eatable = num_hunger,
vessel = 1, dig_immediate = 3,
attached_node = 1, drink = 1, alcohol = alcoholic
},
sounds = snd_g,
@ -109,6 +130,8 @@ function wine:add_drink(name, desc, has_bottle, num_hunger, num_thirst, alcoholi
end
})
wine.add_eatable("wine:glass_" .. name, num_hunger)
-- bottle
if has_bottle then