Advertisement
Guest User

mine

a guest
Jul 2nd, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.68 KB | None | 0 0
  1. os.loadAPI("button")
  2. c1 = peripheral.wrap("container_chest_0")
  3. m = peripheral.wrap("top")
  4. m.clear()
  5. os.startTimer(1)
  6. rednet.open("right")
  7. message = "nothing"
  8.  
  9. function prep()
  10.   m.clear()
  11.   m.setCursorPos(22,14)
  12.   m.write("Counting")
  13.   for i = 2,49 do
  14.     m.setCursorPos(i,15)
  15.     m.write("_")
  16.   end
  17.   for i = 2,49 do
  18.     m.setCursorPos(i,17)
  19.     m.write("-")
  20.   end
  21.   m.setCursorPos(1,16)
  22.   m.write("|")
  23.   m.setCursorPos(50,16)
  24.   m.write("|")
  25. end
  26.  
  27. function centerText(text, SQ)
  28.   m.setBackgroundColor(colors.black)
  29.   m.setTextColor(colors.white)
  30.   length = string.len(text)
  31.   x = 2
  32.   x2 = 48
  33.   y = 16
  34.   y2 = 16
  35.   Start = 48-2-length
  36.   Middle = math.floor(Start/2)
  37.   m.setCursorPos(3+Middle, 16)
  38.   if SQ == Middle+3 or SQ > Middle+3 then
  39.     m.setBackgroundColor(colors.green)
  40.   elseif SQ < Middle+3 then
  41.     m.setBackgroundColor(colors.black)
  42.   end
  43.   m.write(text)
  44.   m.setBackgroundColor(colors.black)
  45. end
  46.  
  47. function sort()
  48.   prep()
  49.   Overall = 0
  50.   for i = 1,27 do
  51.     if c1.getStackInSlot(i) then
  52.       data = c1.getStackInSlot(i)
  53.       num = data.qty
  54.       print(num)
  55.       Overall = Overall+num
  56.     end
  57.   end
  58.   ItemsLeft = 0
  59.   rednet.send(7,"Let's Do It!")
  60.   IronOre = 0
  61.   GoldOre = 0
  62.   SilverOre = 0
  63.   Diamond = 0
  64.   LeadOre = 0
  65.   CopperOre = 0
  66.   TinOre = 0
  67.   Coal = 0
  68.   Lapis = 0
  69.   FerrousOre = 0
  70.   AluminumOre = 0
  71.   Redstone = 0
  72.   while message ~= "done" do
  73.     event,id,message = os.pullEvent("rednet_message")
  74.     print("message Received")
  75.     print(message)
  76.     if message == "count" then
  77.       event,id,message = os.pullEvent("rednet_message")
  78.         ItemsLeft = ItemsLeft + message
  79.         Per = ItemsLeft/Overall
  80.         Squares = Per*48
  81.         Squares = math.floor(Squares)
  82.         if Squares == 0 then
  83.           SendText = ItemsLeft.."/"..Overall
  84.           centerText(SendText, Squares)
  85.         end
  86.         for i = 1,Squares do
  87.           m.setCursorPos(1,16)
  88.           --m.clearLine()
  89.           m.write("|")
  90.           m.setCursorPos(50,16)
  91.           m.write("|")
  92.           m.setCursorPos(1+i,16)
  93.           m.setBackgroundColor(colors.green)
  94.           m.write(" ")
  95.           m.setBackgroundColor(colors.black)
  96.           SendText = ItemsLeft.."/"..Overall
  97.           centerText(SendText, Squares)
  98.         end
  99.         if N == "Iron Ore" then
  100.           IronOre = IronOre + message
  101.         elseif N == "Gold Ore" then
  102.           GoldOre = GoldOre + message
  103.         elseif N == "Copper Ore" then
  104.           CopperOre = CopperOre + message
  105.         elseif N == "Tin Ore" then
  106.           TinOre = TinOre + message
  107.         elseif N == "Silver Ore" then
  108.           SilverOre = SilverOre + message
  109.         elseif N == "Lead Ore" then
  110.           LeadOre = LeadOre + message
  111.         elseif N == "Ferrous Ore" then
  112.           FerrousOre = FerrousOre + message
  113.         elseif N == "Redstone" then
  114.           Redstone = Redstone + message
  115.         elseif N == "Coal" then
  116.           Coal = Coal + message
  117.         end
  118.       c1.condenseItems()
  119.     elseif message == "prepare" then
  120.       data = c1.getStackInSlot(1)
  121.       N = data.display_name
  122.       print(N)
  123.     end
  124.   end
  125. end
  126.  
  127. function fillTable()
  128.   button.setTable("Process",P,1,50,12,15)
  129.   button.screen()
  130. end
  131.  
  132. function P()
  133.   button.clearTable()
  134.   sort()
  135. end
  136.  
  137. function getClick()
  138.   event = {os.pullEvent()}
  139.   if event[1] == "timer" and event[2] == timeout then
  140.     os.startTimer(1)
  141.   elseif event[1] == "rednet_message" then
  142.     message = event[3]
  143.   elseif event[1] == "monitor_touch" then
  144.     x = event[3]
  145.     y = event[4]
  146.     button.checkxy(x,y)
  147.   end
  148. end
  149.  
  150. function setup()
  151.   fillTable()
  152.   button.heading("Nesie Processing System")
  153. end
  154.  
  155. setup()
  156. while true do
  157.   getClick()
  158. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement