Files
2026-07-07 13:15:54 -04:00

36 lines
1.0 KiB
Lua

local function is_mapblock_grid_pos(pos)
return (pos.x % 16 == 0) and (pos.y % 16 == 0) and (pos.z % 16 == 0)
end
minetest.register_on_placenode(function(pos, newnode, placer)
if newnode.name ~= "protector:protect" then
return
end
if is_mapblock_grid_pos(pos) then
return
end
minetest.remove_node(pos)
if placer and placer:is_player() then
local player_name = placer:get_player_name()
if not minetest.is_creative_enabled(player_name) then
local refund = ItemStack("protector:protect")
local inv = placer:get_inventory()
if inv and inv:room_for_item("main", refund) then
inv:add_item("main", refund)
else
minetest.add_item(vector.offset(pos, 0, 1, 0), refund)
end
end
minetest.chat_send_player(
player_name,
"Protector placement failed: place only at coordinates divisible by 16."
)
end
end)