This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Castaras's profile picture

[1.5.2]Refilling Slots in an Inventory using Ender Chests

Started by Castaras, 29 May 2013 - 12:34 PM
Castaras #1
Posted 29 May 2013 - 02:34 PM
So I'm working on a set of programs to get a mining turtle to build my base for me. I have the main bulk of the program sorted of digging out blocks in the way and building up the structure. However, I'm stuck on trying to work out how to refill slots of the turtle.


For the building, I have slot 1 with fuel, slot 2 with floor material, slot 3 with wall material, and slot 4 with glass. I want to have slot 5 be an ender chest which has more of the relevant material in it, and for the turtle to automatically restock on the relevant material when it's running low.

So it'd go something a little like this:


turtle.dig
turtle.select(3) -- select 3rd inventory space [wall block]
if turtle.getItemCount(3)==1 then
turtle.select(5)-- select slot with ender chest in
turtle.place()
turtle.getBlock(3,63) -- not correct code afaik, but I want to suck up 63 of the same id block as is currently in slot 3
turtle.dig() -- pick up ender chest again, due to something being in slot 1,2,3,4 ender chest will default back to slot 5
end
turtle.select(3) -- reselect slot 3, which is the block we want to place
turtle.place() -- restocked and placing blocks again!


turtle.suck doesn't seem to care what sort of block it collects, and just goes for the first in the inventory. I could just have the turtle carry 3 ender chests for the 3 different block ids (using chickenbones' ender storage mod), but if it's possible to have it done through just 1 ender chest that'd be my prefered option.

I'm willing to install peripheral mods if needed to make this program work. Currently have Computercraft + MiscPeripherals installed.
GopherAtl #2
Posted 29 May 2013 - 02:52 PM
you can't control what slot, much less what type, you suck from; turtle.suck pulls from the first available slot, up to the whole stack in that slot, but never pulls from any but the first non-empty slot, and never pulls from more than one slot at a time (so if 1 cobble in slot 1 and a stack in slot 2, you'd have to suck twice to get 2).

Also, I say up to the whole stack, but the only case where it will pull less than the whole stack is the case where there is not room for the whole stack in the turtle's inventory.

The ender chest per type approach, which you've already arrived at yourself, is probably the best way to go.
Castaras #3
Posted 30 May 2013 - 07:45 AM
Damn, that's a shame. Less elegant solution it is then.