Advertisement
murlocking

Untitled

May 10th, 2020
121
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 robot.count(4) <=2 then
  126. right() ; robot.select(5) ; robot.drop()
  127. robot.select(14) ; robot.place() ; robot.select(4)
  128.  
  129. if stack_info == nil then
  130.     return false
  131.   end
  132.   for index, known_rail_name in ipairs(nRail_names) do
  133.     if stack_info.name == known_rail_name then
  134.       return true
  135.     end
  136.   end
  137.   return false
  138. end
  139.  
  140. for slot=1,27 do
  141.   local stack_info = inventory.getStackInSlot(side, slot)
  142.  
  143.   --- inspect the stack_info when it is not nil
  144.   if getRail(stack_info) then
  145.     print(stack_info.name, "found in slot", slot)
  146.     inventory.suckFromSlot(sides.front, slot)
  147.     break
  148.   end
  149. end
  150. robot.select(5) ; inventory.dropIntoSlot(side, 1) ; robot.swing() ; robot.transferTo(14) ; left()
  151. end
  152.  
  153.  
  154.  
  155. local function refuel(stack_info)
  156.   if stack_info == nil then
  157.     return false
  158.   end
  159.   for index, known_fuel_name in ipairs(Fuel_names) do
  160.     if stack_info.name == known_fuel_name then
  161.       return true
  162.     end
  163.   end
  164.   return false
  165. end
  166.  
  167. if computer.energy() <=200 then
  168. right() ; robot.select(14) ; robot.place() ; robot.select(16) ; robot.drop() ; robot.select(15)
  169. for slot=1,27 do
  170.   local stack_info = inventory.getStackInSlot(side, slot)
  171.  
  172.   --- inspect the stack_info when it is not nil
  173.   if refuel(stack_info) then
  174.     print(stack_info.name, "found in slot", slot)
  175.     inventory.suckFromSlot(sides.front, slot)
  176.     break
  177.   end
  178. end
  179. robot.select(14) ; robot.swing()
  180. robot.select(8) ; robot.place() ; robot.select(16) ; g.remove() ; inventory.dropIntoSlot(side, 1) ; robot.select(15) ; g.insert() ; os.sleep(20)
  181. robot.select(8) ; robot.swing()
  182. left()
  183. end
  184.  
  185. local function digit()
  186.   for i = 1, rowsToDig do
  187.  
  188. refuel(stack_info)
  189. getRail(stack_info)
  190. TURN() ; robot.select(4) ; robot.place() ; TURN()
  191. Movement()
  192. end
  193. end
  194.  
  195. digit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement