forked from mtcontrib/farming
added player checks for crop placement
This commit is contained in:
parent
8a4ca846d9
commit
1018a558d2
1
api.txt
1
api.txt
@ -40,7 +40,6 @@ The farming API allows you to easily register plants and hoes.
|
|||||||
|
|
||||||
Note: Any crops registered with the above function will use the new growing routines, also if crops are manually added with the {growing=1} group they will also grow.
|
Note: Any crops registered with the above function will use the new growing routines, also if crops are manually added with the {growing=1} group they will also grow.
|
||||||
|
|
||||||
|
|
||||||
### Crop functions
|
### Crop functions
|
||||||
|
|
||||||
If a mod registers nodes to be used as crops using the {growing=1} group then an additional function can be used for custom growth checks instead of the standard 'are we above wet soil'.
|
If a mod registers nodes to be used as crops using the {growing=1} group then an additional function can be used for custom growth checks instead of the standard 'are we above wet soil'.
|
||||||
|
@ -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?
|
-- am I right-clicking on something that has a custom on_place set?
|
||||||
-- thanks to Krock for helping with this issue :)
|
-- thanks to Krock for helping with this issue :)
|
||||||
local def = minetest.registered_nodes[under.name]
|
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)
|
return def.on_rightclick(pt.under, under, placer, itemstack)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- is player planting crop?
|
||||||
|
local name = placer:get_player_name() or ""
|
||||||
|
|
||||||
-- check for protection
|
-- check for protection
|
||||||
if minetest.is_protected(pt.under, placer:get_player_name()) then
|
if minetest.is_protected(pt.under, name) then
|
||||||
return
|
return
|
||||||
end
|
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})
|
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()
|
itemstack:take_item()
|
||||||
|
|
||||||
|
@ -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?
|
-- am I right-clicking on something that has a custom on_place set?
|
||||||
-- thanks to Krock for helping with this issue :)
|
-- thanks to Krock for helping with this issue :)
|
||||||
local def = minetest.registered_nodes[under.name]
|
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)
|
return def.on_rightclick(pt.under, under, placer, itemstack)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -31,8 +31,11 @@ local function place_cocoa(itemstack, placer, pointed_thing, plantname)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- is player planting crop?
|
||||||
|
local name = placer:get_player_name() or ""
|
||||||
|
|
||||||
-- check for protection
|
-- check for protection
|
||||||
if minetest.is_protected(pt.above, placer:get_player_name()) then
|
if minetest.is_protected(pt.above, name) then
|
||||||
return
|
return
|
||||||
end
|
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})
|
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()
|
itemstack:take_item()
|
||||||
|
|
||||||
|
@ -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?
|
-- am I right-clicking on something that has a custom on_place set?
|
||||||
-- thanks to Krock for helping with this issue :)
|
-- thanks to Krock for helping with this issue :)
|
||||||
local def = minetest.registered_nodes[under.name]
|
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)
|
return def.on_rightclick(pt.under, under, placer, itemstack)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- is player planting seed?
|
||||||
|
local name = placer:get_player_name() or ""
|
||||||
|
|
||||||
-- check for protection
|
-- check for protection
|
||||||
if minetest.is_protected(pt.under, placer:get_player_name()) then
|
if minetest.is_protected(pt.under, name) then
|
||||||
return
|
return
|
||||||
end
|
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})
|
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()
|
itemstack:take_item()
|
||||||
|
|
||||||
|
9
init.lua
9
init.lua
@ -419,7 +419,7 @@ function farming.place_seed(itemstack, placer, pointed_thing, plantname)
|
|||||||
-- am I right-clicking on something that has a custom on_place set?
|
-- am I right-clicking on something that has a custom on_place set?
|
||||||
-- thanks to Krock for helping with this issue :)
|
-- thanks to Krock for helping with this issue :)
|
||||||
local def = minetest.registered_nodes[under.name]
|
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)
|
return def.on_rightclick(pt.under, under, placer, itemstack)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -444,8 +444,11 @@ function farming.place_seed(itemstack, placer, pointed_thing, plantname)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- is player planting seed?
|
||||||
|
local name = placer:get_player_name() or ""
|
||||||
|
|
||||||
-- if not protected then add node and remove 1 item from the itemstack
|
-- if not protected then add node and remove 1 item from the itemstack
|
||||||
if not minetest.is_protected(pt.above, placer:get_player_name()) then
|
if not minetest.is_protected(pt.above, name) then
|
||||||
|
|
||||||
local p2 = minetest.registered_nodes[plantname].place_param2 or 1
|
local p2 = minetest.registered_nodes[plantname].place_param2 or 1
|
||||||
|
|
||||||
@ -455,7 +458,7 @@ function farming.place_seed(itemstack, placer, pointed_thing, plantname)
|
|||||||
|
|
||||||
minetest.sound_play("default_place_node", {pos = pt.above, gain = 1.0})
|
minetest.sound_play("default_place_node", {pos = pt.above, gain = 1.0})
|
||||||
|
|
||||||
if not placer or not farming.is_creative(placer:get_player_name()) then
|
if placer and not farming.is_creative(placer:get_player_name()) then
|
||||||
|
|
||||||
local name = itemstack:get_name()
|
local name = itemstack:get_name()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user