mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-01 05:43:01 +00:00
//orient: it works without crashing.... but very strangely..
This commit is contained in:
parent
02d95cec46
commit
1dd073f14b
2 changed files with 15 additions and 5 deletions
|
@ -48,17 +48,20 @@ function worldeditadditions.orient(pos1, pos2, rotlist)
|
|||
-- nodeid = data[i]
|
||||
local param2_type = "none"
|
||||
if cache_nodeid_2_param2_type[data[i]] == nil then
|
||||
local nodeid = minetest.get_name_from_content_id(data[i])
|
||||
local ndef = minetest.registered_nodes[nodeid]
|
||||
local node_name = minetest.get_name_from_content_id(data[i])
|
||||
local ndef = minetest.registered_nodes[node_name]
|
||||
if type(ndef.paramtype2) ~= nil then
|
||||
param2_type = ndef.paramtype2
|
||||
end
|
||||
cache_nodeid_2_param2_type[data[i]] = param2_type
|
||||
print("DEBUG orient CACHE:PARAM2 MISS node", node_name, "param2_type", param2_type)
|
||||
else
|
||||
param2_type = cache_nodeid_2_param2_type[data[i]]
|
||||
end
|
||||
|
||||
if param2_type ~= "none" then
|
||||
print("DEBUG orient NODEID", data[i], "PARAM2_TYPE", param2_type)
|
||||
|
||||
if param2_type ~= "none" then
|
||||
local key = param2_type.."|"..data_param2[i]
|
||||
if cache_orient[key] == nil then
|
||||
cache_orient[key] = core.param2.orient(
|
||||
|
@ -67,6 +70,7 @@ function worldeditadditions.orient(pos1, pos2, rotlist)
|
|||
rotlist_c
|
||||
)
|
||||
end
|
||||
print("DEBUG orient KEY", key, "BEFORE", data_param2[i], "AFTER", cache_orient[key])
|
||||
|
||||
data_param2[i] = cache_orient[key]
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ local Vector3 = core.Vector3
|
|||
|
||||
local function param2_to_dir(param2_type, param2)
|
||||
if param2_type == "facedir" then
|
||||
return Vector3.clone(minetest.facedir_to_dir(param2_type))
|
||||
return Vector3.clone(minetest.facedir_to_dir(param2))
|
||||
else
|
||||
return nil
|
||||
end
|
||||
|
@ -32,17 +32,23 @@ end
|
|||
-- @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)
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue