Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --asks the user how many items to take
- function takeAmount(size)
- csize = size
- -- Check if there's a block in front of the turtle
- if turtle.detect() then
- -- If there's a block, check if it's a chest
- local success, data = turtle.inspect()
- if success then
- -- 'inspect()' returns true if it succeeded and provides data about the block
- if data.name == "minecraft:chest" then
- print("There is a chest in front of the turtle")
- -- 'data' contains information about the block
- -- Take items from the chest starting from slot 2 (excluding slot 1)
- local slotsToFill = 16 -- Number of slots to attempt to fill
- for slot = 1, slotsToFill do
- if slot ~= 1 and turtle.getItemCount(slot) == 0 then
- -- If the current slot is empty and not the first slot, attempt to take items
- if turtle.suck(slot) then
- print("Took items from slot " .. slot)
- csize = csize - 1
- if csize == 0 then
- print(size .. " Items Collected")
- break
- end
- else
- print("Error")
- end
- end
- end
- turtle.select(1)
- else
- print("There is a block, but it's not a chest")
- end
- else
- print("Failed to inspect")
- end
- else
- print("There's nothing in front of the turtle")
- end
- end
Add Comment
Please, Sign In to add comment