Reverse and combine if statements in the screwdriver
This commit is contained in:
parent
c971ec7dc7
commit
04e560328f
|
@ -72,61 +72,59 @@ local function screwdriver_handler(itemstack, user, pointed_thing)
|
||||||
end
|
end
|
||||||
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 ndef and ndef.paramtype2 == "facedir" then
|
if not ndef or not ndef.paramtype2 == "facedir" or
|
||||||
if ndef.drawtype == "nodebox" and ndef.node_box.type ~= "fixed" then
|
(ndef.drawtype == "nodebox" and
|
||||||
return
|
not ndef.node_box.type == "fixed") or
|
||||||
end
|
node.param2 == nil then
|
||||||
if node.param2 == nil then
|
return
|
||||||
return
|
end
|
||||||
end
|
-- Get ready to set the param2
|
||||||
-- Get ready to set the param2
|
local n = node.param2
|
||||||
local n = node.param2
|
local axisdir = math.floor(n / 4)
|
||||||
local axisdir = math.floor(n / 4)
|
local rotation = n - axisdir * 4
|
||||||
local rotation = n - axisdir * 4
|
if mode == 1 then
|
||||||
if mode == 1 then
|
n = axisdir * 4 + nextrange(rotation, 3)
|
||||||
|
elseif mode == 2 then
|
||||||
|
-- If you are pointing at the axisdir face or the
|
||||||
|
-- opposite one then you can just rotate the node.
|
||||||
|
-- Otherwise change the axisdir, avoiding the facing
|
||||||
|
-- and opposite axes.
|
||||||
|
local face = get_node_face(pointed_thing)
|
||||||
|
if axisdir == face or axisdir == opposite_faces[face] then
|
||||||
n = axisdir * 4 + nextrange(rotation, 3)
|
n = axisdir * 4 + nextrange(rotation, 3)
|
||||||
elseif mode == 2 then
|
else
|
||||||
-- If you are pointing at the axisdir face or the
|
axisdir = nextrange(axisdir, 5)
|
||||||
-- opposite one then you can just rotate the node.
|
-- This is repeated because switching from the face
|
||||||
-- Otherwise change the axisdir, avoiding the facing
|
-- can move to to the opposite and vice-versa
|
||||||
-- and opposite axes.
|
|
||||||
local face = get_node_face(pointed_thing)
|
|
||||||
if axisdir == face or axisdir == opposite_faces[face] then
|
if axisdir == face or axisdir == opposite_faces[face] then
|
||||||
n = axisdir * 4 + nextrange(rotation, 3)
|
|
||||||
else
|
|
||||||
axisdir = nextrange(axisdir, 5)
|
axisdir = nextrange(axisdir, 5)
|
||||||
-- This is repeated because switching from the face
|
|
||||||
-- can move to to the opposite and vice-versa
|
|
||||||
if axisdir == face or axisdir == opposite_faces[face] then
|
|
||||||
axisdir = nextrange(axisdir, 5)
|
|
||||||
end
|
|
||||||
if axisdir == face or axisdir == opposite_faces[face] then
|
|
||||||
axisdir = nextrange(axisdir, 5)
|
|
||||||
end
|
|
||||||
n = axisdir * 4
|
|
||||||
end
|
end
|
||||||
elseif mode == 3 then
|
if axisdir == face or axisdir == opposite_faces[face] then
|
||||||
n = nextrange(axisdir, 5) * 4
|
axisdir = nextrange(axisdir, 5)
|
||||||
elseif mode == 4 then
|
|
||||||
local face = get_node_face(pointed_thing)
|
|
||||||
if axisdir == face then
|
|
||||||
n = axisdir * 4 + nextrange(rotation, 3)
|
|
||||||
else
|
|
||||||
n = face * 4
|
|
||||||
end
|
end
|
||||||
|
n = axisdir * 4
|
||||||
end
|
end
|
||||||
--print (dump(axisdir..", "..rotation))
|
elseif mode == 3 then
|
||||||
node.param2 = n
|
n = nextrange(axisdir, 5) * 4
|
||||||
minetest.swap_node(pos, node)
|
elseif mode == 4 then
|
||||||
local item_wear = tonumber(itemstack:get_wear())
|
local face = get_node_face(pointed_thing)
|
||||||
item_wear = item_wear + 327
|
if axisdir == face then
|
||||||
if item_wear > 65535 then
|
n = axisdir * 4 + nextrange(rotation, 3)
|
||||||
itemstack:clear()
|
else
|
||||||
return itemstack
|
n = face * 4
|
||||||
end
|
end
|
||||||
itemstack:set_wear(item_wear)
|
end
|
||||||
|
--print (dump(axisdir..", "..rotation))
|
||||||
|
node.param2 = n
|
||||||
|
minetest.swap_node(pos, node)
|
||||||
|
local item_wear = tonumber(itemstack:get_wear())
|
||||||
|
item_wear = item_wear + 327
|
||||||
|
if item_wear > 65535 then
|
||||||
|
itemstack:clear()
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
itemstack:set_wear(item_wear)
|
||||||
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
|
|
Loading…
Reference in New Issue