Commit 78524c29 authored by Fedja Beader's avatar Fedja Beader
Browse files

WorldEdit: use screwdriver:screwdriver to rotate nodes to desired param2

parent 310a150e
......@@ -62,6 +62,77 @@ function queued_ensure_node(pos, name, timeout)
end
function queued_ensure_param2(pos, param2, timeout)
if timeout < 0 then
print("Timeout reached while waiting for param2 " .. param2 .. " at " .. minetest.pos_to_string(pos))
queue:clear()
return 0
end
local node = core.get_node_or_nil(pos)
if node and node.param2 == param2 then
return 0
else
queue:prepend(function() return queued_ensure_param2(pos, param2, timeout - 0.01) end)
return 0.01
end
end
local function queued_rotate_node(pos, new_param2)
local name = "screwdriver:screwdriver"
local oldindex = core.get_wield_index()
local my_inv = core.get_inventory()
local index = find_item_index(my_inv["main"], name)
if not index or index > 8 then
l:debug("No '" .. name .. "' in 8-hotbar!")
return
end
local under = { x = pos.x, y = pos.y, z = pos.z, }
local above = { x = pos.x, y = pos.y+1, z = pos.z, }
local node = core.get_node_or_nil(above)
if not node then
l:err("Node is nil!")
return 0
end
local param2 = node.param2
-- TODO: fix the pos/above/below mess
l:debug("Node at " .. minetest.pos_to_string(above) .. " has param2: " .. param2 .. ", desired: " .. new_param2)
-- use rotate turns 0->1->2->3->0
-- place rotate turns 0->4->8->12->16->20->0
local target_vert = math.floor(new_param2/4)
local current_vert = math.floor(param2/4)
if target_vert ~= current_vert then
l:debug("Executing one vertical rotation")
core.set_wield_index(index)
core.place_node(above, under)
core.set_wield_index(oldindex)
queue:prepend(function() return queued_rotate_node(pos, new_param2) end)
queue:prepend(function() return queued_ensure_param2(above, math.mod(current_vert + 4, 24), 5) end)
return 0
end
local target_horiz = math.mod(new_param2, 4)
local current_horiz = math.mod(param2, 4)
if target_horiz ~= current_horiz then
l:debug("Executing one horizontal rotation")
core.set_wield_index(index)
core.use_item(above, under)
core.set_wield_index(oldindex)
queue:prepend(function() return queued_rotate_node(pos, new_param2) end)
queue:prepend(function() return queued_ensure_param2(above, math.mod(current_horiz + 1, 4), 5) end)
return 0
end
return 0
end
local state = {
count = 0,
layer_count = 0,
......@@ -178,6 +249,7 @@ local function compute_next_step_saved()
queue:append(function() return step_place(node_data.node.name, pos, attach_pos) end)
queue:append(function() return queued_ensure_node(attach_pos, node_data.node.name, 5) end)
-- 6) rotate if needed
queue:append(function() return queued_rotate_node(pos, node_data.node.param2) end)
queue:append(compute_next_step_saved)
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment