diff --git a/df_dependencies/nodes.lua b/df_dependencies/nodes.lua index 2372547..b40b442 100644 --- a/df_dependencies/nodes.lua +++ b/df_dependencies/nodes.lua @@ -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_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_string = select_required({"farming:string", "mcl_mobitems:string"}) diff --git a/df_farming/growth_conditions.lua b/df_farming/growth_conditions.lua index c65d441..65bb2ca 100644 --- a/df_farming/growth_conditions.lua +++ b/df_farming/growth_conditions.lua @@ -1,13 +1,44 @@ 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) return growable[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name] 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: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: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:plump_helmet_spawn"] = check_farm_plant_soil \ No newline at end of file +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 \ No newline at end of file diff --git a/df_farming/init.lua b/df_farming/init.lua index 5e96c59..6596db1 100644 --- a/df_farming/init.lua +++ b/df_farming/init.lua @@ -9,6 +9,7 @@ dofile(modpath.."/doc.lua") dofile(modpath.."/aliases.lua") dofile(modpath.."/plants.lua") -- general functions +dofile(modpath.."/growth_conditions.lua") dofile(modpath.."/cave_wheat.lua") dofile(modpath.."/dimple_cup.lua") dofile(modpath.."/pig_tail.lua") @@ -16,4 +17,3 @@ dofile(modpath.."/plump_helmet.lua") dofile(modpath.."/quarry_bush.lua") dofile(modpath.."/sweet_pod.lua") dofile(modpath.."/cooking.lua") -dofile(modpath.."/growth_conditions.lua") \ No newline at end of file diff --git a/df_farming/plants.lua b/df_farming/plants.lua index 53c89ce..bf62ab8 100644 --- a/df_farming/plants.lua +++ b/df_farming/plants.lua @@ -74,18 +74,17 @@ end ----------------------------------------------------------------------------------------- -local marginal = {[df_dependencies.node_name_dirt] = true} -local growable = {[df_dependencies.node_name_dirt_wet] = true, [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} df_farming.plant_timer = function(pos, plantname, elapsed) local next_stage_time = minetest.registered_nodes[plantname]._dfcaverns_next_stage_time 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 below = minetest.get_node(vector.add(pos, {x=0, y=-1, z=0})) - if marginal[below.name] then - next_stage_time = next_stage_time * 5 - end + local growable_factor = df_farming.growth_factor(plantname, pos) or 1 + + next_stage_time = (next_stage_time + math.random(next_stage_time * -0.1, next_stage_time * 0.1)) / growable_factor + if elapsed ~= nil then minetest.get_node_timer(pos):set(next_stage_time, elapsed-next_stage_time) else @@ -142,17 +141,17 @@ local place_seed = function(itemstack, placer, pointed_thing, plantname) return itemstack 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 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}) - - 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) - else - minetest.get_node_timer(pt.above):stop() -- make sure no old timers are running on this node - end + df_farming.plant_timer(pt.above, plantname) -- Run script hook 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 next_stage = node_def._dfcaverns_next_stage if next_stage then - local soil = minetest.get_node(vector.add(pos, {x=0, y=-1, z=0})).name - if growable[soil] then + if df_farming.growth_factor(plant_name, pos) then local next_def = minetest.registered_nodes[next_stage] local node = minetest.get_node(pos) minetest.swap_node(pos, {name=next_stage, param2 = next_def.place_param2 or node.param2}) df_farming.plant_timer(pos, next_stage, elapsed) 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