Jump to content




Resupply a turtle


5 replies to this topic

#1 gheotic

  • Members
  • 64 posts
  • LocationDenmark

Posted 03 February 2013 - 09:51 AM

Hey everybody who is reading this :)

im trying to make a lumberjack program that place saplings and use bone meal on it then cut it down again
but to make it fully automatic i need to make it resupply it self i have 3 stuff so 1 slot for fuel 1 slot for bone meal and 1 slot for sappling

how can i make it resupply it self from a chest???

#2 aaakk

  • Members
  • 58 posts

Posted 03 February 2013 - 10:04 AM

You can do turtle.suck() when there is a chest in front (or turtle.suckUp/down())

#3 gheotic

  • Members
  • 64 posts
  • LocationDenmark

Posted 03 February 2013 - 10:09 AM

but it hard to organise it that way :/

#4 shiphorns

  • Members
  • 50 posts
  • LocationBoston, MA

Posted 03 February 2013 - 02:23 PM

View Postgheotic, on 03 February 2013 - 10:09 AM, said:

but it hard to organise it that way :/
When you go to place saplings, or use bonemeal, or consume a fuel, just make it so your program considers each slot to be empty when it gets down to a count of 1 instead of 0. When, when you suck() from your refill chests, it will automatically refill matching items into those stacks. Or you can have separate refill chests for each item type, and dumping (using drop()) and select each designated slot before sucking items from the corresponding chest. I personally like the former approach, where you keep a reference item.

Either way, it will be simplest if you refill each item from a separate chest that contains only that item. I suggest this because you don't get to pick which chest slot suck() takes from, you just get whatever is in the chest's first empty slot, so in order to refill 2 or more item types from one chest and make sure you refill with some of each of the required items--making no assumptions about how the chest is organized or sorted--you would have to suck from one chest into an empty turtle slot(s), use compareTo() and transferTo() against reference items to get things onto the right stacks, and then drop() unmatching items or items you've already got enough of into another chest so that you don't get in a loop where you keep sucking up and returning one item type over and over and never get all the things you need.

#5 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 03 February 2013 - 02:44 PM

View Postshiphorns, on 03 February 2013 - 02:23 PM, said:

When, when you suck() from your refill chests, it will automatically refill matching items into those stacks.

Sadly, this isn't the case. I just did a test, where the turtle had a sapling for reference in its selected slot, and saplings were in the chest, but coal was the first thing immediately suck-able, the coal was sucked anyway, and the selected saplings did not get filled.

#6 shiphorns

  • Members
  • 50 posts
  • LocationBoston, MA

Posted 04 February 2013 - 05:33 AM

View PostKingdaro, on 03 February 2013 - 02:44 PM, said:

View Postshiphorns, on 03 February 2013 - 02:23 PM, said:

When, when you suck() from your refill chests, it will automatically refill matching items into those stacks.

Sadly, this isn't the case. I just did a test, where the turtle had a sapling for reference in its selected slot, and saplings were in the chest, but coal was the first thing immediately suck-able, the coal was sucked anyway, and the selected saplings did not get filled.

Sorry, you misunderstood me. I didn't mean that the turtle could be told to suck() a specific type preferentially. suck() will always take the first thing from a chest (starting in the upper right, going left to right, then top to bottom). You can't control that. But when it does get to the saplings in the chest, it will stack them on top of the reference sapling already in the turtle inventory. So.. you can keep doing suck() until you detect that the count on that stack has gone up. Things that are not the reference items will end up in the turtle's free slots. Each time the turtle fills, you should drop() those unwanted sucked-up items elsewhere, like into another chest to the right, or something like that. But... if it's filled one more of the reference stacks and still sucking types of items it can use (for example, if it's filled the sapling stack, still looking for bonemeal, but also still sucking up more saplings) then you need to use compareTo() on the free slots so that you only purge items you don't need, you can't just blindly drop() the contents of the non-reference slots.

This is why I recommended having a chest that contains only saplings (and another with bonemeal, another for fuel). It's more work to write all the code to rummage through a chest of potentially many types of items and filter out what you need.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users