vines/turtle.lua: command strings testing 6
authorOlav Bakke Svendsen <mail@olavbs.no>
Tue, 14 May 2024 12:34:25 +0000 (14:34 +0200)
committerOlav Bakke Svendsen <mail@olavbs.no>
Tue, 14 May 2024 12:34:25 +0000 (14:34 +0200)
vines/turtle.lua

index c3405bd94425683c170589653cdead8ff1c2e1dd..1a1201a708856e97d2cd405f0e2b921f6a078178 100644 (file)
@@ -81,7 +81,10 @@ local select = function(t)
     return true
   else
     local i, e = find(t)
-    if i then return turtle.select(i) end
+    if i then 
+      turtle.select(i)
+      return true
+    end
   end
   return false, "Nothing to select: " .. e
 end
@@ -91,8 +94,14 @@ end
 -- requires an empty slot to move items around.
 -- (this function exists because weak automata cannot digBlock with tools in slots >9)
 local transferAndSelect = function(i, t)
-  local msg = "Could not transfer and select: "
   if i < 1 or i > 16 then return false, msg .. "Index out of range" end
+  -- if a wanted item already is in the wanted slot, select it and return early
+  local item = turtle.getItemDetail(i)
+  if oneOf(t, item.name) then
+    turtle.select(i)
+    return true
+  end
+  local msg = "Could not transfer and select: "
   local i_tmp, e = findEmpty()
   if not i_tmp then return false, msg .. e end
   local i_from, e = find(t)