summaryrefslogtreecommitdiff
path: root/crops
diff options
context:
space:
mode:
Diffstat (limited to 'crops')
-rw-r--r--crops/beans.lua9
-rw-r--r--crops/cocoa.lua9
-rw-r--r--crops/grapes.lua9
3 files changed, 18 insertions, 9 deletions
diff --git a/crops/beans.lua b/crops/beans.lua
index 888a0a1..61b195b 100644
--- a/crops/beans.lua
+++ b/crops/beans.lua
@@ -27,12 +27,15 @@ local function place_beans(itemstack, placer, pointed_thing, plantname)
-- am I right-clicking on something that has a custom on_place set?
-- thanks to Krock for helping with this issue :)
local def = minetest.registered_nodes[under.name]
- if def and def.on_rightclick then
+ if placer and def and def.on_rightclick then
return def.on_rightclick(pt.under, under, placer, itemstack)
end
+ -- is player planting crop?
+ local name = placer:get_player_name() or ""
+
-- check for protection
- if minetest.is_protected(pt.under, placer:get_player_name()) then
+ if minetest.is_protected(pt.under, name) then
return
end
@@ -46,7 +49,7 @@ local function place_beans(itemstack, placer, pointed_thing, plantname)
minetest.sound_play("default_place_node", {pos = pt.under, gain = 1.0})
- if not farming.is_creative(placer:get_player_name()) then
+ if placer or not farming.is_creative(placer:get_player_name()) then
itemstack:take_item()
diff --git a/crops/cocoa.lua b/crops/cocoa.lua
index 1510b3a..8424db4 100644
--- a/crops/cocoa.lua
+++ b/crops/cocoa.lua
@@ -21,7 +21,7 @@ local function place_cocoa(itemstack, placer, pointed_thing, plantname)
-- am I right-clicking on something that has a custom on_place set?
-- thanks to Krock for helping with this issue :)
local def = minetest.registered_nodes[under.name]
- if def and def.on_rightclick then
+ if placer and def and def.on_rightclick then
return def.on_rightclick(pt.under, under, placer, itemstack)
end
@@ -31,8 +31,11 @@ local function place_cocoa(itemstack, placer, pointed_thing, plantname)
return
end
+ -- is player planting crop?
+ local name = placer:get_player_name() or ""
+
-- check for protection
- if minetest.is_protected(pt.above, placer:get_player_name()) then
+ if minetest.is_protected(pt.above, name) then
return
end
@@ -41,7 +44,7 @@ local function place_cocoa(itemstack, placer, pointed_thing, plantname)
minetest.sound_play("default_place_node", {pos = pt.above, gain = 1.0})
- if not farming.is_creative(placer:get_player_name()) then
+ if placer and not farming.is_creative(placer:get_player_name()) then
itemstack:take_item()
diff --git a/crops/grapes.lua b/crops/grapes.lua
index 8b0ae2a..8781ece 100644
--- a/crops/grapes.lua
+++ b/crops/grapes.lua
@@ -22,12 +22,15 @@ local function place_grapes(itemstack, placer, pointed_thing, plantname)
-- am I right-clicking on something that has a custom on_place set?
-- thanks to Krock for helping with this issue :)
local def = minetest.registered_nodes[under.name]
- if def and def.on_rightclick then
+ if placer and def and def.on_rightclick then
return def.on_rightclick(pt.under, under, placer, itemstack)
end
+ -- is player planting seed?
+ local name = placer:get_player_name() or ""
+
-- check for protection
- if minetest.is_protected(pt.under, placer:get_player_name()) then
+ if minetest.is_protected(pt.under, name) then
return
end
@@ -41,7 +44,7 @@ local function place_grapes(itemstack, placer, pointed_thing, plantname)
minetest.sound_play("default_place_node", {pos = pt.under, gain = 1.0})
- if not farming.is_creative(placer:get_player_name()) then
+ if placer and not farming.is_creative(placer:get_player_name()) then
itemstack:take_item()