Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Tower Builder
- This is a code fragment to a larger future project. The intent is to demonstrate
- a problem I am having placing ladders using a ComputerCraft Turtle in FTB Ultimate 1.4.7 v 1.1.2.
- This code only produces the desired results if the turtle is initially placed facing SOUTH!
- As it stands this code isn't very useful at the moment. Hopefully some day it will be usable by others.
- blocks go in the first 12 slots
- ladders go in 13-15
- fuel in 16 - not implemented yet
- ]]
- activeslot = 1 -- current slot for pulling building blocks from
- ladderslot = 13 -- current slot for pulling ladders from
- MaxBlock = 12 -- last slot to look in for building blocks
- blockcount = 0 -- running total of successful plocks placed
- MinFuelLevel = 10 -- Minimum initial fuel level
- TowerHeight = 3 -- How high to make the tower to initial platform
- startfuel = turtle.getFuelLevel()
- function fillrup()
- turtle.select(16)
- if turtle.getFuelLevel() < MinFuelLevel then
- print("refueling from slot 16(",turtle.getItemCount(16) , ")")
- if turtle.getItemCount(16) < 1 then
- print("Place fuel in slot 16 and press Enter")
- read()
- end -- do we have aningthing in slot 16 to refuel with?
- turtle.refuel() -- *****add future checks to see if we have just enough fuel to complete the job
- end -- fuel status check
- end -- fillerup
- function placeLadder()
- ladderslot = 13
- if turtle.getItemCount(ladderslot) > 0 then
- turtle.select(ladderslot)
- if not turtle.placeDown(ladderslot) then
- print("I can't place the ladder \nPlease fix and hit Enter")
- read()
- end
- elseif ladderslot < 16 then -- search inventory for a block in valid slots
- while ladderslot < 16 and turtle.getItemCount(ladderslot) < 1 do
- ladderslot = ladderslot + 1
- turtle.select(ladderslot)
- end -- while
- while not turtle.placeDown(ladderslot) do
- print(" can't place the ladder \nPlease fix, reload and hit Enter")
- read()
- end
- end
- if turtle.getItemCount(ladderslot) == 0 and ladderslot >= 15 then
- print("I seem to be out of ladders")
- print("Please refill slots 13-15 \nand press Enter to continue.")
- read()
- end
- end -- function placeLadder
- function placeBlock()
- activeslot = 1
- if turtle.getItemCount(activeslot) > 0 then
- turtle.select(activeslot)
- if turtle.place(activeslot) then blockcount = blockcount +1 end
- elseif activeslot < MaxBlock then -- search inventory for a block in valid slots
- while activeslot < MaxBlock and turtle.getItemCount(activeslot) < 1 do
- activeslot = activeslot + 1
- turtle.select(activeslot)
- end -- while
- if turtle.getItemCount(activeslot) > 0 and turtle.place(activeslot) then blockcount = blockcount + 1 end
- end
- if turtle.getItemCount(activeslot) == 0 and activeslot == MaxBlock then
- print("I seem to be out of building materials")
- print("Please refill slots 1-12 \nand press Enter to continue.")
- -- os.pullEvent("key")
- read()
- end
- end -- Function placeBlock
- -- Future fuel check location fuel slot = 16
- fillrup()
- print("Place blocks in top 3 rows of slots 1-12 \nNO sand,gravel, glass and the like\nladders in 13-15 and fuel in 16")
- while (turtle.getItemCount(activeslot) < 1) and (activeslot < MaxBlock + 1) do -- skip empty slots at the begining of inventory
- activeslot = activeslot + 1
- end -- while
- if activeslot > MaxBlock then
- print("I can't seem to find any \nbuilding materials in slots 1-", MaxBlock)
- print("please reload turtle")
- print("press Enter to continue")
- read()
- end
- while turtle.getItemCount(ladderslot) < 1 and ladderslot < 16 do -- looking for ladders
- ladderslot = ladderslot + 1
- end -- while looking for ladders
- if ladderslot > 15 then -- no ladders found
- print("I seem to be out of ladders")
- print("Please refill slots 13-15 \nand press Enter to continue.")
- read()
- end -- no ladders found
- for j = 1, TowerHeight do -- tower height
- for i = 1,4 do -- build walls
- if i == 3 and j < 3 then turtle.turnLeft() end -- make the door to the tower face the user
- if j > 1 and i == 1 then
- placeLadder()
- end
- placeBlock()
- if not (i == 3 and j < 3) then turtle.turnLeft() end
- end -- build walls
- turtle.up() -- next row
- end -- tower height
- placeLadder() -- finish up placing ladder sections
- print("Fuel used = ", startfuel - turtle.getFuelLevel(), " Block count = ",blockcount)
- print("I seem to be done. Have a nice day:)")
Advertisement
Add Comment
Please, Sign In to add comment