Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SIDE_WIDTH = 10
- TRASH = { 'minecraft:stone', 'minecraft:cobblestone', 'minecraft:gravel', 'minecraft:dirt', 'chisel:basalt2' }
- ORE_ITEMS = {
- { 'minecraft:coal_ore', 'minecraft:coal' },
- { 'minecraft:diamond_ore', 'minecraft:diamond' },
- { 'minecraft:restone_ore', 'minecraft:restone' },
- { 'galacticraftcore:basic_block_ore', 'galacticcraftcore:basic_item' },
- { 'minecraft:quarz_ore', 'minecraft:quarz' },
- { 'minecraft:nether_quarz_ore', 'minecraft:nether_quarz' },
- { 'appliedenergistics:quartz_ore', 'appliedenergistsics2:material' },
- { 'appliedenergistics:charged_quartz_ore', 'appliedenergistics:material' }
- }
- EXTRA_ORE_NAMES = {
- 'galacticraftcore:basic_block_core',
- 'ic2:resource',
- 'thermalfoundation:ore'
- }
- t = turtle
- function contains(list, element)
- i = 0
- while i < #list do
- i = i + 1
- if list[i] == element then
- return true
- end
- end
- return false
- end
- function getItemName(data)
- name = data['name']
- if name == 'minecraft:stone' and data['metadata'] == 0 then
- return 'minecraft:cobblestone'
- end
- i = 1
- while i <= #ORE_ITEMS do
- if ORE_ITEMS[i][1] == name then
- return ORE_ITEMS[i][2]
- end
- i = i + 1
- end
- return name
- end
- function isChest(data)
- if data == nil or not (type(data) == 'table') then
- return false
- end
- return not (string.find(data['name'], 'chest') == nil)
- end
- function selectChest()
- slot = 1
- while slot <= 16 do
- if t.getItemCount(slot) > 0 and isChest(t.getItemDetail(slot)) then
- t.select(slot)
- return true
- end
- slot = slot + 1
- end
- return false
- end
- function autoRefuel()
- slot = 1
- while slot <= 16 do
- if t.getFuelLevel() > 3000 then
- return
- end
- if t.getItemCount(slot) > 0 then
- if t.getItemDetail(slot)['name'] == 'minecraft:coal' then
- t.select(slot)
- neededCoal = math.floor((3000 - t.getFuelLevel()) / 80) + 1
- if t.getItemCount() < neededCoal then
- neededCoal = t.getItemCount()
- end
- t.refuel(neededCoal)
- print('Refueled to ' .. t.getFuelLevel() .. ' using ' .. neededCoal .. ' Coal')
- end
- end
- slot = slot + 1
- end
- print('Running low on fuel: ' .. t.getFuelLevel())
- end
- function countCobble()
- totalCount = 0
- slot = 1
- while slot <= 16 do
- data = t.getItemDetail(slot)
- if data and data['name'] == 'minecraft:cobblestone' then
- totalCount = totalCount + t.getItemCount(slot)
- end
- slot = slot + 1
- end
- return totalCount
- end
- function selectCobble()
- totalCount = 0
- slot = 1
- while slot <= 16 do
- data = t.getItemDetail(slot)
- if data and data['name'] == 'minecraft:cobblestone' then
- t.select(slot)
- return true
- end
- slot = slot + 1
- end
- return false
- end
- function stackInv()
- slot = 1
- while slot <= 16 do
- if t.getItemCount(slot) > 0 then
- otherSlot = slot + 1
- t.select(slot)
- while otherSlot <= 16 and t.getItemSpace(slot) > 0 do
- if t.compareTo(otherSlot) then
- t.select(otherSlot)
- t.transferTo(slot, t.getItemSpace(slot))
- t.select(slot)
- end
- otherSlot = otherSlot + 1
- end
- end
- slot = slot + 1
- end
- end
- function hasGravity(data)
- if data == nil or not (type(data) == 'table') then
- return false
- end
- name = data['name']
- if name == 'minecraft:gravel' or name == 'minecraft:sand' then
- return true
- else
- return false
- end
- end
- function preDig()
- if not (t.getSelectedSlot() == 1) then
- t.select(1)
- end
- end
- function countFreeSlots()
- freeSlots = 0
- slot = 1
- while slot <= 16 do
- if t.getItemCount(slot) == 0 then
- freeSlots = freeSlots + 1
- end
- slot = slot + 1
- end
- return freeSlots
- end
- function disposeTrash()
- slot = 1
- while slot <= 16 do
- if t.getItemCount(slot) > 0 then
- name = t.getItemDetail(slot)['name']
- if contains(TRASH, name) or not (string.find(name, 'botania:') == nil) then
- t.select(slot)
- t.drop()
- end
- end
- slot = slot + 1
- end
- end
- function isOre(data)
- if data == nil or not (type(data) == 'table') then
- return false
- end
- if not (string.find(data['name'], 'ore') == nil) then
- return true
- end
- i = 1
- while i <= #EXTRA_ORE_NAMES do
- if data['name'] == EXTRA_ORE_NAMES[i] then
- return true
- end
- i = i + 1
- end
- i = 1
- while i <= #ORE_ITEMS do
- if data['name'] == ORE_ITEMS[i][1] then
- return true
- end
- i = i + 1
- end
- return false
- end
- function checkOreAndMine(dir)
- -- Mines for ores recursivly
- if dir == 'down' then
- _, data = t.inspectDown()
- if isOre(data) then
- digDownCorrect()
- t.down()
- checkOreAndMine('down')
- checkOreAndMine('front')
- t.turnRight()
- checkOreAndMine('front')
- t.turnRight()
- checkOreAndMine('front')
- t.turnRight()
- checkOreAndMine('front')
- t.turnRight()
- t.up()
- end
- elseif dir == 'up' then
- _, data = t.inspectUp()
- if isOre(data) then
- digUpCorrect()
- t.up()
- checkOreAndMine('up')
- checkOreAndMine('front')
- t.turnRight()
- checkOreAndMine('front')
- t.turnRight()
- checkOreAndMine('front')
- t.turnRight()
- checkOreAndMine('front')
- t.turnRight()
- t.down()
- end
- elseif dir == 'front' then
- _, data = t.inspect()
- if isOre(data) then
- digAndMoveCorrect()
- --digCorrect()
- checkOreAndMine('front')
- checkOreAndMine('down')
- checkOreAndMine('up')
- t.turnRight()
- checkOreAndMine('front')
- t.turnRight()
- t.turnRight()
- checkOreAndMine('front')
- t.turnRight()
- t.back()
- end
- end
- end
- function digSide(length)
- preDig()
- digUpCorrect()
- local pos = 0
- checkOreAndMine('down')
- while pos < length do
- --digCorrect()
- --t.forward()
- digAndMoveCorrect()
- checkOreAndMine('down')
- digUpCorrect()
- --disposeTrash()
- pos = pos + 1
- end
- checkOreAndMine('front')
- t.up()
- digUpCorrect()
- checkOreAndMine('front')
- t.up()
- digUpCorrect()
- checkOreAndMine('front')
- t.up()
- checkOreAndMine('front')
- t.turnLeft()
- t.turnLeft()
- --disposeTrash()
- local pos2 = 0
- checkOreAndMine('up')
- while pos2 < length do
- --digCorrect()
- --t.forward()
- digAndMoveCorrect()
- checkOreAndMine('up')
- digDownCorrect()
- --disposeTrash()
- pos2 = pos2 + 1
- end
- digDownCorrect()
- t.down()
- digDownCorrect()
- t.down()
- t.down()
- disposeTrash()
- end
- function digAndMoveCorrect()
- t.select(1)
- while t.detect() do
- t.dig()
- end
- while not t.forward() do
- print('FAILED TO MOVE')
- t.dig()
- end
- end
- function digCorrect()
- keep_digging = true
- while keep_digging do
- keep_digging = false
- t.dig()
- if hasGravity(data) then
- sleep(1)
- keep_digging = true
- else
- return true
- end
- end
- return false
- end
- function digDownCorrect()
- t.digDown()
- return true
- end
- function digUpCorrect()
- t.digUp()
- return true
- end
- stateChecked = 0
- while true do
- stateChecked = stateChecked - 1
- if stateChecked <= 0 then
- stateChecked = 5
- autoRefuel() -- Keeps fuel at 1000
- stackInv() -- Only very rarely needed
- preDig()
- end
- --digCorrect()
- checkOreAndMine('down')
- --t.forward()
- digAndMoveCorrect()
- --disposeTrash()
- t.turnRight()
- digSide(SIDE_WIDTH)
- --stackInv() -- Recover stack fails
- digSide(SIDE_WIDTH)
- --disposeTrash()
- --stackInv() -- Recover stack fails
- t.turnLeft()
- if t.getFuelLevel() < ((SIDE_WIDTH*4*2) + (4*3) + 20) then
- print('Out of fuel!')
- print('Add fuel and run area_mine again')
- break
- end
- if countFreeSlots() < 3 then
- if selectChest() then
- t.turnRight()
- t.turnRight()
- t.place()
- slot = 1
- totalDeposited = 0
- while slot <= 16 do
- itemData = t.getItemDetail(slot)
- if t.getItemCount(slot) > 0 and not isChest(itemData) and not (itemData['name'] == 'minecraft:coal') then
- t.select(slot)
- count = t.getItemCount()
- t.drop(count)
- totalDeposited = totalDeposited + count
- end
- slot = slot + 1
- end
- print('Deposited ' .. totalDeposited .. ' items into a chest.')
- t.turnRight()
- t.turnRight()
- else
- print('Inventory is too full and no chest is available!')
- print('Clear inv, (add chests) and run area_mine again')
- break
- end
- end
- --if true then
- -- break
- --end
- end
- print('Stopped')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement