mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-07-19 16:10:24 +02:00
Updated food mod and added its items in hud/hunger.lua
- Updated food mod (now splitted between food, containing the API, and food_basic, containing the items/craft recipes) - Added food's items un hud/hunger.lua
This commit is contained in:
4
mods/food/food/depends.txt
Normal file
4
mods/food/food/depends.txt
Normal file
@ -0,0 +1,4 @@
|
||||
diet?
|
||||
hud?
|
||||
intllib?
|
||||
hbhunger?
|
1
mods/food/food/description.txt
Normal file
1
mods/food/food/description.txt
Normal file
@ -0,0 +1 @@
|
||||
(API framework) The largest supporting food mod for Minetest. Adds soups, cakes, bakes and juices.
|
152
mods/food/food/init.lua
Executable file
152
mods/food/food/init.lua
Executable file
@ -0,0 +1,152 @@
|
||||
-- FOOD MOD
|
||||
-- A mod written by rubenwardy that adds
|
||||
-- food to the minetest game
|
||||
-- =====================================
|
||||
-- >> food/api.lua
|
||||
-- The supporting api for the mod
|
||||
-- =====================================
|
||||
|
||||
food = {
|
||||
modules = {},
|
||||
disabled_modules = {},
|
||||
debug = false,
|
||||
version = 2.3
|
||||
}
|
||||
|
||||
-- Checks for external content, and adds support
|
||||
function food.support(group, item)
|
||||
if type(group) == "table" then
|
||||
for i = 1, #group do
|
||||
food.support(group[i], item)
|
||||
end
|
||||
return
|
||||
end
|
||||
if type(item) == "table" then
|
||||
for i = 1, #item do
|
||||
food.support(group, item[i])
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local idx = string.find(item, ":")
|
||||
if idx <= 1 then
|
||||
error("[Food Error] food.support - error in item name ('" .. item .. "')")
|
||||
end
|
||||
local mod = string.sub(item, 1, idx - 1)
|
||||
|
||||
if not minetest.get_modpath(mod) then
|
||||
if food.debug then
|
||||
print("[Food Debug] Mod '"..mod.."' is not installed")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local data = minetest.registered_items[item]
|
||||
if not data then
|
||||
print("[Food Warning] Item '"..item.."' not found")
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
food.disable(group)
|
||||
|
||||
-- Add group
|
||||
local g = {}
|
||||
if data.groups then
|
||||
for k, v in pairs(data.groups) do
|
||||
g[k] = v
|
||||
end
|
||||
end
|
||||
g["food_"..group] = 1
|
||||
minetest.override_item(item, {groups = g})
|
||||
end
|
||||
|
||||
function food.disable(name)
|
||||
if type(name) == "table" then
|
||||
for i = 1, #name do
|
||||
food.disable(name[i])
|
||||
end
|
||||
return
|
||||
end
|
||||
food.disabled_modules[name] = true
|
||||
end
|
||||
|
||||
function food.disable_if(mod, name)
|
||||
if minetest.get_modpath(mod) then
|
||||
food.disable(name)
|
||||
end
|
||||
end
|
||||
|
||||
-- Adds a module
|
||||
function food.module(name, func, ingred)
|
||||
if food.disabled_modules[name] then
|
||||
return
|
||||
end
|
||||
if ingred then
|
||||
for name, def in pairs(minetest.registered_items) do
|
||||
local g = def.groups and def.groups["food_"..name] or 0
|
||||
if g > 0 then
|
||||
print("cancelled")
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if food.debug then
|
||||
print("[Food Debug] Registering " .. name .. " fallback definition")
|
||||
end
|
||||
elseif food.debug then
|
||||
print("[Food Debug] Module " .. name)
|
||||
end
|
||||
func()
|
||||
end
|
||||
|
||||
-- Checks for hunger mods to register food on
|
||||
function food.item_eat(amt)
|
||||
if minetest.get_modpath("diet") and diet and diet.item_eat then
|
||||
return diet.item_eat(amt)
|
||||
elseif minetest.get_modpath("hud") and hud and hud.item_eat then
|
||||
return hud.item_eat(amt)
|
||||
elseif minetest.get_modpath("hphunger") then
|
||||
if hphunger then
|
||||
return hphunger.item_eat(amt)
|
||||
else
|
||||
return hunger.item_eat(amt)
|
||||
end
|
||||
else
|
||||
return minetest.item_eat(amt)
|
||||
end
|
||||
end
|
||||
|
||||
-- Registers craft item or node depending on settings
|
||||
function food.register(name, data, mod)
|
||||
if (minetest.setting_getbool("food_use_2d") or (mod ~= nil and minetest.setting_getbool("food_"..mod.."_use_2d"))) then
|
||||
minetest.register_craftitem(name,{
|
||||
description = data.description,
|
||||
inventory_image = data.inventory_image,
|
||||
groups = data.groups,
|
||||
on_use = data.on_use
|
||||
})
|
||||
else
|
||||
local newdata = {
|
||||
description = data.description,
|
||||
tiles = data.tiles,
|
||||
groups = data.groups,
|
||||
on_use = data.on_use,
|
||||
walkable = false,
|
||||
sunlight_propagates = true,
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
node_box = data.node_box
|
||||
}
|
||||
if (minetest.setting_getbool("food_2d_inv_image")) then
|
||||
newdata.inventory_image = data.inventory_image
|
||||
end
|
||||
minetest.register_node(name,newdata)
|
||||
end
|
||||
end
|
||||
|
||||
-- Allows for overriding in the future
|
||||
function food.craft(craft)
|
||||
minetest.register_craft(craft)
|
||||
end
|
||||
|
Reference in New Issue
Block a user