Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- =============================================================
- -- == Predefine variables
- local HEIGHT = 0
- local WIDTH = 0
- local DEPTH = 0
- local MEASURE = false;
- local INVENTORY_SIZE = 16
- local CHECK_INVENTORY_EVERY = 20
- -- List of accepted fuels
- local ACCEPTED_FUELS = {"minecraft:coal_block", "minecraft:coal", "minecraft:charcoal"}
- -- List of accepted walls
- local ACCEPTED_WALLS = {"minecraft:planks"}
- -- List of accepted filler
- local ACCEPTED_FILLER = {"minecraft:dirt", "minecraft:cobblestone"}
- -- =============================================================
- -- == Argument parsing
- -- Receive arguments and perform some basic validation
- if #arg == 3 then
- HEIGHT = tonumber(arg[1])
- WIDTH = tonumber(arg[2])
- DEPTH = tonumber(arg[3])
- end
- -- filler 7 12 12
- -- Wall: 508 = ~8
- -- Fill: 1176 = ~8
- -- =============================================================
- -- == Functions
- local function IndexOf(list, object)
- local result
- if type(list) == "table" then
- for i = 1, #list do
- -- print(object .. " " .. list[i] .. " " .. tostring(object == list[i]))
- if object == list[i] then
- result = i
- break
- end
- end
- end
- return result
- end
- local function Refuel(once)
- if not once then
- once = false
- end
- local fuelLimit = turtle.getFuelLimit()
- print("Fuel-Limit: " .. fuelLimit)
- while true and not once do
- print("Current fuel level: " .. turtle.getFuelLevel())
- if turtle.getFuelLevel() < fuelLimit / 2 then
- print("Refuel...")
- for inventoryPosition = 1, INVENTORY_SIZE do
- local currentItem = turtle.getItemDetail(inventoryPosition)
- if currentItem ~= nil then
- local indexOf = IndexOf(ACCEPTED_FUELS, currentItem.name)
- if indexOf ~= nil then
- turtle.select(indexOf)
- if turtle.refuel(0) then
- turtle.refuel()
- else
- error(currentItem.name .. " is not a valid fuel material")
- end
- end
- end
- end
- print("New fuel level: " .. turtle.getFuelLevel())
- end
- if not once then
- sleep(5)
- end
- end
- end
- -- Move and dig
- local function MoveUpAndDig()
- while turtle.up() == false do
- turtle.digUp()
- end
- end
- local function MoveForwardAndDig()
- while turtle.forward() == false do
- turtle.dig()
- end
- end
- local function MoveDownAndDig()
- while turtle.down() == false do
- turtle.digDown()
- end
- end
- -- Mining Sequence
- local function MineSequence()
- for depth = 1, DEPTH do
- -- Move on forward
- if depth ~= 1 then
- MoveForwardAndDig()
- if depth % 2 == 0 then
- MoveDownAndDig()
- else
- MoveUpAndDig()
- end
- end
- -- For every height
- for height = 1, HEIGHT do
- if depth % 2 == 0 then
- MoveDownAndDig()
- else
- MoveUpAndDig()
- end
- -- Rotate turtle depending on height
- if height % 2 == 0 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- for width = 1, WIDTH do
- -- Predefine variable
- local wall
- local placed = false
- local toPlaceIndex
- -- Check if wall or fill
- if depth == 1 or depth == DEPTH or height == 1 or height == HEIGHT or width == 1 or width == WIDTH then
- wall = true
- else
- wall = false
- end
- -- Check inventory for element to place
- for inventoryPosition = 1, INVENTORY_SIZE do
- local currentItem = turtle.getItemDetail(inventoryPosition)
- local indexOf;
- if currentItem ~= nil then
- if wall then
- indexOf = IndexOf(ACCEPTED_WALLS, currentItem.name)
- if indexOf == nil then
- currentItem = turtle.getItemDetail(inventoryPosition, true)
- for currentTag in pairs(currentItem.tags) do
- indexOf = IndexOf(ACCEPTED_WALLS, currentTag)
- if indexOf ~= nil then
- toPlaceIndex = inventoryPosition;
- break
- end
- end
- else
- toPlaceIndex = inventoryPosition;
- end
- else
- indexOf = IndexOf(ACCEPTED_FILLER, currentItem.name)
- if indexOf == nil and false then
- currentItem = turtle.getItemDetail(inventoryPosition, true)
- for currentTag in pairs(currentItem.tags) do
- indexOf = IndexOf(ACCEPTED_FILLER, currentTag)
- if indexOf ~= nil then
- toPlaceIndex = inventoryPosition;
- break
- end
- end
- else
- toPlaceIndex = inventoryPosition;
- end
- end
- end
- if toPlaceIndex ~= nill then
- break
- end
- end
- if toPlaceIndex == nil then
- if depth == 1 or depth == DEPTH or height == 1 or height == HEIGHT or width == 1 or width == WIDTH then
- error("Missing material: Wall")
- else
- error("Missing material: Fill")
- end
- end
- if (toPlaceIndex ~= nil) then
- turtle.select(toPlaceIndex)
- if depth % 2 == 0 then
- if turtle.placeUp() then
- placed = true
- end
- else
- if turtle.placeDown() then
- placed = true
- end
- end
- end
- if not placed then
- if depth == 1 or depth == DEPTH or height == 1 or height == HEIGHT or width == 1 or width == WIDTH then
- error("Something went wrong: Wall")
- else
- error("Something went wrong: Fill")
- end
- end
- if width ~= WIDTH then
- MoveForwardAndDig()
- end
- end
- -- Rotate turtle back depending on height
- if height % 2 == 0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- end
- end
- -- =============================================================
- -- == Validate values
- if WIDTH <= 0 or HEIGHT <= 0 or DEPTH <= 0 then
- print("Both the height and width arguments must be greater and 1")
- return
- end
- if HEIGHT % 2 == 1 then
- print("The height should not be odd")
- return
- end
- -- =============================================================
- -- == Output every inventory item name
- for inventoryPosition = 1, INVENTORY_SIZE do
- local currentItem = turtle.getItemDetail(inventoryPosition, true)
- if currentItem ~= nil then
- -- print(textutils.serialize(currentItem))
- -- print(currentItem.name)
- end
- end
- -- =============================================================
- -- == Execute mining
- -- Refuel
- Refuel(true)
- -- Start mining loop
- MineSequence()
- -- parallel.waitForAny(MineSequence, Refuel)
Advertisement
Add Comment
Please, Sign In to add comment