Epuuc

Minecraft CC - Simple Strip Mine

Nov 20th, 2020 (edited)
1,782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.98 KB | None | 0 0
  1. --Epuuc
  2.  
  3. --not my code
  4. function split(pString, pPattern)
  5.    local Table = {}  -- NOTE: use {n = 0} in Lua-5.0
  6.    local fpat = "(.-)" .. pPattern
  7.    local last_end = 1
  8.    local s, e, cap = pString:find(fpat, 1)
  9.    while s do
  10.           if s ~= 1 or cap ~= "" then
  11.          table.insert(Table,cap)
  12.           end
  13.           last_end = e+1
  14.           s, e, cap = pString:find(fpat, last_end)
  15.    end
  16.    if last_end <= #pString then
  17.           cap = pString:sub(last_end)
  18.           table.insert(Table, cap)
  19.    end
  20.    return Table
  21. end
  22. --not my code
  23. --now my code VVV
  24.  
  25. local usefulOres = {"diamond_ore","positite_ore","negatite_ore","gold_ore","iron_ore"}
  26.  
  27. local function getIndex(tbl,value)
  28.     for i=1,#tbl do
  29.         if tbl[i] == value then
  30.             return i
  31.         end
  32.     end
  33.     return false
  34. end
  35.  
  36. local function getId()
  37.     local id = 99
  38.     if fs.exists("/data/owner") then
  39.         local file = fs.open("/data/owner","r")
  40.         local content = file.readAll()
  41.         if content == "" then print("Turtle bot not owned, global frequency used") return id end
  42.         local id = tonumber(split(content,"_")[2])
  43.     else
  44.         print("Turtle bot not owned, global frequency used")
  45.     end
  46.     return id
  47. end
  48.  
  49. local args = {...}
  50.     while true do
  51.         if peripheral.find("modem") then
  52.             local suc,block = turtle.inspect()
  53.             local suc1,blockUp = turtle.inspectUp()
  54.             local suc2,blockDown = turtle.inspectDown()
  55.             local usefulOre
  56.             for i=1,#usefulOres do
  57.                 if suc and string.find(block.name,usefulOres[i]) then
  58.                     if usefulOre ~= nil then
  59.                         if i > getIndex(usefulOre) then
  60.                             usefulOre = usefulOres[i]
  61.                         end
  62.                     else
  63.                         usefulOre = usefulOres[i]
  64.                     end
  65.                 end
  66.                 if suc1 and string.find(blockUp.name,usefulOres[i]) then
  67.                     if usefulOre ~= nil then
  68.                         if i > getIndex(usefulOre) then
  69.                             usefulOre = usefulOres[i]
  70.                         end
  71.                     else
  72.                         usefulOre = usefulOres[i]
  73.                     end
  74.                 end
  75.                 if suc2 and string.find(blockDown.name,usefulOres[i]) then
  76.                     if usefulOre ~= nil then
  77.                         if i > getIndex(usefulOre) then
  78.                             usefulOre = usefulOres[i]
  79.                         end
  80.                 else
  81.                         usefulOre = usefulOres[i]
  82.                     end
  83.                 end
  84.             end
  85.             if usefulOre ~= nil then
  86.                 local id = getId()
  87.                 peripheral.find("modem").transmit(id,id,{Reason="Ore Found!",Content=usefulOre})
  88.             end
  89.         end
  90.         turtle.dig()
  91.         turtle.forward()
  92.         if not turtle.detectDown() then
  93.             local blockHolding = turtle.getItemDetail()
  94.             if not blockHolding or not string.find(blockHolding.name,"cobble") then
  95.                 for i=1,16 do
  96.                     local blockCheck = turtle.getItemDetail(i)
  97.                     if blockCheck and string.find(blockCheck.name,"cobble") then
  98.                         turtle.select(i)
  99.                         break
  100.                     end
  101.                 end
  102.             end
  103.         end
  104.         turtle.placeDown()
  105.         turtle.digUp()
  106.         if turtle.getFuelLevel() <= 0 then
  107.             for i=1,16 do
  108.                 if turtle.getItemDetail(i) ~= nil and turtle.getItemDetail(i).name == "minecraft:coal" then
  109.                     turtle.refuel(64)
  110.                 end
  111.             end
  112.             if turtle.getFuelLevel() == 0 then
  113.                 print("Turtle Out Of Fuel.")
  114.             end
  115.         end
  116.     end
  117.  
  118.  
  119.  
  120. --Epuuc
Add Comment
Please, Sign In to add comment