Created a shared function for planting a seed that can also be consumed.
parent
7ea41a2f21
commit
fb51067c78
|
@ -89,14 +89,7 @@ minetest.register_craftitem("mcl_farming:carrot_item", {
|
|||
groups = {food = 2, eatable = 3, compostability = 65},
|
||||
_mcl_saturation = 3.6,
|
||||
on_secondary_use = minetest.item_eat(3),
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
local new = mcl_farming:place_seed(itemstack, placer, pointed_thing, "mcl_farming:carrot_1")
|
||||
if new then
|
||||
return new
|
||||
else
|
||||
return minetest.do_item_eat(3, nil, itemstack, placer, pointed_thing)
|
||||
end
|
||||
end,
|
||||
on_place = mcl_farming:get_seed_or_eat_callback("mcl_farming:carrot_1", 3),
|
||||
})
|
||||
|
||||
minetest.register_craftitem("mcl_farming:carrot_item_gold", {
|
||||
|
|
|
@ -95,14 +95,7 @@ minetest.register_craftitem("mcl_farming:potato_item", {
|
|||
_mcl_saturation = 0.6,
|
||||
stack_max = 64,
|
||||
on_secondary_use = minetest.item_eat(1),
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
local new = mcl_farming:place_seed(itemstack, placer, pointed_thing, "mcl_farming:potato_1")
|
||||
if new then
|
||||
return new
|
||||
else
|
||||
return minetest.do_item_eat(1, nil, itemstack, placer, pointed_thing)
|
||||
end
|
||||
end,
|
||||
on_place = mcl_farming:get_seed_or_eat_callback("mcl_farming:potato_1", 1),
|
||||
})
|
||||
|
||||
minetest.register_craftitem("mcl_farming:potato_item_baked", {
|
||||
|
|
|
@ -469,6 +469,21 @@ function mcl_farming:stem_color(startcolor, endcolor, step, step_count)
|
|||
return colorstring
|
||||
end
|
||||
|
||||
--[[Get a callback that either eats the item or plants it.
|
||||
|
||||
Used for on_place callbacks for craft items which are seeds that can also be consumed.
|
||||
--]]
|
||||
function mcl_farming:get_seed_or_eat_callback(plantname, hp_change)
|
||||
return function(itemstack, placer, pointed_thing)
|
||||
local new = mcl_farming:place_seed(itemstack, placer, pointed_thing, plantname)
|
||||
if new then
|
||||
return new
|
||||
else
|
||||
return minetest.do_item_eat(hp_change, nil, itemstack, placer, pointed_thing)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_lbm({
|
||||
label = "Add growth for unloaded farming plants",
|
||||
name = "mcl_farming:growth",
|
||||
|
|
Loading…
Reference in New Issue