Advertisement
bowieowie

ly2

Mar 30th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. -- pastebin get Q5RsfX0A ly2
  2.  
  3. local util = require("util")
  4.  
  5. function go()
  6.    gridStep = 4
  7.    gridSize = 3
  8.    while true do
  9.       travel()
  10.  
  11.       if shouldRestock() then
  12.      restock()
  13.       end
  14.       print("all done, sleeping...")
  15.       for i = 1, 12 do
  16.      os.sleep(10)
  17.      print("sleeping... " .. i .. "/12")
  18.       end
  19.    end
  20. end
  21.  
  22.  
  23. function travel()
  24.    local cb = turtle.suck
  25.    local goRight = true
  26.    for j=1, gridSize do
  27.       print("column " .. tostring(j))
  28.       for i=1, gridSize do
  29.      doCell()
  30.      util.moveForward(1)
  31.       end
  32.       if goRight then
  33.      util.turnRight()
  34.      util.moveForward(3, cb)
  35.      util.turnRight()
  36.      util.moveForward(1)
  37.      goRight = false
  38.       else
  39.      util.turnLeft()
  40.      util.moveForward(3, cb)
  41.      util.turnLeft()
  42.      util.moveForward(1, cb)
  43.      goRight = true
  44.       end
  45.    end
  46.    util.moveForward(8, cb)
  47.    util.turnRight()
  48.    util.moveForward(9, cb)
  49.    util.turnRight()
  50. end
  51.  
  52.  
  53. function doCell()
  54.    -- turtle ends up on the OTHER side of the cell
  55.    local _, insp = turtle.inspect()
  56.  
  57.    if insp ~= nil then
  58.       if (insp.name == "minecraft:log" or insp.name == "traverse:fir_log") then
  59.      chopTree()
  60.       elseif insp.name == "minecraft:sapling" or insp.name == "traverse:fir_sapling" then
  61.      util.moveAround(turtle.suck)
  62.       else
  63.      if selectSapling() then
  64.         turtle.place()
  65.      end
  66.      util.moveAround(turtle.suck)
  67.       end
  68.      
  69.    end
  70.  
  71.  
  72.    
  73. end
  74.  
  75.  
  76. function chopTree()
  77.    turtle.dig()
  78.    util.moveForward(1)
  79.    while turtle.digUp() do
  80.       turtle.up()
  81.    end
  82.    while turtle.down() do
  83.       turtle.dig()
  84.    end
  85.    util.moveForward(1)
  86.  
  87.    if selectSapling() then
  88.       util.turnAround()
  89.       turtle.place()
  90.       util.turnAround()
  91.    end
  92.  
  93. end
  94.  
  95. function selectSapling()
  96.    for i = 1,16 do
  97.       local detail = turtle.getItemDetail(i)
  98.       if detail and (detail.name == "minecraft:sapling" or detail.name == "traverse:fir_sapling")  then
  99.      turtle.select(i)
  100.      return i
  101.       end
  102.    end
  103.    print("did not find sapling")
  104.    return false
  105. end
  106.  
  107. function shouldRestock()
  108.    return turtle.getFuelLevel() < 100 or isFull()
  109. end
  110.  
  111. function dropWood()
  112.    for i=1,16 do
  113.       local detail = turtle.getItemDetail(i)
  114.       if detail and (detail.name == "minecraft:log" or detail.name == "traverse:fir_log") then
  115.      turtle.select(i)
  116.      turtle.drop()
  117.       end
  118.    end
  119. end
  120.  
  121. function refuelPls()
  122.    local s = turtle.suck()
  123.    if s then
  124.       useCoalAndDrop()
  125.    end
  126. end
  127.  
  128. function isFull()
  129.    turtle.select(15)
  130.    local detail = turtle.getItemDetail(15)
  131.    if detail and detail.count > 0 then
  132.       return true
  133.    end
  134.    return false
  135. end
  136.  
  137. function useCoalAndDrop()
  138.    local cIndex = -1
  139.    for i=1,16 do
  140.       local detail = turtle.getItemDetail(i)
  141.       if detail and detail.name == "minecraft:coal" then
  142.      cIndex = i
  143.       end
  144.    end
  145.  
  146.    if cIndex == -1 then return end
  147.  
  148.    turtle.select(cIndex)
  149.    turtle.refuel(3)
  150.    turtle.drop()
  151. end
  152.  
  153. function restock()
  154.    util.turnAround()
  155.    util.moveForward(1)
  156.    dropWood()
  157.    util.turnRight()
  158.    refuelPls()
  159.    util.turnRight()
  160.    util.moveForward(1)
  161. end
  162.  
  163.  
  164. go()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement