Change _mcl_on_bonemealing to _on_bone_meal, update API.md to reflect this

This commit is contained in:
teknomunk 2024-03-23 16:44:41 +00:00
parent 42d37210c5
commit e6e13bdc67
16 changed files with 44 additions and 40 deletions

View file

@ -34,7 +34,7 @@ local bamboo_def = {
wield_image = "mcl_bamboo_bamboo_shoot.png", wield_image = "mcl_bamboo_bamboo_shoot.png",
_mcl_blast_resistance = 1, _mcl_blast_resistance = 1,
_mcl_hardness = 1, _mcl_hardness = 1,
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
return mcl_bamboo.grow_bamboo(pos, true) return mcl_bamboo.grow_bamboo(pos, true)
end, end,

View file

@ -3,29 +3,32 @@
Bonemealing callbacks and particle functions. Bonemealing callbacks and particle functions.
## _mcl_on_bonemealing(pointed_thing, placer) ## _on_bone_meal(itemstack, placer, pointed_thing)
The bone meal API provides a callback definition that nodes can use to The bone meal API provides a callback definition that nodes can use to
register a handler that is executed when a bone meal item is used on it. register a handler that is executed when a bone meal item is used on it.
Nodes that wish to use the bone meal API should in their node registration Nodes that wish to use the bone meal API should in their node registration
define a callback handler named `_mcl_on_bonemealing`. define a callback handler named `_on_bone_meal`.
Note that by registering the callback handler, the node declares that bone Note that by registering the callback handler, the node declares that bone
meal can be used on it and as a result, when the user is not in creative meal can be used on it and as a result, when the user is not in creative
mode, the used bone meal is spent and taken from the itemstack passed to mode, the used bone meal is spent and taken from the itemstack passed to
the `on_place()` handler of the bone meal item used. the `on_place()` handler of the bone meal item used regardless of whether
the bone meal had an effect on the node and regardless of the result of
the callback handler.
It is for all intents and purposes up to the callback defined in the node to It is for all intents and purposes up to the callback defined in the node to
decide how to handle the specific effect that bone meal has on that node. decide how to handle the specific effect that bone meal has on that node.
The `_mcl_on_bonemealing` callback handler is a The `_on_bone_meal` callback handler is a
`function(pointed_thing, placer)` `function(itemstack, placer, pointed_thing)`
Its arguments are: Its arguments are:
* `itemstack`: the stack of bonem eal being applied
* `placer`: ObjectRef of the player who aplied the bone meal, can be nil!
* `pointed_thing`: exact pointing location (see Minetest API), where the * `pointed_thing`: exact pointing location (see Minetest API), where the
bone meal is applied bone meal is applied
* `placer`: ObjectRef of the player who aplied the bone meal, can be nil!
The return value of the handler function indicates if the bonemealing had The return value of the handler function indicates if the bonemealing had
its intended effect. If `true`, 'bone meal particles' are spawned at the its intended effect. If `true`, 'bone meal particles' are spawned at the
@ -63,6 +66,7 @@ Called when the bone meal is applied anywhere.
bone meal is applied bone meal is applied
* `placer`: ObjectRef of the player who aplied the bone meal, can be nil! * `placer`: ObjectRef of the player who aplied the bone meal, can be nil!
This function is deprecated and will be removed at some time in the future. This function is deprecated and will be removed at some time in the future.
Bone meal is not consumed unless the provided function returns true.
## mcl_dye.add_bone_meal_particle(pos, def) ## mcl_dye.add_bone_meal_particle(pos, def)
## mcl_dye.register_on_bone_meal_apply(function(pointed_thing, user)) ## mcl_dye.register_on_bone_meal_apply(function(pointed_thing, user))

View file

@ -87,8 +87,8 @@ mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing)
local consume local consume
-- If the pointed node can be bonemealed, let it handle the processing. -- If the pointed node can be bonemealed, let it handle the processing.
if ndef and ndef._mcl_on_bonemealing then if ndef and ndef._on_bone_meal then
success = ndef._mcl_on_bonemealing(pointed_thing, placer) success = ndef._on_bone_meal(itemstack, placer, pointed_thing)
consume = true consume = true
else else
-- Otherwise try the legacy API. -- Otherwise try the legacy API.

View file

@ -137,7 +137,7 @@ for i = 1, 3 do
on_rotate = false, on_rotate = false,
_mcl_blast_resistance = 3, _mcl_blast_resistance = 3,
_mcl_hardness = 0.2, _mcl_hardness = 0.2,
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
return cocoa_grow(pos) return cocoa_grow(pos)
end, end,
@ -149,7 +149,7 @@ for i = 1, 3 do
end end
if i == 3 then if i == 3 then
def.drop = "mcl_cocoas:cocoa_beans 3" def.drop = "mcl_cocoas:cocoa_beans 3"
def._mcl_on_bonemealing = nil def._on_bone_mealing = nil
end end
minetest.register_node("mcl_cocoas:cocoa_" .. i, table.copy(def)) minetest.register_node("mcl_cocoas:cocoa_" .. i, table.copy(def))

View file

@ -280,7 +280,7 @@ function mcl_core.register_sapling(subname, description, longdesc, tt_help, text
nn == "mcl_core:podzol" or nn == "mcl_core:podzol_snow" or nn == "mcl_core:podzol" or nn == "mcl_core:podzol_snow" or
nn == "mcl_core:dirt" or nn == "mcl_core:mycelium" or nn == "mcl_core:coarse_dirt" nn == "mcl_core:dirt" or nn == "mcl_core:mycelium" or nn == "mcl_core:coarse_dirt"
end), end),
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
-- Saplings: 45% chance to advance growth stage -- Saplings: 45% chance to advance growth stage

View file

@ -85,7 +85,7 @@ minetest.register_node("mcl_crimson:warped_fungus", {
light_source = 1, light_source = 1,
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
node_placement_prediction = "", node_placement_prediction = "",
_mcl_on_bonemealing = function(pointed_thing, player) _on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local nodepos = minetest.get_node(vector.offset(pos, 0, -1, 0)) local nodepos = minetest.get_node(vector.offset(pos, 0, -1, 0))
@ -107,7 +107,7 @@ mcl_flowerpots.register_potted_flower("mcl_crimson:warped_fungus", {
name = "warped_fungus", name = "warped_fungus",
desc = S("Warped Fungus"), desc = S("Warped Fungus"),
image = "mcl_crimson_warped_fungus.png", image = "mcl_crimson_warped_fungus.png",
_mcl_on_bonemealing = function(pt,user) _on_bone_meal = function(itemstack, placer, pointed_thing)
local n = has_nylium_neighbor(pt.under) local n = has_nylium_neighbor(pt.under)
if n then if n then
minetest.set_node(pt.under,n) minetest.set_node(pt.under,n)
@ -132,7 +132,7 @@ minetest.register_node("mcl_crimson:twisting_vines", {
fixed = { -3/16, -0.5, -3/16, 3/16, 0.5, 3/16 }, fixed = { -3/16, -0.5, -3/16, 3/16, 0.5, 3/16 },
}, },
node_placement_prediction = "", node_placement_prediction = "",
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
return grow_vines(pointed_thing.under, math.random(1, 3),"mcl_crimson:twisting_vines") return grow_vines(pointed_thing.under, math.random(1, 3),"mcl_crimson:twisting_vines")
end, end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
@ -222,7 +222,7 @@ minetest.register_node("mcl_crimson:weeping_vines", {
fixed = { -3/16, -0.5, -3/16, 3/16, 0.5, 3/16 }, fixed = { -3/16, -0.5, -3/16, 3/16, 0.5, 3/16 },
}, },
node_placement_prediction = "", node_placement_prediction = "",
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
return grow_vines(pointed_thing.under, math.random(1, 3),"mcl_crimson:weeping_vines") return grow_vines(pointed_thing.under, math.random(1, 3),"mcl_crimson:weeping_vines")
end, end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
@ -404,7 +404,7 @@ minetest.register_node("mcl_crimson:warped_nylium", {
_mcl_hardness = 0.4, _mcl_hardness = 0.4,
_mcl_blast_resistance = 0.4, _mcl_blast_resistance = 0.4,
_mcl_silk_touch_drop = true, _mcl_silk_touch_drop = true,
_mcl_on_bonemealing = function(pt,user) _on_bone_meal = function(itemstack, placer, pointed_thing)
local node = minetest.get_node(pt.under) local node = minetest.get_node(pt.under)
spread_nether_plants(pt.under,node) spread_nether_plants(pt.under,node)
return true return true
@ -541,7 +541,7 @@ minetest.register_node("mcl_crimson:crimson_fungus", {
fixed = { -3/16, -0.5, -3/16, 3/16, -2/16, 3/16 }, fixed = { -3/16, -0.5, -3/16, 3/16, -2/16, 3/16 },
}, },
node_placement_prediction = "", node_placement_prediction = "",
_mcl_on_bonemealing = function(pointed_thing, player) _on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local nodepos = minetest.get_node(vector.offset(pos, 0, -1, 0)) local nodepos = minetest.get_node(vector.offset(pos, 0, -1, 0))
if nodepos.name == "mcl_crimson:crimson_nylium" or nodepos.name == "mcl_nether:netherrack" then if nodepos.name == "mcl_crimson:crimson_nylium" or nodepos.name == "mcl_nether:netherrack" then
@ -702,7 +702,7 @@ minetest.register_node("mcl_crimson:crimson_nylium", {
_mcl_hardness = 0.4, _mcl_hardness = 0.4,
_mcl_blast_resistance = 0.4, _mcl_blast_resistance = 0.4,
_mcl_silk_touch_drop = true, _mcl_silk_touch_drop = true,
_mcl_on_bonemealing = function(pt,user) _on_bone_meal = function(itemstack, placer, pointed_thing)
local node = minetest.get_node(pt.under) local node = minetest.get_node(pt.under)
spread_nether_plants(pt.under,node) spread_nether_plants(pt.under,node)
return true return true

View file

@ -41,7 +41,7 @@ for i = 0, 2 do
}, },
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
-- 75% chance to advance to next stage -- 75% chance to advance to next stage

View file

@ -45,7 +45,7 @@ for i=1, 7 do
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}, 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(), sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
local stages = math.random(2, 5) local stages = math.random(2, 5)

View file

@ -109,7 +109,7 @@ for s=1,7 do
groups = {dig_immediate=3, not_in_creative_inventory=1, plant=1,attached_node=1, dig_by_water=1,destroy_by_lava_flow=1, plant_melon_stem=s}, groups = {dig_immediate=3, not_in_creative_inventory=1, plant=1,attached_node=1, dig_by_water=1,destroy_by_lava_flow=1, plant_melon_stem=s},
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
local stages = math.random(2, 5) local stages = math.random(2, 5)

View file

@ -49,7 +49,7 @@ for i=1, 7 do
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}, 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(), sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
local stages = math.random(2, 5) local stages = math.random(2, 5)

View file

@ -79,7 +79,7 @@ for s=1,7 do
groups = {dig_immediate=3, not_in_creative_inventory=1, plant=1,attached_node=1, dig_by_water=1,destroy_by_lava_flow=1,}, groups = {dig_immediate=3, not_in_creative_inventory=1, plant=1,attached_node=1, dig_by_water=1,destroy_by_lava_flow=1,},
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_mealing = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
local stages = math.random(2, 5) local stages = math.random(2, 5)

View file

@ -20,13 +20,13 @@ for i=0, 3 do
minetest.swap_node(pos, {name = "mcl_farming:sweet_berry_bush_1"}) minetest.swap_node(pos, {name = "mcl_farming:sweet_berry_bush_1"})
end end
if i ~= 3 then if i ~= 3 then
on_bonemealing = function(pointed_thing, placer) on_bonemealing = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
return mcl_farming:grow_plant("plant_sweet_berry_bush", pos, node, 0, true) return mcl_farming:grow_plant("plant_sweet_berry_bush", pos, node, 0, true)
end end
else else
on_bonemealing = function(pointed_thing, placer) on_bonemealing = function(itemstack, placer, pointed_thing)
do_berry_drop(pointed_thing.under) do_berry_drop(pointed_thing.under)
end end
end end
@ -64,7 +64,7 @@ for i=0, 3 do
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_hardness = 0, _mcl_hardness = 0,
_mcl_on_bonemealing = on_bonemealing, _on_bone_meal = on_bonemealing,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local pn = clicker:get_player_name() local pn = clicker:get_player_name()
if clicker:is_player() and minetest.is_protected(pos, pn) then if clicker:is_player() and minetest.is_protected(pos, pn) then

View file

@ -60,7 +60,7 @@ for i=1,7 do
dig_by_water=1,destroy_by_lava_flow=1, dig_by_piston=1}, dig_by_water=1,destroy_by_lava_flow=1, dig_by_piston=1},
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
local stages = math.random(2, 5) local stages = math.random(2, 5)

View file

@ -8,7 +8,7 @@
-- mcl_core, such as mcl_flowers. -- mcl_core, such as mcl_flowers.
-- --
-- To work around this restriction, the bonemealing callback is defined here -- To work around this restriction, the bonemealing callback is defined here
-- and the _mcl_on_bonemealing callback in "mcl_core:dirt_with_grass" node -- and the _on_bone_meal callback in "mcl_core:dirt_with_grass" node
-- definition is overwritten with it. -- definition is overwritten with it.
local mg_name = minetest.get_mapgen_setting("mg_name") local mg_name = minetest.get_mapgen_setting("mg_name")
@ -124,12 +124,12 @@ local olddef = minetest.registered_nodes[nodename]
if not olddef then if not olddef then
minetest.log("warning", "'mcl_core:dirt_with_grass' not registered, cannot add override!") minetest.log("warning", "'mcl_core:dirt_with_grass' not registered, cannot add override!")
else else
local oldhandler = olddef._mcl_on_bonemealing local oldhandler = olddef._on_bone_meal
local newhandler = function (pointed_thing, placer) local newhandler = function(itemstack, placer, pointed_thing)
bonemeal_grass(pointed_thing, placer) bonemeal_grass(pointed_thing, placer)
if oldhandler then if oldhandler then
oldhandler(pointed_thing, placer) oldhandler(itemstack, placer, pointed_thing)
end end
end end
minetest.override_item(nodename, {_mcl_on_bonemealing = newhandler}) minetest.override_item(nodename, {_on_bone_meal = newhandler})
end end

View file

@ -162,7 +162,7 @@ local def_tallgrass = {
_mcl_fortune_drop = fortune_wheat_seed_drop, _mcl_fortune_drop = fortune_wheat_seed_drop,
node_placement_prediction = "", node_placement_prediction = "",
on_place = on_place_flower, on_place = on_place_flower,
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
-- Grow into double tallgrass -- Grow into double tallgrass
@ -192,7 +192,7 @@ def_fern.selection_box = {
fixed = { -6/16, -0.5, -6/16, 6/16, 5/16, 6/16 }, fixed = { -6/16, -0.5, -6/16, 6/16, 5/16, 6/16 },
} }
def_fern.groups.compostability = 65 def_fern.groups.compostability = 65
def_fern._mcl_on_bonemealing = function(pointed_thing, placer) def_fern._on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local n = minetest.get_node(pos) local n = minetest.get_node(pos)
-- Grow into double fern. -- Grow into double fern.
@ -272,7 +272,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im
bottom_groups.flower = 1 bottom_groups.flower = 1
bottom_groups.place_flowerlike = 1 bottom_groups.place_flowerlike = 1
bottom_groups.dig_immediate = 3 bottom_groups.dig_immediate = 3
on_bonemealing = function(pointed_thing, placer) on_bonemealing = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
minetest.add_item(pos, "mcl_flowers:"..name) minetest.add_item(pos, "mcl_flowers:"..name)
return true return true
@ -411,7 +411,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im
minetest.remove_node(top) minetest.remove_node(top)
end end
end, end,
_mcl_on_bonemealing = on_bonemealing, _on_bone_meal = on_bonemealing,
groups = bottom_groups, groups = bottom_groups,
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
mesh = mesh mesh = mesh
@ -450,7 +450,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im
minetest.remove_node(bottom) minetest.remove_node(bottom)
end end
end, end,
_mcl_on_bonemealing = on_bonemealing, _on_bone_meal = on_bonemealing,
groups = top_groups, groups = top_groups,
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
}) })

View file

@ -88,7 +88,7 @@ minetest.register_node("mcl_mushrooms:mushroom_brown", {
}, },
node_placement_prediction = "", node_placement_prediction = "",
on_place = on_place, on_place = on_place,
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
local schematic = schempath .. "mcl_mushrooms_huge_brown.mts" local schematic = schempath .. "mcl_mushrooms_huge_brown.mts"
local offset = vector.new(-3, -1, -3) local offset = vector.new(-3, -1, -3)
return apply_bonemeal(pointed_thing.under, schematic, offset) return apply_bonemeal(pointed_thing.under, schematic, offset)
@ -120,7 +120,7 @@ minetest.register_node("mcl_mushrooms:mushroom_red", {
}, },
node_placement_prediction = "", node_placement_prediction = "",
on_place = on_place, on_place = on_place,
_mcl_on_bonemealing = function(pointed_thing, placer) _on_bone_meal = function(itemstack, placer, pointed_thing)
local schematic = schempath .. "mcl_mushrooms_huge_red.mts" local schematic = schempath .. "mcl_mushrooms_huge_red.mts"
local offset = vector.new(-2, -1, -2) local offset = vector.new(-2, -1, -2)
return apply_bonemeal(pointed_thing.under, schematic, offset) return apply_bonemeal(pointed_thing.under, schematic, offset)