ExchangeClone/exchangeclone/infinite_food.lua

55 lines
2.3 KiB
Lua
Raw Normal View History

2023-11-19 01:48:35 +01:00
local S = minetest.get_translator()
local stamina_exists = minetest.get_modpath("stamina")
local stamina_max = minetest.settings:get("stamina.visual_max") or 20
2023-11-08 01:02:24 +01:00
local function infinite_food_function(itemstack, player, pointed_thing)
local click_test = exchangeclone.check_on_rightclick(itemstack, player, pointed_thing)
local original = ItemStack(itemstack)
if click_test ~= false then
return click_test
end
local player_energy = exchangeclone.get_player_energy(player)
if player_energy >= 64 then
2023-12-21 21:37:52 +01:00
if stamina_exists then
if stamina.get_saturation(player) >= stamina_max then
return nil
end
elseif not exchangeclone.mcl and player:get_hp() >= player:get_properties().hp_max then
return nil
end
-- no idea why this is different between games but it works
local hunger_restore = minetest.item_eat(8, exchangeclone.mcl and ItemStack("") or original)
2023-11-08 01:02:24 +01:00
hunger_restore(itemstack, player, pointed_thing)
end
return nil
end
minetest.register_tool("exchangeclone:infinite_food", {
2023-11-19 01:48:35 +01:00
description = S("Infinite Food").."\n"..S("Consumes 64 energy when eaten"),
2023-12-18 23:57:30 +01:00
wield_image = "farming_bread.png^[colorize:#ffff00:128",
inventory_image = "farming_bread.png^[colorize:#ffff00:128",
2023-11-08 01:02:24 +01:00
groups = { food = 2, eatable = 8, disable_repair = 1, fire_immune = 1},
2023-12-15 00:09:59 +01:00
on_place = exchangeclone.mcl and infinite_food_function,
on_secondary_use = exchangeclone.mcl and infinite_food_function,
on_use = (not exchangeclone.mcl) and infinite_food_function,
2023-11-08 01:02:24 +01:00
_mcl_saturation = 12.8,
})
minetest.register_on_item_eat(function(hp_change, replace_with_item, itemstack, player, pointed_thing)
local player_energy = exchangeclone.get_player_energy(player)
if itemstack:get_name() == "exchangeclone:infinite_food" then
exchangeclone.set_player_energy(player, player_energy - 64)
end
2023-12-15 00:09:59 +01:00
end)
local bread_itemstring = exchangeclone.mcl and "mcl_farming:bread" or "farming:bread"
minetest.register_craft({
output = "exchangeclone:infinite_food",
recipe = {
{bread_itemstring, bread_itemstring, bread_itemstring,},
{bread_itemstring, "exchangeclone:transmutation_tablet", bread_itemstring,},
{bread_itemstring, bread_itemstring, bread_itemstring,},
}
})