Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- MineCobbleStationary.lua
- -- This script makes a stationary Turtle mine cobblestone from a cobble generator
- -- until its inventory is full, then pause and wait until the inventory is emptied.
- -- Function to check if the Turtle's inventory is full
- local function isInventoryFull()
- for slot = 1, 16 do
- local itemCount = turtle.getItemCount(slot)
- if itemCount == 0 then
- -- Empty slot found
- return false
- else
- -- Get item details to ensure it's cobblestone
- local itemDetail = turtle.getItemDetail(slot)
- if itemDetail and itemDetail.name == "minecraft:cobblestone" and itemCount < 64 then
- -- Slot has cobblestone but isn't full
- return false
- end
- end
- end
- -- All slots are either full with cobblestone or contain other items
- return true
- end
- -- Function to wait until the inventory has space
- local function waitForInventorySpace()
- print("Inventory full. Please empty the inventory. Waiting...")
- while isInventoryFull() do
- os.sleep(10) -- Wait for 10 seconds before checking again
- end
- print("Inventory has space. Resuming mining.")
- end
- -- Function to ensure the Turtle can dig forward, handling any obstacles
- local function ensureDigForward()
- while not turtle.dig() do
- print("Failed to dig. Retrying in 1 second...")
- os.sleep(1) -- Wait for 1 second before trying again
- end
- end
- -- Function to collect items after digging
- local function collectItems()
- while turtle.suck() do
- -- Keep sucking until no more items can be collected
- end
- end
- -- Main mining loop
- local function mineCobble()
- print("Starting mining operation...")
- while true do
- if isInventoryFull() then
- waitForInventorySpace()
- end
- -- Attempt to dig forward
- ensureDigForward()
- -- Collect the mined cobblestone
- collectItems()
- -- Optional: Wait a short duration to prevent overwhelming the generator
- os.sleep(0.5) -- Wait half a second before the next dig
- end
- end
- -- Start the mining operation
- mineCobble()
Add Comment
Please, Sign In to add comment