Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get QfSCbRgH buildBox
- -- Ask how each side is
- print("How many blocks per side?")
- local side = io.read()
- side = tonumber(side)
- local blocksNeeded = (side * 2) + ((side - 2) * 2)
- print("I will need " .. blocksNeeded .. " blocks.")
- print("Type 'Start' when ready")
- local go = io.read()
- local blockCount = side - 1
- local selected = 1
- local fuel = 16 -- Put some coal into the bottom-right cell
- local itemCount = turtle.getItemCount(selected)
- --[[
- * Check to see if refueling is needed
- ]]
- local function ifRefuel()
- if turtle.getFuelLevel() < side then
- turtle.select(fuel)
- turtle.refuel(1)
- turtle.select(selected)
- end
- end
- if go == "Start" then
- -- Do we need to step up?
- if turtle.detectDown() then
- ifRefuel()
- turtle.up()
- end
- -- Select the starting cell
- turtle.select(selected)
- local s = 0
- local j = 0
- while s < 4 do
- -- Prepare turtle ro do one side of the box
- turtle.select(selected)
- ifRefuel()
- if s == 3 then
- -- Last side
- blockCount = blockCount - 1
- end
- j = 0
- while j < blockCount do
- -- Are we clear to place something?
- if turtle.detectDown() then
- turtle.digDown()
- end
- -- Place block
- turtle.placeDown()
- -- Step forward
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- itemCount = turtle.getItemCount(selected)
- if itemCount == 0 then
- -- Out of items; Switch cells
- selected = selected + 1
- turtle.select(selected)
- end
- j = j + 1
- end
- if s < 3 then
- -- Prepare for the next side
- turtle.turnLeft()
- end
- s = s + 1
- end
- -- Place the last block to complete the box
- if turtle.detectDown() then
- turtle.digDown()
- end
- turtle.placeDown()
- turtle.forward()
- else
- print("Terminating")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement