Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function buildLayer()
- moveUp()
- for i=1,4 do
- turtle.placeDown()
- checkBuildingSupply()
- for j=1,8 do
- moveForward()
- turtle.placeDown()
- checkBuildingSupply()
- end
- turtle.turnRight()
- end
- end
- function checkBuildingSupply()
- if ( turtle.getItemCount(itemSlot) == 0 ) then
- itemSlot = itemSlot + 1
- turtle.select(itemSlot)
- end
- end
- function digFloor()
- for i=1,9 do
- for j=1,8 do
- moveForward()
- end
- if ( i % 2 == 1 ) then
- if ( i ~= 9 ) then
- turtle.turnRight()
- moveForward()
- turtle.turnRight()
- end
- else
- turtle.turnLeft()
- moveForward()
- turtle.turnLeft()
- end
- end
- end
- function moveForward()
- while ( not turtle.forward() ) do
- turtle.dig()
- end
- end
- function moveUp()
- while ( not turtle.up() ) do
- turtle.digUp()
- end
- end
- function moveDown()
- while ( not turtle.down() ) do
- turtle.digDown()
- end
- end
- function digDown()
- while ( turtle.detectDown() ) do
- turtle.digDown()
- end
- end
- function layFloor()
- -- lays the 9x9 floor
- for i=1,9 do
- for j=1,8 do
- digDown()
- turtle.placeDown()
- checkBuildingSupply()
- moveForward()
- end
- digDown()
- turtle.placeDown()
- checkBuildingSupply()
- if ( i%2 == 0 ) then
- turtle.turnLeft()
- moveForward()
- turtle.turnLeft()
- else
- if ( i ~= 9 ) then
- turtle.turnRight()
- moveForward()
- turtle.turnRight()
- end
- end
- end
- end
- function buildRoof()
- --if building from the top down, then turtle stays on roof
- --if building from the bottom or from the sides, needs to do the edges first, otherwise one side can't get done
- --can it be done by a spiral, so that the turtle finishes in the centre block of the newly built house
- design={}
- design[1]={'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'}
- design[2]={'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'}
- design[3]={'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b'}
- design[4]={'b', 'b', 'b', 'b', 'b', 'b', 'b'}
- design[5]={'b', 'b', 'b', 'b', 'b', 'b', 'b'}
- design[6]={'b', 'b', 'b', 'b', 'b', 'b'}
- design[7]={'b', 'b', 'b', 'b', 'b', 'b'}
- design[8]={'b', 'b', 'b', 'b', 'b'}
- design[9]={'g', 'g', 'b', 'g', 'g'}
- design[10]={'g', 'b', 'g', 'g'}
- design[11]={'g', 'b', 'g', 'g'}
- design[12]={'g', 'b', 'g'}
- design[13]={'g', 'b', 'g'}
- design[14]={'b', 'g'}
- design[15]={'b', 'g'}
- design[16]={'b'}
- turtle.select(itemSlot)
- moveUp()
- for i=1,table.getn(design) do
- for j=1,table.getn(design[i]) do
- if ( design[i][j] == 'b' ) then
- turtle.placeDown()
- checkBuildingSupply()
- elseif ( design[i][j] == 'g' ) then
- turtle.select(16)
- turtle.placeDown()
- turtle.select(itemSlot)
- end
- if ( j == table.getn(design[i]) ) then
- turtle.turnRight()
- end
- moveForward()
- end
- end
- moveDown()
- moveDown()
- turtle.placeUp()
- end
- function placeTorches()
- moveForward()
- turtle.turnRight()
- moveForward()
- turtle.turnLeft()
- moveDown()
- turtle.select(15)
- for i=1,4 do
- for j=1,6 do
- if ( j % 2 == 0 ) then
- while ( turtle.detectDown() ) do
- turtle.digDown()
- end
- turtle.placeDown()
- end
- moveForward()
- end
- turtle.turnRight()
- end
- moveUp()
- turtle.turnLeft()
- moveForward()
- turtle.turnRight()
- turtle.back()
- turtle.select(itemSlot)
- end
- function checkInventory()
- -- check that there are 306 identical blocks in slots 1-6
- -- check that there are 12 items in slot 15 (torches)
- -- check that there are 16 items in slot 16 (glass)
- blockCount=turtle.getItemCount(1)
- turtle.select(1)
- for i=2,5 do
- if ( turtle.getItemCount(i) == 0 ) then
- print("Insufficient Base Blocks for building, slots 1-5 must contain identical blocks")
- os.exit(1)
- end
- if ( not turtle.compareTo(i) ) then
- print("Blocks in slot 1 - 5 must be identical")
- os.exit(1)
- end
- blockCount = blockCount + turtle.getItemCount(i)
- end
- if ( blockCount < 306 ) then
- print("Insufficient Base Blocks for building")
- os.exit(1)
- end
- if ( turtle.getItemCount(15) < 12 ) then
- print("Insufficient Torches in slot 15")
- os.exit(1)
- end
- if ( turtle.getItemCount(16) < 16 ) then
- print("Insufficient Glass in slot 16")
- os.exit(1)
- end
- end
- function rotate()
- for i=1,2 do
- turtle.turnLeft()
- end
- end
- itemSlot=1
- checkInventory()
- --moveDown()
- --digFloor()
- --moveUp()
- turtle.select(itemSlot)
- --rotate()
- layFloor()
- rotate()
- for i=1,5 do
- buildLayer()
- end
- placeTorches()
- buildRoof()
- for i=1,4 do
- moveDown()
- end
- print("9x9 built")
Advertisement
Add Comment
Please, Sign In to add comment