Skip to content

Commit da0cc7f

Browse files
sofarparamat
authored andcommittedMar 21, 2016
Beds: priv/griefing fixes.
- disallow placing beds in protected areas - fix rotation of beds(broken after 41c2b2a) - allow using others' beds, but don't change spawn location Fixes #953. #943 isn't something I think was ever implemented, and this does a fair job of addressing the main concern (spawning in others' houses)
1 parent b57dd0f commit da0cc7f

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed
 

‎mods/beds/api.lua

+38-18
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,42 @@ function beds.register_bed(name, def)
4444
fixed = def.selectionbox,
4545
},
4646

47-
after_place_node = function(pos, placer, itemstack)
48-
local n = minetest.get_node_or_nil(pos)
49-
if not n or not n.param2 then
50-
minetest.remove_node(pos)
51-
return true
47+
on_place = function(itemstack, placer, pointed_thing)
48+
local under = pointed_thing.under
49+
local pos
50+
if minetest.registered_items[minetest.get_node(under).name].buildable_to then
51+
pos = under
52+
else
53+
pos = pointed_thing.above
5254
end
53-
local dir = minetest.facedir_to_dir(n.param2)
54-
local p = vector.add(pos, dir)
55-
local n2 = minetest.get_node_or_nil(p)
56-
local def = n2 and minetest.registered_items[n2.name]
57-
if not def or not def.buildable_to then
58-
minetest.remove_node(pos)
59-
return true
55+
56+
if minetest.is_protected(pos, placer:get_player_name()) and
57+
not minetest.check_player_privs(placer, "protection_bypass") then
58+
minetest.record_protection_violation(pos, placer:get_player_name())
59+
return itemstack
60+
end
61+
62+
local dir = minetest.dir_to_facedir(placer:get_look_dir())
63+
local botpos = vector.add(pos, minetest.facedir_to_dir(dir))
64+
65+
if minetest.is_protected(botpos, placer:get_player_name()) and
66+
not minetest.check_player_privs(placer, "protection_bypass") then
67+
minetest.record_protection_violation(botpos, placer:get_player_name())
68+
return itemstack
6069
end
61-
minetest.set_node(p, {name = n.name:gsub("%_bottom", "_top"), param2 = n.param2})
62-
return false
63-
end,
70+
71+
if not minetest.registered_nodes[minetest.get_node(botpos).name].buildable_to then
72+
return itemstack
73+
end
74+
75+
minetest.set_node(pos, {name = name .. "_bottom", param2 = dir})
76+
minetest.set_node(botpos, {name = name .. "_top", param2 = dir})
77+
78+
if not minetest.setting_getbool("creative_mode") then
79+
itemstack:take_item()
80+
end
81+
return itemstack
82+
end,
6483

6584
on_destruct = function(pos)
6685
destruct_bed(pos, 1)
@@ -96,9 +115,10 @@ function beds.register_bed(name, def)
96115
return false
97116
end
98117
node.param2 = new_param2
99-
minetest.swap_node(pos, node)
100-
minetest.remove_node(p)
101-
minetest.set_node(newp, {name = node.name:gsub("%_bottom", "_top"), param2 = new_param2})
118+
-- do not remove_node here - it will trigger destroy_bed()
119+
minetest.set_node(p, {name = "air"})
120+
minetest.set_node(pos, node)
121+
minetest.set_node(newp, {name = name .. "_top", param2 = new_param2})
102122
return true
103123
end,
104124
})

‎mods/beds/spawns.lua

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function beds.read_spawns()
1818
repeat
1919
local x = input:read("*n")
2020
if x == nil then
21-
break
22-
end
21+
break
22+
end
2323
local y = input:read("*n")
2424
local z = input:read("*n")
2525
local name = input:read("*l")
@@ -52,7 +52,10 @@ function beds.set_spawns()
5252
for name,_ in pairs(beds.player) do
5353
local player = minetest.get_player_by_name(name)
5454
local p = player:getpos()
55-
beds.spawn[name] = p
55+
-- but don't change spawn location if borrowing a bed
56+
if not minetest.is_protected(p, name) then
57+
beds.spawn[name] = p
58+
end
5659
end
5760
beds.save_spawns()
5861
end

0 commit comments

Comments
 (0)
Please sign in to comment.