mirror of
https://github.com/mt-mods/xcompat.git
synced 2024-12-22 09:00:17 +01:00
sapling on place function (#40)
This commit is contained in:
parent
655486f465
commit
931a16803e
@ -16,4 +16,40 @@ function functions.can_interact_with_node(player, pos)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function functions.sapling_on_place(
|
||||||
|
itemstack, player, pointed_thing, sapling_name, minp_relative, maxp_relative, interval
|
||||||
|
)
|
||||||
|
if default then
|
||||||
|
return default.sapling_on_place(
|
||||||
|
itemstack, player, pointed_thing, sapling_name, minp_relative, maxp_relative, interval
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos = pointed_thing.above
|
||||||
|
local pname = player and player:get_player_name() or ""
|
||||||
|
local below_node = minetest.get_node_or_nil(pointed_thing.under)
|
||||||
|
|
||||||
|
if below_node and minetest.registered_items[below_node.name] and
|
||||||
|
minetest.registered_items[below_node.name].buildable_to then
|
||||||
|
|
||||||
|
pos = pointed_thing.under
|
||||||
|
end
|
||||||
|
|
||||||
|
--check protection
|
||||||
|
if minetest.is_protected(pos, pname) then
|
||||||
|
minetest.record_protection_violation(pos, pname)
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
--actually place sapling
|
||||||
|
minetest.set_node(pos, {name = sapling_name})
|
||||||
|
|
||||||
|
--handle survival
|
||||||
|
if not minetest.is_creative_enabled(pname) then
|
||||||
|
itemstack:take_item()
|
||||||
|
end
|
||||||
|
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
return functions
|
return functions
|
Loading…
Reference in New Issue
Block a user