Genericize sand-raking API, add gravel support

This commit is contained in:
Aaron Suen 2021-07-03 10:42:45 -04:00
parent 84bdd1d57a
commit 43d1b6df2f

View File

@ -1,30 +1,32 @@
-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore, vector
= math, minetest, nodecore, vector
local math_pi
= math.pi
local math, minetest, nodecore, string, vector
= math, minetest, nodecore, string, vector
local math_pi, string_gsub, string_lower
= math.pi, string.gsub, string.lower
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local sandname = "nc_terrain:sand"
local sanddef = minetest.registered_items[sandname] or {}
local basedef = {
description = "Raked Sand",
function nodecore.register_raked(basename, desc, recipematch, recipeidx)
local name = string_gsub(string_lower(desc), "%W", "_")
local basedef = minetest.registered_items[basename] or {}
local commondef = {
description = "Raked " .. desc,
paramtype2 = "facedir",
falling_replacement = sandname,
silktouch_as = sandname,
falling_replacement = basename,
silktouch_as = basename,
on_door_conveyed = function(pos)
return minetest.set_node(pos, {name = sandname})
return minetest.set_node(pos, {name = basename})
end
}
minetest.register_node(modname .. ":sand_raked",
}
local linearname = modname .. ":" .. name .. "_raked"
minetest.register_node(linearname,
nodecore.underride({
tiles = {
sanddef.tiles[1] .. "^" .. modname
basedef.tiles[1] .. "^" .. modname
.. "_raking_linear.png",
sanddef.tiles[1],
sanddef.tiles[1] .. "^" .. modname
basedef.tiles[1],
basedef.tiles[1] .. "^" .. modname
.. "_raking_side.png"
},
on_place = function(itemstack, placer, pointed_thing)
@ -32,26 +34,28 @@ minetest.register_node(modname .. ":sand_raked",
itemstack, placer, pointed_thing,
false, {force_floor = true})
end
}, basedef, sanddef))
minetest.register_node(modname .. ":sand_raked_nexus",
}, commondef, basedef))
local nexusname = modname .. ":" .. name .. "_raked_nexus"
minetest.register_node(nexusname,
nodecore.underride({
tiles = {
sanddef.tiles[1] .. "^" .. modname
basedef.tiles[1] .. "^" .. modname
.. "_raking_nexus.png",
sanddef.tiles[1],
sanddef.tiles[1] .. "^" .. modname
basedef.tiles[1],
basedef.tiles[1] .. "^" .. modname
.. "_raking_side.png"
}
}, basedef, sanddef))
}, commondef, basedef))
nodecore.register_craft({
label = "rake sand",
nodecore.register_craft({
label = "rake " .. name,
action = "pummel",
wield = {groups = {rakey = true}},
duration = 0.5,
normal = {y = 1},
indexkeys = {"group:sand"},
nodes = {{match = {groups = {sand = true, falling_repose = false}}}},
indexkeys = recipeidx,
nodes = {{match = recipematch}},
after = function(pos, data)
if not (data.crafter and data.crafter.getpos
and data.crafter.get_look_horizontal) then return end
@ -61,7 +65,7 @@ nodecore.register_craft({
ppos.y = pos.y
if vector.distance(pos, ppos) < 0.4 then
newnode = {
name = modname .. ":sand_raked_nexus",
name = nexusname,
param2 = 0
}
else
@ -69,16 +73,24 @@ nodecore.register_craft({
while dir >= math_pi * 3/4 do dir = dir - math_pi end
dir = minetest.yaw_to_dir(dir + math_pi / 4)
newnode = {
name = modname .. ":sand_raked",
name = linearname,
param2 = minetest.dir_to_facedir(dir)
}
end
local node = data.node or minetest.get_node(pos)
if node.name == newnode.name and node.param2 == newnode.param2 then
newnode = {name = sandname}
newnode = {name = basename}
end
nodecore.wear_wield(data.crafter, {snappy = 1}, 1)
return nodecore.set_loud(pos, newnode)
end
})
end
nodecore.register_raked("nc_terrain:sand", "Sand",
{groups = {sand = true, falling_repose = false}},
{"group:sand"})
nodecore.register_raked("nc_terrain:gravel", "Gravel",
{groups = {gravel = true, falling_repose = false}},
{"group:gravel"})