CelticCoder

temp

Nov 20th, 2023 (edited)
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. --asks the user how many items to take
  2. function takeAmount(size)
  3.     csize = size
  4.     -- Check if there's a block in front of the turtle
  5.     if turtle.detect() then
  6.         -- If there's a block, check if it's a chest
  7.         local success, data = turtle.inspect()
  8.        
  9.         if success then
  10.             -- 'inspect()' returns true if it succeeded and provides data about the block
  11.             if data.name == "minecraft:chest" then
  12.                 print("There is a chest in front of the turtle")
  13.                
  14.                 -- 'data' contains information about the block
  15.                
  16.                 -- Take items from the chest starting from slot 2 (excluding slot 1)
  17.                 local slotsToFill = 16  -- Number of slots to attempt to fill
  18.                 for slot = 1, slotsToFill do
  19.                     if slot ~= 1 and turtle.getItemCount(slot) == 0 then
  20.                         -- If the current slot is empty and not the first slot, attempt to take items
  21.                         if turtle.suck(slot) then
  22.                             print("Took items from slot " .. slot)
  23.                             csize = csize - 1
  24.                             if csize == 0 then
  25.                                 print(size .. " Items Collected")
  26.                                 break
  27.                             end
  28.                         else
  29.                             print("Error")
  30.                         end
  31.                     end
  32.                 end
  33.                 turtle.select(1)
  34.             else
  35.                 print("There is a block, but it's not a chest")
  36.             end
  37.         else
  38.             print("Failed to inspect")
  39.         end
  40.     else
  41.         print("There's nothing in front of the turtle")
  42.     end
  43. end
Add Comment
Please, Sign In to add comment