Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function escape(height, msg) -- escape function
- if (msg) then
- print('Escaping SOS')
- end
- local status = 1
- while (status <= height) do
- local up = turtle.detectUp()
- if (up) then
- turtle.digUp()
- end
- turtle.up()
- status = status + 1
- end
- turtle.forward()
- if msg then
- print('Escaping Finished SOS Mode Shutdown')
- end
- end
- function refuel()
- local inventorySlots = 16
- local inventoryCheckingStatus = 1
- while (inventoryCheckingStatus <= inventorySlots) do
- turtle.select(inventoryCheckingStatus)
- turtle.refuel()
- local checkItem = turtle.getItemDetail(inventoryCheckingStatus)
- if (checkItem ~= nil) then
- if (checkItem.name == 'minecraft:coal' or checkItem.name == 'minecraft:coal_block') then
- local checkFuel = getFuelPerc()
- local howMany = turtle.getItemCount(inventoryCheckingStatus)
- if (checkFuel >= 100) then
- turtle.transferTo(16, howMany)
- else
- turtle.refuel()
- end
- end
- end
- inventoryCheckingStatus = inventoryCheckingStatus + 1
- end
- turtle.select(1)
- print('Refuel Finished !')
- end
- function getFuelPerc()
- local fuelLimit = turtle.getFuelLimit()
- local fuelLevel = turtle.getFuelLevel()
- local percentage = ((fuelLevel * 100) / fuelLimit)
- print(percentage .. ' % Fuel in the turtle !')
- return percentage
- end
- local i = 0
- function moveBot(blockAmount, direction)
- if (direction == 'forward') then
- print('Moving ' .. blockAmount .. ' blocks')
- for i = 1, blockAmount, 1 do
- turtle.forward()
- end
- elseif (direction == 'back') then
- print('Moving ' .. blockAmount .. ' block')
- for i = 1, blockAmount, 1 do
- turtle.back()
- end
- elseif (direction == 'up') then
- print('Moving ' .. blockAmount .. ' block')
- for i = 1, blockAmount, 1 do
- turtle.up()
- end
- elseif (direction == 'down') then
- print('Moving ' .. blockAmount .. ' block')
- for i = 1, blockAmount, 1 do
- turtle.down()
- end
- else
- print('Direction error !!')
- return false
- end
- return true
- end
- function turn(side)
- if (side == 'left') then
- turtle.turnLeft()
- return true
- elseif (side == 'right') then
- turtle.turnRight()
- return true
- else
- print('Error arguments side not valid !')
- return false
- end
- end
- function inventoryCheck(item)
- local inventoryCap = 16
- turtle.select(1)
- local storageSlot = nil
- local stackItems = false
- for i = 1, inventoryCap, 1 do
- --print(i)
- turtle.select(i)
- local info = turtle.getItemDetail()
- if (info ~= nil) then
- if(info.name == item) then
- if(stackItems ~= true) then
- stackItems = true
- storageSlot = i
- else
- if (stackItems == false) then
- storageSlot = i
- end
- turtle.transferTo(storageSlot)
- end
- end
- print(info.name .. ' ' .. info.count .. 'X')
- end
- end
- turtle.select(1)
- local infoLast = turtle.getItemDetail(storageSlot)
- if (infoLast ~= nil) then
- local final = {name = infoLast.name, count = infoLast.count, slot = storageSlot}
- return final
- else
- return
- end
- end
- function deposit(side, item)
- if (side == "left") then
- turn('left')
- turtle.select(inventoryInfo.slot)
- turtle.drop()
- turn('right')
- elseif (side == 'right') then
- turn('right')
- turtle.select(inventoryCheck(item).slot)
- turtle.drop()
- turn('left')
- elseif (side == 'back') then
- turtle.select(inventoryInfo.slot)
- turtle.dropBack()
- end
- end
- function followBlock(blockName, long)
- local side = nil
- for i = 1, long, 1 do
- local s, blockUnder = turtle.inspectDown()
- blockUnder = blockUnder.name
- if (blockUnder == blockName) then
- moveBot(1, 'forward')
- else
- moveBot(1, 'back')
- turn('left')
- moveBot(1, 'forward')
- blockUnder = turtle.inspectDown()
- if (blockUnder ~= blockName) then
- moveBot(2, 'back')
- for b = 1, 2, 1 do
- turn('right')
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment