Spiker985

FTB - Auto Spawner - Original

Aug 13th, 2014
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.90 KB | None | 0 0
  1. --[[Edit]]--
  2. local mon = peripheral.find("monitor")  --Name of monitor as peripheral
  3. local spawner = peripheral.find("auto_spawner") --Name of spawner as peripheral
  4. local chest = peripheral.find("container_chest") --Name of chest as peripheral
  5. local header = "Currently Spawning: "   --Appears at the top of the screen
  6. local chestDirection = "east"   --From spawner: north, south, east, west, up, down
  7. local spawnerDirection = "west"     --From chest: north, south, east, west, up, down
  8. local witherSkeletonEggName = "Wither"  --Whatever you name your wither skeleton safari net, this automatically activates exact mode when inserted into the spawner
  9. local lightsSide = "right"  --Redstone control for lights: front, left, back, right, up, down
  10. local grinderSide = "top"   --Redstone control for grinders: front, left, back, right, up, down
  11. local spawnerSide = "back"  --Redstone control for spawner: front, left, back, right, up, down
  12. local showWarning = true    --Shows the warning while loading
  13. local lightsOnDefault = true    --if true, turns the lights on when restarted
  14. local grinderOnDefault = true   --if true, turns the grinders on when restarted
  15. local spawnOnDefault = false    --if true, begins spawning immediately after a restart
  16. local beginAgain = true     --if true when showing the mob list, will revert to page 1 rather than resuming from the last page open --[[DOESNT affect a restart]]--
  17. local config = "config" --Name of the configuration file, used when saving/loading options
  18. local configAutoload = false
  19.  
  20. --[[Debug]]--
  21. local showFound = true  --Print to the computer what has been found in the chest inventory
  22.  
  23.  
  24. --[[Do no edit unless you know what you are doing]]--
  25. local mobPos = {}
  26. local totalCount = 0
  27. local npp = 12
  28. local pages = 0
  29. local pageNum = 1
  30.  
  31. function APILoader(apiName, apiPastebin)
  32.   os.unloadAPI(apiName)
  33.   if fs.exists(apiName) then
  34.     os.loadAPI(apiName)
  35.   else
  36.     shell.run("pastebin","get",apiPastebin,apiName)
  37.     os.loadAPI(apiName)
  38.   end
  39. end
  40.  
  41. function clear()
  42.   mon.clear()
  43.   mon.setCursorPos(1, 1)
  44.   button.clearTable()
  45. end
  46.  
  47. function heading(page)
  48.   if page == "main" then
  49.     if spawner.getStackInSlot(1) == nil then
  50.       button.heading(header)
  51.     else
  52.       button.heading(header..spawner.getStackInSlot(1).display_name)
  53.     end
  54.   end
  55.   if page == "options" then
  56.     button.heading("Options: Green - True, Red - False")
  57.   end
  58. end
  59.  
  60. function setupMainMenu()
  61.   heading("main")
  62.   button.setTable("Mob List", list, "yes", "", false, 15, 25, 3, 5)
  63.   button.setTable("Remove", removeEgg, "", "", false, 27, 37, 3, 5)
  64.  
  65.   button.setTable("Exact", toggleExact, "", "", spawner.getSpawnExact(), 3, 13, 7, 9)
  66.   button.setTable("Grinders", redstone, "grinder", "", not rs.getOutput(grinderSide), 15, 25, 7, 9)
  67.   button.setTable("Lights", redstone, "lights", "", rs.getOutput(lightsSide), 27, 37, 7, 9)
  68.  
  69.   button.setTable("Spawn", redstone, "spawn", "", not rs.getOutput(spawnerSide), 3, 13, 15, 17)
  70.   button.setTable("Options", setupOptionsMenu, "yes", "", false, 15, 25, 15, 17)
  71.   button.setTable("Reboot", os.reboot, "", "", false, 27, 37, 15, 17)
  72.   button.screen()
  73. end
  74.  
  75. function setupOptionsMenu(answer)
  76.   if answer == "yes" then button.flash("Options") end
  77.   clear()
  78.   heading("options")
  79.   button.setTable("Warning", options, "warning", "", showWarning, 3, 13, 3, 5)
  80.   button.setTable("Lights", options, "lights", "", lightsOnDefault, 15, 25, 3, 5)
  81.   button.setTable("Grinders", options, "grinder", "", grinderOnDefault, 27, 37, 3, 5)
  82.   button.setTable("Spawning", options, "spawner", "", spawnOnDefault, 3, 13, 7, 9)
  83.   button.setTable("Begin Again", options, "again", "", beginAgain, 15, 25, 7, 9)
  84.   button.setTable("Save", gamestate, "save", "options", false, 3, 13, 15, 17)
  85.   button.setTable("Load", gamestate, "load", "options", false, 27, 37, 15, 17)
  86.   button.setTable("Return", back, "", "", false, 15, 25, 15, 17)
  87.   button.screen()
  88. end
  89.  
  90. function gamestate(state, menu)
  91.   clear()
  92.   if state == "save" then
  93.     file = fs.open(config, "w")
  94.     button.label(5, 5, "Saving: ")
  95.     sleep(0.4)
  96.     file.writeLine(showWarning)
  97.     button.label(5, 7, "Show Warning: Done")
  98.     sleep(0.4)
  99.     file.writeLine(lightsOnDefault)
  100.     button.label(5, 9, "Lights On by Default: Done")
  101.     sleep(0.4)
  102.     file.writeLine(grinderOnDefault)
  103.     button.label(5, 11, "Grinder On by Default: Done")
  104.     sleep(0.4)
  105.     file.writeLine(spawnOnDefault)
  106.     button.label(5, 13, "Start Spawning by Default: Done")
  107.     sleep(0.4)
  108.     file.writeLine(beginAgain)
  109.     button.label(5, 15, "Begin Again: Done")
  110.     sleep(0.4)
  111.     button.label(5, 17, "Done! Saved as "..config)
  112.     file.close()
  113.     sleep(1)
  114.   end
  115.   if state == "load" then
  116.     file = fs.open(config, "r")
  117.     button.label(5, 5, "Loading: ")
  118.     sleep(0.4)
  119.     if file.readLine() == "true" then showWarning = true else showWarning = false end
  120.     button.label(5, 7, "Show Warning: Done")
  121.     sleep(0.4)
  122.     if file.readLine() == "true" then lightsOnDefault = true else lightsOnDefault = false end
  123.     rs.setOutput(lightsSide, lightsOnDefault)
  124.     button.label(5, 9, "Lights On by Default: Done")
  125.     sleep(0.4)
  126.     if file.readLine() == "true" then grinderOnDefault = true else grinderOnDefault = false end
  127.     rs.setOutput(grinderSide, not grinderOnDefault)
  128.     button.label(5, 11, "Grinder On by Default: Done")
  129.     sleep(0.4)
  130.     if file.readLine() == "true" then spawnOnDefault = true else spawnOnDefault = false end
  131.     rs.setOutput(spawnerSide, not spawnOnDefault)
  132.     button.label(5, 13, "Start Spawning by Default: Done")
  133.     sleep(0.4)
  134.     if file.readLine() == "true" then beginAgain = true else beginAgain = false end
  135.     button.label(5, 15, "Begin Again: Done")
  136.     sleep(0.4)
  137.     button.label(5, 17, "Done! "..config.." loaded!")
  138.     file.close()
  139.     sleep(1)
  140.   end
  141.   if menu == "options" then setupOptionsMenu() end
  142.   if menu == "main" then setupMainMenu() end
  143.   if menu == "check" then button.heading("Checking mobs...") end
  144. end
  145.  
  146. function options(option)
  147.   if option == "warning" then
  148.     showWarning = not showWarning
  149.   end
  150.   if option == "lights" then
  151.     lightsOnDefault = not lightsOnDefault
  152.   end
  153.   if option == "grinder" then
  154.     grinderOnDefault = not grinderOnDefault
  155.   end
  156.   if option == "spawner" then
  157.     spawnOnDefault = not spawnOnDefault
  158.   end
  159.   if option == "again" then
  160.     beginAgain = not beginAgain
  161.   end
  162.   sleep(0.2)
  163.   setupOptionsMenu()
  164. end
  165.  
  166. function redstone(object)
  167.   if object == "lights" then
  168.     rs.setOutput(lightsSide, not rs.getOutput(lightsSide))
  169.   end
  170.   if object == "grinder" then
  171.     rs.setOutput(grinderSide, not rs.getOutput(grinderSide))
  172.   end
  173.   if object == "spawn" then
  174.     rs.setOutput(spawnerSide, not rs.getOutput(spawnerSide))
  175.   end
  176.   sleep(0.2)
  177.   --clear()
  178.   setupMainMenu()
  179. end
  180.  
  181. function clearNreset()
  182.   clear()
  183.   setupMainMenu()
  184. end
  185.  
  186. function toggleExact()
  187.   spawner.setSpawnExact(not spawner.getSpawnExact())
  188.   clear()
  189.   setupMainMenu()
  190. end
  191.  
  192. function removeEgg()
  193.   button.flash("Remove")
  194.   chest.pullItemIntoSlot(spawnerDirection, 1)
  195.   clear()
  196.   button.heading("Re-checking mobs...")
  197.   checkMobs()
  198.   clear()
  199.   setupMainMenu()
  200. end
  201.  
  202. function insert(slot)
  203.   if chest.getStackInSlot(slot).display_name == witherSkeletonEggName then
  204.     spawner.setSpawnExact(true)
  205.   else
  206.     spawner.setSpawnExact(false)
  207.   end
  208.   chest.pullItemIntoSlot(spawnerDirection, 1)
  209.   spawner.pullItemIntoSlot(chestDirection, slot)
  210.   clear()
  211.   setupMainMenu()
  212. end
  213.  
  214. function back(answer)
  215.   button.flash("Return")
  216.   clear()
  217.   setupMainMenu()
  218.   if beginAgain == true and answer == "yes" then pageNum = 1 end
  219. end
  220.  
  221. function page(dir)
  222.   if dir == "prev" then
  223.     button.flash("<")
  224.     if pageNum - 1 >= 1 then
  225.       pageNum = pageNum - 1
  226.     end
  227.   end
  228.   if dir == "next" then
  229.     button.flash(">")
  230.     if pageNum + 1 <= pages then
  231.       pageNum = pageNum + 1
  232.     end
  233.   end
  234.   clear()
  235.   list()
  236. end
  237.  
  238. function loading()
  239.   clear()
  240.   button.heading("Loading...")
  241.   button.screen()
  242. end
  243.  
  244. function list(answer)
  245.   if answer == "yes" then button.flash("Mob List") end
  246.   loading()
  247.   checkMobs()
  248.   clear()
  249.   heading("main")
  250.   if pageNum == 1 then
  251.     k = 0
  252.     j = 0
  253.     for i = 1, 12 do
  254.       if k == 16 and j == 0 then
  255.         j = 12
  256.     k = 0
  257.       end
  258.       if k == 16 and j == 12 then
  259.     j = 24
  260.     k = 0
  261.       end
  262.       if k == 16 and j == 24 then
  263.         break
  264.       end
  265.       button.setTable(mobPos[i].mob, insert, i, "", false, 3+j, 13+j, 3+k, 5+k)
  266.       k = k + 4
  267.     end
  268.   end
  269.   if pageNum == 2 then
  270.     k = 0
  271.     j = 0
  272.     for i = 13, 24 do
  273.       next(mobPos, 11)
  274.       if k == 16 and j == 0 then
  275.         j = 12
  276.         k = 0
  277.       end
  278.       if k == 16 and j == 12 then
  279.         j = 24
  280.         k = 0
  281.       end
  282.       if k == 16 and j == 24 then
  283.         break
  284.       end
  285.       button.setTable(mobPos[i].mob, insert, i, "", false, 3+j, 13+j, 3+k, 5+k)
  286.       k = k + 4
  287.     end
  288.   end
  289.   if pageNum == 3 then
  290.     k = 0
  291.     j = 0
  292.     for i = 25, 16 do
  293.       next(mobPos, 11)
  294.       if k == 16 and j == 0 then
  295.         j = 12
  296.         k = 0
  297.       end
  298.       if k == 16 and j == 12 then
  299.         j = 24
  300.         k = 0
  301.       end
  302.       if k == 16 and j == 24 then
  303.         break
  304.       end
  305.       button.setTable(mobPos[i].mob, insert, i, "", false, 3+j, 13+j, 3+k, 5+k)
  306.       k = k + 4
  307.     end
  308.   end
  309.   if pageNum == 4 then
  310.     k = 0
  311.     j = 0
  312.     for i = 37, 48 do
  313.       next(mobPos, 11)
  314.       if k == 16 and j == 0 then
  315.         j = 12
  316.         k = 0
  317.       end
  318.       if k == 16 and j == 12 then
  319.         j = 24
  320.         k = 0
  321.       end
  322.       if k == 16 and j == 24 then
  323.         break
  324.       end
  325.       button.setTable(mobPos[i].mob, insert, i, "", false, 3+j, 13+j, 3+k, 5+k)
  326.       k = k + 4
  327.     end
  328.   end
  329.   if pageNum == 5 then
  330.     k = 0
  331.     j = 0
  332.     for i = 49, 60 do
  333.       next(mobPos, 11)
  334.       if k == 16 and j == 0 then
  335.         j = 12
  336.         k = 0
  337.       end
  338.       if k == 16 and j == 12 then
  339.         j = 24
  340.         k = 0
  341.       end
  342.       if k == 16 and j == 24 then
  343.         break
  344.       end
  345.       button.setTable(mobPos[i].mob, insert, i, "", false, 3+j, 13+j, 3+k, 5+k)
  346.       k = k + 4
  347.     end
  348.   end
  349.   if pageNum == 6 then
  350.     k = 0
  351.     j = 0
  352.     for i = 61, 72 do
  353.       next(mobPos, 11)
  354.       if k == 16 and j == 0 then
  355.         j = 12
  356.         k = 0
  357.       end
  358.       if k == 16 and j == 12 then
  359.         j = 24
  360.         k = 0
  361.       end
  362.       if k == 16 and j == 24 then
  363.         break
  364.       end
  365.       button.setTable(mobPos[i].mob, insert, i, "", false, 3+j, 13+j, 3+k, 5+k)
  366.       k = k + 4
  367.     end
  368.   end
  369.   if pageNum == 7 then
  370.     k = 0
  371.     j = 0
  372.     for i = 73, 84 do
  373.       next(mobPos, 11)
  374.       if k == 16 and j == 0 then
  375.         j = 12
  376.         k = 0
  377.       end
  378.       if k == 16 and j == 12 then
  379.         j = 24
  380.         k = 0
  381.       end
  382.       if k == 16 and j == 24 then
  383.         break
  384.       end
  385.       button.setTable(mobPos[i].mob, insert, i, "", false, 3+j, 13+j, 3+k, 5+k)
  386.       k = k + 4
  387.     end
  388.   end
  389.   if pageNum == 8 then
  390.     k = 0
  391.     j = 0
  392.     for i = 85, 96 do
  393.       next(mobPos, 11)
  394.       if k == 16 and j == 0 then
  395.         j = 12
  396.         k = 0
  397.       end
  398.       if k == 16 and j == 12 then
  399.         j = 24
  400.         k = 0
  401.       end
  402.       if k == 16 and j == 24 then
  403.         break
  404.       end
  405.       button.setTable(mobPos[i].mob, insert, i, "", false, 3+j, 13+j, 3+k, 5+k)
  406.       k = k + 4
  407.     end
  408.   end
  409.   if pageNum == 9 then
  410.     k = 0
  411.     j = 0
  412.     for i = 97, 100 do
  413.       next(mobPos, 11)
  414.       if k == 16 and j == 0 then
  415.         j = 12
  416.         k = 0
  417.       end
  418.       if k == 16 and j == 12 then
  419.         j = 24
  420.         k = 0
  421.       end
  422.       if k == 16 and j == 24 then
  423.         break
  424.       end
  425.       button.setTable(mobPos[i].mob, insert, i, "", false, 3+j, 13+j, 3+k, 5+k)
  426.       k = k + 4
  427.     end
  428.   end
  429.   if pageNum == 10 then
  430.     k = 0
  431.     j = 0
  432.     for i = 101, 112 do
  433.       next(mobPos, 11)
  434.       if k == 16 and j == 0 then
  435.         j = 12
  436.         k = 0
  437.       end
  438.       if k == 16 and j == 12 then
  439.         j = 24
  440.         k = 0
  441.       end
  442.       if k == 16 and j == 24 then
  443.         break
  444.       end
  445.       button.setTable(mobPos[i].mob, insert, i, "", false, 3+j, 13+j, 3+k, 5+k)
  446.       k = k + 4
  447.     end
  448.   end
  449.   button.remTable("Empty")
  450.   button.setTable("<", page, "prev", "", false, 15, 19, 19, 20)
  451.   button.setTable(">", page, "next", "", false, 21, 25, 19, 20)
  452.   button.setTable("Return", back, "yes", "", false, 3, 13, 19, 20)
  453.   button.label(28, 19, "Page "..pageNum.." of "..pages)
  454.   button.screen()
  455. end
  456.  
  457. function warn()
  458.   button.label(5, 5, "The more slots an inventory has,")
  459.   button.label(5, 7, "the longer it will take to load!")
  460.   button.label(5, 10, "Every safari net needs to be")
  461.   button.label(5, 12, "renamed in an Anvil to show up!")
  462. end
  463.  
  464. function checkMobs()
  465.   u = 0
  466.   for i = 1, chest.getInventorySize() do
  467.     mobPos[i] = {}
  468.     u = u + 1
  469.     if chest.getStackInSlot(i) == nil then
  470.       mobPos[i]["mob"] = "Empty"
  471.       u = u - 1
  472.     else
  473.       mobPos[i]["mob"] = chest.getStackInSlot(i).display_name
  474.     end
  475.     if showFound == true then
  476.       for name, data in pairs(mobPos) do
  477.         print("Found: "..data.mob)
  478.       end
  479.     end
  480.   end
  481.   totalRows = u
  482.   pages = math.ceil(totalRows/npp)
  483. end
  484.  
  485. function checkPress()
  486.   event, side, x, y = os.pullEvent("monitor_touch")
  487.   button.checkxy(x,y)
  488. end
  489.  
  490. APILoader("button","S8x0K3ui")
  491. clear()
  492. if showWarning == true then warn() end
  493. if lightsOnDefault == true then rs.setOutput(lightsSide, true) else rs.setOutput(lightsSide, false) end
  494. if grinderOnDefault == true then rs.setOutput(grinderSide, false) else rs.setOutput(grinderSide, true) end
  495. if spawnOnDefault == true then rs.setOutput(spawnerSide, false) else rs.setOutput(spawnerSide, true) end
  496. if configAutoload == true and fs.exists(config) == true then gamestate("load", "check") else button.label(5, 16, "To enable autoload you must have a") button.label(5, 18, "config saved! *Enable in file*") end
  497. checkMobs()
  498. clear()
  499. setupMainMenu()
  500.  
  501.  
  502. while true do
  503.   checkPress()
  504. end
Advertisement
Add Comment
Please, Sign In to add comment