Advertisement
Guest User

Main

a guest
Apr 9th, 2020
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 KB | None | 0 0
  1. --Move Bot
  2. function moveToLocation()
  3.   newX = botCoords["x"] - newCoords["x"]
  4.   newY = botCoords["y"] - newCoords["y"]
  5.   newZ = botCoords["z"] - newCoords["z"]
  6.  
  7.   if newX > 0 then
  8.     iWantToFace = 3
  9.   else if newX < 0 then
  10.     iWantToFace = 1
  11.   end
  12.  
  13.   if newY > 0 then
  14.     iWantToFace = 0
  15.   else if newY < 0 then
  16.     iWantToFace = 2
  17.   end
  18.  
  19.   if newZ > 0 then
  20.     if turtle.detectDown() then
  21.       turtle.digDown()
  22.     end
  23.     turtle.down()
  24.     botCoords["z"] = botCoords["z"] - 1
  25.   else if newZ < 0 then
  26.     if turtle.detectUp() then
  27.       turtle.digUp()
  28.     end
  29.     turtle.up()
  30.     botCoords["z"] = botCoords["z"] + 1
  31.   end
  32.  
  33.   if facing == iWantToFace then
  34.     if turtle.detect() then
  35.       turtle.dig()
  36.     end
  37.     turtle.forward()
  38.     if facing == 0 then
  39.       botCoords["y"] = botCoords["y"] - 1
  40.     elseif facing == 1 then
  41.       botCoords["x"] = botCoords["x"] + 1
  42.     elseif facing == 2 then
  43.       botCoords["y"] = botCoords["y"] + 1
  44.     elseif facing == 3 then
  45.       botCoords["x"] = botCoords["x"] - 1
  46.     end
  47.   else    
  48.     turtle.turnRight()
  49.     facing = facing + 1
  50.     if facing > 3 then
  51.       faceing = facing - 4
  52.     end
  53.   end
  54. end
  55.  
  56. function canDig()
  57.   hardParimeter = 10
  58.   if botCoords["x"] + hardParimeter > nextCoords["x"] and botCoords["x"] - hardParimeter < nextCoords["x"] and botCoords["y"] +
  59.     hardParimeter > nextCoords["y"] and botCoords["y"] - hardParimeter < nextCoords["y"] and botCoords["z"] +
  60.     hardParimeter > nextCoords["z"] and botCoords["z"] - hardParimeter < nextCoords["z"] then
  61.    
  62.     return false
  63.   else
  64.     return true
  65.   end
  66. end
  67.  
  68. --Main Program
  69. botCoords = {}
  70. homeCoords = {}
  71. chestCoords = {}
  72. facing = 0
  73. iWantToFace = 0
  74. pathBack = {}
  75.  
  76. print("Gathering Coordinates")
  77. file = fs.open("Locations", "r")
  78. file.readLine()
  79.  
  80. x = tonumber(file.readLine())
  81. botCoords["x"] = x
  82. homeCoords["x"] = x
  83.  
  84. y = tonumber(file.readLine())
  85. botCoords["y"] = y
  86. homeCoords["y"] = y
  87.  
  88. z = tonumber(file.readLine())
  89. botCoords["z"] = z
  90. homeCoords["z"] = z
  91.  
  92. file.readLine()
  93. chestCoords["x"] = tonumber(file.readLine())
  94. chestCoords["y"] = tonumber(file.readLine())
  95. chestCoords["z"] = tonumber(file.readLine())
  96.  
  97. goBackAt = 0
  98. isGoingBack = true
  99. needCoords = false
  100.  
  101.  
  102. while true do
  103.   if turtle.getFuelLevel() == 0 and turtle.getItemCount(16) > 0 then
  104.     goBackAt = (turtle.getItemCount(16) * 80) / 2
  105.     turtle.select(16)
  106.     turtle.refuel(turtle.getItemCount(16))
  107.     print("YUM")
  108.     print(turtle.getFuelLevel())
  109.   elseif turtle.getFuelLevel() == 0 then    
  110.     print("Sleepy Time")
  111.     os.sleep(60)
  112.   elseif turtle.getFuelLevel() <= goBackAt or isGoingBack then
  113.     isGoingBack = true
  114.     newCoords["x"] = chestCoords["x"]
  115.     newCoords["y"] = chestCoords["y"]
  116.     newCoords["z"] = chestCoords["z"]
  117.    
  118.     if turtle.detect() then
  119.       data = turtle.inspect()
  120.       if data.name == "Minecraft:Chest" then
  121.         chest = peripheral.isPresent("front")
  122.         for i = 1, 16 do
  123.           turtle.select(i)
  124.           turtle.drop()
  125.         end
  126.         for slot, item in pairs(chest.getAllStacks()) do
  127.           if item.id == "Minecraft:Coal" then
  128.             chest.pushItem("south", slot)
  129.             break
  130.           end
  131.         end
  132.         goBackAt = (turtle.getItemCount(16) * 80) / 2
  133.         turtle.select(16)
  134.         turtle.refuel(turtle.getItemCount(16))
  135.         isGoingBack = false
  136.         needCoords = true
  137.       end
  138.     end
  139.   elseif needCoords then
  140.     newCoords["x"] = math.floor(math.random() * goBackAt)
  141.     newCoords["y"] = math.floor(math.random() * goBackAt)
  142.     newCoords["z"] = math.floor(math.random() * goBackAt)
  143.     needCoords = false
  144.  end
  145.  
  146.   if not needCoords then
  147.     moveToLocation()
  148.   end
  149.   end  
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement