From 34a558ced9e823e5c6a8a652bbe8a702ca41e694 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 28 Nov 2022 11:43:09 +0100 Subject: [PATCH 1/2] Sweetberry, nethervines: Fix placing in protected area --- mods/ITEMS/mcl_crimson/init.lua | 24 ++++++++++++++++++------ mods/ITEMS/mcl_farming/sweet_berry.lua | 12 ++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index 3284f52e92..b57a6f4d29 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -116,14 +116,20 @@ minetest.register_node("mcl_crimson:twisting_vines", { fixed = { -3/16, -0.5, -3/16, 3/16, 0.5, 3/16 }, }, node_placement_prediction = "", - on_rightclick = function(pos, node, pointed_thing, itemstack) - if pointed_thing:get_wielded_item():get_name() == "mcl_crimson:twisting_vines" then + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local pn = clicker:get_player_name() + if clicker:is_player() and minetest.is_protected(vector.offset(pos,0,1,0), pn) then + minetest.record_protection_violation(vector.offset(pos,0,1,0), pn) + return itemstack + end + if clicker:get_wielded_item():get_name() == "mcl_crimson:twisting_vines" then itemstack:take_item() grow_vines(pos, 1, "mcl_crimson:twisting_vines") - elseif pointed_thing:get_wielded_item():get_name() == "mcl_dye:white" then + elseif clicker:get_wielded_item():get_name() == "mcl_dye:white" then itemstack:take_item() grow_vines(pos, math.random(1, 3),"mcl_crimson:twisting_vines") end + return itemstack end, drop = { max_items = 1, @@ -162,14 +168,20 @@ minetest.register_node("mcl_crimson:weeping_vines", { fixed = { -3/16, -0.5, -3/16, 3/16, 0.5, 3/16 }, }, node_placement_prediction = "", - on_rightclick = function(pos, node, pointed_thing, itemstack) - if pointed_thing:get_wielded_item():get_name() == "mcl_crimson:weeping_vines" then + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local pn = clicker:get_player_name() + if clicker:is_player() and minetest.is_protected(vector.offset(pos,0,1,0), pn) then + minetest.record_protection_violation(vector.offset(pos,0,1,0), pn) + return itemstack + end + if clicker:get_wielded_item():get_name() == "mcl_crimson:weeping_vines" then itemstack:take_item() grow_vines(pos, 1, "mcl_crimson:weeping_vines", -1) - elseif pointed_thing:get_wielded_item():get_name() == "mcl_dye:white" then + elseif clicker:get_wielded_item():get_name() == "mcl_dye:white" then itemstack:take_item() grow_vines(pos, math.random(1, 3),"mcl_crimson:weeping_vines", -1) end + return itemstack end, drop = { max_items = 1, diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index 69ac552e5a..1639915b63 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -36,8 +36,14 @@ for i=0, 3 do _mcl_blast_resistance = 0, _mcl_hardness = 0, 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 + minetest.record_protection_violation(pos, pn) + return itemstack + end if mcl_dye and clicker:get_wielded_item():get_name() == "mcl_dye:white" then mcl_dye.apply_bone_meal({under=pos},clicker) + itemstack:take_item() return end local stage @@ -52,6 +58,7 @@ for i=0, 3 do end minetest.swap_node(pos,{name = "mcl_farming:sweet_berry_bush_" .. stage - 1 }) end + return itemstack end, }) minetest.register_alias("mcl_sweet_berry:sweet_berry_bush_" .. i, node_name) @@ -64,6 +71,11 @@ minetest.register_craftitem("mcl_farming:sweet_berry", { groups = { food = 2, eatable = 1, compostability=30 }, on_secondary_use = minetest.item_eat(1), on_place = function(itemstack, placer, pointed_thing) + local pn = placer:get_player_name() + if placer:is_player() and minetest.is_protected(pointed_thing.above, pn) then + minetest.record_protection_violation(pointed_thing.above, pn) + return itemstack + end if pointed_thing.type == "node" and table.indexof(planton,minetest.get_node(pointed_thing.under).name) ~= -1 and minetest.get_node(pointed_thing.above).name == "air" then minetest.set_node(pointed_thing.above,{name="mcl_farming:sweet_berry_bush_0"}) if not minetest.is_creative_enabled(placer:get_player_name()) then From d395c82183252f08832b10d9f3c8906f9c371cc9 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 29 Nov 2022 12:19:27 +0100 Subject: [PATCH 2/2] Fix bonemeal creative for sweet berries and nether vines --- mods/ITEMS/mcl_crimson/init.lua | 20 ++++++++++++++------ mods/ITEMS/mcl_farming/sweet_berry.lua | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index b57a6f4d29..55bfbb6b54 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -118,15 +118,19 @@ minetest.register_node("mcl_crimson:twisting_vines", { node_placement_prediction = "", on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local pn = clicker:get_player_name() - if clicker:is_player() and minetest.is_protected(vector.offset(pos,0,1,0), pn) then + if clicker:is_player() and minetest.is_protected(vector.offset(pos,0,1,0), pn or "") then minetest.record_protection_violation(vector.offset(pos,0,1,0), pn) return itemstack end if clicker:get_wielded_item():get_name() == "mcl_crimson:twisting_vines" then - itemstack:take_item() + if not minetest.is_creative_enabled(clicker:get_player_name()) then + itemstack:take_item() + end grow_vines(pos, 1, "mcl_crimson:twisting_vines") elseif clicker:get_wielded_item():get_name() == "mcl_dye:white" then - itemstack:take_item() + if not minetest.is_creative_enabled(clicker:get_player_name()) then + itemstack:take_item() + end grow_vines(pos, math.random(1, 3),"mcl_crimson:twisting_vines") end return itemstack @@ -170,15 +174,19 @@ minetest.register_node("mcl_crimson:weeping_vines", { node_placement_prediction = "", on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local pn = clicker:get_player_name() - if clicker:is_player() and minetest.is_protected(vector.offset(pos,0,1,0), pn) then + if clicker:is_player() and minetest.is_protected(vector.offset(pos,0,1,0), pn or "") then minetest.record_protection_violation(vector.offset(pos,0,1,0), pn) return itemstack end if clicker:get_wielded_item():get_name() == "mcl_crimson:weeping_vines" then - itemstack:take_item() + if not minetest.is_creative_enabled(clicker:get_player_name()) then + itemstack:take_item() + end grow_vines(pos, 1, "mcl_crimson:weeping_vines", -1) elseif clicker:get_wielded_item():get_name() == "mcl_dye:white" then - itemstack:take_item() + if not minetest.is_creative_enabled(clicker:get_player_name()) then + itemstack:take_item() + end grow_vines(pos, math.random(1, 3),"mcl_crimson:weeping_vines", -1) end return itemstack diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index 1639915b63..be5c7ef2c2 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -72,7 +72,7 @@ minetest.register_craftitem("mcl_farming:sweet_berry", { on_secondary_use = minetest.item_eat(1), on_place = function(itemstack, placer, pointed_thing) local pn = placer:get_player_name() - if placer:is_player() and minetest.is_protected(pointed_thing.above, pn) then + if placer:is_player() and minetest.is_protected(pointed_thing.above, pn or "") then minetest.record_protection_violation(pointed_thing.above, pn) return itemstack end