mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-05-28 09:36:27 -04:00
Merge 3b61a22334
into fe7a982343
This commit is contained in:
commit
e15f525426
2 changed files with 46 additions and 19 deletions
|
@ -17,32 +17,43 @@ function beds.register_bed(name, def)
|
|||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = def.selectionbox,
|
||||
|
||||
},
|
||||
on_construct = function(pos)
|
||||
local n = minetest.get_node(pos)
|
||||
local p = vector.add(pos, minetest.facedir_to_dir(n.param2))
|
||||
local n2 = minetest.get_node_or_nil(p)
|
||||
local def = minetest.registered_nodes[n2.name]
|
||||
if n2
|
||||
and def
|
||||
and def.buildable_to then
|
||||
minetest.set_node(p, {name = name.."_top", param2 = n.param2})
|
||||
end
|
||||
end,
|
||||
after_place_node = function(pos, placer, itemstack)
|
||||
local n = minetest.get_node_or_nil(pos)
|
||||
if not n or not n.param2 then
|
||||
minetest.remove_node(pos)
|
||||
return true
|
||||
end
|
||||
local dir = minetest.facedir_to_dir(n.param2)
|
||||
local p = {x=pos.x+dir.x,y=pos.y,z=pos.z+dir.z}
|
||||
local n2 = minetest.get_node_or_nil(p)
|
||||
local def = minetest.registered_items[n2.name] or nil
|
||||
if not n2 or not def or not def.buildable_to then
|
||||
minetest.remove_node(pos)
|
||||
return true
|
||||
local n2 = minetest.get_node_or_nil(vector.add(pos, minetest.facedir_to_dir(n.param2)))
|
||||
if n2
|
||||
and n2.param2 == n.param2
|
||||
and n2.name == name.."_top" then
|
||||
return false
|
||||
end
|
||||
minetest.set_node(p, {name = n.name:gsub("%_bottom", "_top"), param2 = n.param2})
|
||||
return false
|
||||
end,
|
||||
minetest.remove_node(pos)
|
||||
return true
|
||||
end,
|
||||
on_destruct = function(pos)
|
||||
local n = minetest.get_node_or_nil(pos)
|
||||
if not n then return end
|
||||
if not n then
|
||||
return
|
||||
end
|
||||
local dir = minetest.facedir_to_dir(n.param2)
|
||||
local p = {x=pos.x+dir.x,y=pos.y,z=pos.z+dir.z}
|
||||
local p = vector.add(pos, dir)
|
||||
local n2 = minetest.get_node(p)
|
||||
if minetest.get_item_group(n2.name, "bed") == 2 and n.param2 == n2.param2 then
|
||||
if minetest.get_item_group(n2.name, "bed") == 2
|
||||
and n.param2 == n2.param2 then
|
||||
minetest.remove_node(p)
|
||||
end
|
||||
end,
|
||||
|
|
|
@ -25,14 +25,16 @@ local function screwdriver_handler(itemstack, user, pointed_thing, mode)
|
|||
|
||||
local node = minetest.get_node(pos)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
if not ndef or not ndef.paramtype2 == "facedir" or
|
||||
(ndef.drawtype == "nodebox" and
|
||||
not ndef.node_box.type == "fixed") or
|
||||
node.param2 == nil then
|
||||
if not ndef
|
||||
or not ndef.paramtype2 == "facedir"
|
||||
or (ndef.drawtype == "nodebox"
|
||||
and not ndef.node_box.type == "fixed")
|
||||
or node.param2 == nil then
|
||||
return
|
||||
end
|
||||
|
||||
if ndef.can_dig and not ndef.can_dig(pos, user) then
|
||||
if ndef.can_dig
|
||||
and not ndef.can_dig(pos, user) then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -48,9 +50,23 @@ local function screwdriver_handler(itemstack, user, pointed_thing, mode)
|
|||
rotationPart = nextrange(axisdir, 5) * 4
|
||||
end
|
||||
|
||||
if ndef.on_destruct then
|
||||
ndef.on_destruct(vector.new(pos))
|
||||
end
|
||||
|
||||
local oldnode = ndef.after_destruct and table.copy(node)
|
||||
|
||||
node.param2 = preservePart + rotationPart
|
||||
minetest.swap_node(pos, node)
|
||||
|
||||
if oldnode then
|
||||
ndef.after_destruct(vector.new(pos), oldnode)
|
||||
end
|
||||
|
||||
if ndef.on_construct then
|
||||
ndef.on_construct(vector.new(pos))
|
||||
end
|
||||
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
itemstack:add_wear(65535 / (USES - 1))
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue