mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-05-31 02:56:26 -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 = {
|
selection_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = def.selectionbox,
|
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)
|
after_place_node = function(pos, placer, itemstack)
|
||||||
local n = minetest.get_node_or_nil(pos)
|
local n = minetest.get_node_or_nil(pos)
|
||||||
if not n or not n.param2 then
|
if not n or not n.param2 then
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local dir = minetest.facedir_to_dir(n.param2)
|
local n2 = minetest.get_node_or_nil(vector.add(pos, minetest.facedir_to_dir(n.param2)))
|
||||||
local p = {x=pos.x+dir.x,y=pos.y,z=pos.z+dir.z}
|
if n2
|
||||||
local n2 = minetest.get_node_or_nil(p)
|
and n2.param2 == n.param2
|
||||||
local def = minetest.registered_items[n2.name] or nil
|
and n2.name == name.."_top" then
|
||||||
if not n2 or not def or not def.buildable_to then
|
return false
|
||||||
minetest.remove_node(pos)
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
minetest.set_node(p, {name = n.name:gsub("%_bottom", "_top"), param2 = n.param2})
|
minetest.remove_node(pos)
|
||||||
return false
|
return true
|
||||||
end,
|
end,
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
local n = minetest.get_node_or_nil(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 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)
|
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)
|
minetest.remove_node(p)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -25,14 +25,16 @@ local function screwdriver_handler(itemstack, user, pointed_thing, mode)
|
||||||
|
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local ndef = minetest.registered_nodes[node.name]
|
local ndef = minetest.registered_nodes[node.name]
|
||||||
if not ndef or not ndef.paramtype2 == "facedir" or
|
if not ndef
|
||||||
(ndef.drawtype == "nodebox" and
|
or not ndef.paramtype2 == "facedir"
|
||||||
not ndef.node_box.type == "fixed") or
|
or (ndef.drawtype == "nodebox"
|
||||||
node.param2 == nil then
|
and not ndef.node_box.type == "fixed")
|
||||||
|
or node.param2 == nil then
|
||||||
return
|
return
|
||||||
end
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -48,9 +50,23 @@ local function screwdriver_handler(itemstack, user, pointed_thing, mode)
|
||||||
rotationPart = nextrange(axisdir, 5) * 4
|
rotationPart = nextrange(axisdir, 5) * 4
|
||||||
end
|
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
|
node.param2 = preservePart + rotationPart
|
||||||
minetest.swap_node(pos, node)
|
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
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
itemstack:add_wear(65535 / (USES - 1))
|
itemstack:add_wear(65535 / (USES - 1))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue