Dimencia

farmtest

Mar 21st, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. local fuelSlot = 1
  2. local seedSlot = 2
  3. -- Wheat has all other slots? Or just 3, idk
  4. local wheatSlot = 3
  5. local testSlot = 4
  6.  
  7. turtle.refuel()
  8. while(true) do
  9.    
  10.     turtle.turnRight()
  11.     -- Inspect the block in front of it
  12.     local success, data = turtle.inspect()
  13.     if success then
  14.         -- data contains fields: name, tags, state
  15.         print("Name: ", data.name)
  16.         if data.name == "minecraft:wheat" then
  17.             if data.state.age == 7 then
  18.                 -- Select the seeds to punch it
  19.                 turtle.select(seedSlot)
  20.                 turtle.attack("left") -- Do we need to stand on it and attack down?  Do we need to specify "left" for attacking with seeds/hand?
  21.                 -- You think we can just turtle.place()? Try that later
  22.                 turtle.dig()
  23.                 turtle.suck()
  24.                 turtle.place()
  25.                 turtle.select(wheatSlot)
  26.                 turtle.suck()
  27.             end
  28.         end
  29.     end -- If there's nothing in front of it, it can just keep going that way.
  30.     turtle.forward()
  31.     -- Check if there's a chest in front of it after moving forward, to refuel or offload wheat
  32.     success,data = turtle.inspect()
  33.     if success then
  34.         print("Looking for chest, name: ", data.name)
  35.         if data.name == "minecraft:chest" then
  36.             -- Pick up whatever's in it into slot 4
  37.             turtle.select(testSlot)
  38.             turtle.suck()
  39.             -- See what we picked up
  40.             local slotdata = turtle.getItemDetail()
  41.             print("Slot name: ", data.name)
  42.             if data.name == "minecraft:wheat" then
  43.                 -- Put it back, and put any wheat we have in there
  44.                 turtle.drop()
  45.                 turtle.select(wheatSlot)
  46.                 turtle.drop()
  47.             elseif data.name == "minecraft:coal" then
  48.                 if not turtle.transferTo(fuelSlot) then
  49.                     turtle.drop() -- Put any leftovers back
  50.                 end
  51.             end
  52.         end
  53.     end
  54. end
  55.  
  56. -- For wheat, an age of 7 is what we want.  Name is "minecraft:wheat"
  57. -- We get that from data.state.age
  58.  
  59.  
  60.  
Add Comment
Please, Sign In to add comment