Advertisement
DuckStrom

Computercraft Extractor Extractor

Nov 14th, 2016
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.94 KB | None | 0 0
  1. -- Transfers compatible ores from ME system, to
  2. -- extractor, and returns flakes to ME system.
  3.  
  4. -- Usage: Place on ME interface on extractor,
  5. -- configure the two vars below, and start.
  6.  
  7. -- Direction of extractor relative to interface
  8. ex_dir = "down"
  9. -- limit of ores per type to do in a row
  10. limit_per_type = 256
  11.  
  12. me = peripheral.find("tileinterface")
  13. curr = nil
  14.  
  15. -- List of ores with block name stored as key, and extractable metadatas as values
  16. o = {
  17.   ["minecraft:iron_ore"]={0},
  18.   ["minecraft:gold_ore"]={0},
  19.   ["minecraft:coal_ore"]={0},
  20.   ["minecraft:redstone_ore"]={0},
  21.   ["minecraft:lapis_ore"]={0},
  22.   ["minecraft:diamond_ore"]={0},
  23.   ["minecraft:emerald_ore"]={0},
  24.   ["minecraft:quartz_ore"]={0},
  25.   ["IC2:blockOreTin"]={0},
  26.   ["IC2:blockOreCopper"]={0},
  27.   ["IC2:blockOreLead"]={0},
  28.   ["IC2:blockOreUran"]={0},
  29.   ["DraconicEvolution:draconiumOre"]={0},
  30.   ["Railcraft:ore"]={0,1,2,3,4,5},
  31.   ["ThermalFoundation:Ore"]={0,1,2,3,4,5,6},
  32.   ["TConstruct:GravelOre"]={0,1,2,3,4,5},
  33.   ["TConstruct:SearedBrick"]={1,2,3,4,5},
  34.   ["Forestry:resources"]={0,1,2},
  35.   ["Metallurgy:base.ore"]={0,1,2},
  36.   ["Metallurgy:precious.ore"]={0,1,2},
  37.   ["Metallurgy:utility.ore"]={0,2},
  38.   ["ReactorCraft:reactorcraft_block_ore"]={1,2,3,4,5,6,7,8,9},
  39.   ["ReactorCraft:reactorcraft_block_fluoriteore"]={0,1,2,3,4,5,6,7},
  40.   ["ElectriCraft:electricraft_block_ore"]={0,1,2,3,4,5},
  41.   ["Thaumcraft:blockCustomOre"]={0,1,2,3,4,5,6,7},
  42.   ["appliedenergistics2:tile.OreQuartz"]={0},
  43.   ["libVulpes:libVulpesore0"]={0,4,5,8,9},
  44.   ["Mekanism:OreBlock"]={0,1,2},
  45.   ["BiomesOPlenty:gemOre"]={2,4,12,14},
  46.   ["ProjRed|Exploration:projectred.exploration.ore"]={0,1,2,3,4,5,6},
  47.   ["Mimicry:Sparr_Mimichite Ore"]={0,1,2},
  48.   ["ImmersiveEngineering:ore"]={0,1,2,3,4}
  49. }
  50.  
  51. function isOre(name,ID)
  52.   if o[name] ~= nil then
  53.     for k,v in ipairs(o[name]) do
  54.       if v == ID then
  55.         return true
  56.       end
  57.     end
  58.   end
  59.   return false
  60. end
  61.  
  62. function extractFlakes()
  63.   ct = me.pullItem("down",8,64)
  64.   ct = ct + me.pullItem("down",9,64)
  65.   return ct
  66. end
  67.  
  68. function mainLoop()
  69.   no_ore = 0
  70.   while true do
  71.     no_ore = no_ore + 1
  72.     inv = me.getAvailableItems()
  73.     if inv[1] ~= nil then
  74.       for k,v in ipairs(inv) do
  75.         if isOre(v.fingerprint.id, v.fingerprint.dmg) then
  76.           no_ore = 0
  77.           print("Extracting ore " .. v.fingerprint.id .. ":" .. v.fingerprint.dmg)
  78.           curr = v
  79.           remaining = v.size < limit_per_type and v.size or limit_per_type
  80.           while remaining > 0 do
  81.             extractFlakes()
  82.             pc, results = pcall(me.exportItem, v.fingerprint, "down", remaining > 64 and 64 or remaining)
  83.             if pc == true then
  84.               remaining = remaining - results.size
  85.               sleep(1)
  86.             else
  87.               remaining = 0
  88.             end
  89.           end
  90.           v = nil
  91.         end -- if isOre()
  92.       end --  for k,v in ipairs(inv) do
  93.     end --  if inv[1] ~= nil then
  94.     if (no_ore > 0) then -- hack to make sure flakes get extracted fully
  95.       ex_rem = 2
  96.       while (ex_rem > 1) do
  97.         ex_rem = ex_rem + extractFlakes()
  98.         ex_rem = ex_rem / 2
  99.         -- print("ex_rem: " .. ex_rem)
  100.         sleep(2)
  101.       end
  102.     end
  103.     sleep(no_ore > 0 and math.min(math.pow(2,no_ore),32) or 0)
  104.   end -- while true do
  105. end
  106.  
  107. function skipLoop()
  108.   while true do
  109.     event, key = os.pullEvent("key")
  110.       if key == keys.enter then
  111.         if curr ~= nil then
  112.           print("Skipping " .. curr.fingerprint.id .. ":" .. curr.fingerprint.dmg)
  113.           remaining = 0
  114.         else
  115.           print("Nothing to skip")
  116.         end
  117.       end
  118.    end
  119. end
  120.  
  121. extractFlakes()
  122. parallel.waitForAll(mainLoop,skipLoop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement