Skip to content

Commit

Permalink
Added new param soil_group to plant def
Browse files Browse the repository at this point in the history
  • Loading branch information
ssdaniel24 committed Jun 11, 2024
1 parent 5116192 commit 4b50088
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion game_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ The farming API allows you to easily register plants and hoes.
steps = 8, -- How many steps the plant has to grow, until it can be harvested
-- ^ Always provide a plant texture for each step, format: modname_plantname_i.png (i = stepnumber)
minlight = 13, -- Minimum light to grow
maxlight = default.LIGHT_MAX -- Maximum light to grow
maxlight = default.LIGHT_MAX, -- Maximum light to grow
soil_group = "soil" -- Soil node group where plant can grow ("soil" by default)
}


Expand Down
9 changes: 6 additions & 3 deletions mods/farming/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ local function tick_again(pos)
end

-- Seed placement
farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
farming.place_seed = function(itemstack, placer, pointed_thing, plantname, soil_group)
local pt = pointed_thing
-- check if pointing at a node
if not pt then
Expand Down Expand Up @@ -173,7 +173,7 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
end

-- check if pointing at soil
if minetest.get_item_group(under.name, "soil") < 2 then
if minetest.get_item_group(under.name, soil_group) < 2 then
return itemstack
end

Expand Down Expand Up @@ -279,6 +279,9 @@ farming.register_plant = function(name, def)
if not def.fertility then
def.fertility = {}
end
if not def.soil_group then
def.soil_group = "soil"
end

farming.registered_plants[pname] = def

Expand Down Expand Up @@ -322,7 +325,7 @@ farming.register_plant = function(name, def)
pointed_thing) or itemstack
end

return farming.place_seed(itemstack, placer, pointed_thing, mname .. ":seed_" .. pname)
return farming.place_seed(itemstack, placer, pointed_thing, mname .. ":seed_" .. pname, def.soil_group)
end,
next_plant = mname .. ":" .. pname .. "_1",
on_timer = farming.grow_plant,
Expand Down

0 comments on commit 4b50088

Please sign in to comment.