CelticCoder

turtleChest

Nov 15th, 2023 (edited)
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.69 KB | None | 0 0
  1. local storageBlocks = {
  2.     "minecraft:chest",
  3.     "minecraft:trapped_chest",
  4.     "minecraft:barrel",
  5.     "minecraft:shulker_box",
  6.     "minecraft:white_shulker_box",
  7.     "minecraft:orange_shulker_box",
  8.     "minecraft:magenta_shulker_box",
  9.     "minecraft:light_blue_shulker_box",
  10.     "minecraft:yellow_shulker_box",
  11.     "minecraft:lime_shulker_box",
  12.     "minecraft:pink_shulker_box",
  13.     "minecraft:gray_shulker_box",
  14.     "minecraft:light_gray_shulker_box",
  15.     "minecraft:cyan_shulker_box",
  16.     "minecraft:purple_shulker_box",
  17.     "minecraft:blue_shulker_box",
  18.     "minecraft:brown_shulker_box",
  19.     "minecraft:green_shulker_box",
  20.     "minecraft:red_shulker_box",
  21.     "minecraft:black_shulker_box",
  22.     "minecraft:hopper",
  23.     "computercraft:turtle_normal"
  24. }
  25.  
  26.  
  27. function checkList(list, thing)
  28.     for _, str in ipairs(list) do
  29.         if thing == str then
  30.             return true
  31.         end
  32.     end
  33.     return false
  34. end
  35.  
  36. function stackLimit()
  37.     if turtle.getItemCount() ~= 0 then
  38.         return turtle.getItemCount() + turtle.getItemSpace()
  39.     end
  40.     return 0
  41. end
  42.  
  43. function itemSuckUp()
  44.   local success = turtle.suckUp()
  45.   if not success then
  46.     return nil
  47.   end
  48.  
  49.   local item = turtle.getItemDetail()
  50.   if item then
  51.     return item.name, turtle.getItemCount()
  52.   else
  53.     return nil
  54.   end
  55. end
  56.  
  57. function countCheck()
  58.     local itemCount = 0
  59.     for slot = 1, 16 do
  60.         turtle.select(slot)
  61.         local itemQty = turtle.getItemCount()
  62.  
  63.         if itemQty > 0 then
  64.             itemCount = itemCount + itemQty
  65.         end
  66.     end
  67.     return itemCount
  68. end
  69.  
  70. function takeAll()
  71.     if turtle.detect() then
  72.         local success, data = turtle.inspect()
  73.        
  74.         if success then
  75.             if checkList(storageBlocks, data.name) then
  76.                 print("There is a chest in front of the turtle")
  77.                
  78.                 local slotsToFill = 16  
  79.                 for slot = 1, slotsToFill do
  80.                     if turtle.getItemCount(slot) == 0 then
  81.                         turtle.suck()
  82.                     end
  83.                 end
  84.                 turtle.select(1)
  85.             else
  86.                 print("There is a block, but it's not a chest")
  87.             end
  88.         else
  89.             print("Failed to inspect")
  90.         end
  91.     else
  92.         print("There's nothing in front of the turtle")
  93.     end
  94. end
  95.  
  96. function takeAllUp()
  97.     if turtle.detect() then
  98.         local success, data = turtle.inspect()
  99.        
  100.         if success then
  101.             if checkList(storageBlocks, data.name) then
  102.                 print("There is a chest in front of the turtle")
  103.              
  104.                 local slotsToFill = 16  -- Number of slots to attempt to fill
  105.                 for slot = 1, slotsToFill do
  106.                     if turtle.getItemCount(slot) == 0 then
  107.                         turtle.suckUp()
  108.                     end
  109.                 end
  110.                 turtle.select(1)
  111.             else
  112.                 print("There is a block, but it's not a chest")
  113.             end
  114.         else
  115.             print("Failed to inspect")
  116.         end
  117.     else
  118.         print("There's nothing in front of the turtle")
  119.     end
  120. end
  121.  
  122. function takeAllDown()
  123.     if turtle.detect() then
  124.         local success, data = turtle.inspect()
  125.        
  126.         if success then
  127.             if checkList(storageBlocks, data.name) then
  128.                 print("There is a chest in front of the turtle")
  129.                
  130.                 local slotsToFill = 16  
  131.                 for slot = 1, slotsToFill do
  132.                     if turtle.getItemCount(slot) == 0 then
  133.                         turtle.suckDown()
  134.                     end
  135.                 end
  136.                 turtle.select(1)
  137.             else
  138.                 print("There is a block, but it's not a chest")
  139.             end
  140.         else
  141.             print("Failed to inspect")
  142.         end
  143.     else
  144.         print("There's nothing in front of the turtle")
  145.     end
  146. end
  147.  
  148. function insertSome(start)
  149.     if turtle.detect() then
  150.         local success, data = turtle.inspect()
  151.  
  152.         if success then
  153.             if checkList(storageBlocks, data.name) then
  154.                 print("There is a chest in front of the turtle")
  155.                
  156.                 for slot = start, 16 do
  157.                     if slot ~= 1 and turtle.getItemCount(slot) > 0 then
  158.                         turtle.select(slot)
  159.                         turtle.drop()
  160.                         print("Deposited items from slot " .. slot)
  161.                     end
  162.                 end
  163.                 turtle.select(1)
  164.             else
  165.                 print("There is a block, but it's not a chest")
  166.             end
  167.         else
  168.             print("Failed to inspect")
  169.         end
  170.     else
  171.         print("There's nothing in front of the turtle")
  172.     end
  173. end
  174.  
  175. function insertAll()
  176.    
  177.     if turtle.detect() then
  178.         local success, data = turtle.inspect()
  179.        
  180.         if success then
  181.             if checkList(storageBlocks, data.name) then
  182.                 print("There is a chest in front of the turtle")
  183.                
  184.                 for slot = 1, 16 do
  185.                     if turtle.getItemCount(slot) > 0 then
  186.                         turtle.select(slot)
  187.                         turtle.drop()
  188.                         print("Deposited items from slot " .. slot)
  189.                     end
  190.                 end
  191.                 turtle.select(1)
  192.             else
  193.                 print("There is a block, but it's not a chest")
  194.                 return false
  195.             end
  196.         else
  197.             print("Failed to inspect")
  198.             return false
  199.         end
  200.     else
  201.         print("There's nothing in front of the turtle")
  202.         return false
  203.     end
  204. end
  205.  
  206. function insertAllUp()
  207.     if turtle.detect() then
  208.         local success, data = turtle.inspectUp()
  209.        
  210.         if success then
  211.             if checkList(storageBlocks, data.name)then
  212.                 print("There is a chest in front of the turtle")
  213.                
  214.                 for slot = 1, 16 do
  215.                     if turtle.getItemCount(slot) > 0 then
  216.                         turtle.select(slot)
  217.                         if turtle.dropUp() then
  218.                             condition = true
  219.                         else
  220.                             condition = false
  221.                             break
  222.                         end
  223.                         print("Deposited items from slot " .. slot)
  224.                     end
  225.                 end
  226.                 turtle.select(1)
  227.             else
  228.                 print("There is a block, but it's not a chest")
  229.             end
  230.         else
  231.             print("Failed to inspect")
  232.         end
  233.     else
  234.         print("There's nothing in front of the turtle")
  235.     end
  236.     return condition
  237. end
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244. -- takes a starting slot to deposit from. Using 1 deposits the entire inventory, 2 starts from slot 2 onwards
  245. function insertAllDown()
  246.     condition = 0
  247.     if turtle.detect() then
  248.         local success, data = turtle.inspectDown()
  249.        
  250.         if success then
  251.             if checkList(storageBlocks, data.name) then
  252.                 print("There is a chest in front of the turtle")
  253.                
  254.                 for slot = 1, 16 do
  255.                     if turtle.getItemCount(slot) > 0 then
  256.                         turtle.select(slot)
  257.                         if turtle.dropDown() then
  258.                             condition = 1
  259.                         else
  260.                             condition = 2
  261.                         end
  262.                         print("Deposited items from slot " .. slot)
  263.                     end
  264.                 end
  265.                 turtle.select(1)
  266.             else
  267.                 print("There is a block, but it's not a chest")
  268.             end
  269.         else
  270.             print("Failed to inspect")
  271.         end
  272.     else
  273.         print("There's nothing in front of the turtle")
  274.     end
  275.     return condition
  276. end
Add Comment
Please, Sign In to add comment