Advertisement
Guest User

mobs

a guest
Sep 2nd, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.64 KB | None | 0 0
  1.  
  2. os.loadAPI("button")
  3. local m = peripheral.wrap("top")
  4. local rsOut = {}
  5. local c = peripheral.wrap("container_chest_0")
  6. --local a = peripheral.wrap("tt_magnet_0")
  7. local s = peripheral.wrap("auto_spawner_4")
  8. --print(s)
  9. m.clear()
  10. local mobArray = {}
  11. --local buttonColors = {}
  12. --local attractorStatus = ""
  13. local page = 1
  14. local pages = 0
  15. local currMob = ""
  16.    
  17. function fillMainTable()
  18.    getCurrMob()
  19.    checkExact()
  20.    m.clear()
  21.    
  22.    button.setTable("Lights", lights, 4, 17, 6, 4)
  23.    button.setTable("Grinders", grinders, 4, 17, 6, 8)
  24.    button.setTable("Mob Selector", mobSelect, 20, 33, 14, 16)
  25.    button.setTable("Spawner", spawner, 4, 17, 14, 16)
  26.    button.setTable("Refresh", refresh, 15, 35, 19, 19)
  27.    print("Filled")
  28.   button.screen()
  29.   -- for i,j in pairs(buttonColors) do
  30.     -- if not rsOut[j] then button.toggleButton(i) end
  31.   -- end
  32.   -- button.toggleButton("Attractor")
  33.    button.label(1, 19, "Current Mob: "..currMob)
  34.    button.label(30, 19, "Exact: "..currExact)
  35. end
  36.  
  37. --function getAttractorStatus()
  38.  --  if a.isPulling() then
  39.   --    attractorStatus = "Pulling"
  40.  --  else
  41.  --     attractorStatus = "Pushing"
  42.  --  end
  43. --end
  44.  
  45. --function togglePush()
  46. --   button.flash(attractorStatus)
  47. --   a.setPulling(not a.isPulling())
  48. --   fillMainTable()
  49. --end
  50.  
  51. function fillTable()
  52.    checkMobs()
  53.    checkExact()
  54.    getCurrMob()
  55.    m.clear()
  56.    button.clearTable()
  57.    local totalrows = 0
  58.    local npp = 12 --names per page
  59.    local numNames = 0
  60.    local col = 2
  61.    local row = 12
  62.    local countRow = 1
  63.    local currName = 0
  64.    for i,j in pairs(mobArray) do
  65.       totalrows = totalrows+1
  66.    end
  67.    pages = math.ceil(totalrows/npp)
  68.    print(totalrows)
  69.    for name,slot in pairs(mobArray) do
  70.        currName = currName + 1
  71.        if currName > npp*(page-1) and currName < npp*page+1 then
  72.          row = 4+(countRow)
  73.          button.setTable(string.sub(name, 0, 17), insertMob, slot, col, col+17 , row, row)
  74.          if col == 21 then
  75.            col = 2
  76.            countRow = countRow + 2
  77.          else
  78.            col = col+19
  79.          end
  80.        end
  81.    end
  82.    button.setTable("Next Page", nextPage, "", 27, 38, 1, 1)
  83.    button.setTable("Prev Page", prevPage, "", 2, 13, 1, 1)
  84.    button.setTable("Main Menu", goMainMenu, "", 15, 25, 1, 1)
  85.    button.setTable("Exact: "..currExact, switchExact, "", 21, 38, 18, 19)
  86.    button.setTable("Remove Mob", removeMob, "", 2, 19, 18, 19)
  87.    button.screen()
  88.    button.label(15,3, "Page: "..tostring(page).." of "..tostring(pages))
  89.    button.label(12, 16, "Current Mob: "..currMob)
  90. end      
  91.  
  92. function getCurrMob()
  93.    data = s.getStackInSlot(1)
  94.    if data then
  95.       currMob = data.captured
  96.    else
  97.       currMob = "None"
  98.    end
  99. end
  100.  
  101. function goMainMenu()
  102.    fillMainTable()
  103. --   refresh()
  104. end
  105.  
  106. function checkExact()
  107.    if s.getSpawnExact() then
  108.       currExact = "Yes"
  109.    else
  110.       currExact = "No"
  111.    end
  112. end
  113.  
  114. function switchExact()
  115.    s.setSpawnExact(not s.getSpawnExact())
  116.    fillTable()
  117. end
  118.  
  119. function nextPage()
  120.    if page+1 <= pages then
  121.       page = page+1
  122.    end
  123.    fillTable()
  124.    sleep(0.25)
  125. end
  126.  
  127. function prevPage()
  128.    if page-1 >= 1 then page = page-1 end
  129.    fillTable()
  130.    sleep(0.25)
  131. end  
  132.                            
  133. function getMobs()
  134.    mobArray = {}
  135.    for i = 1,27  do
  136.       if c.getStackInSlot(i) then
  137.          data = c.getStackInSlot(i)
  138.          --print(i..":"..data.captured)
  139.          mobArray[data.captured] = i
  140.       end
  141.    end
  142. end
  143.  
  144. function findEmptySlot()
  145.    for i = 1,27 do
  146.       if not c.getStackInSlot(i) then
  147.          return(i)
  148.       end
  149.    end
  150. end
  151.  
  152. function removeMob()
  153.    local slot = findEmptySlot()
  154.    c.pullItem("down", 1, 1, slot)
  155. end
  156.  
  157. function insertMob(info)
  158.    removeMob()
  159.    c.pushItem("down", info, 1, 1)
  160.    fillTable()
  161. end
  162.  
  163. function checkMobs()
  164.    getMobs()
  165.    --fillTable()
  166. end
  167.  
  168. function initRS()
  169.    rsOut[colors.white] = false
  170.    rsOut[colors.orange] = true
  171.    rsOut[colors.magenta] = false
  172.    rsOut[colors.lightBlue] = true
  173.    rsOut[colors.yellow] = false
  174.    rsOut[colors.lime] = true
  175.   -- buttonColors["Lights"] = colors.white
  176.   -- buttonColors["Spawner"] = colors.orange
  177.   -- buttonColors["Grinders"] = colors.magenta
  178.   -- buttonColors["DrawBridge"] = colors.lightBlue
  179.   -- buttonColors["Attractor"] = colors.yellow
  180.   -- buttonColors["Door"] = colors.lime
  181. end
  182.  
  183. function setRS()
  184.    local colorOutput = 0
  185.    for i,j in pairs(rsOut) do
  186.       if j then colorOutput = colorOutput + i end
  187.     end
  188.     rs.setBundledOutput("left", colorOutput)
  189. end
  190.  
  191. function lights()
  192.    button.toggleButton("Lights")
  193.    rsOut[colors.white] = not rsOut[colors.white]
  194.    setRS()
  195. end
  196.  
  197. function door()
  198.    button.toggleButton("Door")
  199.    rsOut[colors.lime] = not rsOut[colors.lime]
  200.    setRS()
  201. end
  202.  
  203. function spawner()
  204.    button.toggleButton("Spawner")
  205.    rsOut[colors.orange] = not rsOut[colors.orange]
  206.    setRS()
  207. end
  208.  
  209. function grinders()
  210.    button.toggleButton("Grinders")
  211.    rsOut[colors.magenta] = not rsOut[colors.magenta]
  212.    setRS()
  213. end
  214.  
  215. function drawBridge()
  216.    button.toggleButton("DrawBridge")
  217.    rsOut[colors.lightBlue] = not rsOut[colors.lightBlue]
  218.    setRS()
  219. end
  220.  
  221. --function attractorToggle()
  222. --   button.toggleButton("Attractor")
  223.  --  rsOut[colors.yellow] = not rsOut[colors.yellow]
  224. --   setRS()
  225. --end
  226.  
  227. function mobSelect()
  228.    fillTable()
  229. --   refresh()
  230. --   getClick()
  231. end
  232.  
  233. function getClick()
  234.    local event,side,x,y = os.pullEvent()
  235.    if event=="monitor_touch" then
  236.      button.checkxy(x,y)
  237.    end
  238. end
  239.  
  240. function refresh()
  241.    m.clear()
  242.    print("Refreshed")
  243.    button.screen()
  244. end
  245.  
  246. initRS()
  247. setRS()
  248. fillMainTable()
  249. --refresh()
  250. while true do getClick() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement