functional sweeper [WIP]

This commit is contained in:
codexp 2018-07-14 03:20:03 +02:00
parent 10dd84a7f1
commit 7dc8ca812e
3 changed files with 59 additions and 7 deletions

View File

@ -24,6 +24,19 @@ moreblocks.intllib = S
local modpath = minetest.get_modpath("moreblocks")
function moreblocks.check_protection(pos, name, tool, text)
if minetest.is_protected(pos, name) then
minetest.log("action", (name ~= "" and name or "A mod")
.. " tried to " .. text
.. " at protected position "
.. minetest.pos_to_string(pos)
.. " with a " .. (tool or ""))
minetest.record_protection_violation(pos, name)
return true
end
return false
end
dofile(modpath .. "/config.lua")
dofile(modpath .. "/circular_saw.lua")
dofile(modpath .. "/stairsplus/init.lua")
@ -31,6 +44,7 @@ dofile(modpath .. "/nodes.lua")
dofile(modpath .. "/redefinitions.lua")
dofile(modpath .. "/crafting.lua")
dofile(modpath .. "/aliases.lua")
dofile(modpath .. "/sweeper.lua")
if minetest.settings:get_bool("log_mods") then
minetest.log("action", S("[moreblocks] loaded."))

View File

@ -472,10 +472,3 @@ for name, def in pairs(nodes) do
})
end
end
-- Items
minetest.register_craftitem("moreblocks:sweeper", {
description = S("Sweeper"),
inventory_image = "moreblocks_sweeper.png",
})

45
sweeper.lua Normal file
View File

@ -0,0 +1,45 @@
local S = moreblocks.intllib
local check_protection = moreblocks.check_protection
local sweepables = {}
-- example sweepable node
-- TODO API for sweepable node registration
sweepables["default:mossycobble"] = function(pos, node)
-- hit 3 times to clean
if node.param1 < 2 then
node.param1 = node.param1 + 1
minetest.set_node(pos, node)
return false
end
-- set clean node
minetest.set_node(pos, { name = "default:cobble" })
return true
end
-- functional sweeper
minetest.register_craftitem("moreblocks:sweeper", {
description = S("Sweeper"),
inventory_image = "moreblocks_sweeper.png",
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then
-- do nothing if it's not a node
return
end
local node = minetest.get_node(pointed_thing.under)
local sweepable = sweepables[node.name]
if not sweepable then
return
end
if check_protection(pointed_thing.under, user:get_player_name(), "sweeper", "sweep " .. node.name) then
return
end
sweepable(pointed_thing.under, node)
end
})