Advertisement
Neon1432

autofurnace_sender

Feb 18th, 2022 (edited)
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. local param = ...
  2. dofile("bs/apis/wrapper")
  3.  
  4.  
  5.  
  6. --initialization
  7.  
  8.  
  9.  
  10. local args = bs.params.load("bs/files/furnace_sender_params")
  11.  
  12. local hook = bs.rdnt.hook:new()
  13. hook.port = args.port
  14. hook.socketID = args.socketID
  15. hook:connect(1)
  16.  
  17. if param == "connect" then
  18.     args.socketID = nil
  19. end
  20.  
  21.  
  22.  
  23. --methods and classes
  24.  
  25.  
  26.  
  27. local function setParams()
  28.     args.socketID = hook.socketID
  29.     local stable = {}
  30.     ui.clear()
  31.     stable.port = ui.getInput("Which name should this connection have?")
  32.     args.port = stable.port
  33.     hook.port = stable.port
  34.     ui.clear()
  35.     stable.count = ui.getInput("How many furnaces are setup?", true)
  36.     args.count = stable.count
  37.     ui.clear()
  38.     stable.inputc = ui.getInput("Name of the Input chest?")
  39.     args.inputc = stable.inputc
  40.     ui.clear()
  41.     stable.outputc = ui.getInput("Name of the chest in front of the turtle?")
  42.     args.outputc = stable.outputc
  43.     ui.clear()
  44.     hook:request("setParams", stable)
  45.     bs.params.save("bs/files/furnace_sender_params", args)
  46. end
  47.  
  48.  
  49.  
  50. local function getTask()
  51.     local ichest = peripheral.wrap(args.inputc)
  52.    
  53.     local function getCount()
  54.         local count = 0
  55.         local list = ichest.list()
  56.         for I = 1, ichest.size do
  57.             if list[I] ~= nil then
  58.                 count = count + list[I].count
  59.             end
  60.         end
  61.         return count
  62.     end
  63.    
  64.     local function refreshText()
  65.         while true do
  66.             ui.clear()
  67.             print(getCount().." items are in the chest, do you want to smelt them?\n\n -Press enter to confirm-")
  68.             os.sleep(1)
  69.         end
  70.     end
  71.    
  72.     local function waitinput()
  73.         repeat
  74.             local _, key = os.pullEvent("key")
  75.         until key == keys.enter
  76.     end
  77.    
  78.     parallel.waitForAny(refreshText, waitinput)
  79.     local fcount = getCount()
  80.    
  81.     ui.clear()
  82.     print("I will need "..fcount / 8.." coal to smelt this\n")
  83.     print("or ".. fcount/ 1.5.." wooden planks\n")
  84. end
  85.  
  86.  
  87. --program start
  88.  
  89.  
  90.  
  91. if args.socketID == nil or args.port == nil then
  92.     hook.port = "autofurnace"
  93.     hook:connect()
  94.     setParams()
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement