Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("apis/refuel.lua")
- os.loadAPI("apis/stats.lua")
- --Improved turtle.forward()
- --@OptionalArg number amount: The amount it should move forward, default 1
- function forward(amount)
- amount = tonumber(amount,10) or 1
- for i=1,amount do
- turtle.forward()
- end
- stats.add("Times Moved",amount)
- end
- --Improved turtle.back()
- --@OptionalArg number amount: The amount it should move back, default 1
- function back(amount)
- amount = tonumber(amount,10) or 1
- for i=1,amount do
- turtle.back()
- end
- stats.add("Times Moved",amount)
- end
- --Improved turtle.turnRight()
- --@OptionalArg number amount: The amount it should turn, default 1
- function turnRight(amount)
- amount = tonumber(amount,10) or 1
- amount = amount%4
- for i=1,amount do
- turtle.turnRight()
- end
- stats.add("Times Turned Right",amount)
- end
- --Improved turtle.turnLeft()
- --@OptionalArg number amount: The amount it should turn, default 1
- function turnLeft(amount)
- amount = tonumber(amount,10) or 1
- amount = amount%4
- for i=1,amount do
- turtle.turnLeft()
- end
- stats.add("Times Turned Left",amount)
- end
- --Improved turtle.dig(). Will be able to tolerate gravel falling, and won't waste time if theres nothing to dig
- function dig()
- while turtle.detect() do
- turtle.dig()
- stats.add("Amount Dug",1)
- end
- end
- --Improved turtle.digUp(). Will be able to tolerate gravel falling, and won't waste time if theres nothing to dig
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- stats.add("Amount Dug",1)
- end
- end
- --Improved turtle.digDown(). Will be able to tolerate gravel falling, and won't waste time if theres nothing to dig
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- stats.add("Amount Dug",1)
- end
- end
- --Improved turtle.down()
- --@OptionalArg number amount: The amount it should move down, default 1
- function down(amount)
- amount = tonumber(amount) or 1
- for i=1,amount do
- digDown()
- turtle.down()
- end
- stats.add("Times Moved",amount)
- stats.add("Vertical Distance",amount)
- end
- --Improved turtle.down()
- --@OptionalArg number amount: The amount it should move down, default 1
- function up(amount)
- amount = tonumber(amount) or 1
- for i=1,amount do
- digUp()
- turtle.up()
- end
- stats.add("Times Moved",amount)
- stats.add("Vertical Distance",amount)
- end
- --Improved turtle.place()
- --Places the item in a specified slot
- --@OptionalArg number slot: The slot to select before placing
- --@OptionalArg string signText: The sign text to write
- function place(slot,signText)
- if slot then turtle.select(slot) end
- --dig()
- turtle.place(signText)
- stats.add("Blocks Placed",1)
- end
- --Improved turtle.placeDown()
- --Places the item in a specified slot
- --@OptionalArg number slot: The slot to select before placing
- --@OptionalArg string signText: The sign text to write
- function placeDown(slot,signText)
- if slot then turtle.select(slot) end
- turtle.placeDown(signText)
- stats.add("Blocks Placed",1)
- end
- --Improved turtle.placeUp()
- --Places the item in a specified slot
- --@OptionalArg number slot: The slot to select before placing
- --@OptionalArg string signText: The sign text to write
- function placeUp(slot,signText)
- if slot then turtle.select(slot) end
- turtle.placeUp(signText)
- stats.add("Blocks Placed",1)
- end
- --Improved turtle.drop()
- --Drops the item in the selected slot
- --@OptionalArg number slot: The slot to select before dropping
- --@Returns boolean success: Whether the item was dropped
- function drop(slot)
- if slot then turtle.select(slot) end
- local count = turtle.getItemCount()
- if turtle.drop() then
- stats.add("Items Dropped",count or 0)
- return true
- else
- return false
- end
- end
- --Improved turtle.dropDown()
- --Drops the item in the selected slot
- --@OptionalArg number slot: The slot to select before dropping
- --@Returns boolean success: Whether the item was dropped
- function dropDown(slot)
- if slot then turtle.select(slot) end
- local count = turtle.getItemCount()
- if turtle.dropDown() then
- stats.add("Items Dropped",count or 0)
- return true
- else
- return false
- end
- end
- --Improved turtle.dropUp()
- --Drops the item in the selected slot
- --@OptionalArg number slot: The slot to select before dropping
- --@Returns boolean success: Whether the item was dropped
- function dropUp(slot)
- if slot then turtle.select(slot) end
- local count = turtle.getItemCount()
- if turtle.dropUp() then
- stats.add("Items Dropped",count or 0)
- return true
- else
- return false
- end
- end
- --Detects whether the dispenser below the turtle is facing up or not
- --@Returns boolean isDispFacingUp: Whether the block below the turtle is a dispenser that is facing up
- function isDispFacingUp()
- if not turtle.detectDown() then return false end
- local success,data = turtle.inspectDown()
- if not success then return false end
- if not data.name == "minecraft:dispenser" then return false end
- if not data.state.facing == "up" then return false end
- return data.state.facing == "up"
- --return true
- end
- --Runs a routine to store the items, using a dispenser and a backpack
- --MAKE SURE QUARK IS INSTALLED
- --@OptionalArg string backpack: "sophisticatedbackpacks:<tier>_backpack"
- --@Returns boolean success, string errMsg: If it was successful
- function storeItems(backpack)
- local slot = nil
- local dispSlot = refuel.findItem("minecraft:dispenser")
- if not dispSlot then return false, "no dispenser found" end
- if not backpack then
- local tiers = {"","copper_","iron_","gold_","diamond_","netherite_"}
- for i=1,#tiers do
- slot = refuel.findItem("sophisticatedbackpacks:"..tiers[i].."backpack")
- if slot then return storeItems("sophisticatedbackpacks:"..tiers[i].."backpack") end
- end
- return false, "could not find backpack"
- else
- slot = refuel.findItem(backpack)
- end
- if not slot then return false, "no backpack found" end
- digDown()
- placeDown(dispSlot)
- local count = 0
- while not isDispFacingUp() do
- digDown()
- down()
- local slot = refuel.findItem("minecraft:cobblestone") or refuel.findItem("minecraft:cobbled_deepslate")
- if slot then placeDown(slot)
- elseif count >= 10 then
- up()
- error("trouble storing items")
- end
- count = count + 1
- up()
- placeDown(refuel.findItem("minecraft:dispenser"))
- end
- dropDown(slot)
- dig()
- forward()
- digDown()
- down()
- redstone.setOutput("back",true)
- up()
- turnLeft(2)
- for i=1,16 do
- if turtle.getItemCount(i) >0 and not drop(i) then
- dig()
- forward()
- digDown()
- turnLeft(2)
- return false, "inventory full"
- end
- end
- dig()
- forward()
- digDown()
- if count > 0 then
- down()
- digDown()
- up()
- end
- turnLeft(2)
- return true
- end
- --Detects if there is an empty slot in the turtle's inventory
- --@Returns number slot: The slot number, or -1 if there isn't a free slot
- function getFreeSlot()
- for i=1,16 do
- if turtle.getItemCount(i) <= 0 then return i end
- end
- return -1
- end
- --Counts the number of empty slots in the turtle's inventory
- --@Returns number count: The number of free slots in the turtle's inventory
- function countFreeSlots()
- local count = 0
- for i=1,16 do
- if turtle.getItemCount(i) <= 0 then count = count + 1 end
- end
- return count
- end
- --Counts the amount of items of a type can fit in a turtles inventory
- --@OptionalArg string id: The id of the item to be added
- --@Returns number space: The amount of items that can be added
- function getFreeSpace(id)
- local count = 0
- for i=1,16 do
- if not id or not turtle.getItemDetail(i) or turtle.getItemDetail(i).name == id then
- count = count + turtle.getItemSpace(i)
- end
- end
- return count
- end
Add Comment
Please, Sign In to add comment