Advertisement
TechManDylan

ShannonRestocker

Feb 5th, 2023 (edited)
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.45 KB | None | 0 0
  1. monitor = peripheral.wrap("top")
  2. monYCount = 1
  3.  
  4. function clean()
  5.   monitor.clear()
  6.   monitor.setCursorPos(1,1)
  7.   term.clear()
  8.   term.setCursorPos(1,1)
  9.   monYCount = monYCount - monYCount + 1
  10. end
  11.  
  12. function printclr(...)
  13.     local colors = {
  14.         ["white"] = colors.white,
  15.         ["orange"] = colors.orange,
  16.         ["magenta"] = colors.magenta,
  17.         ["lightBlue"] = colors.lightBlue,
  18.         ["yellow"] = colors.yellow,
  19.         ["lime"] = colors.lime,
  20.         ["pink"] = colors.pink,
  21.         ["gray"] = colors.gray,
  22.         ["lightGray"] = colors.lightGray,
  23.         ["cyan"] = colors.cyan,
  24.         ["purple"] = colors.purple,
  25.         ["blue"] = colors.blue,
  26.         ["brown"] = colors.brown,
  27.         ["green"] = colors.green,
  28.         ["red"] = colors.red,
  29.         ["black"] = colors.black,
  30.     }
  31.  
  32.     local args = {...}
  33.     for i = 1, #args do
  34.         local arg = args[i]
  35.         if type(arg) == "string" and colors[arg] then
  36.             term.setTextColor(colors[arg])
  37.             monitor.setTextColor(colors[arg])
  38.         else
  39.             write(tostring(arg))
  40.             monitor.write(tostring(arg))
  41.         end
  42.     end
  43.     term.setTextColor(colors.white)
  44.    
  45.     monYCount = monYCount + 2
  46.     monitor.setCursorPos(1, monYCount)
  47.     monitor.setTextColor(colors.white)
  48.     term.setCursorPos(1, monYCount)
  49. end
  50.  
  51.  
  52. function restockVillagers()
  53.   local peripheralNames = {
  54.     "trading_interface_1",
  55.     "trading_interface_2",
  56.     "trading_interface_3",
  57.     "trading_interface_4",
  58.     "trading_interface_5",
  59.     "trading_interface_6",
  60.     "trading_interface_7",
  61.     "trading_interface_8",
  62.     "trading_interface_9",
  63.     "trading_interface_10"
  64.   }
  65.  
  66.   for i, peripheralName in ipairs(peripheralNames) do
  67.     local success, error = pcall(function()
  68.       peripheral.wrap(peripheralName).restock()
  69.     end)
  70.     if not success then
  71.       --error code can go here.
  72.     end
  73.   end
  74. end
  75.  
  76.  
  77. function activeTimer()
  78.   while timeToWait > 0 do
  79.     clean()
  80.     timeToWait = math.floor((timeToWait - 0.1) * 10) / 10
  81.     printclr("white","Redstone ","red", "active")
  82.     printclr("yellow","Restocking trades")
  83.     printclr("gray","Restocking in:","\n")
  84.     --Jank location fix
  85.     monYCount = monYCount - 1
  86.     monitor.setCursorPos(1, monYCount)
  87.     monitor.setTextColor(colors.white)
  88.     term.setCursorPos(1, monYCount)
  89.     printclr("gray",timeToWait,"gray")
  90.     --Jank location fix
  91.     monYCount = monYCount - 2
  92.     monitor.setCursorPos(5, monYCount)
  93.     monitor.setTextColor(colors.white)
  94.     term.setCursorPos(5, monYCount)
  95.     printclr("gray","Seconds","\n")
  96.     sleep(0.1)
  97.   end
  98. end
  99.  
  100. function inactiveTimer()
  101.   while timeToWait > 0 do
  102.     clean()
  103.     timeToWait = math.floor((timeToWait - 0.1) * 10) / 10
  104.     printclr("white","Redstone ","gray", "inactive")
  105.     printclr("yellow","Not restocking trades")
  106.     printclr("gray","Checking for redstone in:","\n")
  107.     --Jank location fix
  108.     monYCount = monYCount - 1
  109.     monitor.setCursorPos(1, monYCount)
  110.     monitor.setTextColor(colors.white)
  111.     term.setCursorPos(1, monYCount)
  112.     printclr("gray",timeToWait,"gray")
  113.     --Jank location fix
  114.     monYCount = monYCount - 2
  115.     monitor.setCursorPos(5, monYCount)
  116.     monitor.setTextColor(colors.white)
  117.     term.setCursorPos(5, monYCount)
  118.     printclr("gray","Seconds","\n")
  119.     sleep(0.1)
  120.   end
  121. end
  122.  
  123.  
  124. while true do
  125.  
  126.   clean()
  127.  
  128.   if redstone.getInput("right") then
  129.  
  130.   restockVillagers()
  131.  
  132.   timeToWait = 5
  133.  
  134.   activeTimer()
  135.  
  136.   else
  137.  
  138.   timeToWait = 5
  139.  
  140.   inactiveTimer()
  141.  
  142.   end
  143. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement