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

Help with farming turtle slot change

Started by Aoiryuu, 09 November 2015 - 05:09 PM
Aoiryuu #1
Posted 09 November 2015 - 06:09 PM
Hi everyone.

I was wondering if any of you could help me with this farming turtle program that I'm trying to make.

Basically what I want my turtle to do is be able to farm 64 wheat in one go. Unfortunately that means that the bone meal in slot 9 will run out before the seeds in slot 1 so I'm trying to get my turtle to switch from slot 9 to slot 10 when the bone meal in slot 9 runs out. I've spent hours on this with looking up lots of topics and made this code (probably not the best project for a complete newb ha ha but hey ho :)/>).

Anyway, so basically when my bone meal runs out, it doesn't change to slot 10 but instead it replaces slot nine with wheat… is there anyway to make it ignore slot 9 when it become empty and keep putting wheat in the same slot as before?

Help appreciated


function check()
  while true do
	for i=9,14 do
	  if turtle.getItemCount(i) > 0 then
		return turtle.select(i)
	  end
	end
	printError("No more bonemeal")
	os.pullEvent("key")
  end
end

local amount = 64
for DoNotChangeThis=1,amount do
  turtle.select(1)
  turtle.place()
  check()
  turtle.place()
  turtle.place()
  turtle.place()
  turtle.dig()
end
Edited on 09 November 2015 - 07:21 PM
Lupus590 #2
Posted 09 November 2015 - 08:57 PM
When the turtle pick-up items (either through dig or suck) it will place the item/s in the currently selected slot. If it can't it goes into the first available slot (staring from slot one, then slot 2, then 3 and so on).

as for knowing when to switch bonemeal slot, check how many items are in the slot while you know that it contains bonemeal: http://computercraft...le.getItemCount
Edited on 09 November 2015 - 07:57 PM
Bomb Bloke #3
Posted 09 November 2015 - 10:56 PM
Simply performing turtle.select(2) immediately before turtle.dig() will allow the turtle to gather a lot more wheat before breaking.

Seems to me that it'd be more efficient to create a larger wheat farm, and forgo the use of bonemeal. Plant over an area, have the turtle wait an hour, then harvest the whole lot. The bigger the farm the faster you'll gain resources.

But if you're on at least MineCraft 1.7.10, then you've got access to turtle.getItemDetail(), which allows you to check exactly what is in each inventory slot. For example, you could change:

if turtle.getItemCount(i) > 0 then

… to:

local info = turtle.getItemDetail(i)                                  -- Returns either nil or a table, depending on whether something was in the slot.
if info and info.name == "minecraft:dye" and info.damage == 15 then   -- If "info" isn't nil, and the table describes bonemeal, then...

If you're on an earlier build, you'll need to have your code make an assumptions about what's in its slots. For example, you could define a variable "minimumBonemealSlot", initially set to 9; put this in place of the 9 in your "for" loop, and increment it whenever you find an empty slot. The script won't check that slot again, working under the assumption that it'll never find more bonemeal there.
Aoiryuu #4
Posted 11 November 2015 - 08:01 PM
Thank you!

I put in the turtle.getItemDetail command and my program's working just how wanted it :)/>


Thanks again :)/>