Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function find(itemName)
- for curSlot = 1,16 do
- if turtle.getItemCount(curSlot) >= 1 then
- local data = turtle.getItemDetail(curSlot)
- if data.name == itemName then
- return curSlot
- end
- end
- end
- return false
- end
- local function pickSong()
- song = math.random(2)
- if song == 1 then
- return "hi ho"
- elseif song == 2 then
- return "gold"
- end
- end
- local function hi_ho(dist, voicebox)
- local line = dist % 19
- if line == 0 then
- voicebox.speak("Hi ho, hi ho")
- elseif line == 1 then
- voicebox.speak("It's off to work I go")
- elseif line == 2 then
- voicebox.speak("I dig dig dig dig dig dig dig")
- elseif line == 3 then
- voicebox.speak("in a mine the whole day through")
- elseif line == 4 then
- voicebox.speak("To dig dig dig dig dig dig dig")
- elseif line == 5 then
- voicebox.speak("Is what I'm made to do")
- elseif line == 6 then
- voicebox.speak("It ain't no trick to get rich quick")
- elseif line == 7 then
- voicebox.speak("If you dig dig dig with a shovel or a pick")
- elseif line == 8 then
- voicebox.speak("In a mine, in a mine")
- elseif line == 9 then
- voicebox.speak("In a mine, in a mine")
- elseif line == 10 then
- voicebox.speak("Where a million diamonds shine")
- elseif line == 11 then
- voicebox.speak("I dig dig dig dig dig dig dig")
- elseif line == 12 then
- voicebox.speak("from early morn to night")
- elseif line == 13 then
- voicebox.speak("I dig dig dig dig dig dig dig")
- elseif line == 14 then
- voicebox.speak("up everything in sight")
- elseif line == 15 then
- voicebox.speak("I dig up diamonds by the score")
- elseif line == 16 then
- voicebox.speak("A thousand emeralds, sometimes more")
- elseif line == 17 then
- voicebox.speak("I don't know what we dig them for")
- elseif line == 18 then
- voicebox.speak("I dig dig digga dig dig")
- end
- end
- local function traditionaDwarfishSong(voicebox)
- voicebox.speak("gold, gold, gold, gold")
- end
- local function sing(song, dist, voicebox)
- if song == "hi ho" then
- hi_ho(dist,voicebox)
- elseif song == "gold" then
- traditionaDwarfishSong(voicebox)
- end
- end
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: miner <distance>" )
- return
- end
- local maxDist = tonumber( tArgs[1] )
- if maxDist < 1 then
- print( "Distance must be positive" )
- return
- end
- local function getFreeInventorySpace()
- local freeSpace = 16
- for curSlot = 1,16 do
- if turtle.getItemCount(curSlot) ~= 0 then
- freeSpace = freeSpace - 1
- end
- end
- return freeSpace
- end
- local function sortInventory()
- local inventory = {}
- for curSlot=1,16 do
- if turtle.getItemCount(curSlot) ~= 0 then
- inventory[curSlot] = turtle.getItemDetail(curSlot)
- else
- inventory[curSlot] = "empty"
- end
- end
- for slotA=1,16 do
- if inventory[slotA] ~= "empty" then
- for slotB=1,16 do
- if inventory[slotB] ~= "empty" then
- if slotA ~= slotB then
- if (inventory[slotA].name == inventory[slotB].name) and (inventory[slotA].damage == inventory[slotB].damage) then
- if inventory[slotA].count + inventory[slotB].count <= 64 then
- turtle.select(slotB)
- turtle.transferTo(slotA)
- inventory[slotB] = "empty"
- end
- end
- end
- end
- end
- end
- end
- end
- local function digAround()
- while turtle.detectUp() do
- turtle.digUp()
- end
- if turtle.detectDown() then
- local success, data = turtle.inspectDown()
- if success then
- if not (data.name == "minecraft:cobblestone") and not (data.name == "minecraft:stone") and not (data.name == "minecraft:sand") and not (data.name == "minecraft:dirt") and not (data.name == "minecraft:gravel") and not (data.name == "chisel:marble2") and not (data.name == "chisel:limestone2") then
- turtle.digDown()
- end
- end
- end
- if find("minecraft:cobblestone") then
- turtle.select(find("minecraft:cobblestone"))
- turtle.placeDown()
- elseif find("minecraft:stone") then
- turtle.select(find("minecraft:stone"))
- turtle.placeDown()
- end
- end
- local function checkFuel(level)
- if (turtle.getFuelLevel() <= level) and (find("minecraft:coal")) then
- turtle.select(find("minecraft:coal"))
- turtle.refuel(1)
- end
- end
- local function returnToStart(travelled, continue)
- if continue then
- print("Returning to deposit items, then continuing")
- else
- print("Returning to deposit items; job done")
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for curDist=0,travelled do
- checkFuel(10)
- local success, data = turtle.inspect()
- if success then
- if data.name ~= "minecraft:chest" then
- while not turtle.forward() do
- turtle.dig()
- end
- end
- else
- while not turtle.forward() do
- turtle.dig()
- end
- end
- end
- local success, data = turtle.inspect()
- if success then
- if data.name == "minecraft:chest" then
- for curSlot = 1,16 do
- if turtle.getItemCount(curSlot) ~= 0 then
- block = turtle.getItemDetail(curSlot)
- if (block.name ~= "minecraft:coal") and (block.name ~= "minecraft:torch") and (block.name ~= "tconstruct:stone_torch") then
- turtle.select(curSlot)
- turtle.drop()
- end
- end
- end
- end
- end
- if continue then
- turtle.turnLeft()
- turtle.turnLeft()
- for curDist=0,travelled-1 do
- checkFuel(10)
- local success, data = turtle.inspect()
- if success then
- if data.name ~= "minecraft:chest" then
- while not turtle.forward() do
- turtle.dig()
- end
- end
- else
- while not turtle.forward() do
- turtle.dig()
- end
- end
- end
- end
- end
- local travelDist = 0
- local vocal = peripheral.find("speaker")
- local song = pickSong()
- while travelDist <= maxDist do
- sing(song,travelDist,vocal)
- checkFuel(10)
- if (find("minecraft:torch") == false) and (find("tconstruct:stone_torch") == false) then
- break
- end
- sortInventory()
- if getFreeInventorySpace() <= 1 then
- returnToStart(travelDist,true)
- end
- digAround()
- turtle.turnLeft()
- while not turtle.forward() do
- turtle.dig()
- end
- digAround()
- turtle.turnRight()
- turtle.turnRight()
- turtle.forward()
- while not turtle.forward() do
- turtle.dig()
- end
- digAround()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- if (travelDist % 6 == 0) and ((find("minecraft:torch")) or (find("tconstruct:stone_torch"))) then
- if find("tconstruct:stone_torch") then
- turtle.select(find("tconstruct:stone_torch"))
- else
- turtle.select(find("minecraft:torch"))
- end
- turtle.place()
- end
- turtle.turnRight()
- if travelDist <= maxDist then
- while not turtle.forward() do
- turtle.dig()
- end
- travelDist = travelDist + 1
- end
- end
- returnToStart(travelDist,false)
Advertisement
Add Comment
Please, Sign In to add comment