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 --- crops/cocoa.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'crops/cocoa.lua') diff --git a/crops/cocoa.lua b/crops/cocoa.lua index 71d038e..1510b3a 100644 --- a/crops/cocoa.lua +++ b/crops/cocoa.lua @@ -124,7 +124,13 @@ local crop_def = { snappy = 3, flammable = 2, plant = 1, growing = 1, not_in_creative_inventory=1, leafdecay = 1, leafdecay_drop = 1 }, - sounds = default.node_sound_leaves_defaults() + sounds = default.node_sound_leaves_defaults(), + growth_check = function(pos, node_name) + if minetest.find_node_near(pos, 1, {"default:jungletree"}) then + return false + end + return true + end, } -- stage 1 @@ -146,6 +152,7 @@ minetest.register_node("farming:cocoa_3", table.copy(crop_def)) -- stage 4 (final) crop_def.tiles = {"farming_cocoa_4.png"} crop_def.groups.growing = 0 +crop_def.growth_check = nil crop_def.drop = { items = { {items = {'farming:cocoa_beans 2'}, rarity = 1}, -- 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 --- crops/cocoa.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'crops/cocoa.lua') 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() -- 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 --- crops/cocoa.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crops/cocoa.lua') diff --git a/crops/cocoa.lua b/crops/cocoa.lua index 8424db4..19e9c6b 100644 --- a/crops/cocoa.lua +++ b/crops/cocoa.lua @@ -32,7 +32,7 @@ local function place_cocoa(itemstack, placer, pointed_thing, plantname) end -- is player planting crop? - local name = placer:get_player_name() or "" + local name = placer and placer:get_player_name() or "" -- check for protection if minetest.is_protected(pt.above, name) then -- cgit v1.2.3