pick_and_place/rotate.lua
Buckaroo Banzai 9cd093046d
schematic rotation (#1)
* schematic rotation

* fixes

* remove auto-rotation code

* schematic encoding v2

* testing

* working encode/decode

* rotate schematic

* spec

* rotate dialog

* skip if rotation == 0

* wip

* wip

* wip

* fix order

* fix metadata rotation

---------

Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2024-02-29 13:15:18 +01:00

33 lines
765 B
Lua

-- rotates the size for a given rotation
function pick_and_place.rotate_size(size, rotation)
if rotation == 90 or rotation == 270 then
-- invert x/z
return {
x = size.z,
y = size.y,
z = size.x
}
end
-- unchanged in 180 or 0 degrees
return size
end
-- look direction in 90-degree increments
function pick_and_place.get_player_rotation(player)
local yaw = player:get_look_horizontal()
local degrees = yaw / math.pi * 180
local rotation = 0
if degrees > 45 and degrees < (90+45) then
-- x-
rotation = 180
elseif degrees > (90+45) and degrees < (180+45) then
-- z-
rotation = 90
elseif degrees < 45 or degrees > (360-45) then
-- z+
rotation = 270
end
return rotation
end