Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Simple aggregation of function for ease of testing functions or quickly getting block info
- --by hornedcommando
- local tTurtle = require("TrackingTurtle")
- local myTurtle = tTurtle.create()
- -- Select the first slot in the inventory
- turtle.select(1)
- -- Function to check information about the item in the selected slot
- local function checkItem()
- -- Get information about the item in the selected slot
- local itemDetail = turtle.getItemDetail()
- -- Check if an item is present in the selected slot
- if itemDetail then
- -- Print information about the item
- print("All Item Detail Fields:")
- for key, value in pairs(itemDetail) do
- print(key .. ": " .. tostring(value))
- end
- else
- print("No item in the selected slot.")
- end
- end
- -- Function to check the block in front of the turtle
- local function checkBlock()
- -- Get information about the block in front of the turtle
- local success, block = turtle.inspect()
- if success then
- -- Print information about the block
- print("Item Name:".. block.name)
- print("State Table:")
- for key, value in pairs(block.state) do
- print(key .. ": " .. tostring(value))
- end
- else
- print("No item in the selected slot.")
- end
- end
- -- Function to show the fuel level of the turtle
- local function showFuelLevel()
- -- Get the fuel level of the turtle
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel then
- print("Fuel Level: ".. fuelLevel)
- else
- print("Unable to retrieve fuel level.")
- end
- end
- local function showdetect()
- local success, block = turtle.detect()
- if success then
- print("Detect returns true")
- else
- print("Detect returns false")
- end
- end
- local function myPosition()
- local x, y, z = myTurtle.getPosition()
- if x then
- print("Position: x=".. x)
- else
- print("Position is not available.")
- end
- end
- local function myFacing()
- local facing = myTurtle.getFacing()
- if facing then
- print("Facing: ".. facing)
- else
- print("Facing is not available.")
- end
- end
- local fuelValues = {
- ["minecraft:coal"] = 80,
- ["minecraft:charcoal"] = 80,
- ["minecraft:lava_bucket"] = 1000,
- ["minecraft:blaze_rod"] = 120,
- ["minecraft:dried_kelp_block"] = 4000,
- ["minecraft:coal_block"] = 800,
- ["minecraft:planks"] = 15,
- ["minecraft:stick"] = 5,
- ["minecraft:wooden_slab"] = 15,
- ["minecraft:note_block"] = 15,
- ["minecraft:jukebox"] = 15,
- ["minecraft:lectern"] = 15,
- ["minecraft:bookshelf"] = 15,
- ["minecraft:crafting_table"] = 15,
- ["minecraft:cartography_table"] = 15,
- ["minecraft:fletching_table"] = 15,
- ["minecraft:smithing_table"] = 15,
- ["minecraft:looms"] = 15,
- ["minecraft:loom"] = 15,
- ["minecraft:composter"] = 15,
- ["minecraft:barrel"] = 15,
- ["minecraft:smoker"] = 15,
- }
- local function howMuchFuel()
- local fuelLevel = turtle.getFuelLevel()
- local item = turtle.getItemDetail()
- turtle.refuel(1)
- local newfuelLevel = turtle.getFuelLevel()
- print("Fuel Level: ".. newfuelLevel)
- local itemfuel = newfuelLevel - fuelLevel
- print("Name: ".. item.name .. " gives ".. itemfuel .. " fuel.")
- end
- --Moving forward 1 block costs 1 fuel
- local function movementCost()
- local fuelLevel = turtle.getFuelLevel()
- myTurtle.forward()
- local newfuelLevel = turtle.getFuelLevel()
- local moveCost = newfuelLevel - fuelLevel
- print("Moving forward costs: ".. moveCost .. " fuel.")
- end
- local function stackWheat()
- print("Checking inventory")
- for slot = 1, 16 do
- if turtle.getItemDetail(slot) then
- local item = turtle.getItemDetail(slot)
- print("Slot: " .. slot .. " Item: " .. item.name)
- if item.name ~= "minecraft:wheat" then
- print("this is not wheat")
- turtle.select(slot)
- turtle.drop()
- else
- print("Wheat found in slot " .. slot)
- end
- else
- print("Slot: " .. slot .. " is empty")
- end
- end
- end
- -- Suck everything below so long as 1. below is not empty and 2. the turtle can drop the item
- local function suckWhile()
- while turtle.suckDown() do
- if not turtle.suckDown() then
- break
- end
- end
- end
- local function isItem(itemName)
- local item = turtle.getItemDetail()
- if item and item.name == itemName then
- return true
- else
- return false
- end
- end
- local function findEmptySlot()
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- return i
- end
- end
- return false
- end
- local function countInventory()
- local count = 0
- for i = 1, 16 do
- count = count + turtle.getItemCount(i)
- end
- return count
- end
- --Function to pull items from chest below, keep matching items, and drop non matches
- local function sort(itemName)
- local sortChestFull = false
- local pullChestEmpty = false
- local inventoryFull = false
- while not inventoryFull do
- local emptySlot = findEmptySlot()
- if not emptySlot then
- print("Inventory full")
- inventoryFull = true
- break
- end
- if not sortChestFull then
- print("Checking chest below")
- local count = countInventory()
- suckWhile()
- local newCount = countInventory()
- if count == newCount then
- print("No more items in the chest below.")
- pullChestEmpty = true
- end
- for i = 1, 16 do
- turtle.select(i)
- local item = turtle.getItemDetail(i)
- if item and item.name == itemName then
- print("Match found in slot " .. i)
- else
- print("Non-matching item in slot " .. i .. ", dumping...")
- if not turtle.drop() then
- print("Chest is full, waiting...")
- sortChestFull = true
- break
- end
- end
- end
- end
- end
- end
- local function fillAndStack(itemName)
- while true do
- local foundMatch = false
- local emptySlot = false
- if not emptySlot then
- print("Inventory full")
- break -- Exit the loop if inventory is full
- end
- -- Pull items from the chest until the inventory is full
- for i = 1, 16 do
- turtle.select(i)
- if turtle.getItemCount(i) == 0 then
- if turtle.suckDown() then
- print("Pulled items from the chest below into slot " .. i)
- local item = turtle.getItemDetail(i)
- if item and item.name == itemName then
- foundMatch = true
- print("Match found in slot " .. i)
- break -- Exit the loop if a match is found
- else
- print("Non-matching item in slot " .. i .. ", dumping...")
- turtle.drop()
- end
- else
- print("No more items in the chest below.")
- break -- Exit the loop if no more items
- end
- end
- end
- if not foundMatch then
- print("No match found in current inventory slots.")
- sleep(1) -- Wait for a moment before trying again
- end
- end
- end
- local junk = {
- "minecraft:dirt",
- "minecraft:cobblestone",
- "create:dolomite_cobblestone",
- "create:limestone_cobblestone",
- "create:gabbro_cobblestone",
- "create:granite_cobblestone",
- "forbidden_arcanus:darkstone",
- "extcaves:sedimentstone",
- "extcaves:lavastone",
- "extcaves:pebble_sedimentstone",
- "create:andesite_cobblestone",
- "create:diorite_cobblestone",
- "minecraft:gravel",
- "occultism:datura_seeds",
- "minecraft:wheat_seeds",
- "extcaves:pebble_stone",
- "minecraft:stone",
- "minecraft:granite",
- "minecraft:diorite",
- "minecraft:andesite",
- "minecraft:gravel",
- "minecraft:deepslate",
- "railcraft:quarried_stone",
- "minecraft:cobbled_deepslate",
- "minecraft:tuff",
- "minecraft:basalt",
- "minecraft:blackstone",
- "minecraft:calcite"
- -- Add more junk items as needed
- }
- --Function to check if a block is junk
- local function isJunk(blockName)
- for _, junkBlock in ipairs(junk) do
- if blockName == junkBlock then
- return true
- end
- end
- return false
- end
- --Function to drop junk from inventory
- local function dropJunk()
- print("Dropping junk")
- for slot = 1, 16 do
- turtle.select(slot)
- local itemDetail = turtle.getItemDetail()
- if itemDetail and isJunk(itemDetail.name) then
- turtle.drop()
- end
- end
- end
- local function isForbiddenBlock(blockName)
- local forbiddenBlocks = {
- "forbidden_arcanus:stella_arcanum",
- "minecraft:bedrock"
- }
- for _, forbiddenBlock in ipairs(forbiddenBlocks) do
- if blockName == forbiddenBlock then
- return true
- end
- end
- return false
- end
- -- Function to keep as many vauluables as possible, while dropping junk
- local function junkShuffle()
- myTurtle.face(0)
- local success, block = turtle.inspect()
- if isForbiddenBlock(block.name) then
- print("Detected block is forbidden")
- else
- turtle.dig()
- dropJunk()
- while turtle.suckUp() do
- turtle.suckUp()
- dropJunk()
- end
- isJunkShuffle = true
- end
- end
- --Mining Test
- function miningTest()
- for i = 1, 4 do
- local success, block = turtle.inspect()
- if isForbiddenBlock(block.name) or isJunk(block.name) then
- myTurtle.turnRight()
- else
- turtle.dig()
- myTurtle.turnRight()
- end
- end
- end
- -- Call the functions to check item, block, and fuel level
- checkItem()
- --showFuelLevel()
- --showdetect()
- --checkBlock()
- --myPosition()
- --myFacing()
- --howMuchFuel()
- --movementCost()
- --sort("minecraft:wheat")
- --junkShuffle()
- --miningTest()
Add Comment
Please, Sign In to add comment