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",
_mcl_blast_resistance = 1,
_mcl_hardness = 1,
_mcl_on_bonemealing = function(pointed_thing, placer)
_on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under
return mcl_bamboo.grow_bamboo(pos, true)
end,

View File

@ -3,29 +3,32 @@
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
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
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
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
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
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:
* `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
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
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
* `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.
Bone meal is not consumed unless the provided function returns true.
## mcl_dye.add_bone_meal_particle(pos, def)
## 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
-- If the pointed node can be bonemealed, let it handle the processing.
if ndef and ndef._mcl_on_bonemealing then
success = ndef._mcl_on_bonemealing(pointed_thing, placer)
if ndef and ndef._on_bone_meal then
success = ndef._on_bone_meal(itemstack, placer, pointed_thing)
consume = true
else
-- Otherwise try the legacy API.

View File

@ -137,7 +137,7 @@ for i = 1, 3 do
on_rotate = false,
_mcl_blast_resistance = 3,
_mcl_hardness = 0.2,
_mcl_on_bonemealing = function(pointed_thing, placer)
_on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under
return cocoa_grow(pos)
end,
@ -149,7 +149,7 @@ for i = 1, 3 do
end
if i == 3 then
def.drop = "mcl_cocoas:cocoa_beans 3"
def._mcl_on_bonemealing = nil
def._on_bone_mealing = nil
end
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:dirt" or nn == "mcl_core:mycelium" or nn == "mcl_core:coarse_dirt"
end),
_mcl_on_bonemealing = function(pointed_thing, placer)
_on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under
local n = minetest.get_node(pos)
-- Saplings: 45% chance to advance growth stage

View File

@ -85,7 +85,7 @@ minetest.register_node("mcl_crimson:warped_fungus", {
light_source = 1,
sounds = mcl_sounds.node_sound_leaves_defaults(),
node_placement_prediction = "",
_mcl_on_bonemealing = function(pointed_thing, player)
_on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under
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",
desc = S("Warped Fungus"),
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)
if n then
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 },
},
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")
end,
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 },
},
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")
end,
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_blast_resistance = 0.4,
_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)
spread_nether_plants(pt.under,node)
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 },
},
node_placement_prediction = "",
_mcl_on_bonemealing = function(pointed_thing, player)
_on_bone_meal = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under
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
@ -702,7 +702,7 @@ minetest.register_node("mcl_crimson:crimson_nylium", {
_mcl_hardness = 0.4,
_mcl_blast_resistance = 0.4,
_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)
spread_nether_plants(pt.under,node)
return true

View File

@ -41,7 +41,7 @@ for i = 0, 2 do
},
sounds = mcl_sounds.node_sound_leaves_defaults(),
_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 n = minetest.get_node(pos)
-- 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},
sounds = mcl_sounds.node_sound_leaves_defaults(),
_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 n = minetest.get_node(pos)
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},
sounds = mcl_sounds.node_sound_leaves_defaults(),
_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 n = minetest.get_node(pos)
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},
sounds = mcl_sounds.node_sound_leaves_defaults(),
_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 n = minetest.get_node(pos)
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,},
sounds = mcl_sounds.node_sound_leaves_defaults(),
_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 n = minetest.get_node(pos)
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"})
end
if i ~= 3 then
on_bonemealing = function(pointed_thing, placer)
on_bonemealing = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under
local node = minetest.get_node(pos)
return mcl_farming:grow_plant("plant_sweet_berry_bush", pos, node, 0, true)
end
else
on_bonemealing = function(pointed_thing, placer)
on_bonemealing = function(itemstack, placer, pointed_thing)
do_berry_drop(pointed_thing.under)
end
end
@ -64,7 +64,7 @@ for i=0, 3 do
sounds = mcl_sounds.node_sound_leaves_defaults(),
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
_mcl_on_bonemealing = on_bonemealing,
_on_bone_meal = on_bonemealing,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local pn = clicker:get_player_name()
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},
sounds = mcl_sounds.node_sound_leaves_defaults(),
_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 n = minetest.get_node(pos)
local stages = math.random(2, 5)

View File

@ -8,7 +8,7 @@
-- mcl_core, such as mcl_flowers.
--
-- 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.
local mg_name = minetest.get_mapgen_setting("mg_name")
@ -124,12 +124,12 @@ local olddef = minetest.registered_nodes[nodename]
if not olddef then
minetest.log("warning", "'mcl_core:dirt_with_grass' not registered, cannot add override!")
else
local oldhandler = olddef._mcl_on_bonemealing
local newhandler = function (pointed_thing, placer)
local oldhandler = olddef._on_bone_meal
local newhandler = function(itemstack, placer, pointed_thing)
bonemeal_grass(pointed_thing, placer)
if oldhandler then
oldhandler(pointed_thing, placer)
oldhandler(itemstack, placer, pointed_thing)
end
end
minetest.override_item(nodename, {_mcl_on_bonemealing = newhandler})
minetest.override_item(nodename, {_on_bone_meal = newhandler})
end

View File

@ -162,7 +162,7 @@ local def_tallgrass = {
_mcl_fortune_drop = fortune_wheat_seed_drop,
node_placement_prediction = "",
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 n = minetest.get_node(pos)
-- 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 },
}
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 n = minetest.get_node(pos)
-- 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.place_flowerlike = 1
bottom_groups.dig_immediate = 3
on_bonemealing = function(pointed_thing, placer)
on_bonemealing = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under
minetest.add_item(pos, "mcl_flowers:"..name)
return true
@ -411,7 +411,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im
minetest.remove_node(top)
end
end,
_mcl_on_bonemealing = on_bonemealing,
_on_bone_meal = on_bonemealing,
groups = bottom_groups,
sounds = mcl_sounds.node_sound_leaves_defaults(),
mesh = mesh
@ -450,7 +450,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im
minetest.remove_node(bottom)
end
end,
_mcl_on_bonemealing = on_bonemealing,
_on_bone_meal = on_bonemealing,
groups = top_groups,
sounds = mcl_sounds.node_sound_leaves_defaults(),
})

View File

@ -88,7 +88,7 @@ minetest.register_node("mcl_mushrooms:mushroom_brown", {
},
node_placement_prediction = "",
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 offset = vector.new(-3, -1, -3)
return apply_bonemeal(pointed_thing.under, schematic, offset)
@ -120,7 +120,7 @@ minetest.register_node("mcl_mushrooms:mushroom_red", {
},
node_placement_prediction = "",
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 offset = vector.new(-2, -1, -2)
return apply_bonemeal(pointed_thing.under, schematic, offset)