Advertisement
Guest User

minecomp

a guest
May 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. local inch = peripheral.wrap("front")
  2. local outch = peripheral.wrap("back")
  3. local overflow = 28
  4. local slots = 54
  5. local block9 = {1, 2, 3, 5, 6, 7, 9, 10, 11}
  6. local block4 = {1, 2, 5, 6}
  7.  
  8. local function craft(chest, pushDir, slot, count, recipe, target)
  9.     print("craft ", pushDir, " ", count, " from ", slot, " to ", target)
  10.     for _, pos in pairs(recipe) do
  11.         chest.pushItem(pushDir, slot, count / #recipe, pos)
  12.     end
  13.     turtle.craft()
  14.     outch.pullItem("north", 1, count / #recipe, target)
  15.     for _, pos in pairs(recipe) do
  16.         for target = overflow, slots do
  17.             count = turtle.getItemCount(pos)
  18.             if count == 0 then
  19.                 break
  20.             end
  21.             outch.pullItem("north", pos, count, target)
  22.         end
  23.     end
  24. end
  25.  
  26. local function compress(slot, stack, item, recipe, offset, stride, levels)
  27.     if stack and stack.display_name == item and stack.qty >= #recipe then
  28.         print("comp ", stack.qty, "x ", item, " from ", slot)
  29.         craft(inch, "south", slot, stack.qty, recipe, offset)
  30.         for level = 0, levels - 2 do
  31.             local pos = offset + level * stride
  32.             stack = outch.getStackInSlot(pos)
  33.             if stack and stack.qty >= #recipe then
  34.                 craft(outch, "north", pos, stack.qty, recipe, pos + stride)
  35.             end
  36.         end
  37.        
  38.     end
  39. end
  40.  
  41. local function dropIdPrefix(slot, stack, item, dir)
  42.     if string.sub(stack.id, 1, string.len(item)) == item then
  43.         print("drop ", stack.qty, "x ", stack.id)
  44.         inch.pushItem("south", slot, stack.qty)
  45.         turtle.dropUp()
  46.     end
  47. end
  48.  
  49. turtle.select(1)
  50. while true do
  51.     inch.condenseItems()
  52.     for slot, stack in pairs(inch.getAllStacks()) do
  53.         stack = stack.all()
  54.         compress(slot, stack, "Cobblestone", block9, 1, 1, 8)
  55.         compress(slot, stack, "Dirt", block9, 10, 1, 8)
  56.         compress(slot, stack, "Gravel", block9, 9, 9, 2)
  57.         compress(slot, stack, "Redstone", block9, 19, 1, 1)
  58.         compress(slot, stack, "Lapis Lazuli", block9, 20, 1, 1)
  59.         compress(slot, stack, "Electrotine", block9, 21, 1, 1)
  60.         compress(slot, stack, "Ruby", block9, 22, 1, 1)
  61.         compress(slot, stack, "Sapphire", block9, 23, 1, 1)
  62.         compress(slot, stack, "Peridot", block9, 24, 1, 1)
  63.         compress(slot, stack, "Diamond", block9, 25, 1, 1)
  64.         compress(slot, stack, "Certus Quartz Crystal", block4, 26, 1, 1)
  65.         compress(slot, stack, "Salt", block9, 27, 1, 1)
  66.         dropIdPrefix(slot, stack, "chisel:")
  67.         dropIdPrefix(slot, stack, "Thaumcraft:")
  68.         dropIdPrefix(slot, stack, "BiomesOPlenty:")
  69.         dropIdPrefix(slot, stack, "Forestry:")
  70.     end
  71.     sleep(1)
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement