Screwdriver: simplify logic, allow wallmounted rotation.

- Allow rotation of wallmounted nodeboxes (signs) since they are
  now rotating properly.
- Instead of testing `ndef` several times, do it once, correctly.
- Simplify exception logic for nodes that have `on_rotate` set.
- For simplicity, return itemstack, always.
- Remove a useless nil check.
This commit is contained in:
Auke Kok 2017-03-13 12:35:45 -07:00 committed by paramat
parent 6a55e150af
commit ecf160d93d
1 changed files with 10 additions and 15 deletions

View File

@ -93,38 +93,33 @@ screwdriver.handler = function(itemstack, user, pointed_thing, mode, uses)
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 then
return itemstack
end
-- can we rotate this paramtype2? -- can we rotate this paramtype2?
local fn = screwdriver.rotate[ndef.paramtype2] local fn = screwdriver.rotate[ndef.paramtype2]
if not fn then if not fn then
return return itemstack
end end
local should_rotate = true local should_rotate = true
local new_param2 = fn(pos, node, mode) local new_param2 = fn(pos, node, mode)
-- Node provides a handler, so let the handler decide instead if the node can be rotated -- Node provides a handler, so let the handler decide instead if the node can be rotated
if ndef and ndef.on_rotate then if ndef.on_rotate then
-- Copy pos and node because callback can modify it -- Copy pos and node because callback can modify it
local result = ndef.on_rotate(vector.new(pos), local result = ndef.on_rotate(vector.new(pos),
{name = node.name, param1 = node.param1, param2 = node.param2}, {name = node.name, param1 = node.param1, param2 = node.param2},
user, mode, new_param2) user, mode, new_param2)
if result == false then -- Disallow rotation if result == false then -- Disallow rotation
return return itemstack
elseif result == true then elseif result == true then
should_rotate = false should_rotate = false
end end
else elseif ndef.on_rotate == false then
if not ndef or return itemstack
ndef.on_rotate == false or elseif ndef.can_dig and not ndef.can_dig(pos, user) then
(ndef.drawtype == "nodebox" and return itemstack
(ndef.node_box and ndef.node_box.type ~= "fixed")) or
node.param2 == nil then
return
end
if ndef.can_dig and not ndef.can_dig(pos, user) then
return
end
end end
if should_rotate then if should_rotate then