diff --git a/init.lua b/init.lua index 838c6f8..b55d515 100644 --- a/init.lua +++ b/init.lua @@ -3,6 +3,28 @@ sneeker = {} sneeker.modname = core.get_current_modname() sneeker.modpath = core.get_modpath(sneeker.modname) +local debugging = core.settings:get_bool("enable_debug_mods", false) +sneeker.log = function(lvl, msg) + if lvl == "debug" and not debugging then return end + + if msg == nil then + msg = lvl + lvl = nil + end + + msg = "[" .. sneeker.modname .. "] " .. msg + if lvl == "debug" then + msg = "[DEBUG]" .. msg + lvl = nil; + end + + if not lvl then + core.log(msg) + else + core.log(lvl, msg) + end +end + local scripts = { "settings", "tnt_function", diff --git a/settingtypes.txt b/settingtypes.txt index 2247a19..516dc70 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,4 +1,7 @@ +# Extra debugging messages. +enable_debug_mods (Mod debugging) bool false + # Sets possibility for spawn. # # Rate is the inverted value (e.g. 1/value). diff --git a/spawn.lua b/spawn.lua index 11a2521..0183724 100644 --- a/spawn.lua +++ b/spawn.lua @@ -10,6 +10,12 @@ if core.global_exists("nether") then table.insert(spawn_nodes, "nether:rack") end +for _, node_name in ipairs(spawn_nodes) do + if not core.registered_nodes[node_name] then + sneeker.log("warning", "Invalid node for spawn: " .. node_name) + end +end + core.register_abm({ nodenames = spawn_nodes, @@ -40,6 +46,12 @@ core.register_abm({ return end - core.add_entity(pos, "sneeker:sneeker") + local spawned = core.add_entity(pos, "sneeker:sneeker") + if not spawned then + sneeker.log("warning", "Failed to spawn at: " + .. tostring(math.floor(pos.x)) + .. "," .. tostring(math.floor(pos.y)) + .. "," .. tostring(math.floor(pos.z))) + end end })