SHARE
TWEET

startup

a guest Feb 26th, 2020 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("f") -- a monitor API made by myself, it makes my life easier
  2. os.loadAPI("getInput") -- search_bar
  3. local p = peripheral.find("draconic_chest") -- can change for "chest" instead of "draconic_chest"
  4. local m = peripheral.find("monitor") -- running on a monitor
  5. m.setTextScale(0.5)
  6. local list_items,items = {},{}
  7. local a,b,c = 1,1,1
  8. local selected = 0
  9. local side = "west" -- 2nd chest direction from 1st chest
  10. local chestSize = p.getInventorySize()
  11. local w,h = m.getSize()
  12.  
  13. local bg = window.create(m,1,1,w,h)
  14. local list = window.create(m,1,2,w*3/5-1,chestSize)
  15. local up_bar = window.create(m,1,1,w,1)
  16. local down_bar = window.create(m,1,h,w,h)
  17. local scroll_bar = window.create(m,w*(3/5),2,1,h-1)
  18. local bg2 = window.create(m,w*(3/5)+1,2,w,h-1)
  19.  
  20. function reset()
  21.   bg.setBackgroundColor(colors.black)
  22.   bg.clear()
  23.   list.setBackgroundColor(colors.black)
  24.   list.clear()
  25.   up_bar.setBackgroundColor(colors.lightGray)
  26.   up_bar.clear()
  27.   down_bar.setBackgroundColor(colors.lightGray)
  28.   down_bar.clear()
  29.   scroll_bar.setBackgroundColor(colors.lightGray)
  30.   scroll_bar.clear()
  31.   bg2.setBackgroundColor(colors.gray)
  32.   bg2.clear()
  33.   f.centerText(up_bar,1,"selectionner une destination","black")
  34.   f.print(down_bar,"dernier tp : ","black")
  35.   f.cprint(down_bar,13,1,last_dest,"blue","lightGray")
  36.   f.cprint(scroll_bar,1,1,"^","black","gray")
  37.   f.cprint(scroll_bar,1,h-2,"v","black","gray")
  38. end
  39.  
  40. function pulse()
  41.   redstone.setAnalogOutput("right",15)
  42.   sleep(0.5)
  43.   redstone.setAnalogOutput("right",0)
  44.   local last_dest = "none"
  45. end
  46.  
  47. function getItems()
  48.   b = 1
  49.   items = {}
  50.   if chestSize ~= nil then
  51.     for a=1,chestSize do
  52.       list_items[a] = p.getStackInSlot(a)
  53.       if list_items[a] ~= nil and list_items[a].name == "teleporterMKI" then
  54.         items[b] = {}
  55.         items[b][1] = a
  56.         items[b][2] = list_items[a].display_name
  57.         b = b + 1
  58.       end
  59.     end
  60.   end
  61.   table.sort(items, function(a, b) return a[2] < b[2] end)
  62.   table.insert(items,1,{1,">>> retour au Spawn <<<","spawn"})
  63. end
  64.  
  65. function list_display()
  66.   for c=1,#items do
  67.     if c == selected then
  68.       f.drawLine(list,1,c,w,"gray")
  69.       f.centerTextRight(list,c,"ouvrir","white")
  70.     else
  71.       list.setBackgroundColor(colors.black)
  72.     end
  73.     if items[c][3] == nil then
  74.       f.cprint(list,1,c,items[c][2],"blue","black")
  75.     elseif items[c][3] == "spawn" then
  76.       f.centerText(list,c,items[c][2],"cyan")
  77.     end
  78.   end
  79. end
  80.  
  81. function scroll(direction)
  82.   local x,y = list.getPosition()
  83.   if direction == "up" and y <=1 then
  84.     list.reposition(1,y+2)
  85.   elseif direction == "down" and y+#items > h-1 then
  86.     list.reposition(1,y-2)
  87.   end
  88. end
  89.  
  90. pulse()
  91.  
  92. while true do
  93.   reset()
  94.   getItems()
  95.   list_display()
  96.   down_bar.redraw()
  97.   up_bar.redraw()
  98.   x,y = list.getPosition()
  99.   j,k = scroll_bar.getPosition()
  100.   event,p1,p2,p3,p4,p5 = os.pullEvent()
  101.   if event == "monitor_touch" then
  102.     if p3-y+1 == selected and items[selected] ~= nil and p2 < j-1 then
  103.       up_bar.clear()
  104.       f.centerText(up_bar,1,"ouverture...","black")
  105.       pulse()
  106.       p.pushItem(side,items[selected][1])
  107.       last_dest = items[selected][2]
  108.       getItems()
  109.       close = os.startTimer(3)
  110.     elseif p3 > 1 and p2 < j-1 then
  111.       selected = p3-y+1
  112.     elseif p3 == 2 and p2 == j then
  113.       scroll("up")
  114.     elseif p3 == h-1 and p2 == j then
  115.       scroll("down")
  116.     end
  117.   end
  118.   if event == "timer" and p1 == close then
  119.     pulse()
  120.   end
  121.   bg2.setCursorPos(1,1)
  122.   search, ev10, p10 = getInput.read(bg2,30)
  123.   bg2.setCursorPos(1,2)
  124.   print(search)
  125.   display = {}
  126.   for i,v in pairs(items) do
  127.     if string.find(v[2],search) ~= nil then
  128.       table.insert(display,v)
  129.     end
  130.   end
  131. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top