|
|
|
@ -55,15 +55,19 @@ local function calculate_rotating_state(player, data) |
|
|
|
|
local state = {} |
|
|
|
|
|
|
|
|
|
local pointed_thing = data.raycast() |
|
|
|
|
if (not pointed_thing) or pointed_thing.type ~= "node" then return end |
|
|
|
|
if (not pointed_thing) or pointed_thing.type ~= "node" then return nil end |
|
|
|
|
|
|
|
|
|
state.pos = pointed_thing.under |
|
|
|
|
state.node = minetest.get_node(state.pos) |
|
|
|
|
if not registry.is_rotatable(state.node) then return end |
|
|
|
|
if not registry.is_rotatable(state.node) then return nil end |
|
|
|
|
|
|
|
|
|
if vector.equals(pointed_thing.above, pointed_thing.under) then return end |
|
|
|
|
if vector.equals(pointed_thing.above, pointed_thing.under) then return nil end |
|
|
|
|
state.face = pointed_thing.above - pointed_thing.under |
|
|
|
|
|
|
|
|
|
-- When player is sneaking, must be empty-handed for rotating to work. |
|
|
|
|
local is_sneaking = player:get_player_control().sneak |
|
|
|
|
if is_sneaking and (not player:get_wielded_item():is_empty()) then return nil end |
|
|
|
|
|
|
|
|
|
local degrees = 90 |
|
|
|
|
local r = utility.rotation_vector_from_lookat(state.node, pointed_thing, EDGE_DISTANCE) |
|
|
|
|
state.axis = r |
|
|
|
@ -75,8 +79,8 @@ local function calculate_rotating_state(player, data) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- Sneaking causes the direction of the rotation to be inverted. |
|
|
|
|
state.invert = player:get_player_control().sneak |
|
|
|
|
if state.invert then degrees = -degrees end |
|
|
|
|
if is_sneaking then degrees = -degrees end |
|
|
|
|
state.invert = is_sneaking |
|
|
|
|
|
|
|
|
|
state.facedir = rotate.rotate_facedir(state.node.param2, state.axis, -degrees) |
|
|
|
|
state.facedir = registry.fix_rotatable_facedir(state.node, state.facedir) |
|
|
|
|