Update api.lua
authorcodeandfix <F.Maier78@discardmail.com>
Tue, 2 Sep 2014 18:40:06 +0000 (20:40 +0200)
committerparamat <mat.gregory@virginmedia.com>
Tue, 29 Sep 2015 20:01:20 +0000 (21:01 +0100)
added protection for seed placement and hoeing

mods/farming/api.lua

index 4b6f5617b62f782d0738163ec5da8755efda1770..7123cbc1b66c4e273ea01427d0fa2979025c76a9 100644 (file)
@@ -38,6 +38,16 @@ farming.hoe_on_use = function(itemstack, user, pointed_thing, uses)
                return
        end
        
+       if minetest.is_protected(pt.under, user:get_player_name()) then
+               minetest.record_protection_violation(pt.under, user:get_player_name())
+               return
+       end
+       if minetest.is_protected(pt.above, user:get_player_name()) then
+               minetest.record_protection_violation(pt.above, user:get_player_name())
+               return
+       end
+
+       
        -- turn the node into soil, wear out item and play sound
        minetest.set_node(pt.under, {name = regN[under.name].soil.dry})
        minetest.sound_play("default_dig_crumbly", {
@@ -123,6 +133,16 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
        local under = minetest.get_node(pt.under)
        local above = minetest.get_node(pt.above)
        
+       if minetest.is_protected(pt.under, placer:get_player_name()) then
+               minetest.record_protection_violation(pt.under, placer:get_player_name())
+               return
+       end
+       if minetest.is_protected(pt.above, placer:get_player_name()) then
+               minetest.record_protection_violation(pt.above, placer:get_player_name())
+               return
+       end
+
+       
        -- return if any of the nodes is not registered
        if not minetest.registered_nodes[under.name] then
                return