Advertisement
EliteGaming

Kilo'sUberMiner

Jul 14th, 2015
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.unloadAPI("button")
  2. sleep(1)
  3. os.loadAPI("button")
  4. local m = peripheral.wrap("top")
  5. defaultSide = "back"
  6. autoModeBool = false
  7.  
  8. -- BundledCable Color Declarations
  9. local witherColor = colors.black
  10. local forwardColor = colors.blue
  11. local autoModeColor = colors.green
  12. local autoModeColor2 = colors.cyan
  13. local power = colors.purple
  14.  
  15. -- Fixes some API changes
  16. function colors.subtract(r, ...)
  17.         for n, c in ipairs({ ... }) do
  18.                 r = bit.band(r, bit.bnot(c)%2^31)
  19.         end
  20.         return r
  21. end
  22.  
  23. -- Pulses a bundled redstone color
  24. function redstonePulse(color, side)
  25. addColor(color, side)
  26. sleep(.5)
  27. delColor(color, side)
  28. end
  29.  
  30. -- Turns on a color of a bundled cable
  31. function addColor(color , side)
  32.  rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side) + color))
  33. end
  34.  
  35. -- Turns a color off of a bundled cable
  36. function delColor(color, side)
  37.    rs.setBundledOutput(side, colors.subtract(redstone.getBundledOutput(side), color))
  38. end
  39.  
  40. -- Turns on the UberMiner AutoMode
  41. function autoMode()
  42.     bool = checkColor(autoModeColor, defaultSide)
  43.  
  44.     -- If the Server is running the AutoMode it'll turn it on
  45.      if bool then
  46.         addColor(power, defaultSide)
  47.         delColor(autoModeColor, defaultSide)
  48.         term.setTextColor(colors.lime)
  49.         print("AutoMode now Online!")
  50.  
  51.     -- Or Else it'll turn AutoMode off.
  52.     else
  53.         delColor(power, defaultSide)
  54.         addColor(autoModeColor, defaultSide)
  55.         term.setTextColor(colors.red)
  56.         print("AutoMode now Offline!")     
  57.     end
  58.     button.toggleButton("AutoMode ON/OFF")
  59. end
  60.  
  61.  -- Edit's the startup to boot up on this pastebin
  62.  function startupClear()
  63.                 f = fs.open("startup", "w")
  64.                 f.write("shell.run('pastebin run BUDyRH0T')")
  65.                 f.close()
  66.                 end
  67.  
  68.     --Asks and saves where the bundled cable is locatated
  69.     function redstoneVar()
  70.         print("Where will the redstone output be? [left,right,bottom,top]")
  71.         command = read()
  72.         if command == "left" or command == "right" or command == "bottom" or command == "top" then
  73.             print("Redstone set to "..command.." side")
  74.             f = fs.open("redstoneVar", "w")
  75.             f.writeLine(command)
  76.             f.close()
  77.             os.reboot()
  78.         else
  79.             term.setTextColor(colors.red)
  80.             print("Invalid Input")
  81.             sleep(1)
  82.             redstoneVar()
  83.     end
  84.     end
  85.  
  86.  
  87. -- Checks if a file containing where the modem exists, and where the bundled redstone side is, if not
  88. -- Then it asks the user where they want it to be and saves it to modemVar and redstoneVar
  89.  function startupVars()
  90.     if fs.exists("redstoneVar") == false then
  91.         redstoneVar()
  92.     else
  93.     -- If they have already been configured than it loads the configs,
  94.     -- and Prints the current configs to the screen.
  95.  
  96.         f1 = fs.open("redstoneVar", "r")
  97.         defaultSide = f1.readLine()
  98.         f1.close()
  99.         term.setTextColor(colors.cyan)
  100.         print("Loaded with configuration :")
  101.         term.setTextColor(colors.red)
  102.         print("Redstone Side : "..defaultSide)
  103.         term.setTextColor(colors.gray)
  104. end
  105. end
  106.  
  107. -- Checks if a specific color in bundled cable is on or off / Returns a boolean
  108. function checkColor(color, side)
  109.     boolean = rs.testBundledInput(side, color)
  110.     --print("CheckColor : "..side.." - Side Color - "..color.." Bool -"..tostring(boolean))
  111. return boolean
  112. end
  113.  
  114. function wither()
  115. button.flash("WitherSpawn")
  116. redstonePulse(witherColor, defaultSide)
  117. end
  118.  
  119. function forward()
  120. redstonePulse(forwardColor, defaultSide)
  121. button.flash("Forward")
  122. end
  123.  
  124. function updateNumbers(number, total)
  125.     if checkColor(autoModeColor2, defaultSide) then
  126.         term.setTextColor(colors.lime)
  127.         print("Iteration : "..number.."/"..total)
  128.     end
  129. end
  130.  
  131.  
  132. function manMode()
  133. button.flash("Manual Iterations")
  134. term.setTextColor(colors.cyan)
  135. print("How many iterations would you like?")
  136. term.setTextColor(colors.blue)
  137.  
  138. command = read()
  139. autoMode()
  140. i = 0
  141. while i <= tonumber(command) do
  142.     event , p1, p2, p3 = os.pullEvent()
  143.     if event == "redstone" then
  144.         updateNumbers(i, command)
  145.         if i == 0 then
  146.         i = i + 1 else
  147.         i = i + 0.5
  148.         fillMenu()
  149.         m.setCursorPos(0,19)
  150.         button.centerText("Iterations : "..i.."/"..command)
  151.         end    
  152.     else if event == "monitor_touch" then
  153.         button.checkxy(p2,p3)
  154. end
  155. end
  156. end
  157. autoMode()
  158. fillMenu()
  159. end
  160.  
  161. function newTouchMenu()
  162. m.clear()
  163. button.clearTable()
  164. m.setBackgroundColor(colors.black)
  165. m.setTextColor(colors.white)
  166. end
  167.  
  168.    
  169. function fillMenu()
  170.    newTouchMenu()
  171.         button.clearTable()
  172.         button.setTable("AutoMode ON/OFF", autoMode, 2,28 ,3,5)
  173.         button.setTable("Manual Iterations", manMode, 2,28, 7,9)
  174.     button.setTable("Forward", forward, 2,28, 11,13)
  175.         button.setTable("WitherSpawn", wither, 2,28, 15,17)
  176.     print("Main Menu Filled")
  177.     button.screen()
  178.     if checkColor(autoModeColor, defaultSide) then
  179.     button.toggleButton("AutoMode ON/OFF")
  180.     end
  181.     end
  182.  
  183. addColor(autoModeColor, defaultSide)
  184. startupClear()
  185. startupVars()
  186. fillMenu()
  187.  
  188. local function getClick()
  189.         while true do
  190.                 local _,_,x,y = os.pullEvent("monitor_touch")
  191.                 button.checkxy(x,y)
  192.         end
  193. end
  194.  
  195.  
  196. while true do
  197. getClick()
  198. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement