Advertisement
Guest User

bfapi

a guest
May 25th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.46 KB | None | 0 0
  1. args = { ... }
  2. local mode = args[1]
  3. local width = args[2]
  4. local height = args[3]
  5.  
  6. function checkInventory(mode, width, height)
  7.   if not mode or not width or not height then
  8.     print("Wrong parameters!")
  9.     return false
  10.   elseif mode == "dirt" then
  11.     print(mode.." "..width.."x"..height)
  12.     for i = 1, 4 do
  13.       if not ((turtle.getItemCount(i) + turtle.getItemCount(i+4)) == (width*height)-1) then
  14.         print("Fill 1-4 with 4x64 dirt and fill 5-8 with 16 dirt each")
  15.         return false
  16.       end
  17.     end
  18.     return true
  19.   elseif mode == "farm" then
  20.    
  21.   else
  22.     print("What mode? "..mode.." wtf? ")
  23.     return false
  24.   end
  25. end
  26.  
  27. function selectedSlot()
  28.   return turtle.getSelectedSlot()
  29. end
  30.  
  31. function ItemCount(x)
  32.   return turtle.getItemCount(x)
  33. end
  34.  
  35. function selectSlot(x)
  36.   return turtle.select(x)
  37. end
  38.  
  39. function getSlotNr()
  40.   selectSlot(1)
  41.   for i = 1, 4 do
  42.     if ItemCount(selectedSlot()) > 0 then
  43.       return i
  44.     elseif ItemCount(selectedSlot()+4) > 0 then
  45.       return i+4
  46.     else
  47.       assert(false,"Error, no items!")
  48.     end
  49.   end
  50.   return 0  
  51. end
  52.  
  53.  
  54. function up()
  55.   return turtle.up()
  56. end
  57.  
  58. function destroy()
  59.   return turtle.digDown()
  60. end
  61.  
  62. function plant()
  63.   return turtle.placeDown()
  64. end
  65.  
  66. function forward(x)
  67.   if not x then turtle.forward()
  68.   else
  69.     for i = 1, x do
  70.       turtle.forward()
  71.     end
  72.   end
  73. end
  74.  
  75. function turnLeft(x)
  76.   return turtle.turnLeft(x)
  77. end
  78.  
  79. function turnRight(x)
  80.   return turtle.turnRight()
  81. end
  82.  
  83. function changeLine(linenr)
  84.   if ((linenr % 2) > 0) then
  85.     --forward()
  86.     --destroy()
  87.     --plant()
  88.     turnRight()
  89.     forward()
  90.     --destroy()
  91.     --plant()
  92.     turnRight()  
  93.   elseif ((linenr % 2) == 0) then
  94.     --forward()
  95.     --destroy()
  96.     --plant()
  97.     turnLeft()
  98.     forward()
  99.     --destroy()
  100.     --plant()
  101.     turnLeft()
  102.   else
  103.     print("fatal error")
  104.   end
  105. end
  106.  
  107.  
  108. function start(mode, width, height)
  109.   if not mode or not width or not height then
  110.     print("Wrong parameters!")
  111.     return false
  112.   end
  113.  
  114.   if mode == "dirt" then
  115.  
  116.     up()
  117.     forward()
  118.     selectSlot(1)
  119.     for w = 1, width do
  120.       for h = 1, height do
  121.         print("Schritt "..w.."/"..h)
  122.         assert(selectSlot(getSlotNr()),"Error")
  123.        
  124.         destroy()
  125.         plant()
  126.        
  127.        
  128.         if h == height then
  129.           changeLine(w)
  130.         else
  131.         print("else...")
  132.           forward()
  133.         end
  134.       end
  135.     end
  136.   end    
  137. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement