From 9ec33f34f1fc76a70eb9e8aeddcace4042f00979 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Sat, 6 Dec 2014 11:08:41 +0100 Subject: [PATCH] Set param2 to 1 if player places leaves --- game_api.txt | 4 ++++ mods/default/functions.lua | 6 ++++++ mods/default/nodes.lua | 3 +++ 3 files changed, 13 insertions(+) diff --git a/game_api.txt b/game_api.txt index 9052e2ae..4424b20b 100644 --- a/game_api.txt +++ b/game_api.txt @@ -206,5 +206,9 @@ the node can be without decaying. If param2 of the node is ~= 0, the node will always be preserved. Thus, if the player places a node of that kind, you will want to set param2=1 or so. +The function default.after_place_leaves can be set as after_place_node of a node +to set param2 to 1 if the player places the node (should not be used for nodes +that use param2 otherwise (e.g. facedir)). + If the node is in the leafdecay_drop group then it will always be dropped as an item. diff --git a/mods/default/functions.lua b/mods/default/functions.lua index 630cdbdb..ecb7f612 100644 --- a/mods/default/functions.lua +++ b/mods/default/functions.lua @@ -244,6 +244,12 @@ minetest.register_globalstep(function(dtime) math.floor(dtime * finds_per_second) end) +default.after_place_leaves = function(pos, placer, itemstack, pointed_thing) + local node = minetest.get_node(pos) + node.param2 = 1 + minetest.set_node(pos, node) +end + minetest.register_abm({ nodenames = {"group:leafdecay"}, neighbors = {"air", "group:liquid"}, diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index 7e7977c6..a4fe2c37 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -277,6 +277,7 @@ minetest.register_node("default:jungleleaves", { } }, sounds = default.node_sound_leaves_defaults(), + after_place_node = default.after_place_leaves, }) minetest.register_node("default:junglesapling", { @@ -341,6 +342,7 @@ minetest.register_node("default:leaves", { } }, sounds = default.node_sound_leaves_defaults(), + after_place_node = default.after_place_leaves, }) minetest.register_node("default:cactus", { @@ -1505,6 +1507,7 @@ minetest.register_node("default:pine_needles",{ } }, sounds = default.node_sound_leaves_defaults(), + after_place_node = default.after_place_leaves, }) minetest.register_node("default:pine_sapling", { -- 2.25.1