Advertisement
Guest User

Main

a guest
Apr 9th, 2020
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.44 KB | None | 0 0
  1. --Move Bot
  2. function moveToChest()
  3.   newX = botCoords["x"] - chestCoords["x"]
  4.   newY = botCoords["y"] - chestCoords["y"]
  5.   newZ = botCoords["z"] - chestCoords["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.     turtle.down()
  21.     botCoords["z"] = botCoords["z"] - 1
  22.   else if newZ < 0 then
  23.     turtle.up()
  24.     botCoords["z"] = botCoords["z"] + 1
  25.   end
  26.  
  27.   if facing == iWantToFace then
  28.     turtle.forward()
  29.     if facing == 0 then
  30.       botCoords["y"] = botCoords["y"] - 1
  31.     else if facing == 1 then
  32.       botCoords["x"] = botCoords["x"] + 1
  33.     else if facing == 2 then
  34.       botCoords["y"] = botCoords["y"] + 1
  35.     else if facing == 3 then
  36.       botCoords["x"] = botCoords["x"] - 1
  37.     end
  38.   else then
  39.     turtle.turnRight()
  40.     facing = facing + 1
  41.     if facing > 3 then
  42.       faceing = facing - 4
  43.     end
  44.   end
  45. end
  46. --Main Program
  47. botCoords = {}
  48. homeCoords = {}
  49. chestCoords = {}
  50. facing = 0
  51. iWantToFace = 0
  52. pathBack = {}
  53.  
  54. print("Gathering Coordinates")
  55. file = fs.open("Locations", "r")
  56. file.readLine()
  57.  
  58. x = tonumber(file.readLine())
  59. botCoords["x"] = x
  60. homeCoords["x"] = x
  61.  
  62. y = tonumber(file.readLine())
  63. botCoords["y"] = y
  64. homeCoords["y"] = y
  65.  
  66. z = tonumber(file.readLine())
  67. botCoords["z"] = z
  68. homeCoords["z"] = z
  69.  
  70. file.readLine()
  71. chestCoords["x"] = tonumber(file.readLine())
  72. chestCoords["y"] = tonumber(file.readLine())
  73. chestCoords["z"] = tonumber(file.readLine())
  74.  
  75. goBackAt = 0
  76. isGoingBack = false
  77. needTask = false
  78. getResource = false
  79.  
  80. while true do
  81.   if turtle.getFuelLevel() == 0 and turtle.getItemCount(16) > 0 then
  82.     goBackAt = (turtle.getItemCount(16) * 80) / 2
  83.     turtle.select(16)
  84.     turtle.refuel(turtle.getItemCount(16))
  85.     print("YUM")
  86.     print(turtle.getFuelLevel())
  87.   elseif turtle.getFuelLevel() == 0 then    
  88.     print("Sleepy Time")
  89.     os.sleep(60)
  90.   elseif turtle.getFuelLevel() <= goBackAt or isGoingBack then
  91.     isGoingBack = true
  92.     moveToChest()
  93.     if turtle.detect() then
  94.       data = turtle.inspect()
  95.       if data.name == "Minecraft:Chest" then
  96.         chest = peripheral.isPresent("front")
  97.        
  98.         for i = 1, 16 do
  99.           turtle.select(i)
  100.           turtle.drop()
  101.         end
  102.         for slot, item in pairs(chest.getAllStacks()) do
  103.           if item.id == "Minecraft:Coal"
  104.   end
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement