-
Notifications
You must be signed in to change notification settings - Fork 155
support every paramtype2 #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
fae5db9
328a5f3
56d818a
790ccf6
2268437
5f8bb19
150e738
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,10 +31,20 @@ 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 then return end | ||
|
||
local paramtype2 = ndef.paramtype2 | ||
if ( | ||
paramtype2 == nil or | ||
paramtype2 == "color" or | ||
paramtype2 == "meshoptions" or | ||
paramtype2 == "leveled" or | ||
paramtype2 == "flowingliquid" or | ||
paramtype2 == "glasslikeliquidlevel" or | ||
paramtype2 == "wallmounted" or | ||
paramtype2 == "colorwallmounted" | ||
) then | ||
return | ||
end | ||
|
||
|
@@ -50,18 +60,54 @@ local function screwdriver_handler(itemstack, user, pointed_thing, mode) | |
minetest.sound_play("technic_sonic_screwdriver", {pos = pos, gain = 0.3, max_hear_distance = 10}) | ||
|
||
-- Set param2 | ||
local rotationPart = node.param2 % 32 -- get first 4 bits | ||
local preservePart = node.param2 - rotationPart | ||
|
||
local axisdir = math.floor(rotationPart / 4) | ||
local rotation = rotationPart - axisdir * 4 | ||
if mode == ROTATE_FACE then | ||
rotationPart = axisdir * 4 + nextrange(rotation, 3) | ||
elseif mode == ROTATE_AXIS then | ||
rotationPart = nextrange(axisdir, 5) * 4 | ||
local new_param2 | ||
local param2 = node.param2 | ||
|
||
local floor = math.floor | ||
if (paramtype2 == "facedir") or (paramtype2 == "colorfacedir") then | ||
local aux = floor(param2 / 32) | ||
local rotation = param2 % 32 | ||
|
||
if mode == ROTATE_FACE then | ||
rotation = (floor(param2 / 4)) * 4 + ((rotation + 1) % 4) | ||
elseif mode == ROTATE_AXIS then | ||
rotation = ((floor(param2 / 4) + 1) * 4) % 24 | ||
end | ||
|
||
new_param2 = aux * 32 + rotation | ||
elseif (paramtype2 == "4dir") or (paramtype2 == "color4dir") then | ||
local aux = floor(param2 / 4) | ||
local rotation = param2 % 4 | ||
|
||
if mode == ROTATE_FACE then | ||
rotation = (rotation + 1) % 4 | ||
elseif mode == ROTATE_AXIS then | ||
rotation = 0 | ||
end | ||
|
||
new_param2 = aux * 4 + rotation | ||
elseif (paramtype2 == "degrotate") then | ||
if mode == ROTATE_FACE then | ||
new_param2 = param2 + 1 | ||
elseif mode == ROTATE_AXIS then | ||
new_param2 = param2 + 20 | ||
end | ||
new_param2 = new_param2 % 240 | ||
elseif (paramtype2 == "colordegrotate") then | ||
local aux = floor(param2 / 32) | ||
local rotation = param2 % 32 | ||
|
||
if mode == ROTATE_FACE then | ||
rotation = rotation + 1 | ||
elseif mode == ROTATE_AXIS then | ||
rotation = rotation + 4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. describe the jump There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry. I meant that |
||
end | ||
rotation = rotation % 24 | ||
|
||
new_param2 = aux * 32 + rotation | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idea: You could move this code up such that a final Admittedly this code does not look great (magic numbers and many different cases) but I don't see much that could be done to improve it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be done |
||
|
||
node.param2 = preservePart + rotationPart | ||
node.param2 = new_param2 | ||
minetest.swap_node(pos, node) | ||
|
||
if not technic.creative_mode then | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
luacheck is yet unhappy
technic/tools/sonic_screwdriver.lua:11:16: unused function nextrange
To fix that, you could ignore the warning (I hope it's the correct code) or remove the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done: 150e738