Advertisement
murlocking

Untitled

May 11th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.35 KB | None | 0 0
  1. local robot = require("robot")
  2. local computer = require("computer")
  3. local sides = require("sides")
  4. local component = require("component")
  5. local ser = require("serialization")
  6.  
  7. local c = component.crafting
  8. local g = component.generator
  9. local inventory = component.inventory_controller
  10.  
  11. local left = robot.turnLeft
  12. local right = robot.turnRight
  13. local TURN = robot.turnAround
  14. local d = robot.detect
  15. local dUp = robot.detectUp
  16. local dDown = robot.detectDown
  17.  
  18. local side = sides.front
  19.  
  20. local args = {...} -- ... gets the program's arguments somehow
  21. local rowsToDig1 = args[1] -- getting the first argument in the argument table
  22. local rowsToDig2 = args[2]
  23.  
  24.  
  25. local nRail_names = {}
  26. nRail_names[1] = "minecraft:rail"
  27. nRail_names[2] = "TConstruct:rail.wood"
  28.  
  29. local Fuel_names = {}
  30. Fuel_names[1] = "minecraft:coal"
  31. Fuel_names[2] = "minecraft:planks"
  32. Fuel_names[3] = "minecraft:log"
  33. Fuel_names[4] = "minecraft:blaze_rod"
  34. Fuel_names[5] = "minecraft:lava_bucket"
  35.  
  36. local trash_names = {}
  37. trash_names[1] = "minecraft:dirt"
  38. trash_names[2] = "minecraft:sand"
  39. trash_names[3] = "minecraft:cobblestone"
  40. trash_names[4] = "minecraft:gravel"
  41. trash_names[5] = "minecraft:gold_ore"
  42. trash_names[6] = "minecraft:iron_ore"
  43. trash_names[7] = "nevermine:oreLimonite"
  44. trash_names[8] = "minecraft:redstone"
  45. trash_names[10] = "nevermine:oreRosite"
  46. trash_names[11] = "minecraft:coal_ore"
  47.  
  48.  
  49.  
  50.  
  51. -- Functions for movements
  52.  
  53. local function goUp()
  54.   while dUp() do
  55.     robot.swingUp()
  56.     os.sleep(2)
  57.   end
  58.   robot.up()
  59.   os.sleep(0.8)
  60. end
  61.  
  62. local function goDown()
  63.   while dDown() do
  64.     robot.swingDown()
  65.     os.sleep(2)
  66.   end
  67.   robot.down()
  68.   os.sleep(0.8)
  69. end
  70.  
  71. local function go()
  72.   while d() do    --- while robot.detect == true do
  73.     robot.swing()
  74.     os.sleep(2)
  75.   end
  76.   robot.forward()
  77.   os.sleep(0.8)
  78. end
  79.  
  80. -- Extra Functions to break blocks without moving, clear sand blocks or anormalies
  81.  
  82. local function rSand()
  83.   while d() do    --- while robot.detect == true do
  84.     robot.swing()
  85.     os.sleep(2)
  86.   end
  87.   robot.turnAround()
  88.   while d() do
  89.     robot.swing()
  90.   os.sleep(2)
  91. end
  92. end
  93.  
  94.  
  95. -- Place Blocks with Dev/ Null
  96.  
  97. local function Bf()
  98.   if not d() then
  99.     robot.select(13)
  100.     robot.place()
  101.   end
  102. end
  103.  
  104. local function Bd()
  105.   if not dDown() then  
  106.     robot.select(13)
  107.     robot.placeDown()
  108.   end
  109. end
  110.  
  111. local function Bu()
  112.   if not dUp() then
  113.     robot.select(13)
  114.     robot.placeUp()
  115.   end
  116. end
  117.  
  118.  
  119. -- Movement script
  120.  
  121. local function Movement()
  122. Bd() ; go()
  123. Bd() ; left() ; go() ; Bf() ; Bd() ; TURN() ; go() ; go() ; Bd() ; Bf() ; goUp()
  124. Bf() ; TURN() ; go() ; go() ; Bf() ; goUp()
  125. Bf() ; Bu() ; TURN() ; go() ; Bu() ; go() ; Bf() ; Bu()
  126. TURN() ; go() ; goDown() ; goDown() ; rSand() ; left()
  127. end
  128.  
  129.  
  130.  
  131. -- find rails
  132.  
  133. local function findRail(stack_info)
  134.  
  135.   if stack_info == nil then
  136.         return false
  137.       end
  138.  
  139.         for index, known_rail_name in ipairs(nRail_names) do
  140.           if stack_info.name == known_rail_name then
  141.             return true
  142.           end
  143.         end
  144.       return false
  145. end
  146.  
  147. local function findTrash(stack_info)
  148.  
  149.   if stack_info == nil then
  150.         return false
  151.       end
  152.  
  153.         for index, known_trash_name in ipairs(trash_names) do
  154.           if stack_info.name == known_trash_name then
  155.             return true
  156.           end
  157.         end
  158.       return false
  159. end
  160.  
  161.  
  162. -- get rails from a chest inventory
  163.  
  164. local function getRail()
  165.   local stack_info = inventory.getStackInInternalSlot(4)
  166.     if findTrash(stack_info) then
  167.         robot.select(4) ; robot.drop()
  168.     end  
  169.   right() ; robot.select(5) ; robot.drop()
  170.   robot.select(14) ; robot.place() ; robot.select(4)
  171.  
  172.     for slot=1,27 do
  173.               local stack_info = inventory.getStackInSlot(side, slot)
  174.               if findRail(stack_info) then
  175.                 print(stack_info.name, "I found rails in slot", slot, ". Restocking, please stand by!")
  176.                 inventory.suckFromSlot(sides.front, slot)
  177.             break
  178.               end
  179.             end
  180.  
  181.   robot.select(5) ; inventory.dropIntoSlot(side, 1)
  182.   robot.swing() ; robot.transferTo(14) ; left()
  183. end
  184.    
  185.  
  186. -- find usuable fuel materials
  187.  
  188. local function findFuel(stack_info)
  189.  
  190.       if stack_info == nil then
  191.         return false
  192.       end
  193.  
  194.         for index, known_fuel_name in ipairs(Fuel_names) do
  195.           if stack_info.name == known_fuel_name then
  196.             return true
  197.           end
  198.         end
  199.       return false
  200. end
  201.  
  202.  
  203. -- get 'fuel' from a chest inventory, if something was in the robot, it place it into a filter chest, and use the new fuel
  204.  
  205. local function refuel()
  206.   right() ; robot.select(14) ; robot.place() ; robot.select(16) ; robot.drop() ; robot.select(15)
  207.  
  208.  
  209.           for slot=1,27 do
  210.             local stack_info = inventory.getStackInSlot(side, slot)
  211.             if findFuel(stack_info) then
  212.               print(stack_info.name, "I found fuel in slot", slot, "Refueling, stand by!")
  213.               inventory.suckFromSlot(sides.front, slot)
  214.           break
  215.             end
  216.           end
  217.  
  218.   robot.select(14) ; robot.swing()
  219.   robot.select(8) ; robot.place() ; robot.select(16) ; g.remove() ; inventory.dropIntoSlot(side, 1) ; robot.select(15) ; g.insert() ; os.sleep(20)
  220.   robot.select(8) ; robot.swing()
  221.   left()
  222. end
  223.  
  224. -- place rails only if rails are presents in player slot:4
  225.  
  226. local function placeRail()
  227.  
  228. local stack_info = inventory.getStackInInternalSlot(4)
  229.         if findRail(stack_info) then
  230.           print("I'm placing a", stack_info.name, "there.")
  231.           TURN() ;  robot.select(4) ; robot.place() ; TURN() -- place rails
  232.         end
  233. end
  234.  
  235.  
  236.  
  237.  
  238.  
  239. -- Run the program for # defined during start-up, if less than 200 energy.. refuel, if less than 2 rails.. restock,
  240. -- place a rail behind the robot and dig a 3x3.
  241.  
  242. local function digit()
  243.   for i = 1, rowsToDig1 do
  244.  
  245.     if computer.energy() <= 200 then
  246.       refuel() -- refuel duh?
  247.     end
  248.  
  249.       if robot.count(4) <= 2 then
  250.         getRail()      -- restock on rails
  251.       end
  252.  
  253.     placeRail()
  254.   Movement() -- dig a tunnel
  255.  
  256.   end
  257.  
  258.   robot.turnLeft()
  259.  
  260.   for i = 1, rowsToDig2 do
  261.  
  262.     if computer.energy() <= 200 then
  263.       refuel() -- refuel duh?
  264.     end
  265.  
  266.       if robot.count(4) <= 2 then
  267.         getRail()      -- restock on rails
  268.       end
  269.  
  270.     placeRail()
  271.   Movement() -- dig a tunnel
  272.  
  273.   end
  274. end
  275.  
  276. -- Call the program
  277.  
  278. digit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement