Advertisement
murlocking

Untitled

May 14th, 2020
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.38 KB | None | 0 0
  1. --[[
  2. Made by Murlocking for Minecraft 1.7.0 and Opencomputers
  3.              Robot Program to dig a 3x3 tunnel and place rail tracks
  4.  
  5. Requirements: Robot: Computer Tier 3, Inventory Upgrade, Inventory Controller, Hover Upgrade, Angel Upgrade,
  6. Inventory Controller, Disk Drive to copy program to the robot, Generator
  7.  
  8. To use the robot, equip a pickaxe in the 'tool' slot, in slot 1: put an Ender Chest with light source blocks
  9. listed under 'Light_names', in slot 2: any light source blocks from 'Light_names',
  10. in slot 4: add normal rails listed under 'nRail_names', keep slot 5 empty, in slot 6: powered rails,
  11. in slot 7: redstone block, in slot 8: a different Ender Chest to return fuel(mainly empty buckets),
  12. in slot 9: place your building materials (Mat_names), keep slot 10&11 empty, in slot 12:
  13. place a different Ender Chest with your building materials in it, in slot 14: place a different
  14. Ender Chest with your fuels and normal rails (nRail_names / Fuel_names), keep slot 15&16 empty.
  15.  
  16. Place the robot facing a direction where you want it to dig, leave on the side of the robot,
  17. for restocking and also leave an empty space behind the robot.
  18. Make sure there's a block below the 'air' block behind the robot so it can place a rail on it.
  19.  
  20. Run the program like so 'programName X Y Z' where ;
  21. X = number of rows to dig in the direction the robot face,
  22. Y = the number of rows to dig after completing X,
  23. Z = direction the robot turn after completing X (can be left or right).
  24.  
  25. If you don't specify Y or Z arguments, the robot will error out after digging X rows.
  26.  
  27. Robot will automatically restock on materials and place rails, it will also occasionally
  28. place powered rails (15 block) and light source (7 blocks).
  29.  
  30. It's recommended to equip your best mining tool or monitor the robot tool if you are early game.
  31. I used a Tinker Construct Pickaxe that was almost indestructible. You might need to change the program
  32. adjust to that, here's a few ideas :
  33.  
  34. 1. Repair tool from Tinker Tool using robot inventory and crafting upgrade,
  35. use stone tool and add a chest to slot 13 to store your items before crafting.
  36.  
  37. 2. Unbreakable Tool
  38.  
  39. 3. Auto-Repair Tool and long os.sleep period.
  40.  
  41. 4. Chest in slot 13 with new tools to replace broken one.
  42.  
  43. --]]
  44. local robot = require("robot")
  45. local computer = require("computer")
  46. local sides = require("sides")
  47. local component = require("component")
  48. local ser = require("serialization")
  49.  
  50. local c = component.crafting
  51. local g = component.generator
  52. local inventory = component.inventory_controller
  53.  
  54. local left = robot.turnLeft
  55. local right = robot.turnRight
  56. local TURN = robot.turnAround
  57. local d = robot.detect
  58. local dUp = robot.detectUp
  59. local dDown = robot.detectDown
  60.  
  61. local side = sides.front
  62.  
  63. local args = {...}
  64. local rowsToDig1 = args[1]
  65. local rowsToDig2 = args[2]
  66. local direction = string.upper(args[3])
  67.  
  68.  
  69. local nRail_names = {}
  70. nRail_names[1] = "minecraft:rail"
  71. nRail_names[2] = "TConstruct:rail.wood"
  72.  
  73. local Fuel_names = {}
  74. Fuel_names[1] = "minecraft:coal"
  75. Fuel_names[2] = "minecraft:planks"
  76. Fuel_names[3] = "minecraft:log"
  77. Fuel_names[4] = "minecraft:blaze_rod"
  78. Fuel_names[5] = "minecraft:lava_bucket"
  79.  
  80. local trash_names = {}
  81. trash_names[1] = "minecraft:dirt"
  82. trash_names[2] = "minecraft:sand"
  83. trash_names[3] = "minecraft:cobblestone"
  84. trash_names[4] = "minecraft:gravel"
  85. trash_names[5] = "minecraft:gold_ore"
  86. trash_names[6] = "minecraft:iron_ore"
  87. trash_names[7] = "nevermine:oreLimonite"
  88. trash_names[8] = "minecraft:redstone"
  89. trash_names[9] = "nevermine:oreRosite"
  90. trash_names[10] = "minecraft:coal_ore"
  91. trash_names[11] = "minecraft:netherrack"
  92. trash_names[12] = "minecraft:stone_slab"
  93. trash_names[13] = "minecraft:nether_brick_stairs"
  94. trash_names[14] = "minecraft:nether_brick_fence"
  95. trash_names[15] = "minecraft:nether_brick"
  96. trash_names[16] = "minecraft:quartz"
  97. trash_names[17] = "minecraft:quartz_ore"
  98.  
  99. local Mat_names = {}
  100. Mat_names[1] = "minecraft:dirt"
  101. Mat_names[2] = "minecraft:cobblestone"
  102. Mat_names[3] = "minecraft:netherrack"
  103.  
  104. local Light_names = {}
  105. Light_names[1] = "nevermine:deepCrystal"
  106. Light_names[2] = "minecraft:glowstone"
  107. Light_names[3] = "minecraft:lit_pumpkin"
  108.  
  109. local RSBlock_names = {}
  110. RSBlock_names[1] = "minecraft:redstone_block"
  111.  
  112. local PowRail_names = {}
  113. PowRail_names[1] = "minecraft:golden_rail"
  114.  
  115.  
  116.  
  117.  
  118. -- Functions for movements
  119.  
  120. local function goUp()
  121.   while dUp() do
  122.     robot.swingUp()
  123.     os.sleep(2)
  124.   end
  125.   robot.up()
  126.   os.sleep(0.8)
  127. end
  128.  
  129. local function goDown()
  130.   while dDown() do
  131.     robot.swingDown()
  132.     os.sleep(2)
  133.   end
  134.   robot.down()
  135.   os.sleep(0.8)
  136. end
  137.  
  138. local function go()
  139.   while d() do    --- while robot.detect == true do
  140.     robot.swing()
  141.     os.sleep(2)
  142.   end
  143.   robot.forward()
  144.   os.sleep(0.8)
  145. end
  146.  
  147. -- Extra Functions to break blocks without moving, clear sand blocks or anormalies
  148.  
  149. local function rSand()
  150.   while d() do    --- while robot.detect == true do
  151.     robot.swing()
  152.     os.sleep(2)
  153.   end
  154.   robot.turnAround()
  155.   while d() do
  156.     robot.swing()
  157.   os.sleep(2)
  158. end
  159. end
  160.  
  161.  
  162. -- Place Blocks with Dev/ Null
  163.  
  164. local function Bf()
  165.   if not d() then
  166.     robot.select(9)
  167.     robot.place()
  168.   end
  169. end
  170.  
  171. local function Bd()
  172.   if not dDown() then  
  173.     robot.select(9)
  174.     robot.placeDown()
  175.   end
  176. end
  177.  
  178. local function Bu()
  179.   if not dUp() then
  180.     robot.select(9)
  181.     robot.placeUp()
  182.   end
  183. end
  184.  
  185.  
  186. -- Movement script
  187.  
  188. local function Movement()
  189. Bd() ; go()
  190. Bd() ; left() ; go() ; Bf() ; Bd() ; TURN() ; go() ; go() ; Bd() ; Bf() ; goUp()
  191. Bf() ; TURN() ; go() ; go() ; Bf() ; goUp()
  192. Bf() ; Bu() ; TURN() ; go() ; Bu() ; go() ; Bf() ; Bu()
  193. TURN() ; go() ; goDown() ; goDown() ; rSand() ; left()
  194. end
  195.  
  196.  
  197. -- Place Glowstone Blocks
  198.  
  199. local function GBf()
  200.   while d() do    
  201.     robot.swing()
  202.     os.sleep(2)
  203.   end
  204.  
  205.   robot.select(2) ; robot.place()
  206. end
  207.  
  208.  
  209. -- MovementEx script
  210.  
  211. local function MovementEx()
  212. Bd() ; go()
  213. Bd() ; left() ; go() ; Bf() ; Bd() ; TURN() ; go() ; go() ; Bd() ; Bf() ; goUp()
  214. GBf() ; TURN() ; go() ; go() ; Bf() ; goUp()
  215. Bf() ; Bu() ; TURN() ; go() ; Bu() ; go() ; Bf() ; Bu()
  216. TURN() ; go() ; goDown() ; goDown() ; rSand() ; left()
  217. end
  218.  
  219.  
  220. -- find light source blocks
  221.  
  222. local function findLight(stack_info)
  223.   if stack_info == nil then
  224.     return false
  225.   end
  226.  
  227.     for index, known_light_name in ipairs(Light_names) do
  228.       if stack_info.name == known_light_name then
  229.         return true
  230.       end
  231.     end
  232.   return false
  233. end
  234.  
  235. -- restock on light source blocks
  236.  
  237. local function getLight()
  238.   left() ; robot.select(1) ; robot.place() ; robot.select(2) ; robot.drop()
  239.  
  240.     for slot=1,27 do
  241.     local stack_info = inventory.getStackInSlot(side, slot)
  242.       if findLight(stack_info) then
  243.         print(stack_info.name, "I found something in slot", slot, "Restocking, stand by!")
  244.         inventory.suckFromSlot(sides.front, slot)
  245.         break
  246.       end
  247.     end
  248.  
  249.   robot.select(1) ; robot.swing() ; right()
  250. end
  251.  
  252. -- find powered rails
  253.  
  254. local function findPowRail(stack_info)
  255.   if stack_info == nil then
  256.     return false
  257.   end
  258.  
  259.     for index, known_powrail_name in ipairs(PowRail_names) do
  260.       if stack_info.name == known_powrail_name then
  261.         return true
  262.       end
  263.     end
  264.   return false
  265. end
  266.  
  267. -- find redstone block
  268.  
  269. local function findRSBlock(stack_info)
  270.   if stack_info == nil then
  271.     return false
  272.   end
  273.  
  274.     for index, known_rsblock_name in ipairs(RSBlock_names) do
  275.       if stack_info.name == known_rsblock_name then
  276.         return true
  277.       end
  278.     end
  279.   return false
  280. end
  281.  
  282. -- restock on powered rails and redstone blocks
  283.  
  284. local function getPowRail()
  285.   left() ; robot.select(1) ; robot.place()
  286.   robot.select(6)
  287.  
  288.     for slot=1,27 do
  289.     local stack_info = inventory.getStackInSlot(side, slot)
  290.       if findPowRail(stack_info) then
  291.         print(stack_info.name, "I found P.Rails in slot", slot, "Restocking, stand by!")
  292.         inventory.suckFromSlot(sides.front, slot)
  293.         break
  294.       end
  295.     end
  296.  
  297.   robot.select(7)
  298.  
  299.     for slot=1,27 do
  300.     local stack_info = inventory.getStackInSlot(side, slot)
  301.       if findRSBlock(stack_info) then
  302.         print(stack_info.name, "I found RS Blocks in slot", slot, "Restocking, stand by!")
  303.         inventory.suckFromSlot(sides.front, slot)
  304.         break
  305.       end
  306.     end
  307.  
  308. robot.select(1) ; robot.swing() ; right()
  309. end
  310.  
  311.  
  312. -- place powered rail and a redstone block underneath it
  313.  
  314. local function placeRailEx()
  315.  
  316. local stack_info = inventory.getStackInInternalSlot(6)
  317.         if findPowRail(stack_info) then
  318.           print("I'm placing a", stack_info.name, "there.")
  319.           TURN() ;  robot.forward()
  320.           robot.swingDown() ; robot.select(7) ; robot.placeDown()
  321.           robot.back() ; robot.select(6) ; robot.place()
  322.           TURN()
  323.         end
  324. end
  325.  
  326. -- find building materials
  327.  
  328. local function findMat(stack_info)
  329.   if stack_info == nil then
  330.     return false
  331.   end
  332.  
  333.     for index, known_mat_name in ipairs(Mat_names) do
  334.       if stack_info.name == known_mat_name then
  335.         return true
  336.       end
  337.     end
  338.   return false
  339. end
  340.  
  341. -- find rails
  342.  
  343. local function findRail(stack_info)
  344.   if stack_info == nil then
  345.     return false
  346.   end
  347.  
  348.     for index, known_rail_name in ipairs(nRail_names) do
  349.       if stack_info.name == known_rail_name then
  350.         return true
  351.       end
  352.     end
  353.   return false
  354. end
  355.  
  356. -- find trash items collected during dig to clear inventory for other materials, might need to add more materials based on where you are digging
  357.  
  358. local function findTrash(stack_info)
  359.   if stack_info == nil then
  360.     return false
  361.   end
  362.  
  363.     for index, known_trash_name in ipairs(trash_names) do
  364.       if stack_info.name == known_trash_name then
  365.         return true
  366.       end
  367.     end
  368.   return false
  369. end
  370.  
  371.  
  372. -- get rails from a chest inventory
  373.  
  374. local function getRail()
  375.   local stack_info = inventory.getStackInInternalSlot(4)
  376.     if findTrash(stack_info) then
  377.         robot.select(4) ; robot.drop()
  378.     end  
  379.   right() ; robot.select(5) ; robot.drop()
  380.   robot.select(14) ; robot.place() ; robot.select(4)
  381.  
  382.     for slot=1,27 do
  383.       local stack_info = inventory.getStackInSlot(side, slot)
  384.         if findRail(stack_info) then
  385.           print(stack_info.name, "I found rails in slot", slot, ". Restocking, please stand by!")
  386.           inventory.suckFromSlot(sides.front, slot)
  387.           break
  388.         end
  389.     end
  390.  
  391.   robot.select(5) ; inventory.dropIntoSlot(side, 1)
  392.   robot.select(14) ; robot.swing() ; left()
  393. end
  394.    
  395.  
  396. -- find usuable fuel materials
  397.  
  398. local function findFuel(stack_info)
  399.   if stack_info == nil then
  400.     return false
  401.   end
  402.  
  403.     for index, known_fuel_name in ipairs(Fuel_names) do
  404.       if stack_info.name == known_fuel_name then
  405.         return true
  406.       end
  407.     end
  408.   return false
  409. end
  410.  
  411.  
  412. -- get 'fuel' from a chest inventory, if something was in the robot.. it his place into a filter chest, and robot use retrieved fuel
  413.  
  414. local function refuel()
  415.   right() ; robot.select(14) ; robot.place()
  416.   robot.select(16) ; robot.drop() ; robot.select(15) ; robot.drop()
  417.  
  418.           for slot=1,27 do
  419.             local stack_info = inventory.getStackInSlot(side, slot)
  420.             if findFuel(stack_info) then
  421.               print(stack_info.name, "I found fuel in slot", slot, "Refueling, stand by!")
  422.               inventory.suckFromSlot(sides.front, slot)
  423.               break
  424.             end
  425.           end
  426.  
  427.   robot.select(14) ; robot.swing()
  428.   robot.select(8) ; robot.place() ; robot.select(16) ; g.remove() ; inventory.dropIntoSlot(side, 1) ; robot.select(15) ; g.insert() ; os.sleep(20)
  429.   robot.select(8) ; robot.swing()
  430.   left()
  431. end
  432.  
  433. -- restock on building materials
  434.  
  435. local function getMat()
  436.  
  437.   right() ; robot.select(12) ; robot.place()
  438.   robot.select(10) ; robot.drop() ; robot.select(11) ; robot.drop() ;
  439.   robot.select(9)
  440.  
  441.   repeat
  442.     for slot=1,27 do
  443.       local stack_info = inventory.getStackInSlot(side, slot)
  444.       if findMat(stack_info) then
  445.         print("Low building materials", "Restocking from slot" ,slot)
  446.         inventory.suckFromSlot(sides.front, slot)
  447.         break
  448.       end          
  449.     end
  450.   until robot.count(9) >= 13 or robot.count(10) >= 13 or robot.count(11) >= 13
  451.  
  452.     for slot=9, 11 do
  453.       robot.select(slot)
  454.         if robot.count() <= 12 then
  455.           for cslot=1, 3 do
  456.             inventory.dropIntoSlot(side, cslot)
  457.           end
  458.         end
  459.     end      
  460.  
  461.     for slot=10, 11 do
  462.       robot.select(slot)
  463.         if robot.count() >= 13 then
  464.           robot.transferTo(9)
  465.         end
  466.     end
  467.  
  468.   robot.select(12) ; robot.swing()
  469.   left()    
  470. end
  471.  
  472. -- place rails only if rails are presents in player slot:4
  473.  
  474. local function placeRail()
  475.  
  476. local stack_info = inventory.getStackInInternalSlot(4)
  477.   if findRail(stack_info) then
  478.     TURN() ;  robot.select(4) ; robot.place() ; TURN() -- place rails
  479.   end
  480. end
  481.  
  482.  
  483. --[[
  484. Dig a tunnel for # in the direction the robot is facing, then turn, and dig for # in the new direction that was defined during start-up.
  485. It will refuel, restock and place a rail behind the robot and dig a 3x3 hole with a shell around it.
  486. --]]
  487.  
  488. local function digit()
  489.   for i = 1, rowsToDig1 do
  490.  
  491.     if computer.energy() <= 2000 then
  492.       refuel() -- refuel duh?
  493.     end
  494.  
  495.     if robot.count(4) <= 2 then
  496.       getRail()      -- restock on rails
  497.     end
  498.  
  499.     if robot.count(9) <= 12 then
  500.       getMat()     -- restock on building mats
  501.     end
  502.  
  503.     if robot.count(2) <= 1 then
  504.       getLight()
  505.     end
  506.  
  507.     if robot.count(6) <= 1 then
  508.       getPowRail()
  509.     end
  510.  
  511.     if i%15 == 0 then do
  512.       placeRailEx()
  513.     else
  514.       placeRail()
  515.     end
  516.  
  517.     if i%7 == 0 then do
  518.       MovementEx()
  519.     else
  520.       Movement()
  521.     end
  522.    
  523.   end
  524.  
  525.     if direction == "LEFT" then
  526.     left()
  527.     elseif direction == "RIGHT" then
  528.     right()
  529.     end      
  530.  
  531.   for i = 1, rowsToDig2 do
  532.  
  533.     if computer.energy() <= 2000 then
  534.       refuel() -- refuel duh?
  535.     end
  536.  
  537.     if robot.count(4) <= 2 then
  538.       getRail()      -- restock on rails
  539.     end
  540.  
  541.     if robot.count(9) <= 12 then
  542.       getMat()     -- restock on building mats
  543.     end
  544.  
  545.     if robot.count(2) <= 1 then
  546.       getLight()
  547.     end
  548.  
  549.     if robot.count(6) <= 1 then
  550.       getPowRail()
  551.     end
  552.  
  553.     if i%15 == 0 then do
  554.       placeRailEx()
  555.     else
  556.       placeRail()
  557.     end
  558.  
  559.     if i%7 == 0 then do
  560.       MovementEx()
  561.     else
  562.       Movement()
  563.     end
  564.  
  565.   end
  566.  
  567. end
  568.  
  569. -- Call the program
  570.  
  571. digit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement