Diamssword

[CC] ME stock maintener

Dec 17th, 2020 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. me = peripheral.wrap("left")
  2. c1= peripheral.wrap("top")
  3. c2= peripheral.wrap("bottom")
  4. mon = peripheral.wrap("right")
  5. index=0;
  6. craftingjobs = {}
  7. function checkCrafting(item,nbToCraft)
  8.  
  9. found =me.findItem(item)
  10.  
  11. if(found ~= nil) then
  12. flag = true
  13. count=found.getMetadata().count
  14. for k,v in pairs(craftingjobs) do
  15. if(item.name == v.item.id and item.damage == v.item.damage) then
  16. flag= false
  17. break
  18. end
  19. end
  20. if(count<nbToCraft and flag ) then
  21. table.insert(craftingjobs,{craft=found.craft(nbToCraft-count),item={id=found.getMetadata().name,damage = found.getMetadata().damage,name=found.getMetadata().displayName,count=nbToCraft-count}})
  22. end
  23. end
  24.  
  25. end
  26. local currenthour =-1
  27. local tickNumbers =0
  28. function getTime()
  29. if(currenthour ==-1 or tickNumbers >=600) then
  30. local c = http.get("http://worldclockapi.com/api/json/utc/now")
  31. tickNumbers=0
  32. if(c ~= nil) then
  33. jsonbj=textutils.unserialiseJSON(c.readAll())
  34. local s =jsonbj.currentDateTime
  35. local strc=string.sub(s,string.find(s, "T%d%d"))
  36. strc =string.sub(strc,string.find(strc, "%d%d"))
  37. local nb = tonumber(strc)
  38. currenthour = nb+1
  39. return currenthour
  40. end
  41. end
  42. tickNumbers=tickNumbers+1
  43. return currenthour
  44. end
  45. while true do
  46. for k,v in pairs(c1.list()) do
  47. local count = v.count
  48. if(v.count ==1) then
  49. count =64
  50. end
  51. checkCrafting(v,count);
  52. end
  53. if(getTime() >=19) then
  54. for k,v in pairs(c2.list()) do
  55. print(v.count)
  56. checkCrafting(v,v.count);
  57. end
  58. end
  59. mon.clear()
  60. mon.setTextScale(0.5)
  61. if(#craftingjobs >=1) then
  62. if(index > #craftingjobs) then
  63. index=1
  64. end
  65.  
  66. mon.setCursorPos(1,1)
  67. elem = craftingjobs[index];
  68. if(elem ~= nil) then
  69. mon.write("Crafting:")
  70. mon.setCursorPos(1,2)
  71. mon.write(elem.item.name)
  72. mon.setCursorPos(1,3)
  73. mon.write(elem.item.count)
  74.  
  75. if(elem.craft.isFinished() == true or elem.craft.isCanceled() == true) then
  76. table.remove(craftingjobs,index)
  77. end
  78. end
  79. else
  80.  
  81. mon.setCursorPos(1,2)
  82. mon.write("ALL")
  83. mon.setCursorPos(3,4)
  84. mon.write("CLEAR")
  85. end
  86. index=index+1
  87. sleep(1)
  88. end
Add Comment
Please, Sign In to add comment