Advertisement
Guest User

CM3.lua v2.2

a guest
Aug 17th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 28.38 KB | None | 0 0
  1. -- APIs
  2.  
  3. local robot = require("robot")
  4. local component = require("component")
  5. local computer = require("computer")
  6. local me = component.upgrade_me
  7. local db = component.database
  8. local event = require("event")
  9. local filesystem = require("filesystem")
  10. local tunnel = component.tunnel
  11.  
  12. -- Visuals
  13.  
  14. function skipLine(number)
  15.   for i = 1, number do
  16.     print("")
  17.   end
  18. end
  19.  
  20. function printLoad(percent)
  21.   if percent == "0" then
  22.     os.execute("cls")
  23.     skipLine(8)
  24.     print("     Loading.    0%")
  25.   elseif percent == "25" then
  26.     os.execute("cls")
  27.     skipLine(8)
  28.     print("     Loading..  25%")
  29.   elseif percent == "50" then
  30.     os.execute("cls")
  31.     skipLine(8)
  32.     print("     Loading... 50%")
  33.   elseif percent == "75" then
  34.     os.execute("cls")
  35.     skipLine(8)
  36.     print("     Loading.   75%")
  37.   elseif percent == "100" then
  38.     os.execute("cls")
  39.     skipLine(8)
  40.     print("     Loading.. 100%")
  41.   end
  42. end
  43.  
  44. function writeTitle()
  45.   print("     ███████████████████████████████████████")
  46.   print("     █_|___|___|___|___|___|___|___|___|___█")
  47.   print("     █___|__██████╗███╗___███╗██████╗_|___|█")
  48.   print("     █_|___██╔════╝████╗ ████║╚════██╗_|___█")
  49.   print("     █___|_██║___|_██╔████╔██║ █████╔╝|___|█")
  50.   print("     █_|___██║_|___██║╚██╔╝██║ ╚═══██╗_|___█")
  51.   print("     █___|_╚██████╗██║_╚═╝_██║██████╔╝|___|█")
  52.   print("     █_|___|╚═════╝╚═╝_|___╚═╝╚═════╝__|___█")
  53.   print("     █___A Compact Machines 3 Autobuilder_|█")
  54.   print("     █_|___|___|___By: Samir___|___|___|___█")
  55.   print("     ███████████████████████████████████████")
  56. end
  57.  
  58. -- Wireless Mode
  59.  
  60. function getWirelessVariable()
  61.   local file = io.open("wirelessVariable", "r")
  62.   if file:read() == "true" then
  63.     modeWireless = true
  64.   else
  65.     modeWireless = nil
  66.     file:close()
  67.   end
  68. end
  69.  
  70. function activateWireless()
  71.   io.write("Would you like to activate wireless mode? (Y/N) ")
  72.   answer = string.upper(io.read())
  73.   if answer == "Y" then
  74.     print("Connect your linked remote terminal to the robot. (Do 'wireless on')")
  75.     _, _, _, _, _, message = event.pull("modem_message")
  76.     if message == "wirelessOn" then
  77.       local file=io.open("wirelessVariable","w")
  78.       file:write("true")
  79.       file:close()
  80.       computer.shutdown(true)
  81.     elseif answer == "N" then
  82.       print("Cancelling wireless mode activation. Rebooting system.")
  83.       os.sleep(2)
  84.       computer.shutdown(true)
  85.     end
  86.   end
  87. end
  88.  
  89. function deactivateWireless()
  90.   local file=io.open("wirelessVariable","w")
  91.   file:write("nil")
  92.   file:close()
  93.   computer.shutdown(true)
  94. end
  95.  
  96. -- Item Functions
  97.  
  98. function totalItem(name)
  99.   local size = 0
  100.   for i = 1,16 do
  101.     local data=component.inventory_controller.getStackInInternalSlot(i)
  102.     if (data and data.name==name) then
  103.       size = size + data.size
  104.     end
  105.   end
  106.   return size
  107. end
  108.  
  109. function selectItem(name)
  110.   for i = 1,16 do
  111.     local data=component.inventory_controller.getStackInInternalSlot(i)
  112.     if (data and data.name==name) then
  113.       robot.select(i)
  114.       return
  115.     end
  116.   end
  117. end
  118.  
  119. function selectEmpty()
  120.   for i = 1,16 do
  121.     local data=component.inventory_controller.getStackInInternalSlot(i)
  122.     if data == nil then
  123.       robot.select(i)
  124.       return
  125.     end
  126.   end
  127. end
  128.  
  129. function selectFull()
  130.   for i = 1,16 do
  131.     local data=component.inventory_controller.getStackInInternalSlot(i)
  132.     if data ~= nil then
  133.       robot.select(i)
  134.       return
  135.     end
  136.   end
  137. end
  138.  
  139. -- Request Functions
  140.  
  141. function requestWall()
  142.   db.clear(1)
  143.   db.clear(2)
  144.   me.store({name = "minecraft:iron_block"}, db.address, 1)
  145.   me.store({name = "minecraft:redstone"}, db.address, 2)
  146.   selectEmpty()
  147.   me.requestItems(db.address, 1, 1)
  148.   selectEmpty()
  149.   me.requestItems(db.address, 2, 2)
  150. end
  151.  
  152. function requestMaxMachine()
  153.   db.clear(1)
  154.   db.clear(2)
  155.   db.clear(3)
  156.   me.store({name = "compactmachines3:wallbreakable"}, db.address, 1)
  157.   me.store({name = "minecraft:ender_pearl"}, db.address, 2)
  158.   me.store({name = "minecraft:emerald_block"}, db.address, 3)
  159.   selectEmpty()
  160.   me.requestItems(db.address, 1, 64)
  161.   selectEmpty()
  162.   me.requestItems(db.address, 1, 34)
  163.   selectEmpty()
  164.   me.requestItems(db.address, 2, 1)
  165.   selectEmpty()
  166.   me.requestItems(db.address, 3, 1)
  167. end
  168.  
  169. function requestMinMachine()
  170.   db.clear(1)
  171.   db.clear(2)
  172.   db.clear(3)
  173.   me.store({name = "compactmachines3:wallbreakable"}, db.address, 1)
  174.   me.store({name = "minecraft:ender_pearl"}, db.address, 2)
  175.   me.store({name = "minecraft:gold_block"}, db.address, 3)
  176.   selectEmpty()
  177.   me.requestItems(db.address, 1, 26)
  178.   selectEmpty()
  179.   me.requestItems(db.address, 2, 1)
  180.   selectEmpty()
  181.   me.requestItems(db.address, 3, 1)
  182. end
  183.  
  184. function requestTunnel()
  185.   db.clear(1)
  186.   db.clear(2)
  187.   db.clear(3)
  188.   me.store({name = "compactmachines3:wallbreakable"}, db.address, 1)
  189.   me.store({name = "minecraft:redstone"}, db.address, 2)
  190.   me.store({name = "minecraft:hopper"}, db.address, 3)
  191.   selectEmpty()
  192.   me.requestItems(db.address, 1, 1)
  193.   selectEmpty()
  194.   me.requestItems(db.address, 2, 9)
  195.   selectEmpty()
  196.   me.requestItems(db.address, 3, 1)
  197. end
  198.  
  199. function requestRedTunnel()
  200.   db.clear(1)
  201.   db.clear(2)
  202.   db.clear(3)
  203.   me.store({name = "compactmachines3:wallbreakable"}, db.address, 1)
  204.   me.store({name = "minecraft:redstone"}, db.address, 2)
  205.   me.store({name = "minecraft:redstone_block"}, db.address, 3)
  206.   selectEmpty()
  207.   me.requestItems(db.address, 1, 1)
  208.   selectEmpty()
  209.   me.requestItems(db.address, 2, 9)
  210.   selectEmpty()
  211.   me.requestItems(db.address, 3, 1)
  212. end
  213.  
  214. -- Check Functions
  215.  
  216. function checkMaxItems()
  217.   if totalItem("minecraft:emerald_block") < 1 and totalItem("minecraft:ender_pearl") < 1 then
  218.     print("Operation failed. Not enough emerald blocks or ender pearls.")
  219.     os.sleep(2)
  220.     computer.shutdown(true)
  221.   elseif totalItem("minecraft:emerald_block") < 1 then
  222.     print("Operation failed. Not enough emerald blocks.")
  223.     os.sleep(2)
  224.     computer.shutdown(true)
  225.   elseif totalItem("minecraft:ender_pearl") < 1 then
  226.     print("Operation failed. Not enough ender pearls.")
  227.     os.sleep(2)
  228.     computer.shutdown(true)
  229.   end
  230. end
  231.  
  232. function checkMinItems()
  233.   if totalItem("minecraft:gold_block") < 1 and totalItem("minecraft:ender_pearl") < 1 then
  234.     print("Operation failed. Not enough gold blocks or ender pearls.")
  235.     os.sleep(2)
  236.     computer.shutdown(true)
  237.   elseif totalItem("minecraft:gold_block") < 1 then
  238.     print("Operation failed. Not enough gold blocks.")
  239.     os.sleep(2)
  240.     computer.shutdown(true)
  241.   elseif totalItem("minecraft:ender_pearl") < 1 then
  242.     print("Operation failed. Not enough ender pearls.")
  243.     os.sleep(2)
  244.     computer.shutdown(true)
  245.   end
  246. end
  247.  
  248. function checkWallItems()
  249.   if totalItem("minecraft:iron_block") < 1 and totalItem("minecraft:redstone") < 2 then
  250.     print("Operation failed. Not enough iron blocks or redstone.")
  251.     os.sleep(2)
  252.     computer.shutdown(true)
  253.   elseif totalItem("minecraft:iron_block") < 1 then
  254.     print("Operation failed. Not enough iron blocks.")
  255.     os.sleep(2)
  256.     computer.shutdown(true)
  257.   elseif totalItem("minecraft:redstone") < 2 then
  258.     print("Operation failed. Not enough redstone.")
  259.     os.sleep(2)
  260.     computer.shutdown(true)
  261.   end
  262. end
  263.  
  264. function checkTunnelItems()
  265.   if totalItem("minecraft:hopper") < 1 and totalItem("minecraft:redstone") < 8 then
  266.     print("Operation failed. Not enough hoppers or redstone.")
  267.     os.sleep(2)
  268.     computer.shutdown(true)
  269.   elseif totalItem("minecraft:hopper") < 1 then
  270.     print("Operation failed. Not enough hoppers.")
  271.     os.sleep(2)
  272.     computer.shutdown(true)
  273.   elseif totalItem("minecraft:redstone") < 8 then
  274.     print("Operation failed. Not enough redstone.")
  275.     os.sleep(2)
  276.     computer.shutdown(true)
  277.   end
  278. end
  279.  
  280. function checkRedTunnelItems()
  281.   if totalItem("minecraft:redstone_block") < 1 and totalItem("minecraft:redstone") < 8 then
  282.     print("Operation failed. Not enough redstone blocks or redstone.")
  283.     os.sleep(2)
  284.     computer.shutdown(true)
  285.   elseif totalItem("minecraft:redstone_block") < 1 then
  286.     print("Operation failed. Not enough redstone blocks.")
  287.     os.sleep(2)
  288.     computer.shutdown(true)
  289.   elseif totalItem("minecraft:redstone") < 8 then
  290.     print("Operation failed. Not enough redstone.")
  291.     os.sleep(2)
  292.     computer.shutdown(true)
  293.   end
  294. end
  295.  
  296. -- Wireless Check Functions
  297.  
  298. function checkWirelessMaxItems()
  299.   if totalItem("minecraft:emerald_block") < 1 and totalItem("minecraft:ender_pearl") < 1 then
  300.     tunnel.send("failed")
  301.     os.sleep(2)
  302.     computer.shutdown(true)
  303.   elseif totalItem("minecraft:emerald_block") < 1 then
  304.     tunnel.send("failed")
  305.     os.sleep(2)
  306.     computer.shutdown(true)
  307.   elseif totalItem("minecraft:ender_pearl") < 1 then
  308.     tunnel.send("failed")
  309.     os.sleep(2)
  310.     computer.shutdown(true)
  311.   else
  312.     tunnel.send("success")
  313.   end
  314. end
  315.  
  316. function checkWirelessMinItems()
  317.   if totalItem("minecraft:gold_block") < 1 and totalItem("minecraft:ender_pearl") < 1 then
  318.     tunnel.send("failed")
  319.     os.sleep(2)
  320.     computer.shutdown(true)
  321.   elseif totalItem("minecraft:gold_block") < 1 then
  322.     tunnel.send("failed")
  323.     os.sleep(2)
  324.     computer.shutdown(true)
  325.   elseif totalItem("minecraft:ender_pearl") < 1 then
  326.     tunnel.send("failed")
  327.     os.sleep(2)
  328.     computer.shutdown(true)
  329.   else
  330.     tunnel.send("success")
  331.   end
  332. end
  333.  
  334. function checkWirelessWallItems()
  335.   if totalItem("minecraft:iron_block") < 1 and totalItem("minecraft:redstone") < 2 then
  336.     tunnel.send("failed")
  337.     os.sleep(2)
  338.     computer.shutdown(true)
  339.   elseif totalItem("minecraft:iron_block") < 1 then
  340.     tunnel.send("failed")
  341.     os.sleep(2)
  342.     computer.shutdown(true)
  343.   elseif totalItem("minecraft:redstone") < 2 then
  344.     tunnel.send("failed")
  345.     os.sleep(2)
  346.     computer.shutdown(true)
  347.   else
  348.     tunnel.send("success")
  349.   end
  350. end
  351.  
  352. function checkWirelessTunnelItems()
  353.   if totalItem("minecraft:hopper") < 1 and totalItem("minecraft:redstone") < 8 then
  354.     tunnel.send("failed")
  355.     os.sleep(2)
  356.     computer.shutdown(true)
  357.   elseif totalItem("minecraft:hopper") < 1 then
  358.     tunnel.send("failed")
  359.     os.sleep(2)
  360.     computer.shutdown(true)
  361.   elseif totalItem("minecraft:redstone") < 8 then
  362.     tunnel.send("failed")
  363.     os.sleep(2)
  364.     computer.shutdown(true)
  365.   else
  366.     tunnel.send("success")
  367.   end
  368. end
  369.  
  370. function checkWirelessRedTunnelItems()
  371.   if totalItem("minecraft:redstone_block") < 1 and totalItem("minecraft:redstone") < 8 then
  372.     tunnel.send("failed")
  373.     os.sleep(2)
  374.     computer.shutdown(true)
  375.   elseif totalItem("minecraft:redstone_block") < 1 then
  376.     tunnel.send("failed")
  377.     os.sleep(2)
  378.     computer.shutdown(true)
  379.   elseif totalItem("minecraft:redstone") < 8 then
  380.     tunnel.send("failed")
  381.     os.sleep(2)
  382.     computer.shutdown(true)
  383.   else
  384.     tunnel.send("success")
  385.   end
  386. end
  387.  
  388. -- ME Functions
  389.  
  390. function emptyIntoME()
  391.   selectFull()
  392.   me.sendItems()
  393.   selectFull()
  394.   me.sendItems()
  395.   selectFull()
  396.   me.sendItems()
  397.   selectFull()
  398.   me.sendItems()
  399.   selectEmpty()
  400. end
  401.  
  402. function startupEmptyIntoME()
  403.   printLoad("0")
  404.   selectFull()
  405.   me.sendItems()
  406.   printLoad("25")
  407.   selectFull()
  408.   me.sendItems()
  409.   printLoad("50")
  410.   selectFull()
  411.   me.sendItems()
  412.   printLoad("75")
  413.   selectFull()
  414.   me.sendItems()
  415.   printLoad("100")
  416.   selectEmpty()
  417. end
  418.  
  419. -- Movement Functions
  420.  
  421. function forward (dist,place)
  422.   for i = 1, dist do
  423.     robot.forward()
  424.     if place == "down" then
  425.       selectItem("compactmachines3:wallbreakable")
  426.       robot.placeDown()
  427.     end
  428.   end
  429. end
  430.  
  431. function forwardTunnel (dist,place)
  432.   for i = 1, dist do
  433.     robot.forward()
  434.     if place == "down" then
  435.       selectItem("minecraft:redstone")
  436.       robot.placeDown()
  437.     end
  438.   end
  439. end
  440.  
  441. function back (dist,place)
  442.   for i = 1, dist do
  443.     robot.back()
  444.     if place == "down" then
  445.       robot.placeDown()
  446.     elseif place == "up" then
  447.       robot.placeUp()
  448.     elseif place == "forward" then
  449.       robot.place()
  450.     end
  451.   end
  452. end
  453.  
  454. function up (dist)
  455.   for i = 1, dist do
  456.     robot.up()
  457.   end
  458. end
  459.  
  460. function down (dist)
  461.   for i = 1, dist do
  462.     robot.down()
  463.   end
  464. end
  465.  
  466. -- Build Component Functions
  467.  
  468. function buildMaxPlatform()
  469.   for i = 1,5 do
  470.     forward(4,"down")
  471.     if i == 5 then
  472.       return
  473.     end
  474.     if i%2 == 1 then
  475.       robot.turnRight()
  476.       forward(1,"down")
  477.       robot.turnRight()
  478.     else
  479.       robot.turnLeft()
  480.       forward(1,"down")
  481.       robot.turnLeft()
  482.     end
  483.   end
  484. end
  485.  
  486. function buildMaxRing()
  487.   for i = 1,12 do
  488.     forward(4,"down")
  489.     robot.turnLeft()
  490.     if i == 4 then
  491.       up(1)
  492.     elseif i == 8 then
  493.       forward(2,false)
  494.       robot.turnLeft()
  495.       forward(2,false)
  496.       selectItem("minecraft:emerald_block")
  497.       robot.placeDown()
  498.       forward(2,false)
  499.       robot.turnLeft()
  500.       back(2,false)
  501.       up(1)
  502.     end
  503.   end
  504. end
  505.  
  506. function buildMinPlatform()
  507.   for i = 1,3 do
  508.     forward(2,"down")
  509.     if i == 3 then
  510.       return
  511.     end
  512.     if i % 2 == 1 then
  513.       robot.turnRight()
  514.       forward(1,"down")
  515.       robot.turnRight()
  516.     else
  517.       robot.turnLeft()
  518.       forward(1,"down")
  519.       robot.turnLeft()
  520.     end
  521.   end
  522. end
  523.  
  524. function buildMinRing()
  525.   for i = 1,4 do
  526.     forward(2,"down")
  527.     robot.turnLeft()
  528.   end
  529.   forward(1,false)
  530.   robot.turnLeft()
  531.   forward(1,false)
  532.   selectItem("minecraft:gold_block")
  533.   robot.placeDown()
  534. end
  535.  
  536. function buildTunnelLayer()
  537.   for i = 1,4 do
  538.     forwardTunnel(2,"down")
  539.     robot.turnLeft()
  540.   end
  541.   forward(1,false)
  542.   robot.turnLeft()
  543.   forward(1,false)
  544.   selectItem("compactmachines3:wallbreakable")
  545.   robot.placeDown()
  546. end
  547.  
  548. -- Craft Functions
  549.  
  550. function craftWall()
  551.   requestWall()
  552.   io.write("Would you like to construct sixteen machine walls? (Y/N) ")
  553.   answer = string.upper(io.read())
  554.   if answer == "Y" then
  555.     checkWallItems()
  556.     print("Confirmed operation. Constructing machine walls now.")
  557.     forward(4,false)
  558.     selectItem("minecraft:iron_block")
  559.     robot.place()
  560.     up(1)
  561.     selectItem("minecraft:redstone")
  562.     robot.place()
  563.     down(1)
  564.     back(1)
  565.     robot.drop(1)
  566.     os.sleep(5)
  567.     forward(4,false)
  568.     robot.suck()
  569.     back(7,false)
  570.     startProgram()
  571.   elseif answer == "N" then
  572.     print("Operation denied. Cancelling machine wall construction.")
  573.     os.sleep(2)
  574.     computer.shutdown(true)
  575.   end
  576. end
  577.  
  578. function craftNeededWall()
  579.   emptyIntoME()
  580.   requestWall()
  581.   checkWallItems()
  582.   print("Confirmed operation. Constructing machine walls now.")
  583.   forward(4,false)
  584.   selectItem("minecraft:iron_block")
  585.   robot.place()
  586.   up(1)
  587.   selectItem("minecraft:redstone")
  588.   robot.place()
  589.   down(1)
  590.   back(1)
  591.   robot.drop(1)
  592.   os.sleep(5)
  593.   forward(4,false)
  594.   robot.suck()
  595.   back(7,false)
  596.   startProgram()
  597. end
  598.  
  599. function craftMaxMachine()
  600.   requestMaxMachine()
  601.   while totalItem("compactmachines3:wallbreakable") < 98 do
  602.     io.write("Insufficient amount of walls. Would you like to construct more now? (Y/N) ")
  603.     answer = string.upper(io.read())
  604.     if answer == "Y" then
  605.       craftNeededWall()
  606.     elseif answer == "N" then
  607.       print("Operation denied. Cancelling machine wall construction.")
  608.       os.sleep(2)
  609.       computer.shutdown(true)
  610.     end
  611.   end
  612.  
  613.   if totalItem("compactmachines3:wallbreakable") >= 98 then
  614.     io.write("Would you like to construct a maximum compact machine? (5x5x5) (Y/N) ")
  615.     answer = string.upper(io.read())
  616.     if answer == "Y" then
  617.       checkMaxItems()
  618.       print("Confirmed operation. Constructing compact machine now.")
  619.       forward(4,false)
  620.       selectItem("compactmachines3:wallbreakable")
  621.       robot.turnLeft()
  622.       forward(2,false)
  623.       robot.turnRight()
  624.       up(1)
  625.       forward(1,"down")
  626.       buildMaxPlatform()
  627.       up(1)
  628.       robot.turnLeft()
  629.       buildMaxRing()
  630.       robot.turnLeft()
  631.       up(1)
  632.       selectItem("compactmachines3:wallbreakable")
  633.       robot.placeDown()
  634.       buildMaxPlatform()
  635.       robot.turnLeft()
  636.       forward(2,false)
  637.       robot.turnRight()
  638.       back(6,false)
  639.       down(5)
  640.       selectItem("minecraft:ender_pearl")
  641.       robot.drop(1)
  642.       os.sleep(33)
  643.       forward(4,false)
  644.       robot.suck()
  645.       back(7,false)
  646.       startProgram()
  647.     elseif answer == "N" then
  648.       print("Operation denied. Cancelling compact machine construction.")
  649.       os.sleep(2)
  650.       computer.shutdown(true)
  651.     end
  652.   end
  653. end
  654.  
  655. function craftMinMachine()
  656.   requestMinMachine()
  657.   while totalItem("compactmachines3:wallbreakable") < 26 do
  658.     io.write("Insufficient amount of walls. Would you like to construct more now? (Y/N) ")
  659.     answer = string.upper(io.read())
  660.     if answer == "Y" then
  661.       craftNeededWall()
  662.     elseif answer == "N" then
  663.       print("Operation denied. Cancelling machine wall construction.")
  664.       os.sleep(2)
  665.       computer.shutdown(true)
  666.     end
  667.   end
  668.  
  669.   if totalItem("compactmachines3:wallbreakable") >= 26 then
  670.     io.write("Would you like to construct a normal compact machine? (3x3x3) (Y/N) ")
  671.     answer = string.upper(io.read())
  672.     if answer == "Y" then
  673.       checkMinItems()
  674.       print("Confirmed operation. Constructing compact machine now.")
  675.       forward(4,false)
  676.       selectItem("compactmachines3:wallbreakable")
  677.       robot.turnLeft()
  678.       forward(1,false)
  679.       robot.turnRight()
  680.       up(1)
  681.       forward(1,"down")
  682.       buildMinPlatform()
  683.       up(1)
  684.       robot.turnLeft()
  685.       buildMinRing()
  686.       up(1)
  687.       back(1)
  688.       robot.turnLeft()
  689.       back(1)
  690.       selectItem("compactmachines3:wallbreakable")
  691.       robot.placeDown()
  692.       buildMinPlatform()
  693.       robot.turnLeft()
  694.       back(1,false)
  695.       robot.turnRight()
  696.       back(1,false)
  697.       down(3)
  698.       robot.turnLeft()
  699.       back(1)
  700.       selectItem("minecraft:ender_pearl")
  701.       robot.drop(1)
  702.       os.sleep(24)
  703.       forward(4,false)
  704.       robot.suck()
  705.       back(7,false)
  706.       startProgram()
  707.     elseif answer == "N" then
  708.       print("Operation denied. Cancelling compact machine construction.")
  709.       os.sleep(2)
  710.       computer.shutdown(true)
  711.     end
  712.   end
  713. end
  714.  
  715. function craftTunnel()
  716.   requestTunnel()
  717.   while totalItem("compactmachines3:wallbreakable") < 1 do
  718.     io.write("Insufficient amount of walls. Would you like to construct more now? (Y/N) ")
  719.     answer = string.upper(io.read())
  720.     if answer == "Y" then
  721.       craftNeededWall()
  722.     elseif answer == "N" then
  723.       print("Operation denied. Cancelling machine wall construction.")
  724.       os.sleep(2)
  725.       computer.shutdown(true)
  726.     end
  727.   end
  728.  
  729.   if totalItem("compactmachines3:wallbreakable") > 0 then
  730.     io.write("Would you like to construct two tunnels? (Y/N) ")
  731.     answer = string.upper(io.read())
  732.     if answer == "Y" then
  733.       checkTunnelItems()
  734.       print("Confirmed operation. Constructing tunnels now.")
  735.       forward(4)
  736.       robot.turnRight()
  737.       forward(1)
  738.       robot.turnLeft()
  739.       up(1)
  740.       forward(1)
  741.       buildTunnelLayer()
  742.       up(1)
  743.       selectItem("minecraft:hopper")
  744.       robot.placeDown()
  745.       robot.turnRight()
  746.       back(3)
  747.       down(2)
  748.       selectItem("minecraft:redstone")
  749.       robot.drop(1)
  750.       os.sleep(10)
  751.       forward(4)
  752.       robot.suck()
  753.       back(7)
  754.       startProgram()
  755.     elseif answer == "N" then
  756.       print("Operation denied. Cancelling tunnel construction.")
  757.       os.sleep(2)
  758.       computer.shutdown(true)
  759.     end
  760.   end
  761. end
  762.  
  763. function craftRedTunnel()
  764.   requestRedTunnel()
  765.   while totalItem("compactmachines3:wallbreakable") < 1 do
  766.     io.write("Insufficient amount of walls. Would you like to construct more now? (Y/N) ")
  767.     answer = string.upper(io.read())
  768.     if answer == "Y" then
  769.       craftNeededWall()
  770.     elseif answer == "N" then
  771.       print("Operation denied. Cancelling machine wall construction.")
  772.       os.sleep(2)
  773.       computer.shutdown(true)
  774.     end
  775.   end
  776.  
  777.   if totalItem("compactmachines3:wallbreakable") > 0 then
  778.     io.write("Would you like to construct two redstone tunnels? (Y/N) ")
  779.     answer = string.upper(io.read())
  780.     if answer == "Y" then
  781.       checkRedTunnelItems()
  782.       print("Confirmed operation. Constructing redstone tunnels now.")
  783.       forward(4)
  784.       robot.turnRight()
  785.       forward(1)
  786.       robot.turnLeft()
  787.       up(1)
  788.       forward(1)
  789.       buildTunnelLayer()
  790.       up(1)
  791.       selectItem("minecraft:redstone_block")
  792.       robot.placeDown()
  793.       robot.turnRight()
  794.       back(3)
  795.       down(2)
  796.       selectItem("minecraft:redstone")
  797.       robot.drop(1)
  798.       os.sleep(10)
  799.       forward(4)
  800.       robot.suck()
  801.       back(7)
  802.       startProgram()
  803.     elseif answer == "N" then
  804.       print("Operation denied. Cancelling tunnel construction.")
  805.       os.sleep(2)
  806.       computer.shutdown(true)
  807.     end
  808.   end
  809. end
  810.  
  811. -- Wireless Craft Functions
  812.  
  813. function wirelessCraftWall()
  814.   requestWall()
  815.   tunnel.send("wallConfirm")
  816.   _, _, _, _, _, message = event.pull("modem_message")
  817.   if message == "Y" then
  818.     checkWirelessWallItems()
  819.     forward(4,false)
  820.     selectItem("minecraft:iron_block")
  821.     robot.place()
  822.     up(1)
  823.     selectItem("minecraft:redstone")
  824.     robot.place()
  825.     down(1)
  826.     back(1)
  827.     robot.drop(1)
  828.     os.sleep(5)
  829.     forward(4,false)
  830.     robot.suck()
  831.     back(7,false)
  832.     startWirelessProgram()
  833.   elseif message == "N" then
  834.     os.sleep(2)
  835.     computer.shutdown(true)
  836.   end
  837. end
  838.  
  839. function wirelessCraftNeededWall()
  840.   emptyIntoME()
  841.   requestWall()
  842.   checkWirelessWallItems()
  843.   forward(4,false)
  844.   selectItem("minecraft:iron_block")
  845.   robot.place()
  846.   up(1)
  847.   selectItem("minecraft:redstone")
  848.   robot.place()
  849.   down(1)
  850.   back(1)
  851.   robot.drop(1)
  852.   os.sleep(5)
  853.   forward(4,false)
  854.   robot.suck()
  855.   back(7,false)
  856.   startWirelessProgram()
  857. end
  858.  
  859. function wirelessCraftMaxMachine()
  860.   requestMaxMachine()
  861.   while totalItem("compactmachines3:wallbreakable") < 98 do
  862.     tunnel.send("wallConfirm")
  863.     _, _, _, _, _, message = event.pull("modem_message")
  864.     if message == "Y" then
  865.       wirelessCraftNeededWall()
  866.     elseif message == "N" then
  867.       os.sleep(2)
  868.       computer.shutdown(true)
  869.     end
  870.   end
  871.  
  872.   if totalItem("compactmachines3:wallbreakable") >= 98 then
  873.     tunnel.send("maxMachineConfirm")
  874.     _, _, _, _, _, message = event.pull("modem_message")
  875.     if message == "Y" then
  876.       checkWirelessMaxItems()
  877.       forward(4,false)
  878.       selectItem("compactmachines3:wallbreakable")
  879.       robot.turnLeft()
  880.       forward(2,false)
  881.       robot.turnRight()
  882.       up(1)
  883.       forward(1,"down")
  884.       buildMaxPlatform()
  885.       up(1)
  886.       robot.turnLeft()
  887.       buildMaxRing()
  888.       robot.turnLeft()
  889.       up(1)
  890.       selectItem("compactmachines3:wallbreakable")
  891.       robot.placeDown()
  892.       buildMaxPlatform()
  893.       robot.turnLeft()
  894.       forward(2,false)
  895.       robot.turnRight()
  896.       back(6,false)
  897.       down(5)
  898.       selectItem("minecraft:ender_pearl")
  899.       robot.drop(1)
  900.       os.sleep(33)
  901.       forward(4,false)
  902.       robot.suck()
  903.       back(7,false)
  904.       startWirelessProgram()
  905.     elseif message == "N" then
  906.       os.sleep(2)
  907.       computer.shutdown(true)
  908.     end
  909.   end
  910. end
  911.  
  912. function wirelessCraftMinMachine()
  913.   requestMinMachine()
  914.   while totalItem("compactmachines3:wallbreakable") < 26 do
  915.     tunnel.send("wallConfirm")
  916.     _, _, _, _, _, message = event.pull("modem_message")
  917.     if message == "Y" then
  918.       wirelessCraftNeededWall()
  919.     elseif message == "N" then
  920.       os.sleep(2)
  921.       computer.shutdown(true)
  922.     end
  923.   end
  924.  
  925.   if totalItem("compactmachines3:wallbreakable") >= 26 then
  926.     tunnel.send("minMachineConfirm")
  927.     _, _, _, _, _, message = event.pull("modem_message")
  928.     if message == "Y" then
  929.       checkWirelessMinItems()
  930.       forward(4,false)
  931.       selectItem("compactmachines3:wallbreakable")
  932.       robot.turnLeft()
  933.       forward(1,false)
  934.       robot.turnRight()
  935.       up(1)
  936.       forward(1,"down")
  937.       buildMinPlatform()
  938.       up(1)
  939.       robot.turnLeft()
  940.       buildMinRing()
  941.       up(1)
  942.       back(1)
  943.       robot.turnLeft()
  944.       back(1)
  945.       selectItem("compactmachines3:wallbreakable")
  946.       robot.placeDown()
  947.       buildMinPlatform()
  948.       robot.turnLeft()
  949.       back(1,false)
  950.       robot.turnRight()
  951.       back(1,false)
  952.       down(3)
  953.       robot.turnLeft()
  954.       back(1)
  955.       selectItem("minecraft:ender_pearl")
  956.       robot.drop(1)
  957.       os.sleep(24)
  958.       forward(4,false)
  959.       robot.suck()
  960.       back(7,false)
  961.       startWirelessProgram()
  962.     elseif message == "N" then
  963.       os.sleep(2)
  964.       computer.shutdown(true)
  965.     end
  966.   end
  967. end
  968.  
  969. function wirelessCraftTunnel()
  970.   requestTunnel()
  971.   while totalItem("compactmachines3:wallbreakable") < 1 do
  972.     tunnel.send("wallConfirm")
  973.     _, _, _, _, _, message = event.pull("modem_message")
  974.     if message == "Y" then
  975.       wirelessCraftNeededWall()
  976.     elseif message == "N" then
  977.       os.sleep(2)
  978.       computer.shutdown(true)
  979.     end
  980.   end
  981.  
  982.   if totalItem("compactmachines3:wallbreakable") > 0 then
  983.     tunnel.send("tunnelConfirm")
  984.     _, _, _, _, _, message = event.pull("modem_message")
  985.     if message == "Y" then
  986.       checkWirelessTunnelItems()
  987.       forward(4)
  988.       robot.turnRight()
  989.       forward(1)
  990.       robot.turnLeft()
  991.       up(1)
  992.       forward(1)
  993.       buildTunnelLayer()
  994.       up(1)
  995.       selectItem("minecraft:hopper")
  996.       robot.placeDown()
  997.       robot.turnRight()
  998.       back(3)
  999.       down(2)
  1000.       selectItem("minecraft:redstone")
  1001.       robot.drop(1)
  1002.       os.sleep(10)
  1003.       forward(4)
  1004.       robot.suck()
  1005.       back(7)
  1006.       startWirelessProgram()
  1007.     elseif message == "N" then
  1008.       os.sleep(2)
  1009.       computer.shutdown(true)
  1010.     end
  1011.   end
  1012. end
  1013.  
  1014. function wirelessCraftRedTunnel()
  1015.   requestRedTunnel()
  1016.   while totalItem("compactmachines3:wallbreakable") < 1 do
  1017.     tunnel.send("wallConfirm")
  1018.     _, _, _, _, _, message = event.pull("modem_message")
  1019.     if message == "Y" then
  1020.       wirelessCraftNeededWall()
  1021.     elseif message == "N" then
  1022.       os.sleep(2)
  1023.       computer.shutdown(true)
  1024.     end
  1025.   end
  1026.  
  1027.   if totalItem("compactmachines3:wallbreakable") > 0 then
  1028.     tunnel.send("redTunnelConfirm")
  1029.     _, _, _, _, _, message = event.pull("modem_message")
  1030.     if message == "Y" then
  1031.       checkWirelessRedTunnelItems()
  1032.       forward(4)
  1033.       robot.turnRight()
  1034.       forward(1)
  1035.       robot.turnLeft()
  1036.       up(1)
  1037.       forward(1)
  1038.       buildTunnelLayer()
  1039.       up(1)
  1040.       selectItem("minecraft:redstone_block")
  1041.       robot.placeDown()
  1042.       robot.turnRight()
  1043.       back(3)
  1044.       down(2)
  1045.       selectItem("minecraft:redstone")
  1046.       robot.drop(1)
  1047.       os.sleep(10)
  1048.       forward(4)
  1049.       robot.suck()
  1050.       back(7)
  1051.       startWirelessProgram()
  1052.     elseif message == "N" then
  1053.       os.sleep(2)
  1054.       computer.shutdown(true)
  1055.     end
  1056.   end
  1057. end
  1058.  
  1059. -- Command Line Arguments
  1060.  
  1061. function commandLineArgs()
  1062.   skipLine(1)
  1063.   print("    What would you like to build?")
  1064.   print("(maxMachine, minMachine, walls, tunnel, redTunnel)")
  1065.   toBuild = string.upper(io.read())
  1066.   if toBuild == "MAXMACHINE" then
  1067.     craftMaxMachine()
  1068.   elseif toBuild == "MINMACHINE" then
  1069.     craftMinMachine()
  1070.   elseif toBuild == "WALLS" then
  1071.     craftWall()
  1072.   elseif toBuild == "TUNNEL" then
  1073.     craftTunnel()
  1074.   elseif toBuild == "REDTUNNEL" then
  1075.     craftRedTunnel()
  1076.   elseif toBuild == "WIRELESS" then
  1077.     activateWireless()
  1078.   end
  1079. end
  1080.  
  1081. function wirelessArgs()
  1082.   skipLine(1)
  1083.   print("        Wireless Mode")
  1084.   _, _, _, _, _, message = event.pull("modem_message")
  1085.   if message == "walls" then
  1086.     wirelessCraftWall()
  1087.   elseif message == "maxMachine" then
  1088.     wirelessCraftMaxMachine()
  1089.   elseif message == "minMachine" then
  1090.     wirelessCraftMinMachine()
  1091.   elseif message == "tunnel" then
  1092.     wirelessCraftTunnel()
  1093.   elseif message == "redTunnel" then
  1094.     wirelessCraftRedTunnel()
  1095.   elseif message == "wirelessOff" then
  1096.     deactivateWireless()
  1097.   end
  1098. end
  1099.  
  1100. -- Start Program
  1101.  
  1102. function startProgram()
  1103.   tunnel.send("off")
  1104.   startupEmptyIntoME()
  1105.   os.execute("cls")
  1106.   writeTitle()
  1107.   commandLineArgs()
  1108. end
  1109.  
  1110. function startWirelessProgram()
  1111.   tunnel.send("on")
  1112.   startupEmptyIntoME()
  1113.   os.execute("cls")
  1114.   writeTitle()
  1115.   wirelessArgs()
  1116. end
  1117.  
  1118. getWirelessVariable()
  1119.  
  1120. if modeWireless==nil then
  1121.   startProgram()
  1122. elseif modeWireless==true then
  1123.   startWirelessProgram()
  1124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement