Advertisement
Alakazard12

Sort

Nov 5th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. local ihf = peripheral.wrap("front")
  2. local string = peripheral.wrap("top")
  3. local wool = peripheral.wrap("left")
  4.  
  5. turtle.select(1)
  6.  
  7. local function hemp_count()
  8.     local item = ihf.list()[1]
  9.     return item and item.count or 0
  10. end
  11.  
  12. local function step()
  13.     local count = math.floor(math.min(hemp_count(), 64 * 3) / 12) * 4
  14.     if count == 0 then
  15.         print("No hemp available. Waiting..")
  16.         sleep(5)
  17.         return false
  18.     end
  19.     -- Pull hemp in
  20.     ihf.pushItems("north", 1, count, 1)
  21.     ihf.pushItems("north", 1, count, 2)
  22.     ihf.pushItems("north", 1, count, 5)
  23.     while not turtle.craft(count) do
  24.         print("Fix inventory")
  25.         sleep(2)
  26.     end
  27.  
  28.     -- Push to string chest
  29.     repeat
  30.         count = count - string.pullItems("below", 1)
  31.         if count ~= 0 then
  32.             print("Waiting for space in container...")
  33.             sleep(1)
  34.         end
  35.     until count == 0
  36. end
  37.  
  38. local function count_string()
  39.     local amount = 0
  40.     for slot,item in pairs(string.list()) do
  41.         if item.name == "minecraft:string" then
  42.             amount = amount + item.count
  43.         end
  44.     end
  45.     return amount
  46. end
  47.  
  48. local function craft_wool(count)
  49.     local to_slot = 1
  50.     local to_slot_remaining = count
  51.  
  52.     for slot,item in pairs(string.list()) do
  53.         if item.name == "minecraft:string" then
  54.             local to_pull = math.min(to_slot_remaining, item.count)
  55.             string.pushItems("below", slot, to_pull, to_slot)
  56.             to_slot_remaining = to_slot_remaining - to_pull
  57.             if to_slot_remaining == 0 then
  58.                 to_slot = to_slot + 1
  59.                 to_slot_remaining = count
  60.                 if to_slot == 3 then
  61.                     to_slot = 5
  62.                 elseif to_slot == 7 then
  63.                     break
  64.                 end
  65.             end
  66.         end
  67.     end
  68.     if to_slot ~= 7 then
  69.         error("Failed to fill inventory")
  70.     end
  71.  
  72.     while not turtle.craft(count) do
  73.         print("Fix inventory")
  74.         sleep(2)
  75.     end
  76.  
  77.     -- Push to wool container
  78.     repeat
  79.         count = count - wool.pullItems("west", 1)
  80.         if count ~= 0 then
  81.             print("Waiting for space in container...")
  82.             sleep(1)
  83.         end
  84.     until count == 0
  85. end
  86.  
  87.  
  88. while true do
  89.     step()
  90.     if count_string() >= 256 then
  91.         craft_wool(64)
  92.     end
  93.     sleep(0.05)
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement