Refactor rp_farming

This commit is contained in:
Wuzzy 2022-05-04 19:12:01 +02:00
parent 75812fb9e6
commit d75335e10f
2 changed files with 39 additions and 28 deletions

View File

@ -85,20 +85,26 @@ function farming.place_plant(itemstack, placer, pointed_thing)
return itemstack
end
function farming.next_stage(pos, under, underdef, name, plant)
-- Grow plant to next stage.
-- Returns true if plant has grown, false if not (e.g. because of max stage)
function farming.next_stage(pos, plant_name)
local my_node = minetest.get_node(pos)
if my_node.name == name .. "_1" then
minetest.set_node(pos, {name = name .. "_2"})
elseif my_node.name == name .. "_2" then
minetest.set_node(pos, {name = name .. "_3"})
elseif my_node.name == name .. "_3" then
minetest.set_node(pos, {name = name .. "_4"})
if my_node.name == plant_name .. "_1" then
minetest.set_node(pos, {name = plant_name .. "_2"})
return true
elseif my_node.name == plant_name .. "_2" then
minetest.set_node(pos, {name = plant_name .. "_3"})
return true
elseif my_node.name == plant_name .. "_3" then
minetest.set_node(pos, {name = plant_name .. "_4"})
-- Stop the timer on the node so no more growing occurs until needed
minetest.get_node_timer(pos):stop()
return true
end
return false
end
function farming.grow_plant(pos, name)
@ -129,16 +135,13 @@ function farming.grow_plant(pos, name)
-- Grow and check for rain and fertilizer
local under = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
local underdef = minetest.registered_nodes[under.name]
farming.next_stage(pos, under, underdef, name, plant)
farming.next_stage(pos, name)
if minetest.get_item_group(under.name, "plantable_fertilizer") > 0 then
farming.next_stage(pos, under, underdef, name, plant)
farming.next_stage(pos, name)
end
if weather.weather == "storm" then
farming.next_stage(pos, under, underdef, name, plant)
farming.next_stage(pos, name)
end
end

View File

@ -27,8 +27,9 @@ minetest.register_node(
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
},
groups = {snappy=3, handy=2, attached_node=1, seed=1},
sounds=rp_sounds.node_sound_leaves_defaults()
groups = {snappy=3, handy=2, attached_node=1, seed=1, farming_plant=1, plant_wheat=1},
sounds=rp_sounds.node_sound_leaves_defaults(),
_rp_farming_plant_name = "rp_farming:wheat",
}
)
@ -54,8 +55,9 @@ minetest.register_node(
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
},
groups = {snappy=3, handy=2, attached_node=1, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds=rp_sounds.node_sound_leaves_defaults()
groups = {snappy=3, handy=2, attached_node=1, farming_plant=1, plant_wheat=2, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds=rp_sounds.node_sound_leaves_defaults(),
_rp_farming_plant_name = "rp_farming:wheat",
}
)
@ -81,8 +83,9 @@ minetest.register_node(
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
},
groups = {snappy=3, handy=2, attached_node=1, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds=rp_sounds.node_sound_leaves_defaults()
groups = {snappy=3, handy=2, attached_node=1, farming_plant=1, plant_wheat=3, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds=rp_sounds.node_sound_leaves_defaults(),
_rp_farming_plant_name = "rp_farming:wheat",
}
)
@ -111,8 +114,9 @@ minetest.register_node(
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
},
groups = {snappy=3, handy=2, attached_node=1, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds=rp_sounds.node_sound_leaves_defaults()
groups = {snappy=3, handy=2, attached_node=1, farming_plant=1, plant_wheat=4, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds=rp_sounds.node_sound_leaves_defaults(),
_rp_farming_plant_name = "rp_farming:wheat",
}
)
@ -140,8 +144,9 @@ minetest.register_node(
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
},
groups = {snappy=3, handy=2, attached_node=1, seed=1},
sounds=rp_sounds.node_sound_leaves_defaults()
groups = {snappy=3, handy=2, attached_node=1, farming_plant=1, plant_cotton=1, seed=1},
sounds=rp_sounds.node_sound_leaves_defaults(),
_rp_farming_plant_name = "rp_farming:cotton",
}
)
@ -167,8 +172,9 @@ minetest.register_node(
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
},
groups = {snappy=3, handy=2, attached_node=1, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds=rp_sounds.node_sound_leaves_defaults()
groups = {snappy=3, handy=2, attached_node=1, farming_plant=1, plant_cotton=2, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds=rp_sounds.node_sound_leaves_defaults(),
_rp_farming_plant_name = "rp_farming:cotton",
}
)
@ -194,8 +200,9 @@ minetest.register_node(
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
},
groups = {snappy=3, handy=2, attached_node=1, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds=rp_sounds.node_sound_leaves_defaults()
groups = {snappy=3, handy=2, attached_node=1, farming_plant=1, plant_cotton=3, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds=rp_sounds.node_sound_leaves_defaults(),
_rp_farming_plant_name = "rp_farming:cotton",
}
)
@ -260,8 +267,9 @@ minetest.register_node(
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
},
groups = {snappy=3, handy=2, attached_node=1, not_in_craft_guide = 1, not_in_creative_inventory = 1},
groups = {snappy=3, handy=2, attached_node=1, farming_plant=1, plant_cotton=4, not_in_craft_guide = 1, not_in_creative_inventory = 1},
sounds = rp_sounds.node_sound_leaves_defaults(),
_rp_farming_plant_name = "rp_farming:cotton",
-- Trim cotton with shears
_on_trim = trim_cotton,