Epuuc

Minecraft CC Tree Turtle

Nov 22nd, 2020 (edited)
1,310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.62 KB | None | 0 0
  1. --not my code
  2. function split(pString, pPattern)
  3.    local Table = {}  -- NOTE: use {n = 0} in Lua-5.0
  4.    local fpat = "(.-)" .. pPattern
  5.    local last_end = 1
  6.    local s, e, cap = pString:find(fpat, 1)
  7.    while s do
  8.           if s ~= 1 or cap ~= "" then
  9.          table.insert(Table,cap)
  10.           end
  11.           last_end = e+1
  12.           s, e, cap = pString:find(fpat, last_end)
  13.    end
  14.    if last_end <= #pString then
  15.           cap = pString:sub(last_end)
  16.           table.insert(Table, cap)
  17.    end
  18.    return Table
  19. end
  20. --not my code
  21. --now my code VVV
  22.  
  23. local function parseName()
  24.     return split(os.getComputerLabel(),"_")[4]
  25. end
  26.  
  27. local function checkForCoal()
  28.     print("Checking for coal")
  29.     for i=1,16 do
  30.         local item = turtle.getItemDetail(i)
  31.         if item and item.name == "minecraft:coal" then
  32.             print("There's coal!")
  33.             return i
  34.         end
  35.     end
  36.     print("No Coal")
  37.     return false
  38. end
  39. local function getCoal()
  40.     while true do
  41.         local suc = turtle.suckUp()
  42.         if not suc then return false end
  43.         if checkForCoal() then
  44.             return i
  45.         end
  46.     end
  47. end
  48.  
  49. local function checkForSaplings()
  50.     print("Checking for saplings")
  51.     for i=1,16 do
  52.         local item = turtle.getItemDetail(i)
  53.         if item and item.name == "minecraft:sapling" then
  54.             print("sapling found")
  55.             return i
  56.         end
  57.     end
  58.     print("No saplings found")
  59.     return false
  60. end
  61. local function getSaplings()
  62.     while true do
  63.         local suc = turtle.suckUp()
  64.         if not suc then return false end
  65.         if checkForSaplings() then
  66.             return i
  67.         end
  68.     end
  69. end
  70.  
  71. local id = parseName()
  72. print(id)
  73.  
  74. local modem = peripheral.find("modem")
  75. if not modem then turtle.equipRight() turtle.select(1) sleep(1) turtle.equipRight() end
  76. modem.open(tonumber(id)+200)
  77.  
  78. while true do
  79.     local event,side,channel,repchannel,msg,distance = os.pullEvent("modem_message")
  80.     print(distance)
  81.     if distance == 1 and channel == id+200 then
  82.         --refueling
  83.         while true do
  84.             if turtle.getFuelLevel() < 100 then
  85.                 if not checkForCoal() then
  86.                     if getCoal() then
  87.                         turtle.select(i)
  88.                         turtle.refuel(64)
  89.                         print("Refueled")
  90.                     else
  91.                         print("panic no coal")
  92.                         --panic
  93.                         return
  94.                     end
  95.                 else
  96.                     turtle.select(checkForCoal())
  97.                     turtle.refuel(64)
  98.                 end
  99.             else
  100.                 break
  101.             end
  102.         end
  103.         --putting all the items back
  104.         for i=1,16 do
  105.             turtle.select(i)
  106.             if turtle.getItemCount() > 0 and turtle.getItemDetail().name ~= "minecraft:sapling" then
  107.                 turtle.dropUp()
  108.             end
  109.         end
  110.         --grabbing saplings
  111.         if not checkForSaplings() then
  112.             getSaplings()
  113.             local saplingnum = checkForSaplings()
  114.             if not saplingnum then
  115.                 print("panic no saplings")
  116.                 return
  117.                 --panic
  118.             end
  119.             turtle.select(checkForSaplings())
  120.         end
  121.         turtle.select(checkForSaplings())
  122.         --Starting on the journey
  123.         turtle.turnRight()
  124.         turtle.turnRight()
  125.         for i=1,(msg*7)+3 do
  126.             while not turtle.forward() do
  127.                 turtle.dig()
  128.             end
  129.         end
  130.         turtle.turnLeft()
  131.         turtle.forward()
  132.         turtle.dig()
  133.         turtle.forward()
  134.         repeat
  135.             turtle.digUp()
  136.             turtle.up()
  137.             for r=1,4 do
  138.                 turtle.dig()
  139.                 turtle.turnRight()
  140.             end
  141.         until not turtle.detectUp()
  142.         turtle.turnRight()
  143.         turtle.turnRight()
  144.         turtle.forward()
  145.         while true do
  146.             turtle.digDown()
  147.             turtle.down()
  148.             for r=1,4 do
  149.                 turtle.dig()
  150.                 turtle.turnRight()
  151.             end
  152.             local suc,bl = turtle.inspectDown()
  153.             if suc and bl.name == "minecraft:planks" then break end
  154.         end
  155.         turtle.turnRight()
  156.         turtle.turnRight()
  157.         turtle.place()
  158.         turtle.turnRight()
  159.         turtle.turnRight()
  160.         turtle.forward()
  161.         turtle.turnRight()
  162.         for i=1,(msg*7)+3 do
  163.             while not turtle.forward() do
  164.                 turtle.dig()
  165.             end
  166.         end
  167.     end
  168. end
  169.  
Add Comment
Please, Sign In to add comment