Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --not my code
- function split(pString, pPattern)
- local Table = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pPattern
- local last_end = 1
- local s, e, cap = pString:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(Table,cap)
- end
- last_end = e+1
- s, e, cap = pString:find(fpat, last_end)
- end
- if last_end <= #pString then
- cap = pString:sub(last_end)
- table.insert(Table, cap)
- end
- return Table
- end
- --not my code
- --now my code VVV
- local function parseName()
- return split(os.getComputerLabel(),"_")[4]
- end
- local function checkForCoal()
- print("Checking for coal")
- for i=1,16 do
- local item = turtle.getItemDetail(i)
- if item and item.name == "minecraft:coal" then
- print("There's coal!")
- return i
- end
- end
- print("No Coal")
- return false
- end
- local function getCoal()
- while true do
- local suc = turtle.suckUp()
- if not suc then return false end
- if checkForCoal() then
- return i
- end
- end
- end
- local function checkForSaplings()
- print("Checking for saplings")
- for i=1,16 do
- local item = turtle.getItemDetail(i)
- if item and item.name == "minecraft:sapling" then
- print("sapling found")
- return i
- end
- end
- print("No saplings found")
- return false
- end
- local function getSaplings()
- while true do
- local suc = turtle.suckUp()
- if not suc then return false end
- if checkForSaplings() then
- return i
- end
- end
- end
- local id = parseName()
- print(id)
- local modem = peripheral.find("modem")
- if not modem then turtle.equipRight() turtle.select(1) sleep(1) turtle.equipRight() end
- modem.open(tonumber(id)+200)
- while true do
- local event,side,channel,repchannel,msg,distance = os.pullEvent("modem_message")
- print(distance)
- if distance == 1 and channel == id+200 then
- --refueling
- while true do
- if turtle.getFuelLevel() < 100 then
- if not checkForCoal() then
- if getCoal() then
- turtle.select(i)
- turtle.refuel(64)
- print("Refueled")
- else
- print("panic no coal")
- --panic
- return
- end
- else
- turtle.select(checkForCoal())
- turtle.refuel(64)
- end
- else
- break
- end
- end
- --putting all the items back
- for i=1,16 do
- turtle.select(i)
- if turtle.getItemCount() > 0 and turtle.getItemDetail().name ~= "minecraft:sapling" then
- turtle.dropUp()
- end
- end
- --grabbing saplings
- if not checkForSaplings() then
- getSaplings()
- local saplingnum = checkForSaplings()
- if not saplingnum then
- print("panic no saplings")
- return
- --panic
- end
- turtle.select(checkForSaplings())
- end
- turtle.select(checkForSaplings())
- --Starting on the journey
- turtle.turnRight()
- turtle.turnRight()
- for i=1,(msg*7)+3 do
- while not turtle.forward() do
- turtle.dig()
- end
- end
- turtle.turnLeft()
- turtle.forward()
- turtle.dig()
- turtle.forward()
- repeat
- turtle.digUp()
- turtle.up()
- for r=1,4 do
- turtle.dig()
- turtle.turnRight()
- end
- until not turtle.detectUp()
- turtle.turnRight()
- turtle.turnRight()
- turtle.forward()
- while true do
- turtle.digDown()
- turtle.down()
- for r=1,4 do
- turtle.dig()
- turtle.turnRight()
- end
- local suc,bl = turtle.inspectDown()
- if suc and bl.name == "minecraft:planks" then break end
- end
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- for i=1,(msg*7)+3 do
- while not turtle.forward() do
- turtle.dig()
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment