Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --riewestLIB
- --Version "1.0.0"
- --MCVersion "1.10.2"
- --Writer: Riewest (AKA Riewest14)
- function test()
- end
- ---------------
- --ITEM HANDLING
- ---------------
- --Attempts to get fuel from a
- --inventory on side passed and fill
- --the slot passed. Works best if
- --The item is still in slot or
- --Chest only has fuel items
- function getFuel(slot, side)
- if not slot then
- slot = 16
- end
- if not side then
- side = "front"
- end
- oldSlot = turtle.getSelectedSlot()
- turtle.select(slot)
- side = string.lower(side)
- toGet = turtle.getItemSpace()
- if side == "front" then
- turtle.suck(toGet)
- elseif side == "top" then
- turtle.suckUp(toGet)
- elseif side == "bottom" then
- turtle.suckDown(toGet)
- end
- turtle.select(oldSlot)
- end
- --Tries to put all of the items from
- --the all other slots into the
- --passed slot
- function sortItem(slot)
- if not slot then
- return
- end
- oldSlot = turtle.getSelectedSlot()
- turtle.select(slot)
- if turtle.getItemCount() > 0 then
- itemDetail = turtle.getItemDetail()
- for i = 1, 16 do
- turtle.select(i)
- if not (i == slot) and (turtle.getItemCount() > 0) then
- tempDetail = turtle.getItemDetail()
- if (itemDetail.name == tempDetail.name) then
- turtle.transferTo(slot)
- end
- end
- end
- end
- turtle.select(oldSlot)
- end
- --Empty's the slots passed in through
- --the array.
- function emptyInv(slotsToEmpty, side)
- oldSlot = turtle.getSelectedSlot()
- if not side then
- side = "back"
- end
- if not slotsToEmpty then
- count = 16
- else
- count = table.getn(slotsToEmpty)
- end
- rotate(side)
- for i = 1, count do
- dropSide(slotsToEmpty[i], side)
- end
- reverseRotate(side)
- turtle.select(oldSlot)
- end
- --Empty's slots except the passed
- --in values
- function emptyInvExcept(slotsToKeep, side)
- slotsToEmpty = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
- table.sort(slotsToKeep)
- for i = table.getn(slotsToKeep), 1, -1 do
- table.remove(slotsToEmpty, slotsToKeep[i])
- end
- emptyInv(slotsToEmpty, side)
- end
- --Drops all the items in slotNum
- --to the indicated side
- function dropSide(slotNum, side)
- turtle.select(slotNum)
- side = string.lower(side)
- success = false
- if side == "front" then
- success = turtle.drop()
- elseif side == "top" then
- success = turtle.dropUp()
- elseif side == "bottom" then
- success = turtle.dropDown()
- else
- success = turtle.drop()
- end
- return success
- end
- --Method to tell the turtle to suck
- --in front of it and the left and right
- function tSuck(distinctItems)
- for i = 1, distinctItems do
- turtle.suck()
- end
- turtle.turnLeft()
- for i = 1, distinctItems do
- turtle.suck()
- end
- turnAround()
- for i = 1, distinctItems do
- turtle.suck()
- end
- turtle.turnLeft()
- end
- --Method to refuel the turtle
- --if its fuel level is below a
- --critical amount. Fuel slot is
- --passed in, as well as threshold
- function tRefuel(fSlot, thresh)
- if not thresh then
- thresh = 100
- end
- if not fSlot then
- fSlot = 16
- end
- success = false
- if turtle.getFuelLevel() <= thresh then
- oldSlot = turtle.getSelectedSlot()
- turtle.select(fSlot)
- success = turtle.refuel(turtle.getItemCount() - 1)
- turtle.select(oldSlot)
- end
- return success
- end
- ------------------
- --MOVEMENT METHODS
- ------------------
- --Just runs turtle.forward()
- --until the specified amount toMov
- --is met. Digs block if unable to move
- function tMoveF(toMov)
- if not toMov then
- toMov = 1
- end
- for i = 1, toMov do
- while not (turtle.forward()) do
- turtle.dig()
- end
- end
- end
- --Runst turtle.back() toMov times
- function tMoveB(toMov)
- if not toMov then
- toMov = 1
- end
- for i = 1, toMov do
- while not turtle.back() do
- sleep(.1)
- end
- end
- end
- --Runs turtle.up() toMov times
- --and digs up if unable to move up.
- function tMoveU(toMov)
- if not toMov then
- toMov = 1
- end
- for i = 1, toMov do
- while not (turtle.up()) do
- turtle.digUp()
- end
- end
- end
- --Runs turtle.down() toMov times
- -- and digs down if unable to move down
- function tMoveD(toMov)
- if not toMov then
- toMov = 1
- end
- for i = 1, toMov do
- while not (turtle.down()) do
- turtle.digDown()
- end
- end
- end
- --Turns the turtle 180 degrees
- function turnAround()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- --Turns the turtle to the passed side
- function rotate(side)
- if not side then
- return
- elseif side == "back" then
- turnAround()
- elseif side == "left" then
- turtle.turnLeft()
- elseif side == "right" then
- turtle.turnRight()
- else
- end
- end
- --Turns the turtle opposite the
- -- passed side
- function reverseRotate(side)
- if not side then
- return
- elseif side == "back" then
- turnAround()
- elseif side == "left" then
- turtle.turnRight()
- elseif side == "right" then
- turtle.turnLeft()
- else
- end
- end
- --------------
- --DATA METHODS
- --------------
- --Displays fuel level in the upper
- --right corner of the screen
- function displayFuel()
- fuelLevel = turtle.getFuelLevel()
- oldX, oldY = term.getCursorPos()
- displayY = 1
- displayX = 34
- term.setCursorPos(displayX, displayY)
- print("Fuel:")
- term.setCursorPos(displayX, displayY + 1)
- print(fuelLevel)
- term.setCursorPos(oldX, oldY)
- end
- --Function to find the slot number
- --Of the item containing passed in
- --String, Return bool, slot
- function findSlot(name)
- found = false
- slot = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- itemDetail = turtle.getItemDetail(i)
- if string.match(itemDetail.name, string.lower(name)) then
- slot = i
- found = true
- break
- end
- end
- end
- return found, slot
- end
- test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement