Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Programme : volume mining
- --- Auteur : LightKnight51
- --- Dernière modifications : 21/09/2024
- -- TODO Add function what put chest if turtle is full
- local arg = { ... }
- local exit = false
- --- Utils API
- os.loadAPI("MarquitoLuaUtils")
- -- Put chest up
- function DeposeChest()
- if MarquitoLuaUtils.BlockDetection("up", false) == "minecraft:bedrock" then
- MarquitoLuaUtils.Error("minecraft:bedrock")
- elseif string.find(MarquitoLuaUtils.BlockDetection("up", false),"chest") ~= nil then
- print("Coffre deja place !")
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Chest already in place")
- turtle.select(1)
- else
- turtle.digUp()
- chestId = MarquitoLuaUtils.FindIDContains("chest", false)
- if chestId ~= nil then
- turtle.select(chestId)
- turtle.placeUp()
- print("Coffre place !")
- turtle.select(1)
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Chest has been placed")
- end
- end
- end
- -- TODO To finish
- function SecureTurtle()
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Secure turtle position")
- itemID = nil
- if not MarquitoLuaUtils.BlockDetection("up", true) then
- if MarquitoLuaUtils.SelectionID("minecraft:cobblestone") ~= nil then
- itemID = MarquitoLuaUtils.SelectionID("minecraft:cobblestone")
- elseif MarquitoLuaUtils.SelectionID("minecraft:dirt") ~= nil then
- itemID = MarquitoLuaUtils.SelectionID("minecraft:dirt")
- elseif MarquitoLuaUtils.SelectionID("minecraft:netherrack") ~= nil then
- itemID = MarquitoLuaUtils.SelectionID("minecraft:netherrack")
- elseif MarquitoLuaUtils.SelectionID("minecraft:cobbled_deepslate") ~= nil then
- itemID = MarquitoLuaUtils.SelectionID("minecraft:cobbled_deepslate")
- end
- if itemID ~= nil then
- turtle.select(itemID)
- turtle.placeDown()
- turtle.place()
- turtle.turnRight()
- turtle.place()
- turtle.turnRight()
- turtle.place()
- turtle.turnRight()
- turtle.place()
- turtle.turnRight()
- end
- end
- end
- function AskDimension(type, numArg)
- dimension = 0
- bRetry = false
- print(type .. " ?")
- while true do
- if arg[numArg] ~= nil and not bRetry then
- dimension = tonumber(arg[numArg])
- print(dimension)
- else
- dimension = tonumber(read())
- end
- if not dimension or dimension == 0 then
- print("Valeur incorrecte !")
- bRetry = true
- else
- break
- end
- end
- return dimension
- end
- function MiningLine(length)
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Start mining line of length : " .. length)
- for iLength=1,length - 1 do
- while MarquitoLuaUtils.BlockDetection("front", true) == false do
- turtle.dig()
- DropIfNeeded()
- sleep(0.3)
- end
- turtle.forward()
- end
- end
- function MiningDown(height)
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Start mining down of : " .. height - 1)
- for iHeight=1,height - 1 do
- turtle.digDown()
- DropIfNeeded()
- turtle.down()
- end
- end
- function Mining(length, width, height)
- if width == 1 and height == 1 then
- MiningLine(length)
- elseif length == 1 and height == 1 then
- turtle.turnRight()
- MiningLine(width)
- elseif length == 1 and width == 1 then
- MiningDown(height)
- else
- for iHeight = 1, height do
- for iWidth = 1, width do
- MiningLine(length)
- if iWidth ~= width then
- chooseDirectionForTurn(iWidth, width, iHeight)
- turtle.dig()
- DropIfNeeded()
- turtle.forward()
- chooseDirectionForTurn(iWidth, width, iHeight)
- end
- end
- if iHeight ~= height then
- turtle.turnRight()
- turtle.turnRight()
- MiningDown(2)
- end
- end
- end
- ReturnInitPos(length, width, height)
- end
- function DropIfNeeded()
- if MarquitoLuaUtils.GetRemainingSlots() == 0 then
- MarquitoLuaUtils.DropAllItemsInShulkerBox({
- "coal",
- "blaze_rod",
- "shulker_box"
- })
- end
- end
- function chooseDirectionForTurn(number, totalWidth, iHeight)
- if isEven(totalWidth) then
- if isEven(iHeight) then
- if isEven(number) then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- else
- chooseDirectionForTurnClassic(number)
- end
- else
- chooseDirectionForTurnClassic(number)
- end
- end
- function chooseDirectionForTurnClassic(number)
- if isEven(number) then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- function isEven(number)
- return math.mod(number, 2) == 0
- end
- function MoveLine(length)
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Start moving of : " .. length)
- for iLength=1,length - 1 do
- if not MarquitoLuaUtils.BlockDetection("front", true) then
- if string.find(MarquitoLuaUtils.BlockDetection("front", false),"chest") == nil then
- turtle.dig()
- DropIfNeeded()
- else
- -- Un coffre a été déposé, cas a traiter
- end
- end
- turtle.forward()
- end
- end
- function MoveUp(height)
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Start moving up of : " .. height - 1)
- for iHeight=1,height - 1 do
- if not MarquitoLuaUtils.BlockDetection("up", true) then
- if string.find(MarquitoLuaUtils.BlockDetection("up", false),"chest") == nil then
- turtle.digUp()
- DropIfNeeded()
- else
- -- Un coffre a été déposé, cas a traiter
- end
- end
- turtle.up()
- end
- end
- function ReturnInitPos(length, width, height)
- if width == 1 and height == 1 then
- turtle.turnRight()
- turtle.turnRight()
- MoveLine(length)
- elseif length == 1 and height == 1 then
- turtle.turnRight()
- turtle.turnRight()
- MoveLine(width)
- turtle.turnRight()
- elseif length == 1 and width == 1 then
- MoveUp(height)
- else
- MoveUp(height)
- widthHeight = width * height
- if isEven(widthHeight) then
- if isEven(height) then
- turtle.turnRight()
- turtle.turnRight()
- else
- turtle.turnRight()
- MoveLine(width)
- turtle.turnRight()
- end
- else
- if isEven(height) then
- turtle.turnRight()
- turtle.turnRight()
- else
- turtle.turnLeft()
- MoveLine(width)
- turtle.turnLeft()
- MoveLine(length)
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- end
- end
- function MainProgram()
- print("Bienvenue dans le programme de minage de volume !")
- local length, width, height = 1
- length = AskDimension("Longueur", 1)
- width = AskDimension("Largeur", 2)
- height = AskDimension("Hauteur", 3)
- if length == 1 and width == 1 and height == 1 then
- print("Il n'y a rien a miner.")
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Nothing to dig")
- else
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "VolumeMining launch")
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Length : " .. length)
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Width : " .. width)
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Height : " .. height)
- turtle.digDown()
- sleep(0.5)
- turtle.down()
- DeposeChest()
- Mining(length, width, height)
- SecureTurtle()
- MarquitoLuaUtils.DropAllItemsInChest(false, {})
- end
- MarquitoLuaUtils.EndLog()
- end
- -- Program
- parallel.waitForAny(MainProgram, MarquitoLuaUtils.Refuel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement