Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x, y = ...
- local horiDir = false
- local vertDir = false
- local utils = dofile("utils.lua")
- local move = dofile("smartMove.lua")
- local front, back, left, right =
- move.orientation.front,
- move.orientation.back,
- move.orientation.left,
- move.orientation.right
- local blacklist = {
- "minecraft:dirt",
- "minecraft:stone",
- "minecraft:cobblestone",
- "minecraft:grass"
- }
- local chests = {
- "minecraft:chest",
- "bibliocraft:framedchest",
- "ironchest:iron_chest"
- }
- local fuel = {
- "minecraft:coal",
- "minecraft:coal_block"
- }
- local function unload()
- log("Unloading content\n")
- move.turn(back)
- local success, data = turtle.inspect()
- local successUp, dataUp = turtle.inspectUp()
- if not success or not utils.isInList(chests, data.name) then
- error("Cannot unload when not in front of a chest")
- end
- if not successUp or not utils.isInList(chests, dataUp.name) then
- error("Cannot unload when not under a chest")
- end
- for i=1, 16 do
- local item = turtle.getItemDetail(i)
- turtle.select(i)
- if item and utils.isInList(fuel, item.name) then
- turtle.dropUp(64)
- else
- turtle.drop(64)
- end
- end
- end
- local function refuel()
- log("Refueling\n")
- unload()
- if turtle.getFuelLevel() == turtle.getFuelLevel() then
- error("Fuel limit already reached")
- end
- turtle.suckUp(64)
- turtle.refuel(64)
- end
- local function calculateMinimumFuelNeeded(x, y, z)
- return (
- math.abs(x) +
- math.abs(y) +
- math.abs(z)
- ) * 2
- end
- local function fuelToGoBack()
- return calculateMinimumFuelNeeded(move.getLocation()) / 2
- end
- local function saveState(i, j)
- local file = io.open("state", "w")
- file:write(tostring(i).."\n")
- file:write(tostring(j).."\n")
- file:write(tostring(x).."\n")
- file:write(tostring(y).."\n")
- file:write(tostring(horiDir).."\n")
- file:write(tostring(vertDir).."\n")
- file:close()
- end
- local function inventoryFull()
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- return false
- end
- end
- log("Inventory full !\n")
- return true
- end
- local function unloadAndRefuel()
- local x, y, z, o = move.getLocation()
- log("Unloading and refueling\n")
- move.getBack()
- move.turn(back)
- unload()
- while calculateMinimumFuelNeeded(x, y, z) > turtle.getFuelLevel() do
- refuel()
- end
- move.goTo(x, y, z, o)
- end
- function log(str)
- io.write(str)
- local file = io.open("log.log", "a")
- if not file then return end
- file:write(str)
- file:close()
- end
- local firsti, firstj = 1, 1
- if fd.exists("state") then
- else
- x, y = tonumber(x), tonumber(y)
- end
- if not x or not y then
- print("Usage: mine <sizex> <sizey>")
- return
- end
- if x % 4 ~= 0 then
- print("Xsize must be a multiple of 4")
- return
- end
- if not fs.exists("state") then
- move.loadLocation()
- move.getBack()
- unload()
- end
- for j=1, y do
- for i=1, x, 4 do
- while not move.go(horiDir and back or front) do
- move.vertGo(vertDir)
- end
- move.go(horiDir and back or front)
- move.go(horiDir and back or front)
- move.go(horiDir and back or front)
- local zz
- while move.vertGo(vertDir) and (zz ~= 0 or not vertDir) do
- for k=0, 3 do
- move.turn(k)
- local success, data = turtle.inspect()
- if success and not utils.isInList(
- blacklist,
- data.name
- ) then
- turtle.dig()
- end
- end
- zz = move.getLocation()
- if
- inventoryFull() or
- fuelToGoBack() > turtle.getFuelLevel()
- then
- unloadAndRefuel()
- end
- end
- vertDir = not vertDir
- end
- while not move.go(right) do
- move.vertGo(vertDir)
- end
- move.go(horiDir and back or front)
- move.go(horiDir and back or front)
- horiDir = not horiDir
- end
- log("end\n")
- fs.delete(state)
- move.getBack()
- unload()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement