summaryrefslogtreecommitdiff
path: root/api.lua
diff options
context:
space:
mode:
authorrubenwardy <rubenwardy@gmail.com>2014-11-16 12:48:24 +0000
committerrubenwardy <rubenwardy@gmail.com>2014-11-16 12:48:24 +0000
commit30f3b6d7bc3415e37bb4bfb53ad3667dedab42c9 (patch)
treea596b7a0fadb5b77c61f04980cbc032aee1211ca /api.lua
parente2d20a6a2cd41dd156b821c6bc4807e4855e5c37 (diff)
Move stuff around
Diffstat (limited to 'api.lua')
-rw-r--r--api.lua155
1 files changed, 0 insertions, 155 deletions
diff --git a/api.lua b/api.lua
deleted file mode 100644
index 19d019f..0000000
--- a/api.lua
+++ /dev/null
@@ -1,155 +0,0 @@
--- FOOD MOD
--- A mod written by rubenwardy that adds
--- food to the minetest game
--- =====================================
--- >> food/api.lua
--- The supporting api for the mod
--- =====================================
-
--- Boilerplate to support localized strings if intllib mod is installed.
-S = 0
-if (intllib) then
- dofile(minetest.get_modpath("intllib").."/intllib.lua")
- S = intllib.Getter(minetest.get_current_modname())
-else
- S = function ( s ) return s end
-end
-
-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
- 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
- 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") then
- return diet.item_eat(amt)
- elseif minetest.get_modpath("hud") then
- return hud.item_eat(amt)
- 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
-