Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("turtleLib.lua")
- turtleLib.setHome({x=234,y=70,z=-676}, 2)
- turtleLib.setRefuel({x=234,y=70,z=-676}, 1)
- local dumpPosition = {x=234,y=69,z=-676}
- local dumpHeading = 3
- turtleLib.setDump(dumpPosition,dumpHeading)
- turtleLib.goHome(true)
- local pickupPosition={x=234,y=70,z=-676}
- local pickupHeading=4
- local overflowPosition={x=234,y=70,z=-676}
- local overflowHeading=3
- local dumpList = {
- }
- local craftingRecipes = {
- ["minecraft:spruce_planks"] = {
- [1]="minecraft:spruce_log",
- ["count"]=4
- },
- ["minecraft:chest"] = {
- [1]="minecraft:spruce_planks",
- [2]="minecraft:spruce_planks",
- [3]="minecraft:spruce_planks",
- [4]="minecraft:spruce_planks",
- [5]=nil,
- [6]="minecraft:spruce_planks",
- [7]="minecraft:spruce_planks",
- [8]="minecraft:spruce_planks",
- [9]="minecraft:spruce_planks",
- ["count"]=1
- }
- }
- local itemMap = {
- ["Charcoal"] = {
- location={x=234,y=70,z=-676},
- heading=1,
- storedItems = {
- "betterend:charcoal_block",
- "minecraft:charcoal"
- },
- isStack=true
- },
- ["Bones"] = {
- location={x=235,y=70,z=-676},
- heading=1,
- storedItems = {
- "minecraft:bone",
- "minecraft:bone_meal"
- }
- },
- ["Arrows"] = {
- location={x=236,y=70,z=-676},
- heading=1,
- storedItems = {
- "minecraft:arrow"
- }
- },
- ["Bows"] = {
- location={x=237,y=70,z=-676},
- heading=1,
- storedItems = {
- "minecraft:bow"
- },
- discardUnenchanted=true
- },
- ["Blaze Rods"] = {
- location={x=238,y=70,z=-676},
- heading=1,
- storedItems = {
- "minecraft:blaze_rod"
- }
- },
- ["Rotten Flesh"] = {
- location={x=239,y=70,z=-676},
- heading=1,
- storedItems = {
- "minecraft:rotten_flesh",
- }
- },
- ["Carrots"] = {
- location={x=240,y=70,z=-676},
- heading=1,
- storedItems = {
- "minecraft:carrot"
- }
- },
- ["Potatos"] = {
- location={x=241,y=70,z=-676},
- heading=1,
- storedItems = {
- "minecraft:potato"
- }
- },
- ["Wheat"] = {
- location={x=242,y=70,z=-676},
- heading=1,
- storedItems = {
- "minecraft:wheat"
- }
- },
- ["Shields"] = {
- location={x=240,y=71,z=-676},
- heading=1,
- storedItems = {
- "minecraft:shield"
- },
- discardUnenchanted=true
- },
- ["Swords"] = {
- location={x=239,y=71,z=-676},
- heading=1,
- storedItems = {
- "minecraft:wooden_sword",
- "minecraft:stone_sword",
- "minecraft:golden_sword",
- "minecraft:iron_sword"
- },
- discardUnenchanted=true
- },
- ["Boots"] = {
- location={x=238,y=71,z=-676},
- heading=1,
- storedItems = {
- "minecraft:leather_boots",
- "minecraft:iron_boots",
- "minecraft:golden_boots",
- "minecraft:chainmail_boots"
- },
- discardUnenchanted=true
- },
- ["Leggings"] = {
- location={x=237,y=71,z=-676},
- heading=1,
- storedItems = {
- "minecraft:leather_leggings",
- "minecraft:iron_leggings",
- "minecraft:golden_leggings",
- "minecraft:chainmail_leggings",
- },
- discardUnenchanted=true
- },
- ["Chestplates"] = {
- location={x=236,y=71,z=-676},
- heading=1,
- storedItems = {
- "minecraft:leather_chestplate",
- "minecraft:iron_chestplate",
- "minecraft:golden_chestplate",
- "minecraft:chainmail_chestplate"
- },
- discardUnenchanted=true
- },
- ["Helmets"] = {
- location={x=235,y=71,z=-676},
- heading=1,
- storedItems = {
- "minecraft:leather_helmet",
- "minecraft:iron_helmet",
- "minecraft:golden_helmet",
- "minecraft:chainmail_helmet"
- },
- discardUnenchanted=true
- },
- ["Gems"] = {
- location={x=235,y=70,z=-676},
- heading=3,
- storedItems = {
- "minecraft:redstone",
- "minecraft:coal",
- "minecraft:coal_ore",
- "minecraft:diamond",
- "minecraft:lapis_lazuli",
- "minecraft:quartz",
- "minecraft:amethyst_shard",
- "minecraft:emerald",
- "minecraft:glowstone_dust",
- "minecraft:glowstone_block",
- "minecraft:large_amethyst_bud",
- "minecraft:small_amethyst_bud",
- "minecraft:amethyst_block"
- },
- isStack=true
- },
- ["Metals"] = {
- location={x=236,y=70,z=-676},
- heading=3,
- storedItems = {
- "minecraft:iron_ingot",
- "minecraft:raw_iron",
- "minecraft:iron_nugget",
- "minecraft:iron_block",
- "minecraft:gold_ingot",
- "minecraft:raw_gold",
- "minecraft:gold_nugget",
- "minecraft:gold_block",
- "minecraft:copper_ingot",
- "minecraft:raw_copper",
- "minecraft:copper_nugget",
- "minecraft:copper_block",
- "minecraft:copper_ore",
- "minecraft:iron_ore",
- "minecraft:deepslate_iron_ore",
- "tconstruct:raw_cobalt"
- },
- isStack=true
- },
- ["Building Materials"] = {
- location={x=237,y=70,z=-676},
- heading=3,
- storedItems = {
- "minecraft:cobblestone",
- "minecraft:cobblestone_wall",
- "minecraft:cobblestone_slab",
- "minecraft:stone",
- "minecraft:stone_slab",
- "minecraft:stone_bricks",
- "minecraft:stone_brick_slab",
- "minecraft:sand",
- "minecraft:dirt",
- "minecraft:grass_block",
- "minecraft:andesite",
- "minecraft:podzol",
- "minecraft:moss_block",
- "minecraft:coarse_dirt",
- "minecraft:cobbled_deepslate",
- "minecraft:packed_mud",
- "minecraft:tuff",
- "minecraft:acacia_log",
- "minecraft:acacia_planks",
- "minecraft:spruce_planks",
- "minecraft:spruce_slab",
- "minecraft:spruce_door",
- "minecraft:spruce_trapdoor",
- "minecraft:spruce_sign",
- "minecraft:ladder",
- "minecraft:magma_block",
- "minecraft:snow_block",
- "minecraft:obsidian",
- "minecraft:crying_obsidian",
- "minecraft:oak_log",
- "minecraft:oak_door",
- "minecraft:oak_stairs",
- "minecraft:blackstone",
- "minecraft:rooted_dirt",
- "minecraft:glass",
- "minecraft:glass_pane",
- "minecraft:warped_nylium",
- "tconstruct:clear_glass",
- "minecraft:mossy_cobblestone",
- "minecraft:calcite",
- "minecraft:dripstone_block",
- "minecraft:gravel",
- "minecraft:dripstone_block",
- "minecraft:clay_ball",
- "minecraft:clay_block",
- "minecraft:brick",
- "minecraft:bricks",
- "minecraft:netherrack",
- "minecraft:moss_carpet",
- },
- isStack=true
- },
- ["Wood"] = {
- location={x=243,y=70,z=-676},
- heading=1,
- storedItems = {
- "minecraft:spruce_log"
- }
- },
- ["Ender Pearls"] = {
- location={x=244,y=70,z=-676},
- heading=1,
- storedItems = {
- "minecraft:ender_pearl"
- }
- },
- ["Organics"] = {
- location={x=238,y=70,z=-676},
- heading=3,
- storedItems = {
- "minecraft:acacia_sapling",
- "minecraft:brown_mushroom",
- "minecraft:red_mushroom",
- "minecraft:warped_fungus",
- "minecraft:dandelion",
- "minecraft:warped_roots",
- "minecraft:twisting_vines",
- "minecraft:poppy",
- "minecraft:bamboo",
- "minecraft:sugar_cane",
- "minecraft:spruce_sapling",
- "minecraft:oak_sapling",
- "minecraft:vines",
- "minecraft:glow_berries",
- "minecraft:melon_seeds",
- "minecraft:cookie",
- "minecraft:nether_wart",
- "minecraft:cooked_porkchop",
- "minecraft:chicken",
- "minecraft:cooked_chicken",
- "minecraft:apple",
- "minecraft:magma_cream",
- "minecraft:gunpowder",
- "minecraft:slime_ball",
- "minecraft:feather",
- "minecraft:leather",
- "minecraft:steak",
- "minecraft:cooked_cod",
- "minecraft:cooked_salmon",
- "minecraft:vine",
- "minecraft:cactus",
- "minecraft:kelp",
- "minecraft:sea_pickle",
- "botania:yellow_mystical_flower",
- "minecraft:fire_coral",
- "spectrum:clover",
- "minecraft:bread",
- "minecraft:pumpkin",
- "minecraft:string",
- }
- },
- ["Twigs"] = {
- location={x=243,y=71,z=-676},
- heading=1,
- storedItems = {
- "twigs:twig"
- }
- },
- ["Seeds"] = {
- location={x=242,y=71,z=-676},
- heading=1,
- storedItems = {
- "minecraft:wheat_seeds"
- }
- },
- ["Tools"] = {
- location={x=239,y=70,z=-676},
- heading=3,
- storedItems = {
- "minecraft:wooden_shovel",
- "minecraft:stone_shovel",
- "minecraft:iron_shovel",
- "minecraft:golden_shovel",
- "minecraft:diamond_shovel",
- "minecraft:wooden_pickaxe",
- "minecraft:stone_pickaxe",
- "minecraft:iron_pickaxe",
- "minecraft:golden_pickaxe",
- "minecraft:diamond_pickaxe",
- "minecraft:wooden_hoe",
- "minecraft:stone_hoe",
- "minecraft:iron_hoe",
- "minecraft:golden_hoe",
- "minecraft:diamond_hoe",
- "minecraft:wooden_axe",
- "minecraft:stone_axe",
- "minecraft:iron_axe",
- "minecraft:golden_axe",
- "minecraft:diamond_axe",
- "minecraft:flint_and_steel",
- "minecraft:bucket",
- "minecraft:water_bucket",
- "minecraft:lava_bucket",
- "minecraft:torch",
- "minecraft:diamond_sword",
- "minecraft:diamond_boots",
- "minecraft:diamond_leggings",
- "minecraft:diamond_chestplate",
- "minecraft:diamond_helmet",
- "minecraft:golden_apple",
- "minecraft:enchanted_golden_apple",
- "minecraft:saddle",
- "minecraft:iron_horse_armor",
- "minecraft:golden_horse_armor",
- "minecraft:diamond_horse_armor",
- "minecraft:tipped_arrow",
- "minecraft:enchanted_book",
- "minecraft:supplementaries:bomb",
- "minecraft:shears"
- }
- }
- }
- local function getItemQuantity(item)
- local currentSlot = turtle.getSelectedSlot()
- local counter = 0
- for i=3,16,1 do
- turtle.select(i)
- local currentItem = turtle.getItemDetail()
- if currentItem and currentItem.name == item then
- counter = counter + currentItem.count
- end
- end
- turtle.select(currentSlot)
- return counter
- end
- local function dropItemTillQuantity(item,count)
- local currentSlot = turtle.getSelectedSlot()
- local counter = 0
- for i=3,16,1 do
- turtle.select(i)
- local currentItem = turtle.getItemDetail()
- if currentItem and currentItem.name == item then
- counter = counter + currentItem.count
- if counter > count then
- turtle.drop(counter-count)
- counter = count
- end
- end
- end
- turtle.select(currentSlot)
- end
- function getItem(name,count)
- local foundCount = 0
- print("Finding item",name,count)
- for containerName,container in pairs(itemMap) do
- for i,item in ipairs(container.storedItems) do
- if item == name then
- local nextPos = container.location
- repeat
- print("Checking container",containerName)
- turtleLib.navigateToLocation(nextPos,container.heading, true)
- if turtle.detect() == false then
- print("Reached end of container!")
- break
- end
- turtle.select(2)
- turtle.placeUp()
- turtle.select(3)
- while true do
- if turtle.suck() == false then
- break
- end
- local curItem = turtle.getItemDetail()
- if curItem.name == name then
- foundCount = foundCount + turtle.getItemCount()
- local slot = 4;
- while turtle.getItemCount() > 0 do
- turtle.transferTo(slot, 64)
- slot = slot + 1
- end
- if foundCount > count then
- break
- end
- else
- if turtle.dropUp() == false then
- break
- end
- end
- end
- repeat
- turtle.drop()
- until turtle.suckUp() == false
- dropItemTillQuantity(name, count);
- turtle.select(2)
- turtle.digUp()
- if foundCount >= count then
- print("Found all!")
- break
- end
- nextPos.y = nextPos.y + 1
- until container.isStack == false
- end
- end
- end
- return foundCount >= count
- end
- function putAwayItem()
- local currentItem = turtle.getItemDetail()
- for j,exclusion in ipairs(dumpList) do
- if exclusion == currentItem.name then
- print("Dumping item",exclusion)
- turtleLib.navigateToLocation(dumpPosition, dumpHeading, true)
- turtle.drop()
- return
- end
- end
- local seenContainer = false
- for containerName,container in pairs(itemMap) do
- for i,item in ipairs(container.storedItems) do
- if item == currentItem.name then
- if container.discardUnenchanted then
- if turtle.getItemDetail(turtle.getSelectedSlot(), true).enchantments == nil then
- print("Discarding unenchanted item")
- turtleLib.navigateToLocation(dumpPosition, dumpHeading, true)
- turtle.drop()
- return
- end
- end
- print("Going to container",containerName)
- turtleLib.navigateToLocation(container.location,container.heading,true)
- seenContainer = true
- if container.isStack == true then
- while turtle.detect() do
- turtle.drop()
- if turtle.getItemCount() == 0 then
- return
- end
- turtleLib.forceUp()
- end
- else
- turtle.drop()
- if turtle.getItemCount() == 0 then
- return
- end
- end
- end
- end
- end
- if seenContainer == false then
- print("Putting unknown item in overflow")
- turtleLib.navigateToLocation(overflowPosition,overflowHeading,true)
- turtle.drop()
- if turtle.getItemCount() == 0 then
- return
- end
- end
- print("Item overflowed, dumping")
- turtleLib.navigateToLocation(dumpPosition,dumpHeading,true)
- turtle.drop()
- end
- function fillInventory()
- turtle.select(1)
- while turtle.suck() do
- end
- end
- function cycle()
- turtleLib.navigateToLocation(pickupPosition, pickupHeading, true)
- fillInventory()
- for i=3,16,1 do
- turtle.select(i)
- if turtle.getItemCount() ~= 0 then
- putAwayItem()
- end
- end
- end
- function getOrCraftItem(name,count,clear)
- local gotItems = false
- while clear == true do
- turtleLib.goHome(true)
- turtleLib.forceDown()
- turtle.select(3)
- if not turtle.suckDown() then
- if gotItems == true then
- cycle()
- else
- break
- end
- else
- gotItems = true
- end
- end
- if getItem(name, count) then
- turtleLib.goHome(true)
- return true
- end
- local recipe = nil
- for i,tempRecipe in pairs(craftingRecipes) do
- print("Recipe",i)
- if i == name then
- recipe = tempRecipe
- end
- end
- if recipe == nil then
- print("No item or recipe found for",name,count)
- return false
- end
- turtleLib.goHome(true)
- local alreadyRetrieved = getItemQuantity(name);
- turtleLib.forceDown()
- for i=3,16,1 do
- turtle.select(i)
- turtle.dropDown()
- end
- local recipeCount = math.ceil((count-alreadyRetrieved) / recipe.count)
- local recipeRequirements = {}
- -- For each craft slot
- for i=1,9,1 do
- if recipe[i] ~= nil then
- if recipeRequirements[recipe[i]] == nil then
- recipeRequirements[recipe[i]] = recipeCount
- else
- recipeRequirements[recipe[i]] = recipeRequirements[recipe[i]] + recipeCount
- end
- end
- end
- -- For each requirement
- for i,requirement in pairs(recipeRequirements) do
- if getOrCraftItem(i, requirement, true) == false then
- print("Craft / retrieve failed for",i, requirement)
- return false
- end
- turtleLib.goHome(true)
- turtleLib.forceDown()
- for j=3,16,1 do
- turtle.dropDown()
- end
- print("Requirement",i,requirement,"retrieved")
- end
- -- Setup work chest
- turtle.select(2)
- turtle.placeUp()
- -- For each slot
- turtle.select(15)
- for i=1,9,1 do
- if recipe[i] then
- local lastCount = 0
- -- Get enough items for slot
- while lastCount < recipeCount do
- turtle.suckDown()
- local item = turtle.getItemDetail()
- if item.name ~= recipe[i] then
- turtle.dropUp()
- else
- turtle.transferTo(i, recipeCount - lastCount)
- lastCount = turtle.getItemCount(i)
- turtle.dropDown()
- end
- end
- end
- end
- -- Finally we can craft!
- -- Clear standard issue
- turtleLib.turnLeft()
- turtle.select(1)
- turtle.dropUp()
- turtle.select(2)
- turtle.dropUp()
- turtle.equipRight()
- turtle.dropUp()
- turtle.suck()
- turtle.equipRight()
- -- Move all ingredients
- for i=1,6,1 do
- turtle.select(i + 2)
- turtle.drop()
- turtle.select(i+math.floor((i-1)/3))
- turtle.suck()
- end
- -- Craft damn it
- turtle.select(15)
- turtle.craft(recipeCount)
- -- Fix inventory immediately
- turtle.select(1)
- turtle.suckUp()
- turtle.select(2)
- turtle.suckUp()
- turtle.select(3)
- turtle.suckUp()
- turtle.equipRight()
- turtle.drop()
- turtle.select(2)
- turtle.digUp()
- turtle.select(15)
- turtle.turnRight()
- return turtle.getItemCount() >= count
- end
- function handleCraftDropoff()
- turtleLib.goHome(true)
- turtleLib.forceUp()
- turtleLib.forceUp()
- turtleLib.dropUp()
- end
- function craftItem(item, count)
- while count > 64 do
- if getOrCraftItem(item, 64) == false then
- return false
- end
- handleCraftDropoff()
- end
- if getOrCraftItem(item, count) then
- handleCraftDropoff()
- print("Completed job for",item,count)
- return true
- end
- return false
- end
- while true do
- for i=1,32,1 do
- cycle()
- craftItem("minecraft:chest", 8)
- end
- turtleLib.goHome(true)
- turtleLib.goRefuel(true)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement