Refactor rp_farming
This commit is contained in:
parent
75812fb9e6
commit
d75335e10f
@ -85,20 +85,26 @@ function farming.place_plant(itemstack, placer, pointed_thing)
|
|||||||
return itemstack
|
return itemstack
|
||||||
end
|
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)
|
local my_node = minetest.get_node(pos)
|
||||||
|
|
||||||
if my_node.name == name .. "_1" then
|
if my_node.name == plant_name .. "_1" then
|
||||||
minetest.set_node(pos, {name = name .. "_2"})
|
minetest.set_node(pos, {name = plant_name .. "_2"})
|
||||||
elseif my_node.name == name .. "_2" then
|
return true
|
||||||
minetest.set_node(pos, {name = name .. "_3"})
|
elseif my_node.name == plant_name .. "_2" then
|
||||||
elseif my_node.name == name .. "_3" then
|
minetest.set_node(pos, {name = plant_name .. "_3"})
|
||||||
minetest.set_node(pos, {name = name .. "_4"})
|
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
|
-- Stop the timer on the node so no more growing occurs until needed
|
||||||
|
|
||||||
minetest.get_node_timer(pos):stop()
|
minetest.get_node_timer(pos):stop()
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function farming.grow_plant(pos, name)
|
function farming.grow_plant(pos, name)
|
||||||
@ -129,16 +135,13 @@ function farming.grow_plant(pos, name)
|
|||||||
|
|
||||||
-- Grow and check for rain and fertilizer
|
-- Grow and check for rain and fertilizer
|
||||||
|
|
||||||
local under = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
|
farming.next_stage(pos, name)
|
||||||
local underdef = minetest.registered_nodes[under.name]
|
|
||||||
|
|
||||||
farming.next_stage(pos, under, underdef, name, plant)
|
|
||||||
|
|
||||||
if minetest.get_item_group(under.name, "plantable_fertilizer") > 0 then
|
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
|
end
|
||||||
|
|
||||||
if weather.weather == "storm" then
|
if weather.weather == "storm" then
|
||||||
farming.next_stage(pos, under, underdef, name, plant)
|
farming.next_stage(pos, name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -27,8 +27,9 @@ minetest.register_node(
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
|
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},
|
groups = {snappy=3, handy=2, attached_node=1, seed=1, farming_plant=1, plant_wheat=1},
|
||||||
sounds=rp_sounds.node_sound_leaves_defaults()
|
sounds=rp_sounds.node_sound_leaves_defaults(),
|
||||||
|
_rp_farming_plant_name = "rp_farming:wheat",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -54,8 +55,9 @@ minetest.register_node(
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
|
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_wheat=2, not_in_craft_guide = 1, not_in_creative_inventory = 1},
|
||||||
sounds=rp_sounds.node_sound_leaves_defaults()
|
sounds=rp_sounds.node_sound_leaves_defaults(),
|
||||||
|
_rp_farming_plant_name = "rp_farming:wheat",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -81,8 +83,9 @@ minetest.register_node(
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
|
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_wheat=3, not_in_craft_guide = 1, not_in_creative_inventory = 1},
|
||||||
sounds=rp_sounds.node_sound_leaves_defaults()
|
sounds=rp_sounds.node_sound_leaves_defaults(),
|
||||||
|
_rp_farming_plant_name = "rp_farming:wheat",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -111,8 +114,9 @@ minetest.register_node(
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
|
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_wheat=4, not_in_craft_guide = 1, not_in_creative_inventory = 1},
|
||||||
sounds=rp_sounds.node_sound_leaves_defaults()
|
sounds=rp_sounds.node_sound_leaves_defaults(),
|
||||||
|
_rp_farming_plant_name = "rp_farming:wheat",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -140,8 +144,9 @@ minetest.register_node(
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
|
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},
|
groups = {snappy=3, handy=2, attached_node=1, farming_plant=1, plant_cotton=1, seed=1},
|
||||||
sounds=rp_sounds.node_sound_leaves_defaults()
|
sounds=rp_sounds.node_sound_leaves_defaults(),
|
||||||
|
_rp_farming_plant_name = "rp_farming:cotton",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -167,8 +172,9 @@ minetest.register_node(
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
|
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=2, not_in_craft_guide = 1, not_in_creative_inventory = 1},
|
||||||
sounds=rp_sounds.node_sound_leaves_defaults()
|
sounds=rp_sounds.node_sound_leaves_defaults(),
|
||||||
|
_rp_farming_plant_name = "rp_farming:cotton",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -194,8 +200,9 @@ minetest.register_node(
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
|
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=3, not_in_craft_guide = 1, not_in_creative_inventory = 1},
|
||||||
sounds=rp_sounds.node_sound_leaves_defaults()
|
sounds=rp_sounds.node_sound_leaves_defaults(),
|
||||||
|
_rp_farming_plant_name = "rp_farming:cotton",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -260,8 +267,9 @@ minetest.register_node(
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+(4/16), 0.5}
|
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(),
|
sounds = rp_sounds.node_sound_leaves_defaults(),
|
||||||
|
_rp_farming_plant_name = "rp_farming:cotton",
|
||||||
|
|
||||||
-- Trim cotton with shears
|
-- Trim cotton with shears
|
||||||
_on_trim = trim_cotton,
|
_on_trim = trim_cotton,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user