Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- =============================================================
- -- == Predefine variables
- local WIDTH = 0
- local DEPTH = 0
- local MEASURE = false;
- local INVENTORY_SIZE = 16
- -- List of accepted fuels
- local ACCEPTED_FUELS = {"minecraft:coal_block", "minecraft:coal", "minecraft:charcoal"}
- -- List of blacklisted items
- local BLACKLIST_ITEMS = {"minecraft:torch"}
- -- =============================================================
- -- == Argument parsing
- -- Receive arguments and perform some basic validation
- if #arg == 2 then
- WIDTH = tonumber(arg[1])
- DEPTH = tonumber(arg[2])
- elseif #arg == 1 then
- MEASURE = true;
- DEPTH = tonumber(arg[2])
- else
- MEASURE = true;
- end
- -- =============================================================
- -- == Functions
- function Refuel(once)
- if not once then
- once = false
- end
- local fuelLimit = turtle.getFuelLimit()
- print("Fuel-Limit: " .. fuelLimit)
- while true do
- print("Current fuel level: " .. turtle.getFuelLevel())
- if turtle.getFuelLevel() < fuelLimit / 2 then
- print("Refuel...")
- for i = 1, INVENTORY_SIZE do
- local currentItem = turtle.getItemDetail(i)
- if currentItem ~= nil then
- local foundInFuelList = false
- for x = 1, #ACCEPTED_FUELS do
- if currentItem.name == ACCEPTED_FUELS[x] then
- foundInFuelList = true
- break
- end
- end
- if foundInFuelList then
- turtle.select(i)
- if turtle.refuel(0) then
- turtle.refuel()
- end
- end
- end
- end
- turtle.select(1)
- print("New fuel level: " .. turtle.getFuelLevel())
- end
- if (once) then
- break
- else
- sleep(5)
- end
- end
- end
- -- Place Sequence
- function PlaceSequence()
- for depth = 1, DEPTH do
- if depth ~= 1 then
- turtle.forward()
- end
- -- Rotate turtle depending on depth
- if depth % 2 == 0 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- for width = 1, WIDTH - 1 do
- Refuel(true)
- if turtle.detectDown() then
- turtle.digDown()
- end
- local foundAtIndex = nil
- for i = 1, INVENTORY_SIZE do
- local currentItem = turtle.getItemDetail(i)
- if currentItem ~= nil then
- local foundInBlacklist = false
- for x = 1, #BLACKLIST_ITEMS do
- if currentItem.name == BLACKLIST_ITEMS[x] then
- foundInBlacklist = true
- break
- end
- end
- for x = 1, #ACCEPTED_FUELS do
- if currentItem.name == ACCEPTED_FUELS[x] then
- foundInBlacklist = true
- break
- end
- end
- if not foundInBlacklist then
- foundAtIndex = i
- break
- end
- end
- end
- if (foundAtIndex == nil) then
- error("[ERROR] No block found to place")
- end
- turtle.select(foundAtIndex)
- if not turtle.placeDown() then
- error("[ERROR] Failed to place block :/")
- end
- turtle.forward()
- if width % 4 == 0 and depth % 2 == 1 and (depth - 1) % 4 == 0 then
- print("Try to place torch...")
- local found = false;
- for inventoryPosition = 1, INVENTORY_SIZE do
- local currentItem = turtle.getItemDetail(inventoryPosition)
- if currentItem ~= nil and currentItem.name == "minecraft:torch" then
- found = true
- turtle.select(inventoryPosition)
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(1)
- break
- end
- end
- if not found then
- print("[WARN] No torch found :(")
- end
- end
- end
- -- Rotate turtle back depending on depth
- if depth % 2 == 0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- end
- -- =============================================================
- -- == Refuel before start
- Refuel(true)
- -- =============================================================
- -- == Measue
- if MEASURE then
- Refuel(true)
- print("Start measuring...")
- -- Measure width
- turtle.turnRight()
- while turtle.forward() == true do
- WIDTH = WIDTH + 1;
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for width = 1, WIDTH do
- if turtle.forward() == false then
- error("[MEASURE] Failed to move back")
- end
- end
- WIDTH = WIDTH + 1
- print("Width: " .. WIDTH)
- turtle.turnRight()
- -- Measure Depth
- while turtle.forward() == true do
- DEPTH = DEPTH + 1;
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for depth = 1, DEPTH do
- if turtle.forward() == false then
- error("[MEASURE] Failed to move back")
- end
- end
- DEPTH = DEPTH + 1
- print("Depth: " .. DEPTH)
- turtle.turnRight()
- turtle.turnRight()
- end
- -- =============================================================
- -- == Validate values
- if WIDTH <= 0 or DEPTH <= 0 then
- print("Both the height and width arguments must be greater and 1")
- return
- end
- -- =============================================================
- -- == Execute mining
- -- =============================================================
- -- == Execute mining
- -- Refuel
- Refuel(true)
- -- Start mining loop
- PlaceSequence()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement