Add protection support to tools
authorShadowNinja <shadowninja@minetest.net>
Tue, 17 Dec 2013 19:22:10 +0000 (14:22 -0500)
committerShadowNinja <shadowninja@minetest.net>
Tue, 17 Dec 2013 19:22:10 +0000 (14:22 -0500)
This adds support to the chainsaw, mining drill, mining laser,
sonic screwdriver, and tree tap.

technic/tools/chainsaw.lua
technic/tools/mining_drill.lua
technic/tools/mining_lasers.lua
technic/tools/sonic_screwdriver.lua
technic/tools/tree_tap.lua

index fd8ce2c799619b03adb0ee863d30b8b7126fd323..4124265cf7835b85a0c814633eabe33c0a08c8ef 100644 (file)
@@ -203,6 +203,10 @@ end
 
 -- Saw down trees entry point
 local function chainsaw_dig_it(pos, player,current_charge)
+       if minetest.is_protected(pos, player:get_player_name()) then
+               minetest.record_protection_violation(pos, player:get_player_name())
+               return current_charge
+       end
         local remaining_charge=current_charge
 
         -- Save the currently installed dropping mechanism so we can restore it.
index 79eef53bf2d6af840c223f97207f118932ea7476..d7eb49cf050765328465eaa179f47b9b7a0856ce 100644 (file)
@@ -51,6 +51,10 @@ local mining_drill_mode_text = {
 }
 
 local function drill_dig_it0 (pos,player)
+       if minetest.is_protected(pos, player:get_player_name()) then
+               minetest.record_protection_violation(pos, player:get_player_name())
+               return
+       end
        local node=minetest.env:get_node(pos)
        if node.name == "air" or node.name == "ignore" then return end
        if node.name == "default:lava_source" then return end
index 64628ebb351eb0b03fd4ce1a278888da602a4472..e06a00de58c0466c575ec8daaa256570060f1a8a 100644 (file)
@@ -60,6 +60,10 @@ local function node_tab(z, d)
 end
 
 local function laser_node(pos, player)
+       if minetest.is_protected(pos, player:get_player_name()) then
+               minetest.record_protection_violation(pos, player:get_player_name())
+               return
+       end
        local node = minetest.get_node(pos)
        if node.name == "air"
        or node.name == "ignore"
index cd2ce51b463ad0db76d5e6addeb495f71496517f..3951b8b6a8aa01164c8a956270c06334d7660569 100644 (file)
@@ -12,12 +12,16 @@ minetest.register_tool("technic:sonic_screwdriver", {
                if pointed_thing.type ~= "node" then
                        return
                end
-               local pos = minetest.get_pointed_thing_position(pointed_thing, above)
+               local pos = pointed_thing.under
+               if minetest.is_protected(pos, user:get_player_name()) then
+                       minetest.record_protection_violation(pos, user:get_player_name())
+                       return
+               end
                local node = minetest.get_node(pos)
                local node_name = node.name
                if minetest.registered_nodes[node_name].paramtype2 ~= "facedir" and
                   minetest.registered_nodes[node_name].paramtype2 ~= "wallmounted" then
-                       return itemstack
+                       return
                end
                if node.param2 == nil then
                        return
index 183a95b8217f9cedff7ed8640e7a4488ea1c3e95..ab539551aa3ebeb41b4bb8441cb7b6a777cb7a35 100644 (file)
@@ -4,37 +4,38 @@ local S = technic.getter
 minetest.register_tool("technic:treetap", {
        description = S("Tree Tap"),
        inventory_image = "technic_tree_tap.png",
-       on_use = function(itemstack,user,pointed_thing)
+       on_use = function(itemstack, user, pointed_thing)
                if pointed_thing.type ~= "node" then
                        return
                end
-               if user:get_inventory():room_for_item("main",ItemStack("technic:raw_latex")) then
-                       local pos = minetest.get_pointed_thing_position(pointed_thing,above)
-                       local node = minetest.env:get_node(pos)
-                       local node_name = node.name
-                       if node_name == "moretrees:rubber_tree_trunk" then
-                               node.name = "moretrees:rubber_tree_trunk_empty"
-                               user:get_inventory():add_item("main", ItemStack("technic:raw_latex"))
-                               minetest.set_node(pos,node)
-                               local item = itemstack:to_table()
-                               local item_wear = tonumber((item["wear"]))
-                               item_wear = item_wear + 819
-                               if item_wear > 65535 then
-                                       itemstack:clear()
-                                       return itemstack
-                               end
-                               item["wear"] = tostring(item_wear)
-                               itemstack:replace(item)
-                               return itemstack
-                       else
-                               return itemstack
-                       end
-               else
+               local inv = user:get_inventory()
+               if not inv:room_for_item("main", ItemStack("technic:raw_latex")) then
                        return
                end
+               local pos = pointed_thing.under
+               if minetest.is_protected(pos, user:get_player_name()) then
+                       minetest.record_protection_violation(pos, user:get_player_name())
+                       return
+               end
+               local node = minetest.get_node(pos)
+               local node_name = node.name
+               if node_name ~= "moretrees:rubber_tree_trunk" then
+                       return
+               end
+               node.name = "moretrees:rubber_tree_trunk_empty"
+               inv:add_item("main", ItemStack("technic:raw_latex"))
+               minetest.swap_node(pos, node)
+               local item_wear = tonumber(itemstack:get_wear())
+               item_wear = item_wear + 819
+               if item_wear > 65535 then
+                       itemstack:clear()
+                       return itemstack
+               end
+               itemstack:set_wear(item_wear)
+               return itemstack
        end,
 })
-     
+
 minetest.register_craft({
        output = "technic:treetap",
        recipe = {