Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lastSlot = 1
- local fuelSlot = 16
- local function refuelIfNeeded()
- if turtle.getFuelLevel() < 10 then
- turtle.select(fuelSlot)
- turtle.refuel(1)
- return
- end
- end
- -- Function to check if there is a block to the left of the turtle
- local function checkLeft()
- turtle.turnLeft()
- local success = turtle.detect()
- turtle.turnRight()
- return success
- end
- -- Function to place a block in the previous position of the turtle
- local function placeBlock()
- turtle.select(lastSlot)
- if turtle.getItemCount(lastSlot) > 0 then
- turtle.place()
- else
- for slot = 1, 15 do
- if turtle.getItemCount(slot) > 0 then
- lastSlot = slot
- turtle.select(slot)
- turtle.place()
- return
- end
- end
- end
- end
- -- Main function to move backwards and place a block
- local function moveBackwardsAndPlace()
- refuelIfNeeded()
- if checkLeft() then
- if turtle.back() then
- placeBlock()
- else
- turtle.turnLeft()
- end
- else
- turtle.turnRight()
- turtle.back()
- placeBlock()
- end
- end
- local function inventoryNotEmpty()
- local blockFound = false
- for slot = 1, 15 do
- if turtle.getItemCount(slot) > 0 then
- blockFound = true
- break
- end
- end
- return blockFound
- end
- -- Main loop to repeat the movement and block placement
- while true do
- if inventoryNotEmpty() then
- moveBackwardsAndPlace()
- else
- turtle.suckUp(64)
- os.sleep(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement