Refactor beetroots and add bonemealing callback.

* Abstract unripe beetroot plant node registrations into a single
  indexed definition and do the registration in a loop.
* Adds a _mcl_on_bonemealing callback to the unripe melon plants.
This commit is contained in:
kabou 2022-04-30 06:36:09 +02:00 committed by teknomunk
parent d07e8d9536
commit 17f2d85de9

View file

@ -13,78 +13,44 @@ minetest.register_craftitem("mcl_farming:beetroot_seeds", {
end end
}) })
minetest.register_node("mcl_farming:beetroot_0", { local size = {[0]=-5, -3, 2}
description = S("Premature Beetroot Plant (Stage 1)"),
_doc_items_longdesc = S("Beetroot plants are plants which grow on farmland under sunlight in 4 stages. On hydrated farmland, they grow a bit faster. They can be harvested at any time but will only yield a profit when mature."),
_doc_items_entry_name = S("Premature Beetroot Plant"),
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
place_param2 = 3,
walkable = false,
drawtype = "plantlike",
drop = "mcl_farming:beetroot_seeds",
tiles = {"mcl_farming_beetroot_0.png"},
inventory_image = "mcl_farming_beetroot_0.png",
wield_image = "mcl_farming_beetroot_0.png",
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}
},
},
groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1},
sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0,
})
minetest.register_node("mcl_farming:beetroot_1", { for i = 0, 2 do
description = S("Premature Beetroot Plant (Stage 2)"), minetest.register_node("mcl_farming:beetroot_".. i, {
_doc_items_create_entry = false, description = S("Premature Beetroot Plant (Stage ".. i + 1 ..")"),
paramtype = "light", _doc_items_longdesc = S("Beetroot plants are plants which grow on farmland under sunlight in 4 stages. On hydrated farmland, they grow a bit faster. They can be harvested at any time but will only yield a profit when mature."),
paramtype2 = "meshoptions", _doc_items_entry_name = S("Premature Beetroot Plant"),
sunlight_propagates = true, paramtype = "light",
place_param2 = 3, paramtype2 = "meshoptions",
walkable = false, sunlight_propagates = true,
drawtype = "plantlike", place_param2 = 3,
drop = "mcl_farming:beetroot_seeds", walkable = false,
tiles = {"mcl_farming_beetroot_1.png"}, drawtype = "plantlike",
inventory_image = "mcl_farming_beetroot_1.png", drop = "mcl_farming:beetroot_seeds",
wield_image = "mcl_farming_beetroot_1.png", tiles = {"mcl_farming_beetroot_".. i ..".png"},
selection_box = { inventory_image = "mcl_farming_beetroot_".. i ..".png",
type = "fixed", wield_image = "mcl_farming_beetroot_".. i ..".png",
fixed = { selection_box = {
{-0.5, -0.5, -0.5, 0.5, -4/16, 0.5} type = "fixed",
fixed = { {-0.5, -0.5, -0.5, 0.5, size[i]/16, 0.5} },
}, },
}, groups = {
groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1}, dig_immediate=3, not_in_creative_inventory=1,
sounds = mcl_sounds.node_sound_leaves_defaults(), plant=1, attached_node=1, dig_by_water=1,
_mcl_blast_resistance = 0, destroy_by_lava_flow=1,dig_by_piston=1
})
minetest.register_node("mcl_farming:beetroot_2", {
description = S("Premature Beetroot Plant (Stage 3)"),
_doc_items_create_entry = false,
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
place_param2 = 3,
walkable = false,
drawtype = "plantlike",
drop = "mcl_farming:beetroot_seeds",
tiles = {"mcl_farming_beetroot_2.png"},
inventory_image = "mcl_farming_beetroot_2.png",
wield_image = "mcl_farming_beetroot_2.png",
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, -3/16, 0.5}
}, },
}, sounds = mcl_sounds.node_sound_leaves_defaults(),
groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1}, _mcl_blast_resistance = 0,
sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_on_bonemealing = function(pointed_thing, placer)
_mcl_blast_resistance = 0, local pos = pointed_thing.under
}) local n = minetest.get_node(pos)
-- 75% chance to advance to next stage
if math.random(1, 100) <= 75 then
return mcl_farming:grow_plant("plant_beetroot", pos, n, 1, true)
end
end
})
end
minetest.register_node("mcl_farming:beetroot", { minetest.register_node("mcl_farming:beetroot", {
description = S("Mature Beetroot Plant"), description = S("Mature Beetroot Plant"),