Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle program for farming cobblestone in a cobblestone generator
- -- Function to check if there's a cobblestone block in front
- local function isCobble()
- local success, data = turtle.inspect()
- if success and data.name == "minecraft:cobblestone" then
- return true
- end
- return false
- end
- -- Function to check if there's space in the chest behind
- local function hasChestSpace()
- turtle.select(1) -- Ensure a slot is selected
- local detail = turtle.getItemDetail()
- if detail then
- -- Check if the chest can accept this item
- return turtle.dropUp() -- Drop directly into the chest behind
- else
- -- If no items in slot, assume chest has space
- return true
- end
- end
- -- Function to wait until the chest has space
- local function waitForChestSpace()
- while not hasChestSpace() do
- print("Waiting for chest space...")
- os.sleep(1)
- end
- end
- -- Main loop
- while true do
- if isCobble() then
- -- Mine the cobblestone
- turtle.dig()
- -- Check if there's space and deposit cobblestone
- if hasChestSpace() then
- -- Successfully dropped the cobblestone
- else
- -- Wait until the chest has space
- waitForChestSpace()
- turtle.dropUp() -- Deposit once there's space
- end
- end
- -- Wait a short time before checking again to avoid overloading the system
- os.sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement