Advertisement
lucifersamfr

smeltery

Jul 4th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. ores = {"iron_", "tin_", "copper_", "lead_", "silver_", "gold_", "platinum_", "nickel_", "aluminum_"}
  2. currentOre = 1
  3.  
  4. function nextOre()
  5.   name = string.lower(ores[currentOre])
  6.   if currentOre == #ores then
  7.     currentOre = 1
  8.   else
  9.     currentOre = currentOre +1
  10.   end
  11.   return name
  12. end
  13.  
  14. function nextOreSlots()
  15.   local ore = nextOre()
  16.   local oreSlots = {}
  17.   print("Looking for "..ore)
  18.   for tSlot=1,16 do
  19.     -- turtle.select(tSlot)
  20.     local details = turtle.getItemDetail(tSlot)
  21.     if details ~= nil then
  22.       name = string.lower(details.name)
  23.       print("--"..name.."--")
  24.       if string.match(name, ore) ~= nil then
  25.         --turtle slot contains active ore
  26.         oreSlots[#oreSlots+1] = tSlot
  27.       end
  28.     end
  29.   end
  30.   return oreSlots
  31. end
  32.  
  33. function dropSlots(oreSlots)
  34.   for i=1,#oreSlots do
  35.     local tSlot = oreSlots[i]
  36.     print("Dropping slot "..tSlot.." in smeltery")
  37.     turtle.select(tSlot)
  38.     turtle.dropUp()
  39.   end
  40. end
  41.  
  42. function hasLiquid(smelter)
  43.   local content = smelter.getInfo().contents
  44.   if not content then
  45.     return false
  46.   else
  47.     local name = content.rawName
  48.     local amount = content.amount
  49.     --print("--found "..name.."("..amount.." mB)")
  50.     return true
  51.   end
  52. end
  53.  
  54. function hasSolid(smelter)
  55.   local size = smelter.getInventorySize()
  56.   for slot=1,size do
  57.     local s = smelter.getStackInSlot(slot)
  58.     if s ~= nil then
  59.       local name = s.name
  60.       --print("--found "..name.." in slot "..slot)
  61.       return true
  62.     end
  63.   end
  64.   return false
  65. end
  66.  
  67. function isSmelterBusy(side)
  68.   local smelter = peripheral.wrap(side)
  69.   local s = hasSolid(smelter)
  70.   local l = hasLiquid(smelter)
  71.   return s or l
  72. end
  73.  
  74. while true do
  75.  
  76.   while isSmelterBusy("top") do
  77.     sleep(1)
  78.   end
  79.  
  80.   dropSlots(nextOreSlots())
  81.  
  82.   sleep(1)
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement