Advertisement
PhilHibbs

cc_turtle_wheat

Jan 30th, 2013
1,428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.61 KB | None | 0 0
  1. -- ****************************************************************************
  2. -- **                                FARM                                    **
  3. -- ****************************************************************************
  4.  
  5. local n = 0
  6. local refilled = false
  7.  
  8. -- Fill the specified slot from any later slot that contains the same item, i.e. shuffle everything up to the topmost slots
  9. local function fillSlot(slot)
  10.  
  11.    local n = 0
  12.  
  13.    if turtle.getItemSpace(slot) > 0 and turtle.getItemCount(slot) > 0 then
  14.       for n=16,slot+1,-1 do
  15.          turtle.select(n)
  16.          if turtle.compareTo(slot) then
  17.             turtle.transferTo(slot, turtle.getItemSpace(slot))
  18.          end
  19.       end
  20.    end
  21. end
  22.  
  23. local function shuffleLoot()
  24.    
  25.    local n=0
  26.    
  27.    for n=1,15 do
  28.       fillSlot(n)
  29.    end
  30. end
  31.  
  32. local function refillUp(slot)
  33.    
  34.    local n=0
  35.    
  36.    if turtle.getItemSpace(slot) > 0 then
  37.       -- Get more bonemeal or sulfur goo from the chest
  38.       refilled = false
  39.       n=slot+1
  40.       repeat
  41.          n=n+1
  42.       until n > 16 or turtle.getItemCount(n) == 0
  43.       if n <= 16 then
  44.          turtle.select(n)
  45.          turtle.suck()
  46.          -- don't want a full stack, so put some back
  47.          if turtle.getItemSpace(n) == 0 then
  48.             turtle.drop(turtle.getItemCount(2))
  49.          end
  50.          turtle.transferTo(slot, turtle.getItemSpace(2))
  51.       end
  52.    end
  53. end
  54.  
  55. shuffleLoot()
  56. refillUp(2)
  57.  
  58. -- Keep farming while there is still more than 1 fertilizer and free inventory space for at least 1 wheat
  59. while turtle.getItemCount(2) > 1 and turtle.getItemSpace(15) > 0 and turtle.getItemSpace(16) > 0 do
  60.  
  61.    while turtle.getItemCount(2) > 1 and turtle.getItemSpace(15) > 0 and turtle.getItemSpace(16) > 0 do
  62.       -- Use all but one of the seeds and bonemeal (or sulfur goo)
  63.       while turtle.getItemCount(1) > 1 and turtle.getItemCount(2) > 1  do
  64.          turtle.select(1)
  65.          turtle.placeDown()
  66.          sleep(.1)
  67.          turtle.select(2)
  68.          turtle.placeDown()
  69.          sleep(.1)
  70.          turtle.digDown()
  71.          turtle.suckDown()
  72. --         sleep(.1)
  73. --         turtle.suckDown()
  74.       end
  75.       -- Shuffle everything up to the top
  76.       shuffleLoot()
  77.       refillUp(2)
  78.    end
  79.    -- Unload into chest above, first all but one wheat in Slot 3
  80.    turtle.select(3)
  81.    turtle.dropUp(turtle.getItemCount(3)-1)
  82.    -- ...then everything else that doesn't match Slot 2 (bonemeal or sulfur goo)
  83.    for n=4,15 do
  84.       turtle.select(n)
  85.       if not turtle.compareTo(2) then
  86.          turtle.dropUp()
  87.       end
  88.    end
  89.    refillUp(2)
  90. end  
  91.  
  92. turtle.select(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement