ccraftersanonmoose

meautocraft

Mar 6th, 2023
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. ---
  2. --- Made for the Advanced Peripherals documentation - Can be used in production
  3. --- Created by Srendi - https://github.com/SirEndii
  4. --- DateTime: 18.12.2022 04:00
  5. --- Link: https://docs.intelligence-modding.de/1.18/peripherals/me_bridge/
  6. ---
  7.  
  8. label = "Automatic"
  9.  
  10. me = peripheral.find("meBridge") --MeBridge
  11. mon = peripheral.find("monitor") --Monitor
  12.  
  13. --List of the items which should be checked
  14. --Display Name - Technical Name - Minimum Amount
  15. meItems = {
  16. [1] = {"Oak Planks", "minecraft:oak_planks", "180"},
  17. [2] = {"Diorite", "minecraft:polished_diorite", "100"},
  18. [3] = {"Wind Generator", "mekanismgenerators:wind_generator", "20"},
  19. [4] = {"Glass", "minecraft:glass", "500"},
  20. [5] = {"Stick", "minecraft:stick", "100"}
  21. }
  22.  
  23. function checkMe(checkName, name, low)
  24. melist = me.listCraftableItems()
  25. for a = 1, #melist do
  26. size = tostring(melist[a].amount)
  27. ItemName = melist[a].name
  28. --Only craft the items we have in our table
  29. if checkName == ItemName then
  30. row = row + 1
  31. CenterT(name, row, colors.black, colors.lightGray, "left", false)
  32. --Number of items in the system lower than the minimum amount?
  33. if tonumber(size) < tonumber(low) then
  34. --Craft us some delicious items
  35. CenterT(size .. "/" .. low, row, colors.black, colors.red, "right", true)
  36. --If the items is already being crafted - don't start a new crafting job
  37. if not me.isItemCrafting({name = checkName}) then
  38. --Prepare the table for "craftItem"
  39. craftedItem = {name = checkName, count = low - size}
  40. me.craftItem(craftedItem)
  41. print("Crafting some delicious " .. checkName .. " " .. craftedItem.count .. " times")
  42. end
  43. else
  44. --Everything is fine. Print the amount in green
  45. CenterT(size .. "/" .. low, row, colors.black, colors.green, "right", true)
  46. end
  47. end
  48. end
  49. end
  50.  
  51. function checkTable()
  52. row = 2
  53. --Loop through our me items and check if they need to be crafted
  54. for i = 1, #meItems do
  55. checkName = meItems[i][2]
  56. name = meItems[i][1]
  57. low = meItems[i][3]
  58. checkMe(checkName, name, low)
  59. end
  60. end
  61.  
  62. function prepareMonitor()
  63. mon.clear()
  64. CenterT(label, 1, colors.black, colors.white, "head", false)
  65. end
  66.  
  67. --A util method to print text centered on the monitor
  68. function CenterT(text, line, txtback, txtcolor, pos, clear)
  69. monX, monY = mon.getSize()
  70. mon.setTextColor(txtcolor)
  71. length = string.len(text)
  72. dif = math.floor(monX - length)
  73. x = math.floor(dif / 2)
  74.  
  75. if pos == "head" then
  76. mon.setCursorPos(x + 1, line)
  77. mon.write(text)
  78. elseif pos == "left" then
  79. if clear then
  80. clearBox(2, 2 + length, line, line)
  81. end
  82. mon.setCursorPos(2, line)
  83. mon.write(text)
  84. elseif pos == "right" then
  85. if clear then
  86. clearBox(monX - length - 8, monX, line, line)
  87. end
  88. mon.setCursorPos(monX - length, line)
  89. mon.write(text)
  90. end
  91. end
  92.  
  93. --Clear a specific area, prevents flickering
  94. function clearBox(xMin, xMax, yMin, yMax)
  95. mon.setBackgroundColor(colors.black)
  96. for xPos = xMin, xMax, 1 do
  97. for yPos = yMin, yMax do
  98. mon.setCursorPos(xPos, yPos)
  99. mon.write(" ")
  100. end
  101. end
  102. end
  103.  
  104. prepareMonitor()
  105.  
  106. while true do
  107. checkTable()
  108. --Update every 3 seconds
  109. sleep(3)
  110. end
Add Comment
Please, Sign In to add comment