updating farming growth logic

Quarry bushes now require sand, since they're found in blood thorn caverns
Also, I think I've got the timers working better for marginal soil. Marginal soil conditions are controlled centrally through the growth_condition functions.
This commit is contained in:
FaceDeer 2023-02-04 20:42:54 -07:00
parent 22be60bdeb
commit fe203d0ca0
4 changed files with 54 additions and 22 deletions

View File

@ -77,6 +77,8 @@ df_dependencies.node_name_copperblock = select_required({"default:copperblock",
df_dependencies.node_name_dirt_furrowed = select_required({"farming:soil", "mcl_farming:soil"}) df_dependencies.node_name_dirt_furrowed = select_required({"farming:soil", "mcl_farming:soil"})
df_dependencies.node_name_dirt_wet = select_required({"farming:soil_wet", "mcl_farming:soil_wet"}) df_dependencies.node_name_dirt_wet = select_required({"farming:soil_wet", "mcl_farming:soil_wet"})
df_dependencies.node_name_desert_sand_soil_wet = select_required({"farming:desert_sand_soil_wet", "mcl_core:redsand"}) -- TODO: this is much easier in MCL due to the lack of wetted sand, see if there's a way to fix this
df_dependencies.node_name_desert_sand_soil_dry = select_required({"farming:desert_sand_soil", "mcl_core:redsand"})
--df_dependencies.node_name_mortar_pestle = select_optional({"farming:mortar_pestle"}) -- TODO where did this go? --df_dependencies.node_name_mortar_pestle = select_optional({"farming:mortar_pestle"}) -- TODO where did this go?
df_dependencies.node_name_string = select_required({"farming:string", "mcl_mobitems:string"}) df_dependencies.node_name_string = select_required({"farming:string", "mcl_mobitems:string"})

View File

@ -1,13 +1,44 @@
df_farming.growth_permitted = {} df_farming.growth_permitted = {}
local growable = {[df_dependencies.node_name_dirt_wet] = true, [df_dependencies.node_name_dirt] = true} local growable = {
[df_dependencies.node_name_dirt_wet] = 1,
[df_dependencies.node_name_dirt] = 0.2,
}
local sand = {
[df_dependencies.node_name_desert_sand_soil_wet] = 1,
[df_dependencies.node_name_desert_sand] = 0.2,
[df_dependencies.node_name_sand] = 0.2,
[df_dependencies.node_name_silver_sand] = 0.2,
[df_dependencies.node_name_desert_sand_soil_dry] = 0.2,
}
local check_farm_plant_soil = function(pos) local check_farm_plant_soil = function(pos)
return growable[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name] return growable[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name]
end end
local check_sand_plant_soil = function(pos)
return sand[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name]
end
df_farming.growth_permitted["df_farming:cave_wheat_seed"] = check_farm_plant_soil df_farming.growth_permitted["df_farming:cave_wheat_seed"] = check_farm_plant_soil
df_farming.growth_permitted["df_farming:dimple_cup_seed"] = check_farm_plant_soil df_farming.growth_permitted["df_farming:dimple_cup_seed"] = check_farm_plant_soil
df_farming.growth_permitted["df_farming:pig_tail_seed"] = check_farm_plant_soil df_farming.growth_permitted["df_farming:pig_tail_seed"] = check_farm_plant_soil
df_farming.growth_permitted["df_farming:quarry_bush_seed"] = check_farm_plant_soil df_farming.growth_permitted["df_farming:quarry_bush_seed"] = check_sand_plant_soil
df_farming.growth_permitted["df_farming:sweet_pod_seed"] = check_farm_plant_soil df_farming.growth_permitted["df_farming:sweet_pod_seed"] = check_farm_plant_soil
df_farming.growth_permitted["df_farming:plump_helmet_spawn"] = check_farm_plant_soil df_farming.growth_permitted["df_farming:plump_helmet_spawn"] = check_farm_plant_soil
local trunc_to_full = {
["df_farming:cav"] = "df_farming:cave_wheat_seed",
["df_farming:dim"] = "df_farming:dimple_cup_seed",
["df_farming:pig"] = "df_farming:pig_tail_seed",
["df_farming:qua"] = "df_farming:quarry_bush_seed",
["df_farming:swe"] = "df_farming:sweet_pod_seed",
["df_farming:plu"] = "df_farming:plump_helmet_spawn"
}
df_farming.growth_factor = function(plantname, pos)
local trunc_name = trunc_to_full[string.sub(plantname, 1, 14)]
if not trunc_name then
minetest.log("error", "[df_farming] failed to find growth condition function for " .. plantname)
return
end
return df_farming.growth_permitted[trunc_name](pos)
end

View File

@ -9,6 +9,7 @@ dofile(modpath.."/doc.lua")
dofile(modpath.."/aliases.lua") dofile(modpath.."/aliases.lua")
dofile(modpath.."/plants.lua") -- general functions dofile(modpath.."/plants.lua") -- general functions
dofile(modpath.."/growth_conditions.lua")
dofile(modpath.."/cave_wheat.lua") dofile(modpath.."/cave_wheat.lua")
dofile(modpath.."/dimple_cup.lua") dofile(modpath.."/dimple_cup.lua")
dofile(modpath.."/pig_tail.lua") dofile(modpath.."/pig_tail.lua")
@ -16,4 +17,3 @@ dofile(modpath.."/plump_helmet.lua")
dofile(modpath.."/quarry_bush.lua") dofile(modpath.."/quarry_bush.lua")
dofile(modpath.."/sweet_pod.lua") dofile(modpath.."/sweet_pod.lua")
dofile(modpath.."/cooking.lua") dofile(modpath.."/cooking.lua")
dofile(modpath.."/growth_conditions.lua")

View File

@ -74,18 +74,17 @@ end
----------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------
local marginal = {[df_dependencies.node_name_dirt] = true} --local marginal = {[df_dependencies.node_name_dirt] = true}
local growable = {[df_dependencies.node_name_dirt_wet] = true, [df_dependencies.node_name_dirt] = true} --local growable = {[df_dependencies.node_name_dirt_wet] = true, [df_dependencies.node_name_dirt] = true}
df_farming.plant_timer = function(pos, plantname, elapsed) df_farming.plant_timer = function(pos, plantname, elapsed)
local next_stage_time = minetest.registered_nodes[plantname]._dfcaverns_next_stage_time local next_stage_time = minetest.registered_nodes[plantname]._dfcaverns_next_stage_time
if not next_stage_time then return end if not next_stage_time then return end
next_stage_time = next_stage_time + math.random(next_stage_time * -0.1, next_stage_time * 0.1) local growable_factor = df_farming.growth_factor(plantname, pos) or 1
local below = minetest.get_node(vector.add(pos, {x=0, y=-1, z=0}))
if marginal[below.name] then next_stage_time = (next_stage_time + math.random(next_stage_time * -0.1, next_stage_time * 0.1)) / growable_factor
next_stage_time = next_stage_time * 5
end
if elapsed ~= nil then if elapsed ~= nil then
minetest.get_node_timer(pos):set(next_stage_time, elapsed-next_stage_time) minetest.get_node_timer(pos):set(next_stage_time, elapsed-next_stage_time)
else else
@ -142,17 +141,17 @@ local place_seed = function(itemstack, placer, pointed_thing, plantname)
return itemstack return itemstack
end end
-- if the plant can't grow here, don't permit the seed to be placed
local growth_permitted_function = df_farming.growth_permitted[plantname]
if not growth_permitted_function or not growth_permitted_function(pt.above) then
return itemstack
end
-- add the node and remove 1 item from the itemstack -- add the node and remove 1 item from the itemstack
local newnode= {name = itemstack:get_name(), param2 = 1, param1=0} local newnode= {name = itemstack:get_name(), param2 = 1, param1=0}
local oldnode= minetest.get_node(pt.above) local oldnode= above
minetest.add_node(pt.above, {name = plantname, param2 = 1}) minetest.add_node(pt.above, {name = plantname, param2 = 1})
local growth_permitted_function = df_farming.growth_permitted[plantname]
if not growth_permitted_function or growth_permitted_function(pt.above) then
df_farming.plant_timer(pt.above, plantname) df_farming.plant_timer(pt.above, plantname)
else
minetest.get_node_timer(pt.above):stop() -- make sure no old timers are running on this node
end
-- Run script hook -- Run script hook
local take_item = true local take_item = true
@ -226,14 +225,14 @@ df_farming.grow_underground_plant = function(pos, plant_name, elapsed)
local node_def = minetest.registered_nodes[plant_name] local node_def = minetest.registered_nodes[plant_name]
local next_stage = node_def._dfcaverns_next_stage local next_stage = node_def._dfcaverns_next_stage
if next_stage then if next_stage then
local soil = minetest.get_node(vector.add(pos, {x=0, y=-1, z=0})).name if df_farming.growth_factor(plant_name, pos) then
if growable[soil] then
local next_def = minetest.registered_nodes[next_stage] local next_def = minetest.registered_nodes[next_stage]
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
minetest.swap_node(pos, {name=next_stage, param2 = next_def.place_param2 or node.param2}) minetest.swap_node(pos, {name=next_stage, param2 = next_def.place_param2 or node.param2})
df_farming.plant_timer(pos, next_stage, elapsed) df_farming.plant_timer(pos, next_stage, elapsed)
else else
df_farming.plant_timer(pos, plant_name) -- reset timer, check again later df_farming.plant_timer(pos, plant_name) -- not growable substrate. Since the seed was allowed it once *was* growable,
-- so maybe it will be again some day. reset timer, check again later
end end
end end
end end