Let the Land Clear tools replacement block be selectable

This commit is contained in:
Valentin Anger 2018-09-21 13:20:24 +02:00
parent a0257bfb22
commit c64b6cd83b

View File

@ -1,4 +1,4 @@
local function process(itemstack, curr)
local function process(itemstack, curr, node)
local meta = itemstack:get_meta()
local last = meta:to_table().fields
if last.x then
@ -11,7 +11,7 @@ local function process(itemstack, curr)
for y = 0,ymax-ymin do
for x = xmin,xmax do
for z = zmin,zmax do
minetest.set_node({x=x,y=ymax-y,z=z}, {name="air"})
minetest.set_node({x=x,y=ymax-y,z=z}, {name=node})
end
end
end
@ -22,6 +22,20 @@ local function process(itemstack, curr)
return itemstack
end
minetest.register_chatcommand("fillblock", {
desc = "Set the fill block for the Land Clear tool",
params = "nodestring",
func = function (name, param)
local player = minetest.get_player_by_name(name)
if player then
player:set_attribute("sparkdebug_clearnode", param)
return true, "It is done."
else
return false, "Player not online."
end
end
})
minetest.register_tool("sparkdebug:landclear", {
description = "Land Clear",
inventory_image = "landclear.png",
@ -29,11 +43,11 @@ minetest.register_tool("sparkdebug:landclear", {
range = 50.0,
on_use = function(itemstack, player, pointed_thing)
if pointed_thing["type"] == "node" then
return process(itemstack, pointed_thing.under)
return process(itemstack, pointed_thing.under, player:get_attribute("sparkdebug_clearnode") or "air")
end
return itemstack
end,
on_place = function(itemstack, placer, pointed_thing)
return process(itemstack, placer:get_pos())
return process(itemstack, placer:get_pos(), placer:get_attribute("sparkdebug_clearnode") or "air")
end
})