From d7bb017dcaf5182fb95e36115d998f1b2aef3afd Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 2 Jan 2025 06:28:34 -0600 Subject: [PATCH] Fix sweetberry bonemealing crash, fix sweetberry growth, fix double bonemeal usage --- mods/CORE/mcl_util/init.lua | 15 +++++++++++++++ mods/ITEMS/mcl_bone_meal/init.lua | 13 +++---------- mods/ITEMS/mcl_farming/mod.conf | 2 +- mods/ITEMS/mcl_farming/sweet_berry.lua | 20 +++++++------------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 56a4aaa3d..c43731dbc 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -343,6 +343,21 @@ function mcl_util.call_on_rightclick(itemstack, player, pointed_thing) end end end +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") diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index e899ca765..6ce1554e8 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -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, diff --git a/mods/ITEMS/mcl_farming/mod.conf b/mods/ITEMS/mcl_farming/mod.conf index fe4bc1564..c833c031f 100644 --- a/mods/ITEMS/mcl_farming/mod.conf +++ b/mods/ITEMS/mcl_farming/mod.conf @@ -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 diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index 769e7b6cf..76d4d939a 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -14,19 +14,21 @@ for i=0, 3 do local on_bonemealing = nil local function do_berry_drop(pos) - for j=1, berries_to_drop[math.random(2)] do + if not berries_to_drop then return 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"}) end 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 @@ -65,20 +67,12 @@ 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)