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

index 4df09c64b8acf97879dd49dce12a7ae05e94c0f4..fe0ff33c8311b6d3969c9328257e7342e5dfcd24 100644 (file)
@@ -119,7 +119,7 @@ end
 local harvest = function()
   local facing_block, block = turtle.inspect()
   if not (facing_block and block.name == "minecraft:vine") then return false, "Not facing vine" end
-  if not transferAndSelect(shears) then return false, "No shears available" end
+  if not transferAndSelect(1, shears) then return false, "No shears available" end
   local cut, cut_error = automata.digBlock()
   if not cut then return false, "Could not cut vine: " .. cut_error end
   local collect, collect_error = automata.collectItems()
@@ -160,13 +160,13 @@ end
 
 -- rep : number of repeats -> string -> string | nil
 -- repeats string n times
---
-local  = function(n, str)
+local rep = function(n, str)
   if not n or n < 0 then return nil end
   local s = ""
-  for i 1, i do
+  for i = 1, n do
     s = s .. str
   end
+  return s
 end
     
 -- for testing purposes
@@ -174,16 +174,19 @@ local sequence = function()
   print("pretending to unload stray items")
   print("pretending to refuel")
   print("pretending to stock up on shears")
-  local enter_vineyard = "rf3hfhflfr2"
-  local harvest_north =
-    "d2h u4h"
-    .. rep(6,"u2h") .. "lfdrh"
-    .. rep(7,"d2h") .. "lfurh"
-    .. rep(7,"u2h") .. "lfdrh"
-    .. rep(7,"d2h") .. "lfurh"
-    .. rep(7,"u2h") .. "lfdrh"
-  print(cmd)
-  return runCommand(cmd..)
+  local enter_vineyard = "rf3hfhflfr2d2"
+  local harvest_up = function(n) rep(n, "hu2") .. "h" end
+  local harvest_down = function(n) rep(n, "hd2") .. "h" end
+  local harvest_ns = rep(2, harvest_up(8).."lfdr"..harvest_down(7).."lfdr")..harvest_up(8)
+  local harvest_ew = rep(2, harvest_down(8).."lfur"..harvest_up(7).."lfur")..harvest_down(8)
+  local go_to_dropoff = "u2lhfrhf5lf2"
+  print("running harvesting sequence...")
+  local seq =
+       enter_vineyard
+    .. harvest_ns .. "l" .. harvest_ew .. "l"
+    .. harvest_ns .. "l" .. harvest_ew
+    .. go_to_dropoff
+  return runCommand(seq)
 end
 
 while true do