mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-01 05:43:01 +00:00
Starbeamrainbowlabs
02d95cec46
....unfortunately, it doesn't work yet. Next up is a frankly ridiculous number of print()s to figure out what's going on here
54 lines
No EOL
1.9 KiB
Lua
54 lines
No EOL
1.9 KiB
Lua
local core = worldeditadditions_core
|
|
local Vector3 = core.Vector3
|
|
---
|
|
-- @module worldeditadditions_core.param2
|
|
|
|
-- //set <nodename>
|
|
-- //set param2|p2 <param2>
|
|
|
|
-- In future, we'll support more param2_type values here.
|
|
|
|
local function param2_to_dir(param2_type, param2)
|
|
if param2_type == "facedir" then
|
|
return Vector3.clone(minetest.facedir_to_dir(param2_type))
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
|
|
local function dir_to_param2(param2_type, dir)
|
|
if param2_type == "facedir" then
|
|
return minetest.dir_to_facedir(dir, true)
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
|
|
|
|
--- Rotates the given param2 value of the given type by the given COMPILED list of rotations.
|
|
-- In other words, reorients a given param2 value of a given param2_type (aka paramtype2 in the Minetest engine but the Minetest engine naming scheme is dumb in this case) according to a given COMPILED rotation list.
|
|
-- @param param2 number The param2 value to rotate.
|
|
-- @param param2_type string The type of param2 value we're talking about here. Currently, only a value of `facedir` is supported.
|
|
-- @param rotlist_c Vector3[] The list of vector rotations to apply to param2. Call `worldeditadditions_core.rotation.rotlist_compile` on a rotation list to get this value. Each one is iteratively applied using the `rotate` argument to Vector3.rotate3d.
|
|
-- @returns number? Returns the rotated param2 value, or nil if an invalid param2_type value was passed.
|
|
local function orient(param2, param2_type, rotlist_c)
|
|
local dir = param2_to_dir(param2, param2_type)
|
|
if dir == nil then return nil end
|
|
local origin = Vector3.new(0, 0, 0)
|
|
|
|
for _i, rot in ipairs(rotlist_c) do
|
|
dir = Vector3.rotate3d(origin, dir, rot)
|
|
end
|
|
|
|
dir = dir:round() -- Deal with floating-point rounding errors ref https://en.wikipedia.org/wiki/Round-off_error
|
|
-- TODO may need to do this every iteration in the above for loop un the unlikely event we have issues here
|
|
|
|
return dir_to_param2(param2_type, dir)
|
|
end
|
|
|
|
|
|
|
|
|
|
return {
|
|
orient = orient
|
|
} |