Advertisement
Shaka01

lootcount receiver

Oct 19th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.66 KB | None | 0 0
  1. rednet.open("bottom")
  2. m = peripheral.wrap("right")
  3. m.setTextScale(0.5)
  4. m.setBackgroundColor(colors.black)
  5. m.setTextColor(colors.lightGray)
  6. term.setCursorBlink(false)
  7. m.clear()
  8. m.setCursorPos(1, 1)
  9. nocount = false
  10. seconds = 0
  11. minutes = 1
  12. checker = 1
  13. wantedItem = "abcomg"
  14. results2 = { 1, 2,3}
  15.  
  16. local xBorder, yBorder = m.getSize()
  17.  
  18. items = { }
  19.  
  20. function clearscreen()
  21.     m.clear()
  22.     m.setCursorPos(1, 1)
  23. end
  24.  
  25. function cursormovex()
  26.     x, y = m.getCursorPos()
  27.     x = x + 1
  28.     m.setCursorPos(x, y)
  29. end
  30.  
  31. function cursormovey()
  32.     x, y = m.getCursorPos()
  33.     y = y + 1
  34.     m.setCursorPos(x, y)
  35. end
  36.  
  37. function getcursor()
  38.     x, y = m.getCursorPos()
  39. end
  40.  
  41. function nextline()
  42.     y = y + 1
  43.     m.setCursorPos(x, y)
  44. end
  45.  
  46. function saveCursor()
  47.     a = x
  48.     b = y
  49. end
  50.  
  51. function restoreCursor()
  52.     x = a
  53.     y = b
  54. end
  55.  
  56. -----------------------------
  57.  
  58. function writetoTable(Table)
  59.     if Table[itemName] == nil then
  60.         Table[itemName] = 0
  61.     end
  62.     Table[itemName] = Table[itemName] + itemCount
  63. end
  64.  
  65. function split(s, delimiter)
  66.     result = {};
  67.     for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  68.         table.insert(result, match);
  69.     end
  70.     return result;
  71. end
  72.  
  73. function split2(s, delimiter)
  74.     results2 = {};
  75.     for match2 in (s..delimiter):gmatch("(.-)"..delimiter) do
  76.         table.insert(results2, match2);
  77.     end
  78.     return results2;
  79. end
  80.  
  81. function spairs(t, order)
  82.     local keys = {}
  83.     for k in pairs(t) do keys[#keys+1] = k end
  84.  
  85.     if order then
  86.         table.sort(keys, function(a,b) return order(t, a, b) end)
  87.     else
  88.         table.sort(keys)
  89.     end
  90.  
  91.     local i = 0
  92.     return function()
  93.         i = i + 1
  94.         if keys[i] then
  95.             return keys[i], t[keys[i]]
  96.         end
  97.     end
  98. end
  99.  
  100. function calcAll()
  101.     allItems = 0
  102.     for k, v in pairs(items) do
  103.         if k then
  104.             allItems = allItems + v
  105.         end
  106.     end
  107. end
  108.  
  109. function receive()
  110.         senderID, message, protocol = rednet.receive()
  111.         split(message, " ")
  112.         itemName = tostring(result[1])
  113.         itemCount= tonumber(result[2])
  114.         meta = tonumber(result[3])
  115.         itemName = string.match(itemName, ":(.*)")
  116.         if itemName == "ender_pearl" then itemName = "ender pearl" end
  117.         if itemName == "block_enderman_skull" then itemName = "enderman head" end
  118.         if itemName == "item_item_conduit" then itemName = "item conduit" end
  119.         if itemName == "item_extract_speed_upgrade" then itemName = "enderIO speed upgrade" end
  120.         if itemName == "mob_ingredient" and meta == 11 then itemName = "nebulous heart" end
  121.         if itemName == "mob_ingredient" and meta == 0 then itemName = "rib bone" end
  122.         if itemName == "mob_ingredient" and meta == 1 then itemName = "withered rip" end
  123.         if itemName == "mob_ingredient" and meta == 2 then itemName = "chelicerae" end
  124.         if itemName == "mob_ingredient" and meta == 3 then itemName = "catalyzing gland" end
  125.         if itemName == "mob_ingredient" and meta == 6 then itemName = "zombie heart" end
  126.         if itemName == "mob_ingredient" and meta == 7 then itemName = "molten core" end
  127.         if itemName == "stone" and meta == 5 then itemName = "andesite" end
  128.         if itemName == "stone" and meta == 1 then itemName = "granite" end
  129.         if itemName == "stone" and meta == 3 then itemName = "diorite" end
  130.         if itemName == "dye" and meta == 0 then itemName = "ink sac" end
  131.         if itemName == "dye" and meta == 4 then itemName = "lapis lazuli" end
  132.         if itemName == "log" and meta == 0 then itemName = "oak wood" end
  133.         if itemName == "beecomb" and meta == 13 then itemName = "watery comb" end
  134.         if itemName == "bee_combs" and meta == 5 then itemName = "dripping comb" end
  135.         if itemName == "bee_combs" and meta == 2 then itemName = "simmering comb" end
  136.         if itemName == "bee_combs" and meta == 16 then itemName = "mellow comb" end
  137.         if itemName == "bee_combs" and meta == 0 then itemName = "honey comb" end
  138.         if itemName == "bee_combs" and meta == 7 then itemName = "parched comb" end
  139.         if itemName == "honey_comb" and meta == 52 then itemName = "emerald comb" end
  140.         if itemName == "honey_comb" and meta == 11 then itemName = "rocky comb" end
  141.         if itemName == "wax" and meta == 0 then itemName = "magic wax" end
  142.         if itemName == "material" and meta == 0 then itemName = "bitumen" end
  143.         if itemName == "material" and meta == 771 then itemName = "sulfur" end
  144.         if itemName == "material" and meta == 865 then itemName = "rich slag" end
  145.         if itemName == "material" and meta == 866 then itemName = "cinnabar" end
  146.         if itemName == "material" and meta == 128 then itemName = "copper ingot" end
  147.         if itemName == "material" and meta == 129 then itemName = "tin ingot" end
  148.         if itemName == "material" and meta == 130 then itemName = "silver ingot" end
  149.         if itemName == "material" and meta == 131 then itemName = "lead ingot" end
  150.         if itemName == "material" and meta == 132 then itemName = "aluminium ingot" end
  151.         if itemName == "material" and meta == 133 then itemName = "nickel ingot" end
  152.         if itemName == "material" and meta == 134 then itemName = "plat ingot" end
  153.         if itemName == "material" and meta == 135 then itemName = "iridium ingot" end
  154.         if itemName == "item_material" and meta == 20 then itemName = "infinity grain" end
  155.         if itemName == "item_solidified_experience" then itemName = "solid exp" end
  156.         writetoTable(items)
  157.         --calcAll()
  158.         --writeScreen()
  159.         --print(itemName, itemCount)
  160. end
  161.  
  162. function writeScreen()
  163.  
  164.     for k,v in spairs(items, function(t,a,b) return t[b] < t[a] end) do
  165.         perSec = (v / zeituptime) * 60
  166.         --fullperc = v / allItems * 100
  167.         getcursor()
  168.         if x == 1 then
  169.             m.clearLine()
  170.         end
  171.         forcePosition()
  172.         saveCursor()
  173.         m.setTextColor(8192)
  174.         m.setBackgroundColor(128)
  175.         m.write(k)
  176.         restoreCursor()
  177.         nextline()
  178.         saveCursor()
  179.         m.setTextColor(128)
  180.         m.setBackgroundColor(32768)
  181.         m.write("[" ..v.. "]- ".. math.floor(perSec) .."/m" )
  182.         --m.write("[" ..v.. "]-" .. math.floor(fullperc * 10 ) / 10 .. "%-".. perMin .."/m" )
  183.         restoreCursor()
  184.         nextline()
  185.     end
  186.     m.setCursorPos(1, 1)
  187. end
  188.  
  189. function writeSelection(argus)
  190.     if wantedItem == "abcomg" then
  191.         m.clear()
  192.         m.write("Input search in terminal")
  193.     end
  194.     for k,v in spairs(items, function(t,a,b) return t[b] < t[a] end) do
  195.  
  196.     for i=1, 5 do
  197.         if results2[i] ~= nil then
  198.         possibleitems = tostring(results2[i])
  199.         if string.find(k, possibleitems) then
  200.         --print(k)
  201.        
  202.        
  203.             perSec = (v / zeituptime) * 60
  204.             --fullperc = v / allItems * 100
  205.             getcursor()
  206.             if x == 1 then
  207.                 m.clearLine()
  208.             end
  209.             forcePosition()
  210.             saveCursor()
  211.             m.setTextColor(1)
  212.             m.setBackgroundColor(128)
  213.             m.write(k)
  214.             restoreCursor()
  215.             nextline()
  216.             saveCursor()
  217.             m.setTextColor(8192)
  218.             m.setBackgroundColor(32768)
  219.             m.write("[" ..v.. "]- ".. math.floor(perSec) .."/m" )
  220.             restoreCursor()
  221.             nextline()
  222.         end
  223.         end
  224.         end
  225.     end
  226.     m.setCursorPos(1, 1)
  227. end
  228.  
  229.  
  230.  
  231.  
  232.  
  233. function forcePosition()
  234.     --print("y", y, "x", x)
  235.     if y > (yBorder - 4) and x == 1 then
  236.         m.setCursorPos(33, 1)
  237.         getcursor()
  238.     end
  239.     if y > (yBorder - 4) and x == 33 then
  240.         m.setCursorPos(67, 1)
  241.         getcursor()
  242.     end
  243.     if y > (yBorder - 4) and x == 67 then
  244.         m.setCursorPos(200, 1)
  245.         getcursor()
  246.     end
  247. end
  248.  
  249.  
  250.        
  251. function reboot()
  252.     getcursor()
  253.     m.setCursorPos(93, 51)
  254.     m.setBackgroundColor(16384)
  255.     m.setTextColor(32768)
  256.     m.write(" Reboot ")
  257.     m.setBackgroundColor(32768)
  258.     m.setCursorPos(93, 52)
  259.     m.setBackgroundColor(16384)
  260.     m.setTextColor(32768)
  261.     m.write("        ")
  262.     m.setBackgroundColor(32768)
  263.     m.setTextColor(32)
  264.     m.setCursorPos(x, y)
  265. end
  266.  
  267. function searchmode()
  268. if showall == true then
  269.     getcursor()
  270.     m.clear()
  271.     m.setCursorPos(1, 51)
  272.     m.setBackgroundColor(2)
  273.     m.setTextColor(32768)
  274.     m.write(" Search ")
  275.     m.setBackgroundColor(32768)
  276.     m.setCursorPos(1, 52)
  277.     m.setBackgroundColor(2)
  278.     m.setTextColor(32768)
  279.     m.write(" Mode   ")
  280.     m.setBackgroundColor(32768)
  281.     m.setTextColor(32)
  282.     m.setCursorPos(x, y)
  283. else
  284.     getcursor()
  285.     m.clear()
  286.     m.setCursorPos(1, 51)
  287.     m.setBackgroundColor(32)
  288.     m.setTextColor(32768)
  289.     m.write(" Show  ")
  290.     m.setBackgroundColor(32768)
  291.     m.setTextColor(16)
  292.     m.write(" Current")
  293.     m.setCursorPos(1, 52)
  294.     m.setBackgroundColor(32)
  295.     m.setTextColor(32768)
  296.     m.write(" All   ")
  297.     m.setBackgroundColor(32768)
  298.     m.setTextColor(16)
  299.     m.write(" search:")
  300.     for i=1, 5 do
  301.         if results2[i] ~= nil then
  302.             m.write(" [" ..results2[i].."]")
  303.         end
  304.     end
  305.     m.setCursorPos(x, y)
  306.        
  307. end
  308. end
  309.  
  310. function getMonitorTouch()
  311.     event, side, xPos, yPos = os.pullEvent("monitor_touch")
  312.     getcursor()
  313.     --reboot button
  314.     if (xPos >= 93) and (yPos >= 49) then
  315.         os.reboot()
  316.     end
  317.     --search button
  318.     if (xPos >= 1) and (xPos < 10) and (yPos >= 49) then
  319.         if showall == true then
  320.             showall = false
  321.             searchmode()
  322.             reboot()
  323.         elseif showall == false then
  324.             showall = true
  325.             searchmode()
  326.             reboot()
  327.         end
  328.     end
  329. end
  330.  
  331. function uptime()
  332.     while true do
  333.     if showall == true then
  334.         writeScreen()
  335.     else
  336.         writeSelection(wantedItem)
  337.         --print(wantedItem)
  338.     end
  339.     zeituptime = os.clock()
  340.     --print(zeituptime)
  341.     minutesu = math.floor(zeituptime / 60)
  342.     hoursu = math.floor(minutesu / 60)
  343.     secondsu = math.floor(zeituptime - minutesu * 60)
  344.     displayminutes = math.floor(minutesu - hoursu * 60)
  345.     getcursor()
  346.     m.setCursorPos(76, 51)
  347.     m.setTextColor(1)
  348.     m.write("Computer uptime:")
  349.     m.setCursorPos(81, 52)
  350.     m.write(hoursu.. "h" ..displayminutes.. "m" ..secondsu.."s")
  351.     m.setCursorPos(x, y)
  352.     sleep(1)
  353.     searchmode()
  354.     reboot()
  355.     --print(items["ender pearl"])
  356.     end
  357. end
  358.  
  359. function takeinput()
  360.     --print("Input search: ")
  361.     --term.setCursorPos(1, 2)
  362.     term.setCursorBlink(false)
  363.     wantedItem = read()
  364.     showall = false
  365.     searchmode()
  366.     term.setCursorBlink(false)
  367.     term.clear()
  368.     term.setCursorPos(1, 1)
  369.     split2(wantedItem, " ")
  370.     searchmode()
  371.     reboot()
  372. end
  373.  
  374. showall = true
  375.  
  376.  
  377.  
  378. reboot()
  379.  
  380.  
  381. while true do
  382. parallel.waitForAny(receive, getMonitorTouch, uptime, takeinput)
  383. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement