Sir_Popsilots

create mod vault storage test

Dec 25th, 2021 (edited)
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.89 KB | None | 0 0
  1. local vault = peripheral.wrap("create:item_vault_2") --requires create mod vault
  2. local barrel = peripheral.wrap("minecraft:barrel_0") -- requires a barrel
  3. local monitor = peripheral.find("monitor") --requires a monitor tauching the computer
  4. --both need to be connected to the same network
  5. --monitor size is 3x2 or 29 x 12 chars
  6. --midle point at x = 15
  7. local db = {}
  8. local dbCount = 0
  9. local CorrentScreenName
  10. local MainScreenBB = {} --BB = BindingBoxes , Item Options is index 1 to 5
  11.    
  12.  
  13. function resetColors()
  14.     monitor.setTextColor(1); monitor.setBackgroundColor(32768)
  15. end
  16.  
  17. function DoesItemExist(itemDisplayName,database)--function that checks if an item is already in the DataBase based on its displayName
  18.     for name , count  in pairs(database) do
  19.         if name == itemDisplayName then
  20.             return true
  21.         end
  22.     end
  23.     return false
  24. end
  25.  
  26. function WriteDataBase()--function that adds an item and its count to the DataBase if it doesnt exist other wise adds to its count
  27.     for slot , item in pairs(vault.list()) do
  28.         local itemDisplayName = vault.getItemDetail(slot).displayName
  29.         if DoesItemExist(itemDisplayName,db) then
  30.             db[itemDisplayName] = vault.getItemDetail(slot).count + db[itemDisplayName]
  31.         else
  32.             dbCount = dbCount + 1
  33.             db[itemDisplayName] = item.count
  34.         end
  35.     end
  36. end
  37.  
  38. function sortDB()
  39.    
  40. end
  41.  
  42. function WriteItemInMainScreen(Item , count,IsSelected) --function thats writes the item count and item name in a specific way
  43.     monitor.setTextColor(32768); monitor.setBackgroundColor(8)
  44.     local tempPosX,tempPosY = monitor.getCursorPos()
  45.     monitor.write("   ")
  46.     monitor.setCursorPos(tempPosX,tempPosY)
  47.     if count < 1000 then
  48.         monitor.write(tostring(count))
  49.     else
  50.         monitor.write("999")
  51.     end
  52.     if IsSelected then  
  53.         monitor.setTextColor(32768); monitor.setBackgroundColor(8)
  54.         monitor.setCursorPos(tempPosX+3,tempPosY)
  55.         monitor.write(Item)
  56.     else
  57.         resetColors()
  58.         monitor.setCursorPos(tempPosX+3,tempPosY)
  59.         monitor.write(Item)
  60.     end
  61.     resetColors()
  62. end
  63.  
  64. function draw_Item_Options(page,selectedItemIndexOnPage) --function that draws the first 5 times in the db for the page
  65.     monitor.setCursorPos(1,3)
  66.     local ItemOnScreenLimitor = 0
  67.     local startingIndex = 1 + 5*(page-1)
  68.     local correntIndex = 1
  69.     for name , count in pairs(db) do
  70.         if correntIndex >= startingIndex then
  71.             ItemOnScreenLimitor = ItemOnScreenLimitor + 1
  72.             if ItemOnScreenLimitor == 5 then break end
  73.  
  74.             if ItemOnScreenLimitor == selectedItemIndexOnPage then
  75.                 WriteItemInMainScreen(name,count,true)
  76.             else
  77.                 WriteItemInMainScreen(name,count,false)
  78.             end
  79.  
  80.             local tempx ,tempy = monitor.getCursorPos()
  81.             monitor.setCursorPos(1,tempy+2)
  82.              
  83.         end
  84.         correntIndex = correntIndex + 1
  85.     end
  86. end
  87.  
  88. function draw_Empty_button() --function that draws the for the empty barrel button
  89.     monitor.setTextColor(32768);monitor.setBackgroundColor(512)
  90.     monitor.setCursorPos(23,9);monitor.write("       ")
  91.     monitor.setCursorPos(23,10);monitor.write(" Empty>")
  92.     monitor.setCursorPos(23,11);monitor.write("       ")
  93.     resetColors()
  94. end
  95.  
  96.  
  97.  
  98. function clearRightSide()
  99.     monitor.setTextColor(1);monitor.setBackgroundColor(32768)
  100.     for i = 2 ,12,1 do
  101.         monitor.setCursorPos(15,i)
  102.         monitor.write("                                             ")
  103.     end
  104. end
  105.  
  106. function draw_main_screen(page) --function that draws the main screen
  107.     monitor.setCursorPos(8,1)
  108.     monitor.write("Choose an Item")
  109.     draw_Item_Options(page)
  110.     if dbCount > 5 then
  111.         monitor.setCursorPos(1,12)
  112.         monitor.write("[NXT][PRV]")
  113.     end
  114.     clearRightSide()
  115.     draw_Empty_button()
  116. end
  117.  
  118. function EmptyBarrel() --function that emptys the barrel into the main create mod vault
  119.     for slot , item in pairs(barrel.list()) do
  120.         vault.pullItems(peripheral.getName(barrel),slot)
  121.     end
  122.     db = {}
  123.     WriteDataBase()
  124. end
  125.  
  126. function drawNumPad()
  127.     clearRightSide()
  128.     monitor.setCursorPos(17,4)
  129.     resetColors()
  130.     monitor.write(">>")
  131.     monitor.setCursorPos(18,5)
  132.     local tempX,tempY = monitor.getCursorPos()
  133.     for i = 1 ,9,1 do
  134.         monitor.write("|")
  135.         monitor.setTextColor(2048)
  136.         monitor.write(tostring(i))
  137.         resetColors()
  138.         if (i % 3 == 0)then
  139.             monitor.write("|")
  140.             tempY = tempY + 1
  141.             monitor.setCursorPos(tempX,tempY)
  142.         end
  143.     end
  144.     monitor.write("|")
  145.     monitor.setTextColor(2048)
  146.     monitor.write("0")
  147.     resetColors()
  148.     monitor.write("|[")
  149.     monitor.setTextColor(2)
  150.     monitor.write("<<")
  151.     resetColors()
  152.     monitor.write("]")
  153.     tempY = tempY + 1
  154.     monitor.setCursorPos(tempX,tempY)
  155.     monitor.write("|")
  156.     monitor.setTextColor(32)
  157.     monitor.write("ENTER")
  158.     resetColors()
  159.     monitor.write("|")    
  160. end
  161.  
  162. local LASTROW = 12
  163. local LASTPAGEBUTTONXCORDS = 10
  164. function leftSideActions(xcords,ycords)
  165.     if ycords % 2 ~= 0 then
  166.         local indexOnPage = 1
  167.         for i = 3  , 12 ,2 do
  168.             if ycords == i then
  169.                 return indexOnPage
  170.             else
  171.                 indexOnPage = indexOnPage + 1
  172.             end
  173.         end
  174.     elseif (ycords == LASTROW) and (xcords<=LASTPAGEBUTTONXCORDS) then
  175.         local NXTbutton = 5
  176.         local PRVbutton = 10
  177.         if xcords <= 5 then return "NXT"
  178.         elseif xcords<=10 then return "PRV" end
  179.     end
  180. end
  181.  
  182. function RightSideActions(xcords,ycords,IsNumpad)
  183.     -- body
  184. end
  185.  
  186. function TouchDepartment()
  187.     -- body
  188. end
  189.  
  190. monitor.clear()
  191. monitor.setCursorPos(1,1)
  192. EmptyBarrel()
  193. WriteDataBase()
  194. for k,v in pairs(db) do
  195.     print(k,"x",v)
  196. end
  197. draw_main_screen(1)
  198. drawNumPad()
  199. resetColors()
Add Comment
Please, Sign In to add comment