1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-11-14 06:20:18 +01:00

add helper function for {eatable}

This commit is contained in:
tenplus1 2024-07-26 17:00:58 +01:00
parent 8115f61ac9
commit cc14704651

View File

@ -3,6 +3,27 @@ local S = mobs.translate
local FS = function(...) return minetest.formspec_escape(S(...)) end
local mc2 = minetest.get_modpath("mcl_core")
-- helper function to add {eatable} group to food items
local mod_tt_base = minetest.get_modpath("tt_base") -- mod does similar to infotext
function mobs.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
-- recipe items
local items = {
paper = mc2 and "mcl_core:paper" or "default:paper",
@ -45,20 +66,24 @@ minetest.register_craftitem("mobs:leather", {
-- raw meat
minetest.register_craftitem("mobs:meat_raw", {
description = S("Raw Meat") .. " (♥3)",
description = S("Raw Meat"),
inventory_image = "mobs_meat_raw.png",
on_use = minetest.item_eat(3),
groups = {food_meat_raw = 1, flammable = 2, eatable = 3}
groups = {food_meat_raw = 1}
})
mobs.add_eatable("mobs:meat_raw", 3)
-- cooked meat
minetest.register_craftitem("mobs:meat", {
description = S("Meat") .. " (♥8)",
description = S("Meat"),
inventory_image = "mobs_meat.png",
on_use = minetest.item_eat(8),
groups = {food_meat = 1, flammable = 2, eatable = 8}
groups = {food_meat = 1}
})
mobs.add_eatable("mobs:meat", 8)
minetest.register_craft({
type = "cooking",
output = "mobs:meat",
@ -375,12 +400,11 @@ end)
-- Meat Block
minetest.register_node("mobs:meatblock", {
description = S("Meat Block") .. " (♥20)",
description = S("Meat Block"),
tiles = {"mobs_meat_top.png", "mobs_meat_bottom.png", "mobs_meat_side.png"},
paramtype2 = "facedir",
groups = {
choppy = 1, oddly_breakable_by_hand = 1, flammable = 2, axey = 1, handy = 1,
eatable = 20
choppy = 1, oddly_breakable_by_hand = 1, axey = 1, handy = 1
},
is_ground_content = false,
sounds = mod_def and default.node_sound_leaves_defaults(),
@ -390,6 +414,8 @@ minetest.register_node("mobs:meatblock", {
_mcl_blast_resistance = 1
})
mobs.add_eatable("mobs:meatblock", 20)
minetest.register_craft({
output = "mobs:meatblock",
recipe = {
@ -401,12 +427,11 @@ minetest.register_craft({
-- Meat Block (raw)
minetest.register_node("mobs:meatblock_raw", {
description = S("Raw Meat Block") .. " (♥20)",
description = S("Raw Meat Block"),
tiles = {"mobs_meat_raw_top.png", "mobs_meat_raw_bottom.png", "mobs_meat_raw_side.png"},
paramtype2 = "facedir",
groups = {
choppy = 1, oddly_breakable_by_hand = 1, flammable = 2, axey = 1, handy = 1,
eatable = 20
choppy = 1, oddly_breakable_by_hand = 1, axey = 1, handy = 1
},
is_ground_content = false,
sounds = mod_def and default.node_sound_leaves_defaults(),
@ -416,6 +441,8 @@ minetest.register_node("mobs:meatblock_raw", {
_mcl_blast_resistance = 1
})
mobs.add_eatable("mobs:meatblock_raw", 20)
minetest.register_craft({
output = "mobs:meatblock_raw",
recipe = {