Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Floor by itsmartin
- -- Lays a floor in the layer below the turtle.
- -- Fill the inventory with blocks, and put fuel in slot 16. The turtle will place blocks below itself
- -- and change directions whenever it hits a wall.
- function place(slot)
- -- If there is already a block below, do nothing
- if turtle.detectDown() then
- return slot
- end
- -- Find a slot containing blocks. Slot 16 is fuel.
- local slotsTried = 0
- while turtle.getItemCount(slot) == 0 do
- slot = slot + 1
- if slot > 15 then
- slot = 1
- end
- slotsTried = slotsTried + 1
- if slotsTried > 15 then
- print ("Out of blocks!")
- error()
- end
- end
- -- Place a block
- turtle.select(slot)
- turtle.placeDown()
- -- Return the new slot
- return slot
- end
- function turn(direction)
- if direction then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- function moveForward()
- if not checkFuel() then
- print "Out of fuel"
- error()
- end
- return turtle.forward()
- end
- function checkFuel()
- if turtle.getFuelLevel() == 0 then
- turtle.select(16)
- turtle.refuel(1)
- if turtle.getFuelLevel() == 0 then
- return false
- end
- end
- return true
- end
- local direction = true -- true = moving forward, turning right; false = moving backward, turning left
- local slot = 1 -- Start with slot 1
- local finished = false
- while not finished do
- slot = place(slot) -- Place first block
- while moveForward() do
- slot = place(slot)
- end
- turn(direction)
- if not moveForward() then
- finished = true
- end
- turn(direction)
- direction = not direction -- Change direction
- end
Advertisement
Add Comment
Please, Sign In to add comment