Compare commits

..

2 Commits

  1. 2
      README.md
  2. 16
      init.lua

@ -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 an edge, and the node will be rotated 90° away from you.
- Click near a corner, and the node will rotate 120° around it. - 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 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. their valid orientations can't be determined just by their node definition.

@ -12,7 +12,7 @@ local registry = include("registry")
-- TODO: Add particles to preview rotation? -- TODO: Add particles to preview rotation?
-- Distance at which we want to rotate by "pushing" on an edge. -- Distance at which we want to rotate by "pushing" on an edge.
local EDGE_DISTANCE = 1.5 / 16 -- texels (at 16² texture resolution) local EDGE_DISTANCE = 2.5 / 16 -- texels (at 16² texture resolution)
-- Contains a per-player state that holds information, created by a raycast -- Contains a per-player state that holds information, created by a raycast
-- done in `playerstep`, about the node this player might rotate. This is used -- done in `playerstep`, about the node this player might rotate. This is used
@ -55,15 +55,19 @@ local function calculate_rotating_state(player, data)
local state = {} local state = {}
local pointed_thing = data.raycast() 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.pos = pointed_thing.under
state.node = minetest.get_node(state.pos) 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 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 degrees = 90
local r = utility.rotation_vector_from_lookat(state.node, pointed_thing, EDGE_DISTANCE) local r = utility.rotation_vector_from_lookat(state.node, pointed_thing, EDGE_DISTANCE)
state.axis = r state.axis = r
@ -75,8 +79,8 @@ local function calculate_rotating_state(player, data)
end end
-- Sneaking causes the direction of the rotation to be inverted. -- Sneaking causes the direction of the rotation to be inverted.
state.invert = player:get_player_control().sneak if is_sneaking then degrees = -degrees end
if state.invert then degrees = -degrees end state.invert = is_sneaking
state.facedir = rotate.rotate_facedir(state.node.param2, state.axis, -degrees) state.facedir = rotate.rotate_facedir(state.node.param2, state.axis, -degrees)
state.facedir = registry.fix_rotatable_facedir(state.node, state.facedir) state.facedir = registry.fix_rotatable_facedir(state.node, state.facedir)

Loading…
Cancel
Save