From e6e13bdc6764ce912f507c8e6ce786fcc0099e0a Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 23 Mar 2024 16:44:41 +0000 Subject: [PATCH] Change _mcl_on_bonemealing to _on_bone_meal, update API.md to reflect this --- mods/ITEMS/mcl_bamboo/bamboo_base.lua | 2 +- mods/ITEMS/mcl_bone_meal/API.md | 16 ++++++++++------ mods/ITEMS/mcl_bone_meal/init.lua | 4 ++-- mods/ITEMS/mcl_cocoas/init.lua | 4 ++-- mods/ITEMS/mcl_core/nodes_trees.lua | 2 +- mods/ITEMS/mcl_crimson/init.lua | 14 +++++++------- mods/ITEMS/mcl_farming/beetroot.lua | 2 +- mods/ITEMS/mcl_farming/carrots.lua | 2 +- mods/ITEMS/mcl_farming/melon.lua | 2 +- mods/ITEMS/mcl_farming/potatoes.lua | 2 +- mods/ITEMS/mcl_farming/pumpkin.lua | 2 +- mods/ITEMS/mcl_farming/sweet_berry.lua | 6 +++--- mods/ITEMS/mcl_farming/wheat.lua | 2 +- mods/ITEMS/mcl_flowers/bonemealing.lua | 10 +++++----- mods/ITEMS/mcl_flowers/init.lua | 10 +++++----- mods/ITEMS/mcl_mushrooms/small.lua | 4 ++-- 16 files changed, 44 insertions(+), 40 deletions(-) diff --git a/mods/ITEMS/mcl_bamboo/bamboo_base.lua b/mods/ITEMS/mcl_bamboo/bamboo_base.lua index 3c0de0509..15f9da5b0 100644 --- a/mods/ITEMS/mcl_bamboo/bamboo_base.lua +++ b/mods/ITEMS/mcl_bamboo/bamboo_base.lua @@ -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, diff --git a/mods/ITEMS/mcl_bone_meal/API.md b/mods/ITEMS/mcl_bone_meal/API.md index a404d29a9..b365c3900 100644 --- a/mods/ITEMS/mcl_bone_meal/API.md +++ b/mods/ITEMS/mcl_bone_meal/API.md @@ -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)) diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index 2e79ab678..3a0309003 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -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. diff --git a/mods/ITEMS/mcl_cocoas/init.lua b/mods/ITEMS/mcl_cocoas/init.lua index 91026ce83..1af306355 100644 --- a/mods/ITEMS/mcl_cocoas/init.lua +++ b/mods/ITEMS/mcl_cocoas/init.lua @@ -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)) diff --git a/mods/ITEMS/mcl_core/nodes_trees.lua b/mods/ITEMS/mcl_core/nodes_trees.lua index 96b619f73..c71693408 100644 --- a/mods/ITEMS/mcl_core/nodes_trees.lua +++ b/mods/ITEMS/mcl_core/nodes_trees.lua @@ -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 diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index d0620539f..1f8273b22 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -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 diff --git a/mods/ITEMS/mcl_farming/beetroot.lua b/mods/ITEMS/mcl_farming/beetroot.lua index 605c41005..66d47d461 100644 --- a/mods/ITEMS/mcl_farming/beetroot.lua +++ b/mods/ITEMS/mcl_farming/beetroot.lua @@ -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 diff --git a/mods/ITEMS/mcl_farming/carrots.lua b/mods/ITEMS/mcl_farming/carrots.lua index a008f73ed..119d108af 100644 --- a/mods/ITEMS/mcl_farming/carrots.lua +++ b/mods/ITEMS/mcl_farming/carrots.lua @@ -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) diff --git a/mods/ITEMS/mcl_farming/melon.lua b/mods/ITEMS/mcl_farming/melon.lua index deda6ba10..2dcaaf835 100644 --- a/mods/ITEMS/mcl_farming/melon.lua +++ b/mods/ITEMS/mcl_farming/melon.lua @@ -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) diff --git a/mods/ITEMS/mcl_farming/potatoes.lua b/mods/ITEMS/mcl_farming/potatoes.lua index da837009a..eae52abcd 100644 --- a/mods/ITEMS/mcl_farming/potatoes.lua +++ b/mods/ITEMS/mcl_farming/potatoes.lua @@ -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) diff --git a/mods/ITEMS/mcl_farming/pumpkin.lua b/mods/ITEMS/mcl_farming/pumpkin.lua index 3d6062f0b..df01d0124 100644 --- a/mods/ITEMS/mcl_farming/pumpkin.lua +++ b/mods/ITEMS/mcl_farming/pumpkin.lua @@ -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) diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index a768fab37..769e7b6cf 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -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 diff --git a/mods/ITEMS/mcl_farming/wheat.lua b/mods/ITEMS/mcl_farming/wheat.lua index d8ed0d0fb..c0013e2ce 100644 --- a/mods/ITEMS/mcl_farming/wheat.lua +++ b/mods/ITEMS/mcl_farming/wheat.lua @@ -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) diff --git a/mods/ITEMS/mcl_flowers/bonemealing.lua b/mods/ITEMS/mcl_flowers/bonemealing.lua index 26fc8a44c..d64bfe092 100644 --- a/mods/ITEMS/mcl_flowers/bonemealing.lua +++ b/mods/ITEMS/mcl_flowers/bonemealing.lua @@ -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 diff --git a/mods/ITEMS/mcl_flowers/init.lua b/mods/ITEMS/mcl_flowers/init.lua index 20c153dfa..311b7d8ce 100644 --- a/mods/ITEMS/mcl_flowers/init.lua +++ b/mods/ITEMS/mcl_flowers/init.lua @@ -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(), }) diff --git a/mods/ITEMS/mcl_mushrooms/small.lua b/mods/ITEMS/mcl_mushrooms/small.lua index 260fe700a..a32507e78 100644 --- a/mods/ITEMS/mcl_mushrooms/small.lua +++ b/mods/ITEMS/mcl_mushrooms/small.lua @@ -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)