Advertisement
jdroid91

lumber

Oct 7th, 2023 (edited)
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.84 KB | None | 0 0
  1. local currentDirection = nil
  2. local sideLogs = {}
  3. local numberOfSideLogs = 0
  4. local logName = "minecraft:cherry_log"
  5. local leavesName = "minecraft:cherry_leaves"
  6.  
  7. function getCurrentDirection()
  8.     local tp1X, tp1Y, tp1Z = gps.locate()
  9.     turtle.back()
  10.     local tp2X, tp2Y, tp2Z = gps.locate()
  11.     turtle.forward()
  12.  
  13.     if (tp1X == tp2X)
  14.     then
  15.         if (tp1Z > tp2Z)
  16.         then
  17.             currentDirection = "South"
  18.         else
  19.             currentDirection = "North"
  20.         end
  21.     else
  22.         if (tp1X > tp2X)
  23.         then
  24.             currentDirection = "East"
  25.         else
  26.             currentDirection = "West"
  27.         end
  28.     end
  29. end
  30.  
  31. function turnLeft()
  32.     if (currentDirection == "North")
  33.     then
  34.         currentDirection = "West"
  35.     elseif (currentDirection == "West")
  36.     then
  37.         currentDirection = "South"
  38.     elseif (currentDirection == "South")
  39.     then
  40.         currentDirection = "East"
  41.     else
  42.         currentDirection = "North"
  43.     end
  44.     turtle.turnLeft()
  45. end
  46.  
  47. function turnRight()
  48.     if (currentDirection == "North")
  49.     then
  50.         currentDirection = "East"
  51.     elseif (currentDirection == "East")
  52.     then
  53.         currentDirection = "South"
  54.     elseif (currentDirection == "South")
  55.     then
  56.         currentDirection = "West"
  57.     else
  58.         currentDirection = "North"
  59.     end
  60.     turtle.turnRight()
  61. end
  62.  
  63. function checkSideLogs()
  64.     local index = 0
  65.     while (index < 4)
  66.     do
  67.         local currentSideStatus, currentSideData = turtle.inspect()
  68.         if (currentSideStatus and currentSideData.name == logName)
  69.         then
  70.             turtle.dig()
  71.             turtle.forward()
  72.            
  73.             local hasSideLogs = false
  74.             local tempStatus, tempData = turtle.inspectUp()
  75.             if (tempStatus and tempData.name == logName)
  76.             then
  77.                 hasSideLogs = true
  78.             else
  79.                 local index2 = 0
  80.                 while (index2 < 4)
  81.                 do
  82.                     local tempSideStatus, tempSideData = turtle.inspect()
  83.                     if (tempSideStatus and tempSideData.name == logName)
  84.                     then
  85.                         hasSideLogs = true
  86.                     end
  87.                     index2 = index2 + 1
  88.                 end
  89.                 local tempSideStatus, tempSideData = turtle.inspectDown()
  90.                 if (tempSideStatus and tempSideData.name == logName)
  91.                 then
  92.                     hasSideLogs = true
  93.                 end
  94.             end
  95.            
  96.             if (hasSideLogs)
  97.             then
  98.                 tempGPSX, tempGPSY, tempGPSZ  = gps.locate()
  99.                 sideLogs[numberOfSideLogs] = {
  100.                     x = tempGPSX,
  101.                     y = tempGPSY,
  102.                     Z = tempGPSZ
  103.                 }
  104.                 numberOfSideLogs = numberOfSideLogs + 1
  105.             end
  106.             turtle.turnLeft()
  107.             turtle.turnLeft()
  108.             turtle.forward()
  109.             turtle.turnLeft()
  110.             turtle.turnLeft()
  111.         end
  112.         index = index + 1
  113.         turtle.turnLeft()
  114.     end
  115.     local currentSideStatus, currentSideData = turtle.inspectDown()
  116.     if (currentSideStatus and currentSideData.name == logName)
  117.     then
  118.         turtle.digDown()
  119.         turtle.down()
  120.        
  121.         tempGPSX, tempGPSY, tempGPSZ  = gps.locate()
  122.         sideLogs[numberOfSideLogs] = {
  123.             x = tempGPSX,
  124.             y = tempGPSY,
  125.             Z = tempGPSZ
  126.         }
  127.         numberOfSideLogs = numberOfSideLogs + 1
  128.        
  129.         turtle.up()
  130.     end
  131. end
  132.  
  133. function gotoSideLog()
  134.     local clX, clY, clZ = gps.locate()
  135.    
  136.     local slX = sideLogs[0].x
  137.     local slY = sideLogs[0].y
  138.     local slZ = sideLogs[0].Z
  139.    
  140.     while (clY ~= slY)
  141.     do
  142.         if (clY > slY)
  143.         then
  144.             local currentSideStatus, currentSideData = turtle.inspectDown()
  145.             if (currentSideStatus == false)
  146.             then
  147.                 turtle.down()
  148.             else
  149.                  if (currentSideData.name == leavesName)
  150.                  then
  151.                     turtle.digDown()
  152.                     turtle.down()
  153.                  elseif (currentSideData.name == logName)
  154.                  then
  155.                     turtle.digDown()
  156.                     turtle.down()
  157.                     tempGPSX, tempGPSY, tempGPSZ  = gps.locate()
  158.                     sideLogs[numberOfSideLogs] = {
  159.                         x = tempGPSX,
  160.                         y = tempGPSY,
  161.                         Z = tempGPSZ
  162.                     }
  163.                     numberOfSideLogs = numberOfSideLogs + 1
  164.                  end
  165.             end
  166.         else
  167.             local currentSideStatus, currentSideData = turtle.inspectUp()
  168.             if (currentSideStatus == false)
  169.             then
  170.                 turtle.up()
  171.             else
  172.                  if (currentSideData.name == leavesName)
  173.                  then
  174.                     turtle.digUp()
  175.                     turtle.up()
  176.                  elseif (currentSideData.name == logName)
  177.                  then
  178.                     turtle.digUp()
  179.                     turtle.up()
  180.                     tempGPSX, tempGPSY, tempGPSZ  = gps.locate()
  181.                     sideLogs[numberOfSideLogs] = {
  182.                         x = tempGPSX,
  183.                         y = tempGPSY,
  184.                         Z = tempGPSZ
  185.                     }
  186.                     numberOfSideLogs = numberOfSideLogs + 1
  187.                  end
  188.             end
  189.         end
  190.         clX, clY, clZ = gps.locate()   
  191.     end
  192.     while (clX ~= slX)
  193.     do
  194.         if (clX > slX)
  195.         then
  196.             while (currentDirection ~= "West")
  197.             do
  198.                 turnLeft()
  199.             end
  200.         else
  201.             while (currentDirection ~= "East")
  202.             do
  203.                 turnLeft()
  204.             end
  205.         end
  206.         local currentSideStatus, currentSideData = turtle.inspect()
  207.         if (currentSideStatus == false)
  208.         then
  209.             turtle.forward()
  210.         else
  211.             if (currentSideData.name == leavesName)
  212.             then
  213.                 turtle.dig()
  214.                 turtle.forward()
  215.             elseif (currentSideData.name == logName)
  216.             then
  217.                 turtle.dig()
  218.                 turtle.forward()
  219.                 tempGPSX, tempGPSY, tempGPSZ  = gps.locate()
  220.                 sideLogs[numberOfSideLogs] = {
  221.                     x = tempGPSX,
  222.                     y = tempGPSY,
  223.                     Z = tempGPSZ
  224.                 }
  225.                 numberOfSideLogs = numberOfSideLogs + 1
  226.              end
  227.         end
  228.         clX, clY, clZ = gps.locate()
  229.     end
  230.     while (clZ ~= slZ)
  231.     do
  232.         if (clZ > slZ)
  233.         then
  234.             while (currentDirection ~= "North")
  235.             do
  236.                 turnLeft()
  237.             end
  238.         else
  239.             while (currentDirection ~= "South")
  240.             do
  241.                 turnLeft()
  242.             end
  243.         end
  244.         local currentSideStatus, currentSideData = turtle.inspect()
  245.         if (currentSideStatus == false)
  246.         then
  247.             turtle.forward()
  248.         else
  249.             if (currentSideData.name == leavesName)
  250.             then
  251.                 turtle.dig()
  252.                 turtle.forward()
  253.             elseif (currentSideData.name == logName)
  254.             then
  255.                 turtle.dig()
  256.                 turtle.forward()
  257.                 tempGPSX, tempGPSY, tempGPSZ  = gps.locate()
  258.                 sideLogs[numberOfSideLogs] = {
  259.                     x = tempGPSX,
  260.                     y = tempGPSY,
  261.                     Z = tempGPSZ
  262.                 }
  263.                 numberOfSideLogs = numberOfSideLogs + 1
  264.              end
  265.         end
  266.         clX, clY, clZ = gps.locate()
  267.     end
  268. end
  269.  
  270. function lumberUntilSideLogsGone()
  271.     getCurrentDirection()
  272.     oX, oY, oZ = gps.locate()
  273.     checkSideLogs()
  274.     local looperStatus, looperData = turtle.inspectUp()
  275.    
  276.     while (looperStatus and looperData.name == logName) or (numberOfSideLogs ~= 0)
  277.     do
  278.         local upStatus, upData = turtle.inspectUp()
  279.         if (upStatus and (upData.name == logName))
  280.         then
  281.             turtle.digUp()
  282.             turtle.up()
  283.             checkSideLogs()
  284.         else
  285.             gotoSideLog()
  286.             numberOfSideLogs = numberOfSideLogs - 1
  287.             table.remove(sideLogs, 0)
  288.             checkSideLogs()
  289.         end
  290.         looperStatus, looperData = turtle.inspectUp()
  291.     end
  292.    
  293.     local cX, cY, cZ = gps.locate()
  294.     while (cY ~= oY)
  295.     do
  296.         if (cY > oY)
  297.         then
  298.             local currentSideStatus, currentSideData = turtle.inspectDown()
  299.             if (currentSideStatus == false)
  300.             then
  301.                 turtle.down()
  302.             else
  303.                 if (currentSideData.name == logName)
  304.                 then
  305.                     tempGPSX, tempGPSY, tempGPSZ  = gps.locate()
  306.                     sideLogs[numberOfSideLogs] = {
  307.                         x = tempGPSX,
  308.                         y = tempGPSY,
  309.                         Z = tempGPSZ
  310.                     }
  311.                     lumberUntilSideLogsGone()
  312.                 end
  313.                 turtle.digDown()
  314.                 turtle.down()
  315.             end
  316.         else
  317.             local currentSideStatus, currentSideData = turtle.inspectUp()
  318.             if (currentSideStatus == false)
  319.             then
  320.                 turtle.up()
  321.             else
  322.                 if (currentSideData.name == logName)
  323.                 then
  324.                     tempGPSX, tempGPSY, tempGPSZ  = gps.locate()
  325.                     sideLogs[numberOfSideLogs] = {
  326.                         x = tempGPSX,
  327.                         y = tempGPSY,
  328.                         Z = tempGPSZ
  329.                     }
  330.                     lumberUntilSideLogsGone()
  331.                 end
  332.                 turtle.digUp()
  333.                 turtle.up()
  334.             end
  335.         end
  336.         cX, cY, cZ = gps.locate()
  337.     end
  338.     turtle.up()
  339. end
  340.  
  341. lumberUntilSideLogsGone()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement