From 09ef071c8128555d97abe8cbbca7a84b95091fb8 Mon Sep 17 00:00:00 2001 From: Gael-de-Sailly Date: Fri, 30 Jan 2015 14:32:51 +0100 Subject: [PATCH] Fixed sand replacing non-buildable-to nodes on place --- minetestforfun_game/mods/default/nodes.lua | 78 ++++++++-------------- 1 file changed, 27 insertions(+), 51 deletions(-) diff --git a/minetestforfun_game/mods/default/nodes.lua b/minetestforfun_game/mods/default/nodes.lua index 105c5d8b..5e275a3a 100644 --- a/minetestforfun_game/mods/default/nodes.lua +++ b/minetestforfun_game/mods/default/nodes.lua @@ -273,6 +273,30 @@ minetest.register_abm({ end }) +local function sand_on_place(itemstack, placer, pointed_thing) + if not pointed_thing.type == "node" then + return itemstack + end + local pn = placer:get_player_name() + if minetest.is_protected(pointed_thing.above, pn) then + return itemstack + end + local node = minetest.get_node(pointed_thing.above) + local def = minetest.registered_nodes[node.name] + if def and def.buildable_to then + minetest.add_node(pointed_thing.above, {name=itemstack:get_name()}) + local meta = minetest.get_meta(pointed_thing.above) + meta:set_string("owner", pn) + nodeupdate(pointed_thing.above) + if not minetest.setting_getbool("creative_mode") then + itemstack:take_item() + end + return itemstack + else + return itemstack + end +end + minetest.register_node("default:sand", { description = "Sand", tiles = {"default_sand.png"}, @@ -284,23 +308,7 @@ minetest.register_node("default:sand", { }, groups = {crumbly = 3, falling_node = 1, sand = 1}, sounds = default.node_sound_sand_defaults(), - on_place = function(itemstack, placer, pointed_thing) - if not pointed_thing.type == "node" then - return itemstack - end - local pn = placer:get_player_name() - if minetest.is_protected(pointed_thing.above, pn) then - return itemstack - end - minetest.add_node(pointed_thing.above, {name=itemstack:get_name()}) - local meta = minetest.get_meta(pointed_thing.above) - meta:set_string("owner", pn) - nodeupdate(pointed_thing.above) - if not minetest.setting_getbool("creative_mode") then - itemstack:take_item() - end - return itemstack - end + on_place = sand_on_place }) minetest.register_node("default:desert_sand", { @@ -314,23 +322,7 @@ minetest.register_node("default:desert_sand", { }, groups = {crumbly = 3, falling_node = 1, sand = 1}, sounds = default.node_sound_sand_defaults(), - on_place = function(itemstack, placer, pointed_thing) - if not pointed_thing.type == "node" then - return itemstack - end - local pn = placer:get_player_name() - if minetest.is_protected(pointed_thing.above, pn) then - return itemstack - end - minetest.add_node(pointed_thing.above, {name=itemstack:get_name()}) - local meta = minetest.get_meta(pointed_thing.above) - meta:set_string("owner", pn) - nodeupdate(pointed_thing.above) - if not minetest.setting_getbool("creative_mode") then - itemstack:take_item() - end - return itemstack - end + on_place = sand_on_place }) minetest.register_node("default:gravel", { @@ -344,23 +336,7 @@ minetest.register_node("default:gravel", { }, }, sounds = default.node_sound_gravel_defaults(), - on_place = function(itemstack, placer, pointed_thing) - if not pointed_thing.type == "node" then - return itemstack - end - local pn = placer:get_player_name() - if minetest.is_protected(pointed_thing.above, pn) then - return itemstack - end - minetest.add_node(pointed_thing.above, {name=itemstack:get_name()}) - local meta = minetest.get_meta(pointed_thing.above) - meta:set_string("owner", pn) - nodeupdate(pointed_thing.above) - if not minetest.setting_getbool("creative_mode") then - itemstack:take_item() - end - return itemstack - end + on_place = sand_on_place }) minetest.register_node("default:sandstone", {