Advertisement
Guest User

fusionCrafting.lua

a guest
Jun 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.55 KB | None | 0 0
  1. local modem = peripheral.wrap('left')
  2.  
  3. turtle.select(1)
  4. local crafting = {}
  5. local tm = {}
  6.  
  7. function tm.fw(number)
  8.     modem.transmit(25, 26, turtle.getFuelLevel())
  9.  
  10.     for i=1,number do
  11.         while not turtle.forward() do
  12.             modem.transmit(27, 28, 'Blocked')
  13.         end
  14.     end
  15. end
  16.  
  17. function tm.bw(number)
  18.     modem.transmit(25, 26, turtle.getFuelLevel())
  19.  
  20.     for i=1,number do
  21.         while not turtle.back() do
  22.             modem.transmit(27, 28, 'Blocked')
  23.         end
  24.     end
  25. end
  26.  
  27. function tm.up(number)
  28.     modem.transmit(25, 26, turtle.getFuelLevel())
  29.  
  30.     for i=1,number do
  31.         while not turtle.up() do
  32.             modem.transmit(27, 28, 'Blocked')
  33.         end
  34.     end
  35. end
  36.  
  37. function tm.down(number)
  38.     modem.transmit(25, 26, turtle.getFuelLevel())
  39.  
  40.     for i=1,number do
  41.         while not turtle.down() do
  42.             modem.transmit(27, 28, 'Blocked')
  43.         end
  44.     end
  45. end
  46.  
  47. function safeDropDown(ammount)
  48.     if ammount == nil then
  49.         ammount = 64
  50.     end
  51.    
  52.     local currentAmmount = turtle.getItemCount()
  53.    
  54.     if currentAmmount < ammount then
  55.         turtle.dropDown()
  56.         turtle.select(turtle.getSelectedSlot() + 1)
  57.         safeDropDown(ammount - currentAmmount)
  58.     else
  59.         turtle.dropDown(ammount)
  60.     end
  61. end
  62.  
  63.  
  64. function crafting.prepare()
  65.     local itemCount = 0
  66.     turtle.transferTo(16)
  67.     turtle.select(turtle.getSelectedSlot() - 1)
  68.     turtle.transferTo(15)
  69.    
  70.     for i=1,14 do
  71.         itemCount = itemCount + turtle.getItemCount(i)
  72.     end
  73.    
  74.     local injectors = ( itemCount - turtle.getItemCount(15) ) / turtle.getItemCount(16)
  75.     return injectors
  76. end
  77.  
  78. function crafting.craft(amount1, amount2)
  79.     local injectors = crafting.prepare()
  80.     local toCraft = amount1
  81.     local injectorsDone = 0
  82.     tm.fw(1)
  83.     tm.down(1)
  84.     tm.fw(2)
  85.     tm.up(1)
  86.     tm.fw(2)
  87.     turtle.turnLeft()
  88.     turtle.select(1)
  89.    
  90.     for i=1,3 do
  91.         for j=1,3 do
  92.             if turtle.getItemCount() == 0 then turtle.select(turtle.getSelectedSlot() + 1) end
  93.             if injectorsDone < injectors then safeDropDown(toCraft) end
  94.             injectorsDone = injectorsDone + 1
  95.             tm.fw(1)
  96.         end
  97.         turtle.turnRight()
  98.         tm.fw(1)
  99.     end
  100.    
  101.     tm.fw(1)
  102.     turtle.turnRight()
  103.     tm.fw(2)
  104.     while turtle.getItemCount() == 0 or turtle.getSelectedSlot() == 15 or turtle.getSelectedSlot() == 16 do turtle.select(turtle.getSelectedSlot() + 1) end
  105.     turtle.dropDown()
  106.     tm.bw(1)
  107.     turtle.turnLeft()
  108.    
  109.     tm.fw(4)
  110.     tm.down(1)
  111.     tm.fw(2)
  112.     tm.up(1)
  113.     tm.fw(1)
  114.     turtle.select(16)
  115.     turtle.drop()
  116.     turtle.select(15)
  117.     turtle.drop()
  118.     turtle.turnRight()
  119.     turtle.turnRight()
  120.     turtle.select(1)
  121. end
  122.  
  123. function crafting.idle()
  124.     local prevCount = 0
  125.     while true do
  126.         for i=1,16 do
  127.             data = turtle.getItemDetail(i)
  128.             if data then
  129.                 if data.name == 'minecraft:stone' then
  130.                 sleep(0.5)
  131.                     if prevCount < data.count then
  132.                         prevCount = data.count
  133.                     elseif data.count == prevCount then
  134.                         turtle.select(i)
  135.                         crafting.craft(data.count, turtle.getItemCount(i - 1))
  136.                         break
  137.                     end
  138.                 end
  139.             end
  140.             modem.transmit(27, 28, 'Waiting')
  141.             modem.transmit(25, 26, turtle.getFuelLevel())
  142.             sleep(0)
  143.         end
  144.     end
  145.     crafting.idle()
  146. end
  147.  
  148. crafting.idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement