From 8a4ca846d90abf5732b436c1f31b72c6b52e61dc Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Sun, 17 Jun 2018 09:55:26 +0100 Subject: [PATCH] added growth_check(pos, nodename) function --- README.md | 1 + api.txt | 13 +++++++++++++ crops/cocoa.lua | 9 ++++++++- init.lua | 11 ++++++++--- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 40b55d5..99ac101 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ This mod works by adding your new plant to the {growing=1} group and numbering t ### Changelog: +- 1.37 - Added custom 'growth_check(pos, nodename) function for crop nodes to use (check cocoa.lua for example) - 1.36 - Added Beetroot, Beetroot Soup (6x beetroot, 1x bowl), fix register_plant() issue, add new recipes - 1.35 - Deprecated bronze/mese/diamond hoe's, added hoe bomb and deprecated hoe's as lucky block prizes - 1.34 - Added scarecrow Base (5x sticks in a cross shape) diff --git a/api.txt b/api.txt index 042d041..ed51214 100644 --- a/api.txt +++ b/api.txt @@ -39,3 +39,16 @@ 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. + + +### 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'. + +growth_check = function(pos, node_name) + -- check surrounding for jungle tree + if minetest.find_node_near(pos, 1, {"default:jungletree"}) then + return false -- place next growth stage + end + return true -- condition not met, skip next growth stage until next check +end, 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}, 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 })