make center return boolean if centered. (needed for some moveto operations)
This commit is contained in:
22
src/main.lua
22
src/main.lua
@@ -293,12 +293,16 @@ local function getnearestunplaced(buf, pbuf, cx,cy,cz,co, sx,sz, setceiling)
|
||||
return selected
|
||||
end
|
||||
local function center(direction, wanted)
|
||||
if direction == 1 and wanted ~= 1 then
|
||||
move("left")
|
||||
end
|
||||
if direction == -1 and wanted ~= -1 then
|
||||
move("right")
|
||||
end
|
||||
if direction == 1 and wanted ~= 1 then
|
||||
move("left")
|
||||
return true
|
||||
end
|
||||
if direction == -1 and wanted ~= -1 then
|
||||
move("right")
|
||||
return true
|
||||
end
|
||||
if direction == 0 then return true end
|
||||
return false
|
||||
end
|
||||
local function moveto(x,y,cx,cz,direction)
|
||||
while x ~= cx or y ~= cz do
|
||||
@@ -314,16 +318,14 @@ local function moveto(x,y,cx,cz,direction)
|
||||
end
|
||||
|
||||
if y > cz then -- z
|
||||
center(direction, 1)
|
||||
if center(direction, 1) then move("right") end
|
||||
cz = cz + 1
|
||||
move("right")
|
||||
move("forward")
|
||||
direction = 1
|
||||
end
|
||||
if y < cz then
|
||||
center(direction, -1)
|
||||
if center(direction, -1) then move("left") end
|
||||
cz = cz - 1
|
||||
move("left")
|
||||
move("forward")
|
||||
direction = -1
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user