Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get bSBgdCDF StorageTurtle
- TT = require("TT")
- TURT = {}
- local function isTurtleBlock(data)
- return data and type(data.name) == "string" and data.name:match("computercraft:turtle")
- end
- local function getDirectionInQueue()
- local initData = SDM.TURTLE.loadInitData()
- local posQueueLeft = CVF.sub(initData.diskFinishCoord, initData.dirSection)
- local posQueueRight = CVF.add(posQueueLeft, CVF.mult(4, initData.dirTopBelt))
- posQueueLeft.y = POS.position.y
- posQueueRight.y = POS.position.y
- if CVF.equalCoords(posQueueLeft, POS.position) then
- local strBlocks = ""
- for i = 1, 4 do
- local success, data = turtle.inspect()
- if success and not isTurtleBlock(data) then
- if i < 4 or strBlocks ~= "1" then
- strBlocks = strBlocks .. tostring(i)
- if #strBlocks == 2 then
- POS.direction = {x=initData.dirBottomBelt.x, z=initData.dirBottomBelt.z}
- return true
- end
- else
- strBlocks = tostring(i) .. strBlocks
- if #strBlocks == 2 then
- POS.direction = {x = -initData.dirSection.x, z = -initData.dirSection.z}
- return true
- end
- end
- end
- BM.turnRight()
- end
- return false
- elseif CVF.equalCoords(posQueueRight, POS.position) and not (posQueueLeft.y == initData.diskFinishCoord.y + 1) then
- local strBlocks = ""
- for i = 1, 4 do
- local success, data = turtle.inspect()
- if success and not isTurtleBlock(data) then
- if i < 4 or strBlocks ~= "1" then
- strBlocks = strBlocks .. tostring(i)
- if #strBlocks == 2 then
- POS.direction = {x = -initData.dirSection.x, z = -initData.dirSection.z}
- return true
- end
- else
- strBlocks = tostring(i) .. strBlocks
- if #strBlocks == 2 then
- POS.direction = {x=initData.dirTopBelt.x, z=initData.dirTopBelt.z}
- return true
- end
- end
- end
- BM.turnRight()
- end
- return false
- else
- for i = 1, 4 do
- local success, data = turtle.inspect()
- if success and not isTurtleBlock(data) then
- POS.direction = {x = -initData.dirSection.x, z = -initData.dirSection.z}
- return true
- end
- BM.turnRight()
- end
- end
- end
- local function getDirectionPerMovement()
- local initData = SDM.TURTLE.loadInitData()
- local bQueue = SDM.TURTLE.getQueueState()
- if bQueue then
- if getDirectionInQueue() then return true end
- end
- if POS.isOnElevatorDown() then
- local bModY = initData.lowBeltY % initData.blockHeight
- while POS.position.y % initData.blockHeight ~= bModY do BM.down() end
- elseif POS.isOnElevatorUp() then
- local bModY = initData.lowBeltY % initData.blockHeight
- while POS.position.y % initData.blockHeight ~= bModY do BM.up() end
- end
- local cnt = 0
- while not BM.forward() do
- if cnt == 4 then
- return false
- end
- BM.turnLeft()
- cnt = cnt + 1
- end
- if not POS.isInSystem() then
- while not BM.back() do sleep(0.1) end
- end
- return true
- end
- function TURT.init()
- local bInit, num = POS.init()
- if not bInit and num == 3 then
- if not getDirectionPerMovement() then
- print("Can't get direction")
- return false
- end
- elseif not bInit then
- return false
- end
- return true
- end
- function TURT.main()
- local minFuelLevel = 2000
- local initData = SDM.TURTLE.loadInitData()
- local taskOutputCoord = initData.diskOutCoord
- local finishCoord = initData.diskFinishCoord
- local refuelCoord = initData.chestRefuelCoord
- taskOutputCoord.y = taskOutputCoord.y + 1
- finishCoord.y = initData.diskFinishCoord.y + 1
- refuelCoord.y = refuelCoord.y - 1
- while not TURT.init() do sleep(5) end
- refuelCoord[POS.sectionDir] = refuelCoord[POS.sectionDir] + initData.dirSection[POS.sectionDir]
- while true do
- if CVF.equalCoords(taskOutputCoord, POS.position) then
- SDM.TURTLE.setQueueState(false)
- if SDM.TURTLE.update_SE() then
- os.reboot()
- end
- SDM.TURTLE.setQueueState(false)
- if turtle.getFuelLevel() < minFuelLevel then
- while not AM.goToCoord(refuelCoord) do
- while not POS.get_GPS_Position() do sleep(1) end
- end
- return true
- end
- end
- if SDM.TURTLE.getQueueState() then
- AM.queueForTask()
- elseif CVF.equalCoords(taskOutputCoord, POS.position) then
- if SDM.TURTLE.update_SE() then
- os.reboot()
- end
- SDM.TURTLE.setQueueState(false)
- if turtle.getFuelLevel() < minFuelLevel then
- while not AM.goToCoord(refuelCoord) do
- while not POS.get_GPS_Position() do sleep(1) end
- end
- return true
- end
- while not TT.getTask() do sleep(0.5) end
- if SDM.TURTLE.update_SE() then
- os.reboot()
- end
- elseif not TT.getTask() then
- while not AM.goToCoord(finishCoord) do
- while not POS.get_GPS_Position() do sleep(1) end
- end
- AM.joinQueue()
- end
- if TT.getTask() then
- if TT.Task.taskType == "incoming" then
- TT.doIncomingTask()
- elseif TT.Task.taskType == "requested" then
- TT.doOutgoingTask()
- elseif TT.Task.taskType == "create chests" then
- TT.doCreateChest()
- elseif TT.Task.taskType == "check chests" then
- TT.doCheckChests()
- else
- end
- end
- end
- end
- return TURT
Advertisement
Add Comment
Please, Sign In to add comment