diff --git a/README.md b/README.md index 25d4794..db74e27 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Rotating a node can be done in three ways: - Click near an edge, and the node will be rotated 90° away from you. - Click near a corner, and the node will rotate 120° around it. -Sneaking inverts the direction of the rotation. +Sneaking while empty-handed inverts the direction of the rotation. At this time, nodes that can be rotated are hardcoded into the mod, since their valid orientations can't be determined just by their node definition. diff --git a/init.lua b/init.lua index b7f35c7..cc2bdb1 100755 --- a/init.lua +++ b/init.lua @@ -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)