-- Minetest 0.4 mod: default -- See README.txt for licensing and other information. -- The API documentation in here was moved into "game_api.txt" -- Definitions made by this mod that other mods can use too -- =================================================================== default = {} default.LIGHT_MAX = 14 default.core_item_eat = minetest.item_eat local modname = minetest.get_current_modname() local modpath = minetest.get_modpath (modname) default.modpath = modpath -- =================================================================== -- This variable is set to true for Maksym 2 and to false for Final -- MT 4. default.ismc = false if (rawget (_G, "nodeupdate") == nil) or (nodeupdate == nil) then minetest.log ("action", "nodeupdate isn't present") nodeupdate = function (p) core.check_for_falling (p) end default.ismc = true -- 210712 RJK: Fix a missing-biomes bug local mg_flags = minetest.get_mapgen_setting ("mg_flags") if mg_flags:find "biomes" == nil then mg_flags = mg_flags .. ",biomes" minetest.set_mapgen_setting ("mg_flags", mg_flags, true) end else minetest.log ("action", "nodeupdate is present") end -- =================================================================== if minetest.get_natural_light == nil then minetest.get_natural_light = minetest.get_node_light minetest.get_artificial_light = minetest.get_node_light end -- =================================================================== if (rawget (_G, "nodeupdate_single") == nil) or (nodeupdate_single == nil) then minetest.log ("action", "nodeupdate_single isn't present") nodeupdate_single = function (p) core.check_single_for_falling (p) end else minetest.log ("action", "nodeupdate_single is present") end -- =================================================================== dofile (modpath .. "/ocutil.lua") -- =================================================================== default.dont_reduce_node_count = true default.reduce_node_count = false -- if ocutil.bool_setting ("reduce_node_count") then default.dont_reduce_node_count = false default.reduce_node_count = true end -- =================================================================== default.old_content_id = minetest.get_content_id minetest.get_content_id = function (s) if (ocutil.node_missing (s)) then return nil end return default.old_content_id (s) end -- =================================================================== default.override_item = minetest.override_item minetest.override_item = function (s, def) if (ocutil.thing_missing (s)) then return nil end return default.override_item (s, def) end -- =================================================================== default.old_register_entity = minetest.register_entity minetest.register_entity = function (name, def) -- minetest.log ("action", "register_entity " .. name) if default.ismc then if def.automatic_rotate == false or def.automatic_rotate == true then def.automatic_rotate = 0 end end default.old_register_entity (name, def) end -- =================================================================== default.old_register_node = minetest.register_node minetest.register_node = function (name, def) -- minetest.log ("action", "regnode " .. name) if default.ismc then local obj if def.drowning == false then def.drowning = 0 end if def.drowning == true then def.drowning = 1 end obj = def.inventory_image if obj ~= nil and type (obj) == 'table' then def.inventory_image = def.inventory_image [0] end obj = def.use_texture_alpha if obj ~= nil and type (obj) == 'string' and obj == 'blend' then def.use_texture_alpha = true end obj = def.wield_image if obj ~= nil and type (obj) == 'table' then def.wield_image = def.wield_image [0] end end default.old_register_node (name, def) end -- =================================================================== if table.insert_all == nil then table.insert_all = function (t, other) for i=1, #other do t [#t + 1] = other [i] end return t end end -- =================================================================== local function safe_gsub (s, replace, with) local i1, i2 = s:find(replace, 1, true) if not i1 then return s, false end return s:sub(1, i1 - 1) .. with .. s:sub(i2 + 1), true end -- =================================================================== -- Chat message formatter -- Implemented in Lua to allow redefinition core.format_chat_message = function (name, message) local error_str = "Invalid chat message format - missing %s" local str = core.settings:get("chat_message_format") local replaced -- Name str, replaced = safe_gsub(str, "@name", name) if not replaced then error(error_str:format("@name"), 2) end -- Timestamp str = safe_gsub(str, "@timestamp", os.date("%H:%M:%S", os.time())) -- Insert the message into the string only after finishing all other processing str, replaced = safe_gsub(str, "@message", message) if not replaced then error(error_str:format("@message"), 2) end return str end -- =================================================================== local savereg = minetest.register_node minetest.register_node = function (name, def) -- minetest.log ("action", "register_node " .. name) if default.ismc then if def.drowning == false then def.drowning = 0 end if def.drowning == true then def.drowning = 1 end if def.inventory_image ~= nil and type (def.inventory_image) == 'table' then def.inventory_image = def.inventory_image [0] end if def.wield_image ~= nil and type (def.wield_image) == 'table' then def.wield_image = def.wield_image [0] end end savereg (name, def) end -- =================================================================== local enable_fixfloods = minetest.setting_getbool ("enable_fixflood" ) or minetest.setting_getbool ("enable_fixfloods" ) local enable_moontest = minetest.setting_getbool ("enable_moon" ) or minetest.setting_getbool ("enable_moontest" ) default.safe_lava = minetest.setting_getbool ("safe_lava" ) default.stop_lava = minetest.setting_getbool ("stop_lava" ) -- =================================================================== -- GUI related stuff default.gui_bg = "bgcolor[#080808BB;true]" default.gui_bg_img = "background[5,5;1,1;gui_formbg.png;true]" default.gui_slots = "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]" function default.get_hotbar_bg(x,y) local out = "" for i=0,7,1 do out = out .."image["..x+i..","..y..";1,1;gui_hb_bg.png]" end return out end -- =================================================================== function default.register_leafdecay() end default.gui_survival_form = "size[8,8.5]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. "list[current_player;main;0,4.25;8,1;]".. "list[current_player;main;0,5.5;8,3;8]".. "list[current_player;craft;1.75,0.5;3,3;]".. "list[current_player;craftpreview;5.75,1.5;1,1;]".. "image[4.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]".. "listring[current_player;main]".. "listring[current_player;craft]".. default.get_hotbar_bg(0,4.25) -- =================================================================== minetest.register_privilege ("lava", { description = "Can place lava manually" , give_to_singleplayer = true }) -- =================================================================== dofile (modpath .. "/functions.lua" ) dofile (modpath .. "/sound_defaults.lua" ) dofile (modpath .. "/convert.lua" ) dofile (modpath .. "/lava_blue.lua" ) dofile (modpath .. "/lava_green.lua" ) dofile (modpath .. "/lava_regular.lua" ) dofile (modpath .. "/nodes_water.lua" ) dofile (modpath .. "/nodes_other.lua" ) dofile (modpath .. "/chests.lua" ) dofile (modpath .. "/furnace.lua" ) dofile (modpath .. "/furnace_locked.lua" ) dofile (modpath .. "/tools.lua" ) dofile (modpath .. "/craftitems.lua" ) if enable_moontest then minetest.setting_set ("enable_clouds", 0) else dofile (modpath .. "/mapgen.lua") end dofile (modpath .. "/player.lua" ) dofile (modpath .. "/trees.lua" ) dofile (modpath .. "/aliases.lua" ) dofile (modpath .. "/legacy.lua" ) dofile (modpath .. "/crafting.lua" ) dofile (modpath .. "/outerspace.lua" ) if enable_fixfloods then dofile (modpath .. "/fixfloods.lua") end -- =================================================================== -- This variable saves a pointer to the original "minetest.item_eat" -- function. default.core_item_eat = minetest.item_eat -- =================================================================== -- "rt_" here is short for "runtime_". -- This version of "default.rt_item_eat" performs the runtime opera- -- tions expected of MT item-eat code in cases where Unified Foods -- isn't installed or hunger isn't enabled. -- If Unified Foods is installed and hunger is enabled, Unified Foods -- will overwrite this function at a later point to make it support -- additional features. -- "hc" and "rep_item" are the legacy "minetest.item_eat" hunger- -- change and replace-with-item parameters. -- =================================================================== default.rt_item_eat = function (itemstack, user, pointed_thing, hc, rep_item) if itemstack:take_item() == nil or user == nil then return itemstack end local hp = user:get_hp() if hp < 20 and hc then hp = hp + hc if hp > 20 then hp = 20 end user:set_hp (hp) end if rep_item then if itemstack:is_empty() then itemstack:add_item (rep_item) else local inv = user:get_inventory() if inv:room_for_item ("main", { name=rep_item }) then inv:add_item ("main", rep_item) else local pos = user:getpos() pos.y = math.floor (pos.y + 0.5) core.add_item (pos, rep_item) end end end return itemstack end -- =================================================================== -- If Unified Foods isn't installed or hunger isn't enabled, this -- function is roughly equivalent to the legacy version of the "mine- -- test.item_eat" function. -- Otherwise, this is an extended version of the latter function which -- uses Unified Foods code at runtime (even though the code hasn't -- been loaded at the point where this function is defined). -- To accomplish the switch, Unified Foods overwrites "default.rt_ -- item_eat". -- Unified Foods overwrites this function as well. However, this ver- -- sion of this function is used to support Unified Foods setup opera- -- tions prior to the point where Unified Foods is loaded. -- =================================================================== minetest.item_eat = function (hc, rep_item) return function (itemstack, user, pointed_thing) return default.rt_item_eat (itemstack, user, pointed_thing, hc, rep_item) end end -- =================================================================== -- This code allows simple non-furnace cooking appliances such as the -- "mapop" microwave and oven to use standard cooking recipes. default.old_register_craft = minetest.register_craft default.cookmap = {} minetest.register_craft = function (tab) if tab.type == "cooking" and type (tab.recipe) == "string" and type (tab.output) == "string" then default.cookmap [tab.recipe] = tab.output end return default.old_register_craft ({ output = tab.output , type = tab.type , recipe = tab.recipe , }) end -- =================================================================== -- End of file.