What code do I put in to scan a chest for items, only take specific ones and then craft, in my case, bread?
My current system, doesn't have the crafting implemented but maybe it could help if you know what my code looks like. 2cnwkCQv
Thanks!
chest.pushItemIntoSlot("north", 5) -- push to the north side from slot 5.
local function goToChest()
...
end
...
while true do
goToChest()
sleep(2)
comeBack()
sleep(90)
startBack()
end
If you have a narcissistic turtle I presume you have OpenPeripherals installed. This provides a pushItemIntoSlot method:chest.pushItemIntoSlot("north", 5) -- push to the north side from slot 5.
You can use getAllStacks and getStackInSlot to get the contents of the chest.
Also, don't override the table methods. Instead do:local function goToChest() ... end ... while true do goToChest() sleep(2) comeBack() sleep(90) startBack() end
local the_luggage = peripheral.wrap("front") -- This find the chest at the front and allows you do do things to it.
-- getAllStacks returns a table of slot id to stacks
for slot, item in pairs(the_luggage.getAllStacks()) do
if item.id == "minecraft:wheat" then
-- If the chest is on the north side of the turtle, the turtle is on the south side of the peripheral
the_luggage.pushItem("south", slot)
end
end
turtle.select(1) -- If wheat is in the 1st slot
turtle.suck() -- Suck wheat from the chest
This isn't a guarantee, turtle.suck will get the next item in the inventory regardless of whether it matches the currently selected slot. The only guaranteed way with turtle.suck is to ensure every slot in the turtle is full with at least one wheat in it, otherwise anything other than wheat can be sucked from the chest into a slot.An alternative method is to ensure the turtle always has one wheat in it and use turtle.suck:turtle.select(1) -- If wheat is in the 1st slot turtle.suck() -- Suck wheat from the chest
Ah OK, shows you how little I use turtles. :P/> Learn something new every day I guess.This isn't a guarantee, turtle.suck will get the next item in the inventory regardless of whether it matches the currently selected slot. The only guaranteed way with turtle.suck is to ensure every slot in the turtle is full with at least one wheat in it, otherwise anything other than wheat can be sucked from the chest into a slot.
This isn't a guarantee, turtle.suck will get the next item in the inventory regardless of whether it matches the currently selected slot. The only guaranteed way with turtle.suck is to ensure every slot in the turtle is full with at least one wheat in it, otherwise anything other than wheat can be sucked from the chest into a slot.An alternative method is to ensure the turtle always has one wheat in it and use turtle.suck:turtle.select(1) -- If wheat is in the 1st slot turtle.suck() -- Suck wheat from the chest
turtle.select(1)
turtle.suck()
turtle.select(2)
turtle.push()
You could also put 1 wheat in the first slot and doturtle.select(1) turtle.suck() turtle.select(2) turtle.push()