Jayex_Designs

atmFront

Jun 20th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. rednet.open("right")
  2.  
  3. SLOT_COUNT = 16
  4. SendersId = nil
  5.  
  6. Prices = {
  7.     ["minecraft:iron_ingot"] = 1,
  8.     ["minecraft:iron_block"] = 10,
  9.     ["minecraft:diamond"] = 14,
  10.     ["minecraft:netherite_scrap"] = 144
  11. }
  12.  
  13.  
  14.  
  15. while true do
  16.     local function suckItems()
  17.         while true do
  18.             if SendersId then
  19.                 if turtle.suckUp() then
  20.                     local balance = 0
  21.                     for i = 1, SLOT_COUNT, 1 do
  22.                         turtle.select(i)
  23.                         local item = turtle.getItemDetail()
  24.  
  25.                         if item then
  26.                             if Prices[item["name"]] then
  27.                                 balance = balance + Prices[item["name"]] * item["count"]
  28.                                 turtle.dropDown()
  29.  
  30.                             else
  31.                                 turtle.dropUp()
  32.                             end
  33.                         end
  34.                     end
  35.                     turtle.select(1)
  36.                     rednet.send(SendersId, balance, "balanceUpdate")
  37.                 end
  38.             end
  39.  
  40.             sleep(0.2)
  41.         end
  42.     end
  43.  
  44.     local function waitForRequests()
  45.         while true do
  46.             local id, message, protocol = rednet.receive()
  47.             if protocol == "userLogged" then
  48.                 if not message then
  49.                     SendersId = nil
  50.                 elseif message then
  51.                     SendersId = id
  52.                 end
  53.             end
  54.         end
  55.     end
  56.  
  57.     parallel.waitForAny(suckItems, waitForRequests)
  58. end
Advertisement
Add Comment
Please, Sign In to add comment