2023-10-13 07:19:13 +00:00
|
|
|
local function create_plain_wrapper (function_name)
|
|
|
|
local wrapper = function (...)
|
2023-10-13 07:31:55 +00:00
|
|
|
--[[
|
2023-10-13 07:19:13 +00:00
|
|
|
local args = {...}
|
|
|
|
|
|
|
|
-- labels will be used later, probably.
|
2023-10-13 07:31:55 +00:00
|
|
|
local label = #args > 1 and args[1] or "unlabeled"
|
2023-10-13 07:19:13 +00:00
|
|
|
local callback = #args > 1 and args[2] or args[1]
|
|
|
|
|
|
|
|
minetest[function_name](callback)
|
2023-10-13 07:31:55 +00:00
|
|
|
]]--
|
|
|
|
minetest[function_name](...)
|
2023-10-13 07:19:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
blockgame[function_name] = wrapper
|
|
|
|
end
|
|
|
|
|
|
|
|
for name in pairs({
|
|
|
|
register_abm = true,
|
2023-10-13 07:55:09 +00:00
|
|
|
register_lbm = true,
|
2023-10-13 07:19:13 +00:00
|
|
|
register_on_joinplayer = true,
|
2023-10-13 07:31:55 +00:00
|
|
|
register_item = true,
|
|
|
|
register_on_placenode = true,
|
|
|
|
register_on_dignode = true,
|
|
|
|
register_on_punchnode = true,
|
|
|
|
register_globalstep = true,
|
2023-10-13 07:19:13 +00:00
|
|
|
}) do
|
|
|
|
create_plain_wrapper(name)
|
|
|
|
end
|
2023-10-17 18:20:42 +00:00
|
|
|
|
|
|
|
local function capitalize (str)
|
|
|
|
return string.upper(string.sub(str, 1, 1)) .. string.sub(str, 2)
|
|
|
|
end
|
|
|
|
|
2023-10-17 18:39:13 +00:00
|
|
|
local events = blockgame.events.namespace("api")
|
|
|
|
|
2023-10-21 09:56:50 +00:00
|
|
|
function blockgame.register_node (fullname, def)
|
|
|
|
-- make sure the right names are used in the right contexts, by manually extracting them here.
|
|
|
|
-- this makes `blockgame.register_node` more flexible/reliable.
|
|
|
|
local modname
|
|
|
|
local basename
|
2023-10-17 18:20:42 +00:00
|
|
|
|
2023-10-21 09:56:50 +00:00
|
|
|
local colon_pos = string.find(fullname, ":")
|
|
|
|
if colon_pos then
|
|
|
|
modname = string.sub(fullname, 1, colon_pos - 1)
|
|
|
|
basename = string.sub(fullname, colon_pos + 1)
|
|
|
|
else
|
|
|
|
modname = minetest.get_current_modname()
|
|
|
|
basename = fullname
|
|
|
|
fullname = modname .. ":" .. basename
|
|
|
|
end
|
|
|
|
|
|
|
|
def.description = def.description or capitalize(basename)
|
2023-10-17 18:20:42 +00:00
|
|
|
def.tiles = def.tiles or {
|
2023-10-21 09:56:50 +00:00
|
|
|
modname .. "_" .. basename .. ".png",
|
2023-10-17 18:20:42 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 18:39:13 +00:00
|
|
|
events.broadcast("before_register_node", {
|
2023-10-21 09:56:50 +00:00
|
|
|
name = fullname,
|
2023-10-17 18:39:13 +00:00
|
|
|
def = def,
|
|
|
|
mod = modname,
|
2023-10-21 09:56:50 +00:00
|
|
|
basename = basename
|
2023-10-17 18:39:13 +00:00
|
|
|
})
|
|
|
|
|
2023-10-21 09:56:50 +00:00
|
|
|
minetest.register_node(fullname, def)
|
2023-10-17 18:39:13 +00:00
|
|
|
|
|
|
|
events.broadcast("after_register_node", {
|
2023-10-21 09:56:50 +00:00
|
|
|
name = fullname,
|
2023-10-17 18:39:13 +00:00
|
|
|
def = def,
|
|
|
|
mod = modname,
|
2023-10-21 09:56:50 +00:00
|
|
|
basename = basename
|
2023-10-17 18:39:13 +00:00
|
|
|
})
|
2023-10-17 18:20:42 +00:00
|
|
|
end
|