Mathilde411

turtlekelp.lua

Feb 15th, 2023 (edited)
1,532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.83 KB | None | 0 0
  1. function returnToOrigin()
  2.  
  3.     local inspect, result = turtle.inspect()
  4.     if (inspect and result.name == "minecraft:chest") then
  5.         return
  6.     end
  7.  
  8.     while(not turtle.inspectDown()) do
  9.         turtle.down()
  10.     end
  11.  
  12.     inspect, result = turtle.inspect()
  13.  
  14.     while((not inspect) or result.name ~= "minecraft:smoker") do
  15.         turtle.turnLeft()
  16.         inspect, result = turtle.inspect()
  17.     end
  18.  
  19.     turtle.turnRight()
  20.     inspect, result = turtle.inspect()
  21.  
  22.     while((not inspect) or result.name ~= "minecraft:chest") do
  23.         turtle.forward()
  24.         inspect, result = turtle.inspect()
  25.     end
  26.  
  27. end
  28.  
  29. function craft()
  30.     returnToOrigin()
  31.     local craft = true
  32.     while(craft) do
  33.         turtle.select(1)
  34.         if(turtle.getItemCount(1) < 9) then
  35.             turtle.suckDown()
  36.         end
  37.  
  38.         local items = turtle.getItemCount(1)
  39.         if(items >= 9) then
  40.             local craftedBlocks = math.floor(items/9)
  41.             turtle.transferTo(2, math.max(0, craftedBlocks - turtle.getItemCount(2)))
  42.             turtle.transferTo(3, math.max(0, craftedBlocks - turtle.getItemCount(3)))
  43.             turtle.transferTo(5, math.max(0, craftedBlocks - turtle.getItemCount(5)))
  44.             turtle.transferTo(6, math.max(0, craftedBlocks - turtle.getItemCount(6)))
  45.             turtle.transferTo(7, math.max(0, craftedBlocks - turtle.getItemCount(7)))
  46.             turtle.transferTo(9, math.max(0, craftedBlocks - turtle.getItemCount(9)))
  47.             turtle.transferTo(10, math.max(0, craftedBlocks - turtle.getItemCount(10)))
  48.             turtle.transferTo(11, math.max(0, craftedBlocks - turtle.getItemCount(11)))
  49.  
  50.             turtle.dropDown(turtle.getItemCount(1) - craftedBlocks)
  51.            
  52.             turtle.select(16)
  53.             turtle.craft()
  54.             turtle.drop()
  55.         else
  56.             craft = false
  57.         end
  58.     end
  59.     turtle.select(1)
  60.     turtle.dropDown()
  61. end
  62.  
  63. function refuel()
  64.     returnToOrigin()
  65.     turtle.select(16)
  66.     if(turtle.getFuelLevel() < 50) then
  67.         turtle.suck(1)
  68.         turtle.refuel()
  69.     end
  70. end
  71.  
  72. function distribute()
  73.     returnToOrigin()
  74.     turtle.select(16)
  75.     turtle.suck(32)
  76.  
  77.     turtle.turnLeft()
  78.     local toIdle = true
  79.     local distribute = true
  80.     while(distribute) do
  81.         turtle.suck()
  82.         turtle.drop(3)
  83.         local inspect, result = turtle.inspect()
  84.         toIdle = toIdle and (not result.state.lit)
  85.  
  86.         turtle.turnLeft()
  87.         local inspect, result = turtle.inspect()
  88.  
  89.         if(inspect) then
  90.             distribute = false
  91.             turtle.turnRight()
  92.             turtle.turnRight()
  93.         else
  94.             turtle.forward()
  95.             turtle.turnRight()
  96.         end
  97.     end
  98.  
  99.     local inspect, result = turtle.inspect()
  100.  
  101.     while((not inspect) or result.name ~= "minecraft:chest") do
  102.         turtle.forward()
  103.         inspect, result = turtle.inspect()
  104.     end
  105.  
  106.     turtle.drop()
  107.  
  108.     return toIdle
  109. end
  110.  
  111.  
  112. returnToOrigin()
  113.  
  114. for i = 1,15 do
  115.     turtle.select(i)
  116.     turtle.dropDown()
  117. end
  118. turtle.select(16)
  119. turtle.drop()
  120.  
  121. while(true) do
  122.     craft()
  123.     refuel()
  124.     local idle = distribute()
  125.  
  126.     if(idle) then
  127.         turtle.select(1)
  128.         turtle.suckDown()
  129.         while(not turtle.suckDown()) do
  130.             sleep(10)
  131.         end
  132.         turtle.dropDown()
  133.     end
  134. end
Advertisement
Add Comment
Please, Sign In to add comment