Advertisement
Guest User

mobrev

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