Advertisement
Guest User

mobs

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