Guest User

control

a guest
Nov 17th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1.  
  2. local input = peripheral.wrap("front")
  3. or error("Unable to wrap input chest!",0)
  4. local output = peripheral.wrap("bottom")
  5. or error("Unable to wrap output chest!",0)
  6.  
  7. local signal = "back"
  8. -- side of the redstone torch
  9.  
  10. local inputslot = 1
  11. local fuelslot = 2
  12. local outputslot = 3
  13. -- slots inside furnace inv
  14.  
  15. local fuel = {
  16.   -- {id=number,dmg=number,burn=number}
  17.   -- burn = burntime, how many items
  18.   -- the fuel can burn.
  19.   -- ex: coal/charcoal burns 8
  20.   -- and wood burns 1.5
  21.   {id=263,dmg=0,burn=8},--coal
  22.   {id=263,dmg=1,burn=8},--charcoal
  23.   --{id=5,dmg=-1,burn=1.5},--planks
  24.   --{id=17,dmg=-1,burn=1.5},--wood
  25.   --{id=6,dmg=-1,burn=.5},--sapling
  26.   --{id=280,dmg=0,burn=.5},--stick
  27. }
  28.  
  29. local furnaceToOutput = "west"
  30. local inputToFurnace = "down"
  31. local inputSlot = 1
  32. local outputSlot = 3
  33.  
  34. -- returns statement,fuel
  35. -- statement = boolean
  36. -- fuel = table
  37. local function isFuel(item)
  38.   for _,fuel in pairs(fuel) do
  39.     if item.id == fuel.id
  40.     and (item.dmg == fuel.dmg
  41.     or fuel.dmg == -1) then
  42.       return true,fuel
  43.     end
  44.   end
  45.   return false
  46. end
  47.  
  48. -- returns slot,fuel,item
  49. local function findFuel()
  50.   local items = input.getAllStacks()
  51.   for slot,item in pairs(items) do
  52.     local state,fuel = isFuel(item)
  53.     if state then
  54.       return slot,fuel
  55.     end
  56.   end
  57. end
  58.  
  59. -- returns slot,item
  60. local function findItem()
  61.   local slot,fuel = findFuel()
  62.   if slot and fuel then
  63.     local items = input.getAllStacks()
  64.     for slot,item in pairs(items) do
  65.       local state = isFuel(item)
  66.       if not state then
  67.         if item.qty >= fuel.burn then
  68.           return slot,item
  69.         end
  70.       end
  71.     end
  72.   end
  73. end
  74.  
  75. local function emptyFurnace()
  76.   output.pullItem("east",outputslot,64)
  77. end
  78.  
  79. local function cook()
  80.   -- if furnace is empty
  81.   if rs.getInput(signal) == false then
  82.     -- get fuel and item
  83.     local fuelslot,fuel,fueli = findFuel()
  84.     local itemslot,item = findItem()
  85.    
  86.     -- no fuel/item found: cancel out
  87.     if not fuel then return end
  88.     if not item then return end
  89.    
  90.     -- # items to move
  91.     local fuelmove = math.floor(item.qty/fuel.burn)
  92.     local itemmove = item.qty-(item.qty%fuel.burn)
  93.    
  94.     -- move items
  95.     input.pushItemIntoSlot("down",fuelslot,fuelmove,fuelslot)
  96.     input.pushItemIntoSlot("down",itemslot,itemmove,inputslot)
  97.   end
  98. end
  99.  
  100. cook()
Advertisement
Add Comment
Please, Sign In to add comment