Merge pull request 'Fix sweetberry bonemealing crash, growth, double bonemeal usage' (#4788) from fix-sweetberry-bonemealing into master

Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4788
Reviewed-by: the-real-herowl <the-real-herowl@noreply.git.minetest.land>
This commit is contained in:
the-real-herowl 2025-01-03 20:07:12 +01:00
commit cc82293c74
4 changed files with 39 additions and 37 deletions

@ -344,6 +344,23 @@ function mcl_util.call_on_rightclick(itemstack, player, pointed_thing)
end
end
--- TODO: replace with global right-click handler patched in with core.on_register_mods_loaded()
function mcl_util.handle_node_rightclick(itemstack, player, pointed_thing)
-- Call on_rightclick if the pointed node defines it
if pointed_thing and pointed_thing.type == "node" then
local pos = pointed_thing.under
local node = minetest.get_node(pos)
if player and not player:get_player_control().sneak then
local nodedef = minetest.registered_nodes[node.name]
local on_rightclick = nodedef and nodedef.on_rightclick
if on_rightclick then
return on_rightclick(pos, node, player, itemstack, pointed_thing) or itemstack, true
end
end
end
return itemstack, false
end
function mcl_util.calculate_durability(itemstack)
local unbreaking_level = mcl_enchanting.get_enchantment(itemstack, "unbreaking")
local armor_uses = minetest.get_item_group(itemstack:get_name(), "mcl_armor_uses")

@ -123,17 +123,10 @@ minetest.register_craftitem("mcl_bone_meal:bone_meal", {
inventory_image = "mcl_bone_meal.png",
groups = {craftitem=1},
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.under
local node = minetest.get_node(pos)
local ndef = minetest.registered_nodes[node.name]
-- Use pointed node's on_rightclick function first, if present.
if placer and not placer:get_player_control().sneak then
if ndef and ndef.on_rightclick then
local new_stack = mcl_util.call_on_rightclick(itemstack, placer, pointed_thing)
if new_stack and new_stack ~= itemstack then return new_stack end
end
end
local called
itemstack, called = mcl_util.handle_node_rightclick(itemstack, placer, pointed_thing)
if called then return itemstack end
return mcl_bone_meal.use_bone_meal(itemstack, placer, pointed_thing)
end,

@ -1,3 +1,3 @@
name = mcl_farming
depends = mcl_core, mcl_sounds, mcl_wool, mcl_torches, mcl_weather, mobs_mc, mcl_colors, mcl_init
depends = mcl_core, mcl_sounds, mcl_wool, mcl_torches, mcl_weather, mobs_mc, mcl_colors, mcl_init, mcl_bone_meal
optional_depends = mcl_armor, doc

@ -9,24 +9,26 @@ for i=0, 3 do
if i > 0 then
groups.sweet_berry_thorny = 1
end
local drop_berries = (i >= 2)
local berries_to_drop = drop_berries and {i - 1, i} or nil
local on_bonemealing = nil
local berries_to_drop = (i >= 2) and {i - 1, i} or nil
local function do_berry_drop(pos)
for j=1, berries_to_drop[math.random(2)] do
if not berries_to_drop then return false end
for _=1, berries_to_drop[math.random(2)] do
minetest.add_item(pos, "mcl_farming:sweet_berry")
end
minetest.swap_node(pos, {name = "mcl_farming:sweet_berry_bush_1"})
return true
end
local on_bonemealing = nil
if i ~= 3 then
on_bonemealing = function(itemstack, placer, pointed_thing)
on_bonemealing = function(_, _, 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)
return mcl_farming:grow_plant("plant_sweet_berry_bush", pos, node, 1, true)
end
else
on_bonemealing = function(itemstack, placer, pointed_thing)
on_bonemealing = function(_, _, pointed_thing)
do_berry_drop(pointed_thing.under)
end
end
@ -47,13 +49,13 @@ for i=0, 3 do
liquid_range = 0,
walkable = false,
-- Dont even create a table if no berries are dropped.
drop = not drop_berries and "" or {
drop = berries_to_drop and {
max_items = 1,
items = {
{ items = {"mcl_farming:sweet_berry " .. berries_to_drop[1] }, rarity = 2 },
{ items = {"mcl_farming:sweet_berry " .. berries_to_drop[2] } }
}
},
} or "",
selection_box = {
type = "fixed",
fixed = {-6 / 16, -0.5, -6 / 16, 6 / 16, (-0.30 + (i*0.25)), 6 / 16},
@ -65,28 +67,18 @@ for i=0, 3 do
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
_on_bone_meal = on_bonemealing,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
on_rightclick = function(pos, _, clicker, itemstack, pointed_thing)
local pn = clicker:get_player_name()
if clicker:is_player() and minetest.is_protected(pos, pn) then
minetest.record_protection_violation(pos, pn)
return itemstack
end
if 3 ~= i and mcl_dye and
clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then
mcl_dye.apply_bone_meal({under=pos, above=vector.offset(pos,0,1,0)},clicker)
if not minetest.is_creative_enabled(pn) then
itemstack:take_item()
end
return
end
if i >= 2 then
do_berry_drop(pos)
else
-- Use bonemeal
if mcl_bone_meal and clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then
return mcl_bone_meal.use_bone_meal(itemstack, clicker, pointed_thing)
end
if do_berry_drop(pos) then return itemstack end
-- Use bonemeal
if mcl_bone_meal and clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then
return mcl_bone_meal.use_bone_meal(itemstack, clicker, pointed_thing)
end
return itemstack
end,