scaffold: improve organization, add HereScaffold

This commit is contained in:
cron 2020-11-22 01:29:56 +00:00
parent a3ec41ec99
commit 712b331c97
2 changed files with 22 additions and 15 deletions

View File

@ -41,6 +41,14 @@ function scaffold.can_place_at(pos)
return (node and (node.name == "air" or minetest.get_node_def(node.name).buildable_to))
end
-- should check if wield is placeable
-- minetest.get_node(wielded:get_name()) ~= nil should probably work
-- otherwise it equips armor and eats food
function scaffold.can_place_wielded_at(pos)
local wield_empty = minetest.localplayer:get_wielded_item():is_empty()
return not wield_empty and scaffold.can_place_at(pos)
end
function scaffold.find_any_swap(items)
for i, v in ipairs(items) do
local n = minetest.find_item(v)
@ -89,3 +97,16 @@ local mpath = minetest.get_modpath(minetest.get_current_modname())
dofile(mpath .. "/sapscaffold.lua")
dofile(mpath .. "/slowscaffold.lua")
dofile(mpath .. "/autofarm.lua")
scaffold.register_template_scaffold("CheckScaffold", "scaffold_check", function(pos)
if scaffold.can_place_wielded_at(pos) then
minetest.place_node(pos)
end
end)
scaffold.register_template_scaffold("HereScaffold", "scaffold_here", function(pos)
if scaffold.can_place_wielded_at(pos) then
minetest.place_node(pos)
end
end, {x = 0, y = 0, z = 0})

View File

@ -45,22 +45,8 @@ local function place(pos)
end
end
-- should check if wield is placeable
-- minetest.get_node(wielded:get_name()) ~= nil should probably work
-- otherwise it equips armor and eats food
local function can_place(pos)
local wield_empty = minetest.localplayer:get_wielded_item():is_empty()
return not wield_empty and scaffold.can_place_at(pos)
end
scaffold.register_template_scaffold("SlowScaffold", "scaffold_slow", function(pos)
if can_place(pos) then
if scaffold.can_place_wielded_at(pos) then
place(pos)
end
end)
scaffold.register_template_scaffold("CheckScaffold", "scaffold_check", function(pos)
if can_place(pos) then
minetest.place_node(pos)
end
end)