eniallator

Ender Chest Both

Aug 31st, 2016
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 KB | None | 0 0
  1. local screenDim = {}
  2. screenDim.x, screenDim.y = term.getSize()
  3. local players = {eniallator = 3584, YaEyezOnMe = 2816, eriyo2000 = 267}
  4. local numPlayers = 3
  5. local selectedPlayer = "no one"
  6. local boxWidth = math.floor(screenDim.x /numPlayers +0.5)
  7. local displayTab = {}
  8. local nameDisplayLimit = boxWidth -2
  9. local community = {name = "Community", id = 1536}
  10. community.button = {screenDim.x -#community.name -1, 1, screenDim.x, 1, colours.lime, community.name, community.name}
  11.  
  12. term.setBackgroundColor(colours.black)
  13. shell.run("clear")
  14. turtle.dig()
  15.  
  16. local function findDamageVal(val)
  17.   for i=1,16 do
  18.     local chest = turtle.getItemDetail(i)
  19.  
  20.     if chest and chest.name == "EnderStorage:enderChest" and chest.damage == val then
  21.       return i
  22.     end
  23.   end
  24.  
  25.   return false
  26. end
  27.  
  28. local function makeDisplayTab()
  29.   for k,v in pairs(players) do
  30.     table.insert(displayTab,{#displayTab *boxWidth +2, 3, (#displayTab +1) *boxWidth -1, screenDim.y -1, colours.blue, k:sub(1, nameDisplayLimit), k})
  31.   end
  32. end
  33.  
  34. makeDisplayTab()
  35.  
  36. -- tab format {x1,y1,x2,y2,background colour, substringed app name (for display purposes), original app name}
  37. local function fillArea(tab)
  38.   term.setBackgroundColor(tab[5])
  39.  
  40.   for i=0,tab[4]-tab[2] do
  41.     local j = 0
  42.  
  43.     while j <= tab[3]-tab[1] do
  44.       term.setCursorPos(tab[1]+j,tab[2]+i)
  45.  
  46.       if tab[6] and math.floor(j-((tab[3]-tab[1])/2)+#tab[6]/2) == 0 and math.floor(i-(tab[4]-tab[2])/2) == 0 then
  47.         -- If statement seeing whether the iterators have hit the place where it should be writing the word out
  48.  
  49.         term.write(tab[6])
  50.         j = j + #tab[6]
  51.       else
  52.  
  53.         j = j + 1
  54.         term.write(" ")
  55.       end
  56.     end
  57.   end
  58. end
  59.  
  60. local function displayScreen()
  61.   fillArea({1,1,screenDim.x,1,colours.black})
  62.   term.setCursorPos(1,1)
  63.   term.write("Selected: " .. selectedPlayer)
  64.   fillArea(community.button)
  65.  
  66.   for i=1,#displayTab do
  67.     fillArea(displayTab[i])
  68.   end
  69. end
  70.  
  71. local function detectClick(tab, x, y)
  72.   if tab[1] <= x and tab[3] >= x and tab[2] <= y and tab[4] >= y then
  73.     return tab[7]
  74.   end
  75. end
  76.  
  77. local function clickDetectDisplay(x, y)
  78.   for i=1, #displayTab do
  79.     if detectClick(displayTab[i], x, y) then
  80.       return displayTab[i][7]
  81.     end
  82.   end
  83.  
  84.   return false
  85. end
  86.  
  87. while true do
  88.   makeDisplayTab()
  89.   displayScreen()
  90.  
  91.   if justSent then
  92.     checkDone()
  93.     justSent = false
  94.   end
  95.  
  96.   local event = {}
  97.   event.type, event.button, event.x, event.y = os.pullEvent()
  98.  
  99.   if event.type == "mouse_click" or event.type == "monitor_touch" then
  100.     local clickedPlayer = clickDetectDisplay(event.x, event.y)
  101.     local slot
  102.  
  103.     if clickedPlayer then
  104.       selectedPlayer = clickedPlayer
  105.       slot = findDamageVal(players[clickedPlayer])
  106.  
  107.     elseif detectClick(community.button, event.x, event.y) then
  108.       selectedPlayer = community.name
  109.       slot = findDamageVal(community.id)
  110.     end
  111.  
  112.     if slot then
  113.       turtle.dig()
  114.       turtle.select(slot)
  115.  
  116.       while not turtle.place() do turtle.dig() end
  117.     end
  118.   end
  119. end
Advertisement
Add Comment
Please, Sign In to add comment