~fgaz/minetest-extruder

986b6582e2356f67f0e1ab77f1333aad40d7f307 — Francesco Gazzetta 1 year, 6 months ago 69db0f2
Add "extruder" privilege required to use the tool
1 files changed, 13 insertions(+), 1 deletions(-)

M init.lua
M init.lua => init.lua +13 -1
@@ 1,6 1,8 @@
local modname = "extruder"
extruder = {}

minetest.register_privilege("extruder")

-- TODO look into integrating with stuff like worldedit undo

-- Get the four unit vectors parallel to axes that are perpendicular to a given one (also parallel to an axis)


@@ 67,6 69,16 @@ local function extrude(surface, direction)
  end
end

local function check_privs_with_msg(player_or_name)
  local success, missing_privs = minetest.check_player_privs(player_or_name, "extruder")
  if not success then
    local player_name = type(player_or_name) == "string" and player_or_name or player_or_name:get_player_name()
    minetest.chat_send_player(player_name, modname .. ": Missing privileges: extruder")
    return false
  end
  return true
end

minetest.register_tool(modname .. ":extruder", {
  description = "Extruder tool\nClick to extrude a surface, right click to adjust options",
  inventory_image = "extruder.png",


@@ 75,7 87,7 @@ minetest.register_tool(modname .. ":extruder", {
  -- MAYBE switch to on_place since a node should be pointed?
  on_use = function(_, placer, pointed_thing)
    if placer == nil or pointed_thing == nil then return end
    -- TODO check for permissions
    if not check_privs_with_msg(placer) then return end
    if pointed_thing.type == "node" then
      local direction = vector.direction(pointed_thing.under, pointed_thing.above)
      local surface = visit(pointed_thing.under, direction)