Advertisement
DarkSiders061

mobfarm

Oct 3rd, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. --[[
  2. Gangsir's mob farm controller
  3. This program uses TankNut's interface program. Download at
  4. https://github.com/OpenPrograms/MiscPrograms/blob/master/TankNut/interface.lua
  5. If an internet card is present, the program will auto-fetch it.
  6. To set up, connect a bundled redstone cable that OC supports to the computer,
  7. and set colours on other ends to be as follows:
  8. Red:Mob spawner
  9. White:Lights
  10. Orange:Door
  11. Black:Killing Method
  12. I recommend using some type of wireless redstone to avoid having to place cables everywhere.
  13. --]]
  14.  
  15. os = require("os")
  16. component = require("component")
  17. gui = nil --variable for the gui library
  18. redstone = nil
  19. colors = require("colors")
  20. outputSide = require("sides").bottom --change this if you want to use a different side.
  21. maxX , maxY = component.gpu.maxResolution() --get the size of the resolution
  22. computer = require("computer")
  23.  
  24. --check if screen is correct, ie tier 2 or greater
  25. if component.gpu.getDepth() < 4 then
  26. error("Screen/gpu does not meet graphics requirements.")
  27. end
  28. component.gpu.setResolution(80,25) --set the resolution to be correct
  29. component.screen.setTouchModeInverted(true) --inverts touch mode.
  30.  
  31. if not component.isAvailable("redstone") then
  32. error("This program requires a connection to a redstone io block or a tier 2 redstone card.")
  33. else
  34. redstone = component.redstone
  35. end
  36.  
  37.  
  38. print("Init mob farm manager...")
  39. os.sleep(1)
  40. print("Connect bundled redstone cables to mob spawner(red), lights(white), door(orange), and killing method(black). Set each machine to be active on the same type of signal.")
  41. print("If the gui messes up and starts turning things off and on again quickly, just reboot the computer and script.")
  42. os.sleep(8)
  43.  
  44. --check for gui library
  45. if require("filesystem").exists("/lib/interface.lua") then
  46. gui = require("interface")
  47. elseif component.isAvailable("internet") then
  48. print("Gui lib not found, internet card installed, trying to auto-fetch.")
  49. os.execute("wget https://raw.githubusercontent.com/OpenPrograms/MiscPrograms/master/TankNut/interface.lua /lib/interface.lua")
  50. print("Computer needs to reboot to note changes to available libs, rebooting in 3 seconds...")
  51. os.sleep(3)
  52. computer.shutdown(true) --reboots the computer
  53. else
  54. error("TankNut's GUI framework must be present and available to use this program. Download from his github at openprograms, and place in /lib, or install an internet card.")
  55. end
  56.  
  57. if not require("filesystem").exists("/lib/interface.lua") then --if the library is still unloadable
  58. error("Still can't load the library, program won't work.")
  59. end
  60.  
  61. --init all functions
  62.  
  63. --toggles output on specified colour, returns boolean based on success
  64. local function toggle(color)
  65. if redstone.getBundledOutput(outputSide,color) == 15 then
  66. redstone.setBundledOutput(outputSide,color,0)
  67. return true
  68. else
  69. redstone.setBundledOutput(outputSide,color,15)
  70. return true
  71. end
  72. return false
  73. end
  74.  
  75. --init gui
  76. redstone.setBundledOutput(outputSide,colors.red,0)
  77. redstone.setBundledOutput(outputSide,colors.white,0)
  78. redstone.setBundledOutput(outputSide,colors.orange,0) --set all outputs false
  79. redstone.setBundledOutput(outputSide,colors.black,0)
  80.  
  81. --setup gui, button args are id,label,x,y,width,function,params,oncolour,offcolour
  82. gui.clearAllObjects()
  83. gui.newButton("mobspawner","Mob Spawner",3,6,33,7,function() toggle(colors.red) end,nil,0x00FF00,0xFF0000,true)
  84. gui.newButton("lights","Lights",3,15,33,7,function() toggle(colors.white) end,nil,0x00FF00,0xFF0000,true)
  85. gui.newButton("door","Door",46,6,33,7,function() toggle(colors.orange) end,nil,0x00FF00,0xFF0000,true)
  86. gui.newButton("kill","Killing",46,15,33,7,function() toggle(colors.black) end,nil,0x00FF00,0xFF0000,true)
  87. gui.newLabel("title","Mob Farm",0,0,maxX,3,0x0000FF) --title label
  88.  
  89. gui.updateAll() --draws the screen
  90.  
  91. --check for clicks
  92. while true do
  93. local _,_,x,y = require("event").pull("touch")
  94. if x and y then
  95. gui.processClick(x,y)
  96. end
  97. end
  98. --eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement