Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. local lib = {}
  2. lib.blocks = {}
  3.  
  4. lib.blocks["minecraft:cobble"] = "path"
  5. lib.blocks["minecraft:stone"] = "refuel"
  6. lib.blocks["minecraft:sand"] = "tree"
  7. lib.blocks["minecraft:gravel"] = "clear"
  8. lib.blocks["minecraft:clay"] = "left"
  9. lib.blocks["minecraft:pumpkin"] = "right"
  10. lib.blocks["minecraft:bedrock"] = "stop"
  11. lib.tree_distance = 3
  12. lib.tree_size = 5
  13. lib.needed_fuel = 800
  14.  
  15. lib.tick = 1
  16.  
  17. function lib.coal_to_get()
  18. fuel_stock = turtle.getFuel()
  19. fuel_to_get = needed_fuel - fuel_stock
  20. coal_to_get = math.ceil(fuel_to_get/80)
  21. return math.max(coal_to_get, 0)
  22. end
  23.  
  24. function lib.refuel()
  25. turtle.turnLeft()
  26. turtle.select(1)
  27. to_get = lib.coal_to_get()
  28. while to_get > 0 do
  29. while not turtle.suck(to_get) do sleep(lib.tick) end
  30. turtle.refuel()
  31. to_get = lib.coal_to_get()
  32. turtle.turnRight()
  33. end
  34.  
  35. function lib.clear()
  36. turtle.turnLeft()
  37. for i = 1, 16 do
  38. turtle.select(i)
  39. turtle.drop()
  40. end
  41. turtle.turnRight()
  42. end
  43.  
  44. function lib.tree()
  45. turtle.turnLeft()
  46. for i=1, lib.tree_distance do lib.digForward() end
  47. for i=1, lib.tree_size do lib.digUp() end
  48. for i=1, lib.tree_size do turtle.down() end
  49. for i=1, lib.tree_distance do turtle.back() end
  50. turtle.turnRight()
  51. end
  52.  
  53. function lib.analyse(meta)
  54. if meta == nil then return "unknown" end
  55. bind = lib.blocks[meta.name]
  56. if bind == nil then return "unknown" end
  57. return bind
  58. end
  59.  
  60. function lib.getBlock()
  61. res, meta = turtle.inspectDown()
  62. return lib.analyse(meta)
  63. end
  64.  
  65. function lib.inspect()
  66. res, meta = turtle.inspect()
  67. return lib.analyse(meta)
  68. end
  69.  
  70. function lib.init()
  71. while not(turtle.detectDown()) do turtle.down() end
  72.  
  73. block = lib.getBlock()
  74. while block == "unknown" do
  75. turtle.back()
  76. block = lib.getBlock()
  77. end
  78.  
  79. if block == "stop" then
  80. return false
  81. elseif block == "tree" then
  82. turtle.turnRight()
  83. elseif block == "refuel" or block == "clear" then
  84. while not(lib.inspect() == "chest") then turtle.turnLeft() end
  85. turtle.turnRight()
  86. else
  87. turtle.forward()
  88. sblock = lib.getBlock()
  89. while not(sblock == "flag") then
  90. turtle.back()
  91. turtle.turnRight()
  92. turtle.forward()
  93. sblock = lib.getBlock()
  94. end
  95. end
  96. return true
  97. end
  98.  
  99. function lib.execute()
  100. block = lib.getBlock()
  101. if block == "tree" then lib.tree()
  102. elseif block == "left" then turtle.turnLeft()
  103. elseif block == "right" then turtle.turnRight()
  104. elseif block == "refuel" then lib.refuel()
  105. elseif block == "clear" then lib.clear()
  106. else block == "stop" then return false end
  107. turtle.forward()
  108. return true
  109. end
  110.  
  111. function lib.loop()
  112. running = lib.init()
  113. while running do
  114. running = lib.execute()
  115. end
  116. end
  117.  
  118. lib.loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement