simplify node registration.

make the wrapper `blockgame.register_node` make reasonable assumptions
that make node registration more convenient.

change other code to take advantage of that change.

also remove the `blockgame.reg_simple_node` utility since it's now
redundant.
This commit is contained in:
trans_soup 2023-10-17 20:20:42 +02:00
parent c6157df12c
commit 75e66075d0
8 changed files with 48 additions and 44 deletions

View file

@ -1,16 +1,3 @@
function blockgame.reg_simple_node (name, desc, groups)
local my_modname = minetest.get_current_modname()
return blockgame.register_node(my_modname .. ":" .. name, {
description = desc,
tiles = {
my_modname .. "_" .. name .. ".png",
},
groups = groups,
})
end
function blockgame.air_flows_through (pos, node)
node = node or minetest.get_node(pos)
return blockgame.item_matches(node.name, {

View file

@ -19,7 +19,6 @@ for name in pairs({
register_abm = true,
register_lbm = true,
register_on_joinplayer = true,
register_node = true,
register_item = true,
register_on_placenode = true,
register_on_dignode = true,
@ -28,3 +27,19 @@ for name in pairs({
}) do
create_plain_wrapper(name)
end
local function capitalize (str)
return string.upper(string.sub(str, 1, 1)) .. string.sub(str, 2)
end
function blockgame.register_node (name, def)
local modname = minetest.get_current_modname()
local full_name = modname .. ":" .. name
def.description = def.description or capitalize(name)
def.tiles = def.tiles or {
modname .. "_" .. name .. ".png",
}
minetest.register_node(full_name, def)
end

View file

@ -1,7 +1,11 @@
blockgame.reg_simple_node("bricks", "Bricks", {
stoney = 1,
blockgame.register_node("bricks", {
groups = {
stoney = 1,
},
})
blockgame.reg_simple_node("tile", "Tile", {
stoney = 1,
blockgame.register_node("tile", {
groups = {
stoney = 1,
},
})

View file

@ -1,10 +1,7 @@
local modname = minetest.get_current_modname()
blockgame.register_node(modname .. ":stone", {
blockgame.register_node("stone", {
description = "Stone",
tiles = {
modname .. "_stone.png",
},
groups = {
cracky = 3,
stoney = 1,
@ -12,11 +9,8 @@ blockgame.register_node(modname .. ":stone", {
drop = modname .. ":cobblestone",
})
blockgame.register_node(modname .. ":cobblestone", {
blockgame.register_node("cobblestone", {
description = "Cobblestone",
tiles = {
modname .. "_cobblestone.png",
},
groups = {
cracky = 3,
stoney = 1,
@ -27,22 +21,16 @@ blockgame.register_node(modname .. ":cobblestone", {
minetest.register_alias("mapgen_stone", modname .. ":stone")
minetest.register_alias("mapgen_water_source", "air")
blockgame.register_node(modname .. ":grass", {
blockgame.register_node("grass", {
description = "Grass",
tiles = {
modname .. "_grass.png",
},
groups = {
dirty = 1,
},
drop = modname .. ":dirt",
})
blockgame.register_node(modname .. ":dirt", {
blockgame.register_node("dirt", {
description = "Dirt",
tiles = {
modname .. "_dirt.png",
},
groups = {
dirty = 1,
grassable = 1,

View file

@ -3,13 +3,21 @@ local modname = minetest.get_current_modname()
load_file("node_log")
load_file("node_leaves")
blockgame.reg_simple_node("nut", "Nut", {
woody = 1,
blockgame.register_node("nut", {
groups = {
woody = 1,
},
})
blockgame.reg_simple_node("root", "Root", {
woody = 1,
blockgame.register_node("root", {
groups = {
woody = 1,
},
})
blockgame.reg_simple_node("root_alive", "Growing Root", {
woody = 1,
blockgame.register_node("root_alive", {
description = "Growing Root",
groups = {
woody = 1,
},
})

View file

@ -16,7 +16,7 @@ local function reg_leaves (name, def)
falling_node = 1,
})
blockgame.register_node(modname .. ":" .. name, def)
blockgame.register_node(name, def)
end
local nutty_drops = {

View file

@ -17,7 +17,7 @@ local function reg_log (name, def)
supports_leaves = 1,
})
blockgame.register_node(modname .. ":" .. name, def)
blockgame.register_node(name, def)
end
reg_log("log", {

View file

@ -1,5 +1,7 @@
local modname = minetest.get_current_modname()
blockgame.reg_simple_node("plank", "Plank", {
woody = 1,
blockgame.register_node("plank", {
groups = {
woody = 1,
},
})