Advertisement
Guest User

mobs

a guest
Jul 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.23 KB | None | 0 0
  1. os.loadAPI("button")
  2. local m = peripheral.wrap("right")
  3. local rsOut = {}
  4. local c = peripheral.wrap("ender_chest_2")
  5. local s = peripheral.wrap("auto_spawner_2")
  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.    fillTable()
  139. end
  140.  
  141. function insertMob(info)
  142.    removeMob()
  143.    c.pushItem("up", info, 1, 1)
  144.    fillTable()
  145. end
  146.  
  147. function checkMobs()
  148.    getMobs()
  149.    --fillTable()
  150. end
  151.  
  152. function initRS()
  153.    rsOut[colors.white] = true
  154.    rsOut[colors.orange] = true
  155.    rsOut[colors.magenta] = false
  156.    rsOut[colors.lightBlue] = false
  157.    rsOut[colors.yellow] = false
  158.    buttonColors["Top Lights"] = colors.white
  159.    buttonColors["Bottom Lights"] = colors.orange
  160.    buttonColors["Top Grinder"] = colors.magenta
  161.    buttonColors["Main Grinders"] = colors.lightBlue
  162.    buttonColors["Spawner"] = colors.yellow
  163. end
  164.  
  165. function setRS()
  166.    local colorOutput = 0
  167.    for i,j in pairs(rsOut) do
  168.       if j then colorOutput = colorOutput + i end
  169.     end
  170.     rs.setBundledOutput("back", colorOutput)
  171. end
  172.  
  173. function tLights()
  174.    button.toggleButton("Top Lights")
  175.    rsOut[colors.white] = not rsOut[colors.white]
  176.    setRS()
  177. end
  178.  
  179. function bLights()
  180.    button.toggleButton("Bottom Lights")
  181.    rsOut[colors.orange] = not rsOut[colors.orange]
  182.    setRS()
  183. end
  184.  
  185. function tGrinder()
  186.    button.toggleButton("Top Grinder")
  187.    rsOut[colors.magenta] = not rsOut[colors.magenta]
  188.    setRS()
  189. end
  190.  
  191. function mGrinders()
  192.    button.toggleButton("Main Grinders")
  193.    rsOut[colors.lightBlue] = not rsOut[colors.lightBlue]
  194.    setRS()
  195. end
  196.  
  197. function spawner()
  198.    button.toggleButton("Spawner")
  199.    rsOut[colors.yellow] = not rsOut[colors.yellow]
  200.    setRS()
  201. end
  202.  
  203. function mobSelect()
  204.    fillTable()
  205. --   refresh()
  206. --   getClick()
  207. end
  208.  
  209. function getClick()
  210.    local event,side,x,y = os.pullEvent()
  211.    if event=="monitor_touch" then
  212.      button.checkxy(x,y)
  213.    end
  214. end
  215.  
  216. function refresh()
  217.    m.clear()
  218.    print("Refreshed")
  219.    button.screen()
  220. end
  221.  
  222. initRS()
  223. setRS()
  224. fillMainTable()
  225. --refresh()
  226. while true do getClick() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement