From 354160e9e60581c1b298109a3483ae0c672a845e Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 19 Apr 2024 10:31:45 +0000 Subject: [PATCH] Check both above and below in pointed_thing for bonemealing (and pass thru the position as .under), make crimson vines and twisting vines compostable by rightclicking on the composter --- mods/ITEMS/mcl_bone_meal/init.lua | 51 +++++++++++++++++-------------- mods/ITEMS/mcl_crimson/init.lua | 30 ++++++++++++------ 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index 3a0309003..2b3bf7041 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -76,34 +76,39 @@ end -- End legacy bone meal API mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing) - local pos = pointed_thing.under + local positions = {pointed_thing.under, pointed_thing.above} + for i = 1,2 do + local pos = positions[i] - -- Check protection - if mcl_util.check_area_protection(pos, pointed_thing.above, placer) then return false end + -- Check protection + if mcl_util.check_area_protection(pos, pointed_thing.above, placer) then return false end - local node = minetest.get_node(pos) - local ndef = minetest.registered_nodes[node.name] - local success = false - local consume + local node = minetest.get_node(pos) + local ndef = minetest.registered_nodes[node.name] + local success = false + local consume - -- If the pointed node can be bonemealed, let it handle the processing. - 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. - success = legacy_apply_bone_meal(pointed_thing, placer) - consume = success - end + -- If the pointed node can be bonemealed, let it handle the processing. + if ndef and ndef._on_bone_meal then + success = ndef._on_bone_meal(itemstack, placer, {under = pos, above = vector.offset(pos, 0, 1, 0)}) + consume = true + else + -- Otherwise try the legacy API. + success = legacy_apply_bone_meal(pointed_thing, placer) + consume = success + end - -- Particle effects - if success then - mcl_bone_meal.add_bone_meal_particle(pos) - end + -- Particle effects + if success then + mcl_bone_meal.add_bone_meal_particle(pos) + end - -- Take the item - if consume and ( not placer or not minetest.is_creative_enabled(placer:get_player_name()) ) then - itemstack:take_item() + -- Take the item + if consume and ( not placer or not minetest.is_creative_enabled(placer:get_player_name()) ) then + itemstack:take_item() + end + + if success then return itemstack end end return itemstack diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index 3f68921d1..e5c86841f 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -161,17 +161,22 @@ minetest.register_node("mcl_crimson:twisting_vines", { end, on_place = function(itemstack, placer, pointed_thing) local under = pointed_thing.under - local above = pointed_thing.above local unode = minetest.get_node(under) + local unode_def = minetest.registered_nodes[unode.name] + + local above = pointed_thing.above + local anode = minetest.get_node(above) + local anode_def = minetest.registered_nodes[anode.name] + if under.y < above.y then minetest.set_node(above, {name = "mcl_crimson:twisting_vines"}) if not minetest.is_creative_enabled(placer:get_player_name()) then itemstack:take_item() end - else - if unode.name == "mcl_crimson:twisting_vines" then - return minetest.registered_nodes[unode.name].on_rightclick(under, unode, placer, itemstack, pointed_thing) - end + elseif unode_def and unode_def.on_rightclick then + return unode_def.on_rightclick(under, unode, placer, itemstack, pointed_thing) + elseif anode_def and anode_def.on_rightclick then + return unode_def.on_rightclick(above, anode, placer, itemstack, pointed_thing) end return itemstack end, @@ -251,17 +256,22 @@ minetest.register_node("mcl_crimson:weeping_vines", { end, on_place = function(itemstack, placer, pointed_thing) local under = pointed_thing.under - local above = pointed_thing.above local unode = minetest.get_node(under) + local unode_def = minetest.registered_nodes[unode.name] + + local above = pointed_thing.above + local anode = minetest.get_node(above) + local anode_def = minetest.registered_nodes[anode.name] + if under.y > above.y then minetest.set_node(above, {name = "mcl_crimson:weeping_vines"}) if not minetest.is_creative_enabled(placer:get_player_name()) then itemstack:take_item() end - else - if unode.name == "mcl_crimson:weeping_vines" then - return minetest.registered_nodes[unode.name].on_rightclick(under, unode, placer, itemstack, pointed_thing) - end + elseif unode_def and unode_def.on_rightclick then + return unode_def.on_rightclick(under, unode, placer, itemstack, pointed_thing) + elseif anode_def and anode_def.on_rightclick then + return unode_def.on_rightclick(above, anode, placer, itemstack, pointed_thing) end return itemstack end,