Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Epuuc
- --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 usefulOres = {"diamond_ore","positite_ore","negatite_ore","gold_ore","iron_ore"}
- local function getIndex(tbl,value)
- for i=1,#tbl do
- if tbl[i] == value then
- return i
- end
- end
- return false
- end
- local function getId()
- local id = 99
- if fs.exists("/data/owner") then
- local file = fs.open("/data/owner","r")
- local content = file.readAll()
- if content == "" then print("Turtle bot not owned, global frequency used") return id end
- local id = tonumber(split(content,"_")[2])
- else
- print("Turtle bot not owned, global frequency used")
- end
- return id
- end
- local args = {...}
- while true do
- if peripheral.find("modem") then
- local suc,block = turtle.inspect()
- local suc1,blockUp = turtle.inspectUp()
- local suc2,blockDown = turtle.inspectDown()
- local usefulOre
- for i=1,#usefulOres do
- if suc and string.find(block.name,usefulOres[i]) then
- if usefulOre ~= nil then
- if i > getIndex(usefulOre) then
- usefulOre = usefulOres[i]
- end
- else
- usefulOre = usefulOres[i]
- end
- end
- if suc1 and string.find(blockUp.name,usefulOres[i]) then
- if usefulOre ~= nil then
- if i > getIndex(usefulOre) then
- usefulOre = usefulOres[i]
- end
- else
- usefulOre = usefulOres[i]
- end
- end
- if suc2 and string.find(blockDown.name,usefulOres[i]) then
- if usefulOre ~= nil then
- if i > getIndex(usefulOre) then
- usefulOre = usefulOres[i]
- end
- else
- usefulOre = usefulOres[i]
- end
- end
- end
- if usefulOre ~= nil then
- local id = getId()
- peripheral.find("modem").transmit(id,id,{Reason="Ore Found!",Content=usefulOre})
- end
- end
- turtle.dig()
- turtle.forward()
- if not turtle.detectDown() then
- local blockHolding = turtle.getItemDetail()
- if not blockHolding or not string.find(blockHolding.name,"cobble") then
- for i=1,16 do
- local blockCheck = turtle.getItemDetail(i)
- if blockCheck and string.find(blockCheck.name,"cobble") then
- turtle.select(i)
- break
- end
- end
- end
- end
- turtle.placeDown()
- turtle.digUp()
- if turtle.getFuelLevel() <= 0 then
- for i=1,16 do
- if turtle.getItemDetail(i) ~= nil and turtle.getItemDetail(i).name == "minecraft:coal" then
- turtle.refuel(64)
- end
- end
- if turtle.getFuelLevel() == 0 then
- print("Turtle Out Of Fuel.")
- end
- end
- end
- --Epuuc
Add Comment
Please, Sign In to add comment