mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-01 22:03:02 +00:00
Starbeamrainbowlabs
e2167c4ba3
Ref https://discord.com/channels/1135598362821935254/1247681375935533119
---------------------------------------
Hi, a wild //orient+ appeared! While it (probably) doesn't crash, it also unfortunately doesn't work yet.
This is because facedir e.g. points towards the direction the node is pointing, and minetest.facedir_to_dir doesn't capture all the nuance of how the node is pointing, and e.g. if a node is pointing +y and you want to rotate by (0, 90, 0) [degrees], then the current implementation won't do anything.
Then I decided that this is silly and there has to be a solution. After all, screwdriver2 has a great implementation! https://content.minetest.net/packages/12Me21/screwdriver2/
....then I found this lookup table in their codebase: https://github.com/12Me21/screwdriver2/blob/master/init.lua#L75-L79
....aaaaarrrggggghhhhh //orient+ is such a pain to implement!
and my existing implementation is so neat 😢 1dd073f14b/worldeditadditions_core/utils/param2.lua
so, in other words, although I've implemented //orient+ I'm going to have to reimplement the nuts-and-bolts function that does the rotation, which may make it slightly more complicated and annoying to implement support for nodes with param2 types other than facedir.
/rant about Minetest's param2 value and rotations 😛
63 lines
No EOL
2.2 KiB
Lua
63 lines
No EOL
2.2 KiB
Lua
local core = worldeditadditions_core
|
|
local Vector3 = core.Vector3
|
|
---
|
|
-- @module worldeditadditions_core.param2
|
|
|
|
-- TODO Reimplement for facedir ref https://github.com/12Me21/screwdriver2/blob/master/init.lua#L75-L79
|
|
|
|
-- //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))
|
|
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_type, param2)
|
|
|
|
print("DEBUG:param2>orient dir", core.inspect(dir), "param2_type", 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)
|
|
print("DEBUG:param2>orient STEP AFTER dir", dir, "ROT", rot, "ORIGIN", origin)
|
|
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
|
|
|
|
print("DEBUG:param2>orient FINAL dir", dir)
|
|
|
|
return dir_to_param2(param2_type, dir)
|
|
end
|
|
|
|
|
|
|
|
|
|
return {
|
|
orient = orient
|
|
} |