murlocking

Untitled

May 10th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.17 KB | None | 0 0
  1. -- pastebin.com/xg7p10Vt
  2. -- pastebin.com/hrXuWsAS
  3.  
  4. local robot = require("robot")
  5. local computer = require("computer")
  6. local sides = require("sides")
  7. local component = require("component")
  8. local ser = require("serialization")
  9.  
  10. local c = component.crafting
  11. local g = component.generator
  12. local inventory = component.inventory_controller
  13.  
  14. local left = robot.turnLeft
  15. local right = robot.turnRight
  16. local TURN = robot.turnAround
  17. local d = robot.detect
  18. local dUp = robot.detectUp
  19. local dDown = robot.detectDown
  20.  
  21. local side = sides.front
  22.  
  23. local args = {...} -- ... gets the program's arguments somehow
  24. local rowsToDig = args[1] -- getting the first argument in the argument table
  25.  
  26.  
  27. local nRail_names = {}
  28. nRail_names[1] = "minecraft:rail"
  29. nRail_names[2] = "TConstruct:rail.wood"
  30.  
  31. local Fuel_names = {}
  32. Fuel_names[1] = "minecraft:coal"
  33. Fuel_names[2] = "minecraft:planks"
  34. Fuel_names[3] = "minecraft:log"
  35. Fuel_names[4] = "minecraft:blaze_rod"
  36. Fuel_names[5] = "minecraft:lava_bucket"
  37.  
  38.  
  39. print(robot.detect())
  40.  
  41.  
  42. -- Functions for movements
  43.  
  44. local function goUp()
  45.   while dUp() do
  46.     robot.swingUp()
  47.     os.sleep(2)
  48.   end
  49.   robot.up()
  50.   os.sleep(0.8)
  51. end
  52.  
  53. local function goDown()
  54.   while dDown() do
  55.     robot.swingDown()
  56.     os.sleep(2)
  57.   end
  58.   robot.down()
  59.   os.sleep(0.8)
  60. end
  61.  
  62. local function go()
  63.   while d() do    --- while robot.detect == true do
  64.     robot.swing()
  65.     os.sleep(2)
  66.   end
  67.   robot.forward()
  68.   os.sleep(0.8)
  69. end
  70.  
  71. -- Extra Functions to break blocks without moving, clear sand blocks or anormalies
  72.  
  73. local function rSand()
  74.   while d() do    --- while robot.detect == true do
  75.     robot.swing()
  76.     os.sleep(2)
  77.   end
  78.   robot.turnAround()
  79.   while d() do
  80.     robot.swing()
  81.   os.sleep(2)
  82. end
  83. end
  84.  
  85.  
  86. -- Place Blocks with Dev/ Null
  87.  
  88. local function Bf()
  89.   if not d() then
  90.     robot.select(13)
  91.     robot.place()
  92.   end
  93. end
  94.  
  95. local function Bd()
  96.   if not dDown() then  
  97.     robot.select(13)
  98.     robot.placeDown()
  99.   end
  100. end
  101.  
  102. local function Bu()
  103.   if not dUp() then
  104.     robot.select(13)
  105.     robot.placeUp()
  106.   end
  107. end
  108.  
  109.  
  110. -- Movement script
  111.  
  112. local function Movement()
  113. Bd() ; go()
  114. Bd() ; left() ; go() ; Bf() ; Bd() ; TURN() ; go() ; go() ; Bd() ; Bf() ; goUp()
  115. Bf() ; TURN() ; go() ; go() ; Bf() ; goUp()
  116. Bf() ; Bu() ; TURN() ; go() ; Bu() ; go() ; Bf() ; Bu()
  117. TURN() ; go() ; goDown() ; goDown() ; rSand() ; left()
  118. end
  119.  
  120.  
  121.  
  122.  
  123.  
  124. local function getRail(stack_info)
  125.   if stack_info == nil then
  126.     return false
  127.   end
  128.   for index, known_rail_name in ipairs(nRail_names) do
  129.     if stack_info.name == known_rail_name then
  130.       return true
  131.     end
  132.   end
  133.   return false
  134. end
  135.  
  136. if robot.count(4) <=2 then
  137. right() ; robot.select(5) ; robot.drop()
  138. robot.select(14) ; robot.place() ; robot.select(4)
  139. for slot=1,27 do
  140.   local stack_info = inventory.getStackInSlot(side, slot)
  141.  
  142.   --- inspect the stack_info when it is not nil
  143.   if getRail(stack_info) then
  144.     print(stack_info.name, "found in slot", slot)
  145.     inventory.suckFromSlot(sides.front, slot)
  146.     break
  147.   end
  148. end
  149. robot.select(5) ; inventory.dropIntoSlot(side, 1) ; robot.swing() ; robot.transferTo(14) ; left()
  150. end
  151.  
  152.  
  153.  
  154. local function refuel(stack_info)
  155.   if stack_info == nil then
  156.     return false
  157.   end
  158.   for index, known_fuel_name in ipairs(Fuel_names) do
  159.     if stack_info.name == known_fuel_name then
  160.       return true
  161.     end
  162.   end
  163.   return false
  164. end
  165.  
  166. if computer.energy() <=200 then
  167. right() ; robot.select(14) ; robot.place() ; robot.select(16) ; robot.drop() ; robot.select(15)
  168. for slot=1,27 do
  169.   local stack_info = inventory.getStackInSlot(side, slot)
  170.  
  171.   --- inspect the stack_info when it is not nil
  172.   if refuel(stack_info) then
  173.     print(stack_info.name, "found in slot", slot)
  174.     inventory.suckFromSlot(sides.front, slot)
  175.     break
  176.   end
  177. end
  178. robot.select(14) ; robot.swing()
  179. robot.select(8) ; robot.place() ; robot.select(16) ; g.remove() ; inventory.dropIntoSlot(side, 1) ; robot.select(15) ; g.insert() ; os.sleep(20)
  180. robot.select(8) ; robot.swing()
  181. left()
  182. end
  183.  
  184. local function digit()
  185.   for i = 1, rowsToDig do
  186.  
  187. refuel(stack_info)
  188. getRail(stack_info)
  189. TURN() ; robot.select(4) ; robot.place() ; TURN()
  190. Movement()
  191. end
  192. end
  193.  
  194. digit()
Add Comment
Please, Sign In to add comment