diff options
author | ubq323 <ubq323@ubq323.website> | 2024-04-04 00:40:21 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-04-04 00:40:21 +0100 |
commit | fa7f48bac1c8e87695598e66aadb7b198805b919 (patch) | |
tree | 819c38e2d8b33c4a83d338119010f69321197092 | |
parent | 8de5a7af338ee389df076fb3451f4009db2fa26e (diff) |
launch cactus
-rw-r--r-- | cactus.lua | 33 |
1 files changed, 23 insertions, 10 deletions
@@ -37,6 +37,7 @@ local function moveby_y(delta) local fn = turtle.up if delta < 0 then fn = turtle.down delta = -delta end for i=1,delta do fn() end + POS.y = POS.y + delta end local function rotatev(v,nq) @@ -60,21 +61,33 @@ end local function turn_to_face(newfacing) if newfacing == FACING then return - elseif newfacing == -FACING then turtle.turnRight() turtle.turnRight() - elseif newfacing == rotatev(FACING,1) then turtle.turnRight() - elseif newfacing == rotatev(FACING,-1) then turtle.turnLeft() + elseif newfacing == -FACING then turn_right() turn_right() + elseif newfacing == rotatev(FACING,1) then turn_right() + elseif newfacing == rotatev(FACING,-1) then turn_left() else error("invalid facing "..tostring(newfacing),2) end end +local function move_linear(n) + local dir = turtle.forward + if n < 0 then dir = turtle.back end + for i = 1,math.abs(n) do dir() end + POS = POS + n*FACING +end + local function moveby_xz(dv) - if dv.x ~= 0 then - turn_to_face(vector.new(numutil.sign(dv.x), 0, 0)) - for i=1,math.abs(dv.x) do turtle.forward() end - end - if dv.z ~= 0 then - turn_to_face(vector.new(0, 0, numutil.sign(dv.z))) - for i=1,math.abs(dv.z) do turtle.forward() end + if FACING.x ~= 0 then + move_linear(dv.x) + if dv.z ~= 0 then + turn_to_face(0,0,numutil.sign(dv.z)) + move_linear(math.abs(dv.z)) + end + elseif FACING.z ~= 0 then + move_linear(dv.z) + if dv.x ~= 0 then + turn_to_face(numutil.sign(dv.x),0,0) + move_linear(math.abs(dv.x)) + end end end |