From 8a4ca846d90abf5732b436c1f31b72c6b52e61dc Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Sun, 17 Jun 2018 09:55:26 +0100 Subject: added growth_check(pos, nodename) function --- init.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 8baf53e..8c92ce7 100644 --- a/init.lua +++ b/init.lua @@ -7,7 +7,7 @@ farming = {} farming.mod = "redo" -farming.version = "20180609" +farming.version = "20180617" farming.path = minetest.get_modpath("farming") farming.select = { type = "fixed", @@ -301,11 +301,16 @@ function farming.plant_growth_timer(pos, elapsed, node_name) return false end - if stages.plant_name == "farming:cocoa" then + -- custom growth check + local chk = minetest.registered_nodes[node_name].growth_check - if not minetest.find_node_near(pos, 1, {"default:jungletree"}) then + if chk then + + if chk(pos, node_name) then return true end + + -- otherwise check for wet soil beneath crop else local under = minetest.get_node({ x = pos.x, y = pos.y - 1, z = pos.z }) -- cgit v1.2.3 From 1018a558d2b92eb5cdba657c0f6367243c1b85a8 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Tue, 19 Jun 2018 18:36:00 +0100 Subject: added player checks for crop placement --- init.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 8c92ce7..4f5f2be 100644 --- a/init.lua +++ b/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? -- 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 @@ -444,8 +444,11 @@ function farming.place_seed(itemstack, placer, pointed_thing, plantname) return 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 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 @@ -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}) - 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() -- cgit v1.2.3 From 10abb996c10c310f8cea66e7e085b852897a0a23 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Tue, 19 Jun 2018 18:42:13 +0100 Subject: nil check --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 4f5f2be..038ba6d 100644 --- a/init.lua +++ b/init.lua @@ -445,7 +445,7 @@ function farming.place_seed(itemstack, placer, pointed_thing, plantname) end -- is player planting seed? - local name = placer:get_player_name() or "" + local name = placer and placer:get_player_name() or "" -- if not protected then add node and remove 1 item from the itemstack if not minetest.is_protected(pt.above, name) then -- cgit v1.2.3