From 263588009694ff83f66da3446e92b8920a3a301e Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 11 Mar 2017 17:04:38 +0100 Subject: [PATCH] Don't allow placement of vines on ceiling --- mods/ITEMS/mcl_core/nodes.lua | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/mods/ITEMS/mcl_core/nodes.lua b/mods/ITEMS/mcl_core/nodes.lua index a574c6ae3..85efbfd07 100644 --- a/mods/ITEMS/mcl_core/nodes.lua +++ b/mods/ITEMS/mcl_core/nodes.lua @@ -1334,6 +1334,50 @@ minetest.register_node("mcl_core:vine", { minetest.add_item(pos, oldnode.name) end end, + node_placement_prediction = "", + -- Restrict placement of vines + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" then + -- no interaction possible with entities + return itemstack + end + + local under = pointed_thing.under + local node = minetest.get_node(under) + local def = minetest.registered_nodes[node.name] + local groups = def.groups + + -- Check special rightclick action of pointed node + if def and def.on_rightclick then + if not placer:get_player_control().sneak then + return def.on_rightclick(under, node, placer, itemstack, + pointed_thing) or itemstack, false + end + end + + -- Only allow placement on solid nodes + if (not groups) or (not groups.solid) then + return itemstack + end + + local above = pointed_thing.above + + -- Vines may not be placed on the ceiling + if under.y > above.y then + return itemstack + end + local idef = itemstack:get_definition() + local success = minetest.item_place_node(itemstack, placer, pointed_thing) + + if success then + if idef.sounds and idef.sounds.place then + minetest.sound_play(idef.sounds.place, {pos=above, gain=1}) + end + end + return itemstack + end, + + _mcl_blast_resistance = 1, _mcl_hardness = 0.2, })