Advertisement
jdroid91

warpListen

Jan 18th, 2024 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.36 KB | None | 0 0
  1. local currentDirection = nil
  2. local warper = peripheral.wrap("right")
  3. rednet.open("left")
  4.  
  5. function getCurrentDirection()
  6.     local blockStatus, blockData = turtle.inspect()
  7.     if (blockStatus == false)
  8.     then
  9.         local tp1X, tp1Y, tp1Z = gps.locate()
  10.         turtle.forward()
  11.         local tp2X, tp2Y, tp2Z = gps.locate()
  12.         turtle.back()
  13.      
  14.         if (tp1X == tp2X)
  15.         then
  16.             if (tp1Z < tp2Z)
  17.             then
  18.                 currentDirection = "South"
  19.             else
  20.                 currentDirection = "North"
  21.             end
  22.         else
  23.             if (tp1X < tp2X)
  24.             then
  25.                 currentDirection = "East"
  26.             else
  27.                 currentDirection = "West"
  28.             end
  29.         end
  30.     else
  31.         turtle.turnRight()
  32.         getCurrentDirection()
  33.     end
  34. end
  35.  
  36. function turnLeft()
  37.     if (currentDirection == "North")
  38.     then
  39.         currentDirection = "West"
  40.     elseif (currentDirection == "West")
  41.     then
  42.         currentDirection = "South"
  43.     elseif (currentDirection == "South")
  44.     then
  45.         currentDirection = "East"
  46.     else
  47.         currentDirection = "North"
  48.     end
  49.     turtle.turnLeft()
  50. end
  51.  
  52. function turnRight()
  53.     if (currentDirection == "North")
  54.     then
  55.         currentDirection = "East"
  56.     elseif (currentDirection == "East")
  57.     then
  58.         currentDirection = "South"
  59.     elseif (currentDirection == "South")
  60.     then
  61.         currentDirection = "West"
  62.     else
  63.         currentDirection = "North"
  64.     end
  65.     turtle.turnRight()
  66. end
  67.  
  68. function warpToFuel()
  69.     warper.savePoint("temp")
  70.     warper.warpToPoint("refuel")
  71.     getCurrentDirection()
  72.     while (currentDirection ~= "North")
  73.     do
  74.         turnLeft()
  75.     end
  76.      
  77.     local index = 1
  78.     while (index <= 16)
  79.     do
  80.         turtle.suck()
  81.         index = index + 1
  82.     end
  83.        
  84.     warper.warpToPoint("temp")
  85.        
  86.     local blockStatus, blockData = turtle.inspect()
  87.     while (blockData.name ~= "computercraft:turtle_advanced")
  88.     do
  89.         turtle.turnRight()
  90.         blockStatus, blockData = turtle.inspect()
  91.     end
  92.        
  93.     index = 1
  94.     while (index <= 16)
  95.     do
  96.         turtle.select(index)
  97.         turtle.drop()
  98.         index = index + 1
  99.     end
  100. end
  101.  
  102. function warpToFuelSelf()
  103.     warper.savePoint("temp")
  104.     warper.warpToPoint("refuel")
  105.     getCurrentDirection()
  106.     while (currentDirection ~= "North")
  107.     do
  108.         turnLeft()
  109.     end
  110.      
  111.     local index = 1
  112.     while (index <= 16)
  113.     do
  114.         turtle.suck()
  115.         index = index + 1
  116.     end
  117.        
  118.     shell.run("refuel")
  119.    
  120.     turtle.turnRight()
  121.    
  122.     index = 1
  123.     while (index <= 16)
  124.     do
  125.         turtle.select(index)
  126.         turtle.drop()
  127.         index = index + 1
  128.     end
  129.    
  130.     os.sleep(1)
  131.    
  132.     warper.warpToPoint("temp")
  133. end
  134.  
  135. while true do
  136.     id, message = rednet.receive()
  137.    
  138.     if (message == "Refuel")
  139.     then
  140.         warpToFuelSelf()
  141.         os.sleep(1)
  142.         warpToFuel()        
  143.         rednet.send(49, "Refuel")
  144.        
  145.         local isWaiting = true
  146.         while (isWaiting)
  147.         do
  148.             id, message = rednet.receive()
  149.             if (message == "Continue Refuel")
  150.             then
  151.                 warpToFuel()
  152.                 isWaiting = false
  153.  
  154.                 rednet.send(49, "Finish Refuel")
  155.             end
  156.         end
  157.     end
  158. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement