Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Turtle program to Package items which can be 3x3 crafted between a front chest and a bottom chest
- --Will be integrated into the Butler.lua program at some point.
- --by hornedcommando
- --Function to drop all inventory
- function emptyInventory()
- for slot = 1, 16 do
- turtle.select(slot)
- turtle.drop()
- end
- --reselect the first slot (just in case)
- turtle.select(1)
- end
- --Function to package items
- function threeByThree()
- --make sure we're on the first inventory slot
- turtle.select(1)
- --get the count, and name of the item
- local slotDetail = turtle.getItemDetail()
- if slotDetail and slotDetail.name then
- if isCraftable(slotDetail.name) then
- local count = turtle.getItemCount(1)
- print("i'm holding " .. count .. " " .. slotDetail.name)
- --verify at least 1 craft can be done
- if count >= 9 then
- --calculate how many crafts can be done
- local maxCrafts = math.floor(count / 9)
- --distribute the named item into Slots 1,2,3,5,6,7,9,10,11.
- turtle.transferTo(2, maxCrafts)
- turtle.transferTo(3, maxCrafts)
- turtle.transferTo(5, maxCrafts)
- turtle.transferTo(6, maxCrafts)
- turtle.transferTo(7, maxCrafts)
- turtle.transferTo(9, maxCrafts)
- turtle.transferTo(10, maxCrafts)
- turtle.transferTo(11, maxCrafts)
- --craft the items
- turtle.craft(maxCrafts)
- --drop crafts and leftovers
- emptyInventory()
- else
- --if not enough of an item to craft, drop it
- print("Not enough " .. slotDetail.name)
- turtle.drop()
- return nil
- end
- else
- --if the item is not craftable, drop it
- print("I can't package this")
- turtle.drop()
- return nil
- end
- end
- end
- --Function to verify if an item can be packaged
- function isCraftable(name)
- local craftable = {
- "minecraft:wheat",
- "minecraft:potato",
- "minecraft:carrot",
- "minecraft:beetroot",
- "minecraft:melon_slice",
- "minecraft:charcoal",
- "minecraft:coal",
- "farmersdelight:tomato",
- "farmersdelight:onion",
- "farmersdelight:rice",
- "farmersdelight:cabbage",
- "thermal:apatite",
- "thermal:sulfur",
- "thermal:niter",
- "thermal:cinnabar",
- "minecraft:bone_meal",
- "minecraft:lapis_lazuli",
- "minecraft:redstone",
- "minecraft:iron_ingot",
- "minecraft:gold_ingot",
- "minecraft:emerald",
- "minecraft:diamond",
- "supplementaries:flax"
- }
- for _, craftable in ipairs(craftable) do
- if name == craftable then
- return true
- end
- end
- return false
- end
- -- Function to empty the front chest and restart the packaging process
- function empty_filter_chest()
- while turtle.suck() do
- turtle.dropDown()
- end
- end
- -- Loops through functions to continually package between the two chests
- while true do
- turtle.select(1)
- while turtle.suckDown() do
- threeByThree()
- end
- empty_filter_chest()
- end
Add Comment
Please, Sign In to add comment