1
0
Fork 0

Bonemealing mechanics bugfix.

When applying bonemeal to eg. farm crops, these have a chance to grow in
response to the application of bone meal. When a node can be bonemealed, the
applied bone meal item should always be spent after using it, regardless of
the results.  Currently this does not work correctly, if the result of
bonemealing has no effect on the node, the used bone meal item is not spent.

This commit fixes the behavior of the bone meal item to always be taken when
used on a node that defines a `_mcl_on_bonemealing()` callback.

The nodes that implement the callback imay use the handler's return value
only to signal if the bonemealing was succesful, not to signal if it was at
all possible.  For this reason, some nodes need to be made more strictly
conforming to the API.

* Always take the used bone meal item (if user is not in creative mode),
  regardless of whether the bonemealed node's handler returned `true`.
* Make dispensers spawn particles after succesful bonemealing.
* Trivial comment fix.
* Ripe cocoa pod cannot be bonemealed.
* Update API.md to describe the stricter API semantics.
This commit is contained in:
kabou 2022-05-04 12:17:51 +02:00
parent c83076b756
commit 521fc1972a
3 changed files with 21 additions and 10 deletions

View File

@ -8,7 +8,17 @@ 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`. This handler is a define a callback handler named `_mcl_on_bonemealing`.
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.
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
`function(pointed_thing, placer)` `function(pointed_thing, placer)`
@ -17,10 +27,9 @@ Its arguments are:
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!
The function should return `true` if the bonemealing was succesful. The return value of the handler function indicates if the bonemealing had
its intended effect. If `true`, 'bone meal particles' are spawned at the
It is for all intents and purposes up to the callback defined in the node to position of the bonemealed node.
decide how to handle the effect that bone meal has on that particular node.
The `on_place` code in the bone meal item will spawn bone meal particles and The `on_place` code in the bone meal item will spawn bone meal particles and
decrease the bone meal itemstack if the handler returned `true` and the decrease the bone meal itemstack if the handler returned `true` and the

View File

@ -49,7 +49,7 @@ end
-- --
mcl_bone_meal.bone_meal_callbacks = {} mcl_bone_meal.bone_meal_callbacks = {}
-- Shims for the old API are still available in mcl_dye and refer to -- Shims for the old API are still available in mcl_dye and defer to
-- the real functions in mcl_bone_meal. -- the real functions in mcl_bone_meal.
-- --
function mcl_bone_meal.register_on_bone_meal_apply(func) function mcl_bone_meal.register_on_bone_meal_apply(func)
@ -91,9 +91,9 @@ minetest.register_craftitem("mcl_bone_meal:bone_meal", {
if ndef and ndef._mcl_on_bonemealing then if ndef and ndef._mcl_on_bonemealing then
if ndef._mcl_on_bonemealing(pointed_thing, placer) then if ndef._mcl_on_bonemealing(pointed_thing, placer) then
mcl_bone_meal.add_bone_meal_particle(pos) mcl_bone_meal.add_bone_meal_particle(pos)
if not minetest.is_creative_enabled(placer:get_player_name()) then end
itemstack:take_item() if not minetest.is_creative_enabled(placer:get_player_name()) then
end itemstack:take_item()
end end
-- Otherwise try the legacy API. -- Otherwise try the legacy API.
elseif apply_bone_meal(pointed_thing, placer) and elseif apply_bone_meal(pointed_thing, placer) and
@ -114,8 +114,9 @@ minetest.register_craftitem("mcl_bone_meal:bone_meal", {
-- 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._mcl_on_bonemealing then
if ndef._mcl_on_bonemealing(pointed_thing, nil) then if ndef._mcl_on_bonemealing(pointed_thing, nil) then
itemstack:take_item() mcl_bone_meal.add_bone_meal_particle(pos)
end end
itemstack:take_item()
else else
-- Otherwise try the legacy API. -- Otherwise try the legacy API.
if apply_bone_meal(pointed_thing, nil) then if apply_bone_meal(pointed_thing, nil) then

View File

@ -167,6 +167,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
end end
minetest.register_node("mcl_cocoas:cocoa_" .. i, table.copy(def)) minetest.register_node("mcl_cocoas:cocoa_" .. i, table.copy(def))