Advertisement
EdgeLordKirito

Receiver Slave code

May 27th, 2023 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.00 KB | None | 0 0
  1. -- Slot1 = Fuel
  2. -- Slot2 = Light
  3. -- Slot3 = Blocks
  4.  
  5. --still error Retreat does not work
  6.  
  7. --Globals Start
  8. FUELVALUE = 0
  9. Facing = 0
  10. MASTERID = 0
  11. ACTIVE = true
  12. ChestX,ChestY,ChestZ = 0,0,0
  13. FuelX,FuelY,FuelZ = 0,0,0
  14. StartX,StartY,StartZ = 0,0,0
  15. SavedX,SavedY,SavedZ = 0,0,0
  16. DISTANCETOHOMEBASE = 0
  17. TOTALFUEL = 0
  18. FUELSLOT = 16
  19. EMERGENCYFUELSLOT = 15
  20. COMMAND = ""
  21. --Globals End
  22. function Main()
  23.     print("Slave Script now Running")
  24.     OpenRednetSpecificForDevice()
  25.     os.setComputerLabel("Slave")
  26.     InitTurtle()
  27.     CriticallyLowFuelCheck()
  28.     GetCommand()
  29.     print("Programm terminated with Code 0 " .. tostring(os.epoch("utc")))
  30. end
  31.  
  32. -- Print Functions Start
  33. function PrintChestLocation()
  34.     print(("Chest is at X %d Y %d Z %d"):format(ChestX,ChestY,ChestZ))
  35. end
  36.  
  37. function PrintFuelLocation()
  38.     print(("Fuel is at X %d Y %d Z %d"):format(FuelX,FuelY,FuelZ))
  39. end
  40.  
  41. function PrintStartLocation()
  42.     print(("Start is at X %d Y %d Z %d"):format(StartX,StartY,StartZ))
  43. end
  44.  
  45. function PrintSavedLocation()
  46.     print(("Saved is at X %d Y %d Z %d"):format(SavedX,SavedY,SavedZ))
  47. end
  48.  
  49. function PrintAllLocations()
  50.     PrintChestLocation()
  51.     PrintFuelLocation()
  52.     PrintStartLocation()
  53.     PrintSavedLocation()
  54. end
  55. --Print Functions End
  56.  
  57.  
  58. -- Important Functions Start
  59. function Retreat()
  60.     os.setComputerLabel("Retreating")
  61.     print("Fuel: " .. turtle.getFuelLevel())
  62.     print("Home: " .. DISTANCETOHOMEBASE)
  63.     PrintSysMessage("About To Pathfind NonBlocking 1")
  64.     PathfindToCoordinateNonBlocking(StartX,StartY,StartZ)
  65.     PrintSysMessage("About To Homebase")
  66.     HomeBase()
  67.     PrintSysMessage("About To Pathfind NonBlocking 2")
  68.     PathfindToCoordinateNonBlocking(StartX,StartY,StartZ)
  69.     RotateToNegZ()
  70.     PrintSysMessage("About To Pathfind NonBlocking 3")
  71.     PathfindToCoordinateNonBlocking(SavedX,SavedY,SavedZ)
  72.     os.setComputerLabel("Slave")
  73.     PrintSysMessage("Resume Action")
  74.     EvaluateCommand(COMMAND)
  75. end
  76.  
  77. -- Important Functions End
  78. -- Rotation Logic Start
  79.     -- facing = 0 means North Neg Z
  80.     -- facing = 1 means East Pos X
  81.     -- facing = 2 means South Pos Z
  82.     -- facing = 3 means West Neg x
  83. function RotateToNegZ()
  84.     TurnUntilFacingMatches(0)
  85. end
  86.  
  87. function RotateToPosX()
  88.     TurnUntilFacingMatches(1)
  89. end
  90.  
  91. function RotateToPosZ()
  92.     TurnUntilFacingMatches(2)
  93. end
  94.  
  95. function RotateToNegX()
  96.     TurnUntilFacingMatches(3)
  97. end
  98.  
  99. function TurnUntilFacingMatches(facing)
  100.     if Facing == facing then
  101.         return true
  102.     end
  103.     TurnRight()
  104.     if Facing == facing then
  105.         return true
  106.     end
  107.     TurnRight()
  108.     if Facing == facing then
  109.         return true
  110.     end
  111.     TurnRight()
  112.     if Facing == facing then
  113.         return true
  114.     end
  115.     TurnRight()
  116.     if Facing == facing then
  117.         return true
  118.     end
  119.  
  120. end
  121.  
  122. function MatchFacing(facing)
  123.     if Facing == facing then
  124.         return true
  125.     end
  126. end
  127.  
  128. function TurnRight()
  129.     turtle.turnRight()
  130.     Facing = math.fmod(Facing + 1,4)
  131. end
  132.  
  133. function RotateUnitlFacingId(input)
  134.     for i = 0, 3 do
  135.         if FacingId(input) then
  136.             return true
  137.         else
  138.             TurnRight()
  139.         end
  140.     end
  141. end
  142.  
  143. function FacingId(input)
  144.     local succes, data = turtle.inspect()
  145.     if succes then
  146.         if data.name == input then
  147.             return true
  148.         else
  149.             return false
  150.         end
  151.     else
  152.         return false
  153.     end
  154. end
  155.  
  156. function InvertHeading()
  157.     if Facing == 0 then
  158.         RotateToPosZ()
  159.     end
  160.     if Facing == 1 then
  161.         RotateToNegX()
  162.     end
  163.     if Facing == 2 then
  164.         RotateToNegZ()
  165.     end
  166.     if Facing == 3 then
  167.         RotateToPosX()
  168.     end
  169. end
  170. -- Rotation Logic End
  171.  
  172. -- Movement Logic Start
  173. function MoveForwardByOne()
  174.     CriticallyLowFuelCheck()
  175.     if CheckRetreatParam() then
  176.         local x,y,z = gps.locate()
  177.         SetSavedCoords(x,y,z)
  178.         ReturnHome()
  179.         return
  180.     end
  181.     if CheckForBedrockBeneath() then
  182.         BedrockFound()
  183.     end
  184.     if turtle.getFuelLevel() < 20 then
  185.         Refuel()
  186.     end
  187.     local existence = turtle.inspect()
  188.     if existence then
  189.         turtle.dig()
  190.     end
  191.     UpdateTurtleValues()
  192.     turtle.forward()
  193. end
  194.  
  195. function MoveForwardByXBlocks(x)
  196.     for i = 1, x do
  197.         MoveForwardByOne()
  198.     end
  199. end
  200.  
  201. function MoveUpwardByOne()
  202.     CriticallyLowFuelCheck()
  203.     if CheckRetreatParam() then
  204.         local x,y,z = gps.locate()
  205.         SetSavedCoords(x,y,z)
  206.         ReturnHome()
  207.         return
  208.     end
  209.     if CheckForBedrockBeneath() then
  210.         BedrockFound()
  211.     end
  212.     if turtle.getFuelLevel() < 20 then
  213.         Refuel()
  214.     end
  215.     local existence = turtle.inspectUp()
  216.     if existence then
  217.         turtle.digUp()
  218.     end
  219.     UpdateTurtleValues()
  220.     turtle.up()
  221. end
  222.  
  223. function MoveUpwardByXBlocks(x)
  224.     for i = 1, x do
  225.         MoveUpwardByOne()
  226.     end
  227. end
  228.  
  229. function MoveDownwardByOne()
  230.     CriticallyLowFuelCheck()
  231.     if CheckRetreatParam() then
  232.         local x,y,z = gps.locate()
  233.         SetSavedCoords(x,y,z)
  234.         ReturnHome()
  235.         return
  236.     end
  237.     if CheckForBedrockBeneath() then
  238.         BedrockFound()
  239.     end
  240.     if turtle.getFuelLevel() < 20 then
  241.         Refuel()
  242.     end
  243.     local existence = turtle.inspectDown()
  244.     if existence then
  245.         turtle.digDown()
  246.     end
  247.     UpdateTurtleValues()
  248.     turtle.down()
  249. end
  250.  
  251. function MoveDownwardByXBlocks(x)
  252.     for i = 1, x do
  253.         MoveDownwardByOne()
  254.     end
  255. end
  256. -- Movement Logic End
  257.  
  258. -- Pathfinding Logic Start
  259. function PathfindToCoordinate(destinationX,destinationY,destinationZ)
  260.     local currentX,currentY,currentZ = gps.locate()
  261.     local xDistance = CalculateDistance(destinationX,currentX)
  262.     local yDistance = CalculateDistance(destinationY,currentY)
  263.     local zDistance = CalculateDistance(destinationZ,currentZ)
  264.     local totalDistance = CalculateTotalDistance(xDistance,yDistance,zDistance)
  265.     local totalFuel = CalculateTotalFuel()
  266.     if totalFuel < totalDistance then
  267.         --Send Distress Signal To Low Fuel for Retreat
  268.         os.setComputerLabel("Fuel Critical")
  269.     else
  270.         CorrectYAxis(destinationY,currentY,yDistance)
  271.         CorrectXAxis(destinationX,currentX,xDistance)
  272.         CorrectZAxis(destinationZ,currentZ,zDistance)
  273.         if CompareCoordinate(destinationX,destinationY,destinationZ) then
  274.             print("Location has been Successfully reached")
  275.         else
  276.             print("Location has not been reached")
  277.         end
  278.     end
  279. end
  280.  
  281. function CompareCoordinate(destinationX,destinationY,destinationZ)
  282.     local currentX,currentY,currentZ = gps.locate()
  283.     if currentX == destinationX and currentY == destinationY and currentZ == destinationZ then
  284.         return true
  285.     else
  286.         return false
  287.     end
  288. end
  289.  
  290. function CorrectXAxis(destinationX,currentX,xDistance)
  291.     local comparison = CompareTo(currentX,destinationX)
  292.     local xDistance = xDistance
  293.     if comparison == 1 then
  294.         RotateToNegX()
  295.         MoveForwardByXBlocks(xDistance)
  296.     end
  297.     if comparison == -1 then
  298.         RotateToPosX()
  299.         MoveForwardByXBlocks(xDistance)
  300.     end
  301. end
  302.  
  303. function CorrectZAxis(destinationZ,currentZ,zDistance)
  304.     local comparison = CompareTo(currentZ,destinationZ)
  305.     local zDistance = zDistance
  306.     if comparison == 1 then
  307.         RotateToNegZ()
  308.         MoveForwardByXBlocks(zDistance)
  309.     end
  310.     if comparison == -1 then
  311.         RotateToPosZ()
  312.         MoveForwardByXBlocks(zDistance)
  313.     end
  314. end
  315.  
  316. function CorrectYAxis(destinationY,currentY,yDistance)
  317.     local comparison = CompareTo(currentY,destinationY)
  318.     local yDistance = yDistance
  319.     if comparison == 1 then
  320.         MoveDownwardByXBlocks(yDistance)
  321.     end
  322.     if comparison == -1 then
  323.         MoveUpwardByXBlocks(yDistance)
  324.     end
  325. end
  326.  
  327. -- Pathfinding Logic End
  328.  
  329. -- Non Blocking Pathfind Logic Start
  330. function MoveNonBlockingForwardByOne()
  331.     CriticallyLowFuelCheck()
  332.     if turtle.getFuelLevel() < 20 then
  333.         Refuel()
  334.     end
  335.     local existence = turtle.inspect()
  336.     if existence then
  337.         turtle.dig()
  338.     end
  339.     turtle.forward()
  340.     UpdateTurtleValues()
  341. end
  342.  
  343. function MoveNonBlockingForwardByXBlocks(x)
  344.     for i = 1, x do
  345.         MoveNonBlockingForwardByOne()
  346.     end
  347. end
  348.  
  349. function MoveNonBlockingUpByOne()
  350.     CriticallyLowFuelCheck()
  351.     if turtle.getFuelLevel() < 20 then
  352.         Refuel()
  353.     end
  354.     local existence = turtle.inspectUp()
  355.     if existence then
  356.         turtle.digUp()
  357.     end
  358.     turtle.up()
  359.     UpdateTurtleValues()
  360. end
  361.  
  362. function MoveNonBlockingUpByXBlocks(x)
  363.     for i = 1, x do
  364.         MoveNonBlockingUpByOne()
  365.     end
  366. end
  367.  
  368. function MoveNonBlockingDownbyOne()
  369.     CriticallyLowFuelCheck()
  370.     if turtle.getFuelLevel() < 20 then
  371.         Refuel()
  372.     end
  373.     local existence = turtle.inspectDown()
  374.     if existence then
  375.         turtle.digDown()
  376.     end
  377.     turtle.down()
  378.     UpdateTurtleValues()
  379. end
  380.  
  381. function MoveNonBlockingDownByXBlocks(x)
  382.     for i = 1, x do
  383.         MoveNonBlockingDownbyOne()
  384.     end
  385. end
  386.  
  387. function CorrectYAxisNonBlocking(destinationY,currentY,yDistance)
  388.     local comparison = CompareTo(currentY,destinationY)
  389.     local yDistance = yDistance
  390.     if comparison == 1 then
  391.         MoveNonBlockingDownByXBlocks(yDistance)
  392.     end
  393.     if comparison == -1 then
  394.         MoveNonBlockingUpByXBlocks(yDistance)
  395.     end
  396. end
  397.  
  398. function CorrectZAxisNonBlocking(destinationZ,currentZ,zDistance)
  399.     local comparison = CompareTo(currentZ,destinationZ)
  400.     local zDistance = zDistance
  401.     if comparison == 1 then
  402.         RotateToNegZ()
  403.         MoveNonBlockingForwardByXBlocks(zDistance)
  404.     end
  405.     if comparison == -1 then
  406.         RotateToPosZ()
  407.         MoveNonBlockingForwardByXBlocks(zDistance)
  408.     end
  409. end
  410.  
  411. function CorrectXAxisNonBlocking(destinationX,currentX,xDistance)
  412.     local comparison = CompareTo(currentX,destinationX)
  413.     local xDistance = xDistance
  414.     if comparison == 1 then
  415.         RotateToNegX()
  416.         MoveNonBlockingForwardByXBlocks(xDistance)
  417.     end
  418.     if comparison == -1 then
  419.         RotateToPosX()
  420.         MoveNonBlockingForwardByXBlocks(xDistance)
  421.     end
  422. end
  423.  
  424. function PathfindToCoordinateNonBlocking(destinationX,destinationY,destinationZ)
  425.     local currentX,currentY,currentZ = gps.locate()
  426.     local xDistance = CalculateDistance(destinationX,currentX)
  427.     local yDistance = CalculateDistance(destinationY,currentY)
  428.     local zDistance = CalculateDistance(destinationZ,currentZ)
  429.     local totalDistance = CalculateTotalDistance(xDistance,yDistance,zDistance)
  430.     local totalFuel = CalculateTotalFuel()
  431.     if totalFuel < totalDistance then
  432.     else
  433.         CorrectYAxisNonBlocking(destinationY,currentY,yDistance)
  434.         CorrectXAxisNonBlocking(destinationX,currentX,xDistance)
  435.         CorrectZAxisNonBlocking(destinationZ,currentZ,zDistance)
  436.         if CompareCoordinate(destinationX,destinationY,destinationZ) then
  437.             print("Successfully Reached Coords")
  438.         else
  439.             print("UnSuccessfully Reached Coords")
  440.         end
  441.     end
  442. end
  443. -- Non Blocking PathFind Logic End
  444.  
  445. -- Mining Logic Start
  446. function MineLine(length)
  447.     if CheckRetreatParam() then
  448.         local x,y,z = gps.locate()
  449.         SetSavedCoords(x,y,z)
  450.         ReturnHome()
  451.     end
  452.     if CheckForBedrockBeneath() then
  453.         BedrockFound()
  454.     end
  455.     MoveForwardByXBlocks(length)
  456.     MoveDownwardByOne()
  457.     TurnRight()
  458.     TurnRight()
  459. end
  460.  
  461. function MineDownToSpecifiedLevel(level)
  462.     local x,y,z = gps.locate()
  463.     local newY = tonumber(y)
  464.     local height = tonumber(level)
  465.     local distance = CalculateDistance(height,newY)
  466.     MoveDownwardByXBlocks(distance)
  467. end
  468.  
  469.  
  470. function ExecuteMineCommand(level,length)
  471.     MineDownToSpecifiedLevel(level)
  472.     while true do
  473.         MineLine(length)
  474.     end
  475.     print("Ended MineLine if you reach this big error")
  476. end
  477.  
  478. function CheckRetreatParam()
  479.     if LowFuel() then
  480.         print("Fuel")
  481.         return true
  482.     end
  483.     if InventoryHasfreeSpace() then
  484.         print("Inventory")
  485.         return true
  486.     end
  487.     return false
  488. end
  489.  
  490.  
  491.  
  492. -- always call CheckRetreatParameter and Checkforbedrock
  493.  
  494. -- Mining Logic End
  495.  
  496. -- Math Logic Start
  497. function CompareTo(num1,num2)
  498.     if num1 == nil then
  499.         print("num1 is nil")
  500.     end
  501.     if num2 == nil then
  502.         print("num2 is nil")
  503.     end
  504.     local val1 = tonumber(num1)
  505.     local val2 = tonumber(num2)
  506.     if val1 > val2 then
  507.         return 1
  508.     else if val1 < val2 then
  509.         return -1
  510.     else if val1 == val2 then
  511.         return 0
  512.     end
  513.     end
  514.     end
  515. end
  516.  
  517. function CalculateDistance(value1,value2)
  518.     return math.abs(value1 - value2)
  519. end
  520.  
  521. function CalculateTotalDistance(xDistance,yDistance,zDistance)
  522.     local result = xDistance + yDistance + zDistance
  523.     return result
  524. end
  525.  
  526. function CalculateHomebaseDistance(baseX,BaseY,BaseZ)
  527.     local x,y,z = gps.locate()
  528.     local result = CalculateTotalDistance(CalculateDistance(baseX,x),CalculateDistance(BaseY,y),CalculateDistance(BaseZ,z))
  529.     return result
  530. end
  531.  
  532. function CalculateTotalFuel()
  533.     local result = turtle.getFuelLevel() + turtle.getItemCount(FUELSLOT) * FUELVALUE
  534.     return result
  535. end
  536. --Math Logic End
  537.  
  538. -- Send and Receive Logic Start
  539. function EnterWaitModeAndReturnMessage()
  540.     local id,message = rednet.receive()
  541.     return id,message
  542. end
  543.  
  544. function SendImportantMessage()
  545.     SendMessage("IMPORTANT")
  546. end
  547.  
  548. function SendMessage(input)
  549.     rednet.send(MASTERID,input)
  550.     PrintSysMessage(("%s Message has been sent to Computer %d"):format(input,MASTERID) .. tostring(os.epoch("utc")))
  551. end
  552. -- Send and Receive Logic End
  553.  
  554. -- Terminal Logic Start
  555. function PrintStringInColor(string,color)
  556.     term.setTextColor(color)
  557.     print(string)
  558.     ResetTerminal()
  559. end
  560.  
  561. function PrintSysMessage(string)
  562.     PrintStringInColor(string,colors.magenta)
  563. end
  564.  
  565. function ResetTerminal()
  566.     term.setTextColor(colors.white)
  567. end
  568. -- Terminal Logic End
  569.  
  570. -- Turtle Functions Start
  571. function UnloadInventory()
  572.     local success,data = turtle.inspect()
  573.     if success then
  574.         if data.name == "minecraft:chest" or "minecraft:ender_chest" then
  575.             for i = 1, 16 do
  576.                 turtle.select(i)
  577.                 turtle.drop()
  578.             end
  579.         end
  580.     end
  581. end
  582.  
  583. function FuelUp()
  584.     local success,data = turtle.inspect()
  585.     if success then
  586.         turtle.select(FUELSLOT)
  587.         turtle.suck()
  588.         turtle.select(EMERGENCYFUELSLOT) --Emergency FuelSlot
  589.         turtle.suck()
  590.         turtle.select(1)
  591.     end
  592. end
  593.  
  594. function SetFuelValue(input)
  595.         FUELVALUE = input
  596. end
  597.  
  598. function CheckForBedrockBeneath()
  599.     local success,data = turtle.inspectDown()
  600.     if success then
  601.         if data.name == "minecraft:bedrock" then
  602.             return true
  603.         else
  604.             return false
  605.         end
  606.     else
  607.         return false
  608.     end
  609. end
  610.  
  611. function Refuel()
  612.     local success = false
  613.     if turtle.getItemCount(FUELSLOT) > 0 then
  614.             turtle.select(FUELSLOT)
  615.             success = turtle.refuel(1)
  616.             turtle.select(1)
  617.     end
  618.     return success
  619. end
  620.  
  621. function EmergencyRefuel()
  622.     local success = false
  623.     if turtle.getItemCount(EMERGENCYFUELSLOT) > 0 then
  624.             turtle.select(EMERGENCYFUELSLOT)
  625.             success = turtle.refuel()
  626.             turtle.select(1)
  627.     end
  628.     return success
  629. end
  630.  
  631. function LowFuel()
  632.     if DISTANCETOHOMEBASE == TOTALFUEL then
  633.         print(("Distance equals Totalfuel %d"):format(TOTALFUEL))
  634.         return true
  635.     end
  636.  
  637.     if DISTANCETOHOMEBASE < TOTALFUEL then
  638.         print("I can Still reach Home")
  639.         return false
  640.     end
  641.  
  642.     if DISTANCETOHOMEBASE > TOTALFUEL then
  643.         print("Home is to faraway")
  644.         print("Using Emergency Fuel")
  645.         EmergencyRefuel()
  646.         return true
  647.     end
  648. end
  649.  
  650.  
  651. function InventoryHasfreeSpace()
  652.     local count = turtle.getItemCount(14)
  653.     if count == 0 then
  654.         return false
  655.     else
  656.         return true
  657.     end
  658. end
  659.  
  660. function InitTurtle()
  661.     print("initializing Turtle")
  662.     local id, chestMessage = EnterWaitModeAndReturnMessage()
  663.     print(chestMessage)
  664.     local id, fuelMessage = EnterWaitModeAndReturnMessage()
  665.     print(fuelMessage)
  666.     local id,fuelType = EnterWaitModeAndReturnMessage()
  667.     print(fuelType)
  668.     local fuelCoords = MySplit(fuelMessage)
  669.     local chestCoords = MySplit(chestMessage)
  670.     local currentX,currentY,currentZ = gps.locate()
  671.     EvaluateFuelType(fuelType)
  672.     SetFuelCoords(fuelCoords[1],fuelCoords[2],fuelCoords[3])
  673.     SetChestCoords(chestCoords[1],chestCoords[2],chestCoords[3])
  674.     SetStartCoords(currentX,currentY,currentZ)
  675.     SetSavedCoords(currentX,currentY,currentZ)
  676.     Refuel()
  677.     UpdateTurtleValues()
  678. end
  679.  
  680. function GetCommand()
  681.     local id, message = EnterWaitModeAndReturnMessage()
  682.     COMMAND = message
  683.     EvaluateCommand(message)
  684. end
  685.  
  686. function EvaluateCommand(input)
  687.     print("Evaluating Command")
  688.     local command = MySplit(input)
  689.     if command[1] == "line" then
  690.         if command[2] ~= nil then
  691.             print("Mining at Height")
  692.             ExecuteMineCommand(tonumber(command[2]),tonumber(command[3]))
  693.         else
  694.             print("Mining from the Top")
  695.             local x,y,z = gps.locate()
  696.             ExecuteMineCommand(y,tonumber(command[3]))
  697.         end
  698.     end
  699. end
  700.  
  701. function EvaluateFuelType(input)
  702.     if input == "coal" then
  703.         SetFuelValue(80)
  704.     else if input == "coal_block" then
  705.         SetFuelValue(800)
  706.     end
  707.     end
  708.  end
  709.  
  710.  function CriticallyLowFuelCheck()
  711.     if turtle.getFuelLevel() == 0 then
  712.         os.setComputerLabel("Critical Fuel level")
  713.         --os.shutdown()
  714.     end
  715.  end
  716.  
  717.  function BedrockFound()
  718.     os.setComputerLabel("Bedrock Found")
  719.     PathfindToCoordinateNonBlocking(StartX,StartY,StartZ)
  720.     RotateToNegZ()
  721.     os.shutdown()
  722.  end
  723.  
  724.  function UpdateTotalFuel()
  725.     TOTALFUEL = CalculateTotalFuel()
  726.  end
  727.  
  728.  function UpdateHomeBaseDistance()
  729.     local dis = CalculateHomebaseDistance(FuelX,FuelY,FuelZ)
  730.     SetHomebaseDistance(dis)
  731.  end
  732.  
  733.  function UpdateTurtleValues()
  734.     print("Starting Update of values")
  735.     UpdateHomeBaseDistance()
  736.     print(DISTANCETOHOMEBASE)
  737.     UpdateTotalFuel()
  738.     print(TOTALFUEL)
  739.     print("End of Value Update")
  740.  end
  741.  
  742.  function ReturnHome()
  743.     print("Going Home")
  744.     Retreat()
  745.  end
  746.  
  747.  function IncreaseRetreatCounter()
  748.     INTERNALRETREATCOUNTER = INTERNALRETREATCOUNTER + 1
  749.  end
  750.  
  751.  function CheckMaximumRetreats()
  752.     if INTERNALRETREATCOUNTER == MAXRETREATS then
  753.         os.setComputerLabel("I retreated The Max Amount")
  754.         os.shutdown()
  755.     end
  756.  end
  757. -- Turtle Functions End
  758.  
  759. -- HomeBase Operations Start
  760. function ArrivedAtFuelHub()
  761.     if CompareCoordinate(FuelX,FuelY,FuelZ) then
  762.         return true
  763.     else
  764.         return false
  765.     end
  766. end
  767.  
  768. function RefuelAtFuelHub()
  769.     RotateToPosZ()
  770.     --RotateUnitlFacingId("functionalstorage:oak_1")
  771.     FuelUp()
  772. end
  773.  
  774. function MoveToFuelHub()
  775.     PathfindToCoordinateNonBlocking(FuelX,FuelY,FuelZ)
  776.     if ArrivedAtFuelHub() then
  777.         return true
  778.     end
  779. end
  780.  
  781. function MoveAwayFromRefuelHub()
  782.     PathfindToCoordinateNonBlocking(StartX,StartY,StartZ)
  783. end
  784.  
  785. function RefuelAtTheFuelHub()
  786.     MoveToFuelHub()
  787. end
  788.  
  789. function FuelHub()
  790.     MoveToFuelHub()
  791.     RefuelAtFuelHub()
  792.     MoveAwayFromRefuelHub()
  793. end
  794.  
  795. function OutputChest()
  796.     MoveToOutputChest()
  797.     OutputInventory()
  798. end
  799.  
  800. function MoveToOutputChest()
  801.     PathfindToCoordinateNonBlocking(ChestX,ChestY,ChestZ)
  802.     RotateToPosZ()
  803.     --RotateUnitlFacingId("minecraft:chest")
  804. end
  805.  
  806. function OutputInventory()
  807.     UnloadInventory()
  808. end
  809.  
  810. function HomeBase()
  811.     OutputChest()
  812.     FuelHub()
  813. end
  814. -- Homebase Operations End
  815.  
  816. -- Os Functions Start
  817. function WhatDeviceAmIRunningOn()
  818.     return getDeviceType()
  819. end
  820.  
  821. function getDeviceType()
  822.     if turtle then
  823.      return "turtle"
  824.    elseif pocket then
  825.      return "pocket"
  826.    elseif commands then
  827.      return "command_computer"
  828.    else
  829.      return "computer"
  830.    end
  831.  end
  832.  
  833.  function OpenRednetSpecificForDevice()
  834.     local device = WhatDeviceAmIRunningOn()
  835.     device = string.upper(device)
  836.     if device == "TURTLE"then
  837.         rednet.open("left")
  838.     else if device == "COMPUTER" or device == "COMMAND_COMPUTER" or device == "PAD" then
  839.         rednet.open("back")
  840.     end
  841.     end
  842.  end
  843.  
  844. -- Os Functions End
  845.  
  846. -- General Functions Start
  847. function SetChestCoords(x,y,z)
  848.     ChestX = x
  849.     ChestY = y
  850.     ChestZ = z
  851. end
  852.  
  853. function SetFuelCoords(x,y,z)
  854.     FuelX = x
  855.     FuelY = y
  856.     FuelZ = z
  857. end
  858.  
  859. function SetSavedCoords(x,y,z)
  860.     SavedX = x
  861.     SavedY = y
  862.     SavedZ = z
  863. end
  864.  
  865. function SetStartCoords(x,y,z)
  866.     StartX = x
  867.     StartY = y
  868.     StartZ = z
  869. end
  870.  
  871. function SetHomebaseDistance(distance)
  872.     DISTANCETOHOMEBASE = distance
  873. end
  874. -- General Start End
  875.  
  876. -- String Funtion Start
  877. function MySplit (inputstr, sep)
  878.     if sep == nil then
  879.        sep = "%s"
  880.     end
  881.     local t={}
  882.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  883.        table.insert(t, str)
  884.     end
  885.     return t
  886.  end
  887. -- String funtion End
  888.  
  889.  
  890. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement