summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inv_utils.lua13
-rw-r--r--nav.lua43
2 files changed, 56 insertions, 0 deletions
diff --git a/inv_utils.lua b/inv_utils.lua
new file mode 100644
index 0000000..830e39e
--- /dev/null
+++ b/inv_utils.lua
@@ -0,0 +1,13 @@
+local function getEmptySlotInStorage(storage)
+ return 5 -- TODO
+end
+
+local function swapSlotsInStorage(storage, slotA, slotB)
+ local emptySlot = getEmptySlotInStorage(storage)
+ storage.pushItems(peripheral.getName(storage), slotA, nil, emptySlot)
+ storage.pushItems(peripheral.getName(storage), slotB, nil, slotA)
+ storage.pushItems(peripheral.getName(storage), emptySlot, nil, slotB)
+end
+
+
+return { swapSlotsInStorage = swapSlotsInStorage }
diff --git a/nav.lua b/nav.lua
new file mode 100644
index 0000000..354897a
--- /dev/null
+++ b/nav.lua
@@ -0,0 +1,43 @@
+-- orientation: east 1 x+, south 2 z+, west 3 x-, north 4 z-
+
+local function turnTo(o1, o2)
+ if o1 == o2 then
+ return nil
+ end
+
+ if math.abs(o2 - o1) == 2 then
+ turtle.turnLeft()
+ turtle.turnLeft()
+ elseif o2 - o1 == 1 or o2 - o1 == -3 then
+ turtle.turnRight()
+ else
+ turtle.turnLeft()
+ end
+end
+
+local function moveX(x1, x2, o1)
+ if x1 == x2 then
+ return o1
+ end
+
+ local amount = x2 - x1
+ local o2 = amount > 0 and 1 or 3
+ turnTo(o1, o2)
+
+ for ii = 1, math.abs(amount) do
+ turtle.forward()
+ end
+
+ return o2
+end
+
+local function travel(x1, y1, z1, o1, x2, y2, z2, o2, safe_y)
+ local dx = x2 - x1
+ local dz = z2 - z1
+ local move_safe = dx ~= 0 or dz ~= 0
+ if move_safe then
+
+ end
+end
+
+return { turnTo = turnTo, moveX = moveX }