added growth_check(pos, nodename) function

This commit is contained in:
TenPlus1 2018-06-17 09:55:26 +01:00
parent 9d6728053a
commit 8a4ca846d9
4 changed files with 30 additions and 4 deletions

View File

@ -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)

13
api.txt
View File

@ -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,

View File

@ -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},

View File

@ -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 })