ExchangeClone/exchangeclone/infinite_food.lua

55 lines
2.2 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
2024-02-13 22:51:51 +01:00
local player_emc = exchangeclone.get_player_emc(player)
if player_emc >= 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
2024-01-23 00:31:22 +01:00
elseif exchangeclone.mtg 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", {
description = S("Infinite Food").."\n"..S("Consumes 64 EMC 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 = exchangeclone.mtg 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)
2024-02-13 22:51:51 +01:00
local player_emc = exchangeclone.get_player_emc(player)
2023-11-08 01:02:24 +01:00
if itemstack:get_name() == "exchangeclone:infinite_food" then
2024-02-13 22:51:51 +01:00
exchangeclone.set_player_emc(player, player_emc - 64)
2023-11-08 01:02:24 +01:00
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,},
}
})