Advertisement
nagoL2015

hopperVert.lua

Jul 26th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. modem1 = 6565
  2. modem2 = 6566
  3. modem3 = 6567
  4. modem4 = 6568
  5.  
  6. local channel = 3000
  7.  
  8. if fs.exists(".channel") then
  9.     local f = fs.open(".channel","r")
  10.     local n = f.readLine()
  11.     if not tonumber(n) then error("contents of .channel is not a number") end
  12.     channel = tonumber(n)
  13.     f.close()
  14. end
  15.  
  16. os.setComputerLabel("Hopper [VERT] | "..channel)
  17.  
  18. local modems = {peripheral.find("modem")}
  19.  
  20. if #modems == 0 then error("no modems attached") end
  21. local modem = modems[1]
  22.  
  23. modem.open(channel)
  24.  
  25. while turtle.up() do end
  26.  
  27. function normalOperation()
  28.     while true do
  29.         local e,side,chnl,rChnl,msg,dist = os.pullEvent("modem_message")
  30.         if chnl == channel then
  31.             while turtle.down() do end
  32.            
  33.             local b,insp = turtle.inspectDown()
  34.             if b and (insp.name == "minecraft:chest" or insp.name == "minecraft:trapped_chest") then
  35.                 while turtle.suckDown() and turtle.getItemCount(16) == 0 do turtle.select(1) end
  36.             end
  37.            
  38.             while turtle.up() do end
  39.             for slot = 1,16 do
  40.                 if turtle.getItemCount(slot) ~= 0 then
  41.                     turtle.select(slot)
  42.                     turtle.dropUp()
  43.                 end
  44.             end
  45.         end
  46.     end
  47. end
  48.  
  49. function modemListener()
  50.     while true do
  51.         local e,side,chnl,rChnl,msg,dist = os.pullEvent("modem_message")
  52.         if chnl == modem1 then
  53.             local x,y,z = gps.locate()
  54.            
  55.             local inv = {}
  56.            
  57.             for slot = 1,16 do
  58.                 local detail = turtle.getItemDetail(slot)
  59.                 if detail == nil then
  60.                     inv[slot] = {}
  61.                 else
  62.                     inv[slot] = detail
  63.                 end
  64.             end
  65.            
  66.             modem.transmit(rChnl,chnl,{type="infoHopperResponse",fuel=turtle.getFuelLevel(),location={x=x,y=y,z=z},inventory=inv,channel=channel})
  67.             print("Sent info")
  68.         end
  69.     end
  70. end
  71.  
  72. modem.open(modem1)
  73. parallel.waitForAny(normalOperation,modemListener)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement