harvest_1.lua
65 lines · 1.2 KB
Copy & run
wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/BigBaemingGamers/farm/harvest_1.lua
| 1 | function getItemIndex(itemName) |
| 2 | for slot = 1, 16, 1 do |
| 3 | local item = turtle.getItemDetail(slot) |
| 4 | if(item ~= nil) then |
| 5 | if(item["name"] == itemName) then |
| 6 | return slot |
| 7 | end |
| 8 | end |
| 9 | end |
| 10 | end |
| 11 | |
| 12 | function checkLeft() |
| 13 | turtle.turnLeft() |
| 14 | if (turtle.detect()) |
| 15 | then |
| 16 | return true |
| 17 | end |
| 18 | turtle.forward() |
| 19 | turtle.turnRight() |
| 20 | return false |
| 21 | end |
| 22 | |
| 23 | |
| 24 | function succ() |
| 25 | for i = 1, 6, 1 |
| 26 | do |
| 27 | turtle.suck() |
| 28 | end |
| 29 | end |
| 30 | |
| 31 | while(1) |
| 32 | do |
| 33 | isBlock, data = turtle.inspect() |
| 34 | |
| 35 | if(isBlock) |
| 36 | then |
| 37 | if (data['state']['age'] == 7) |
| 38 | then |
| 39 | turtle.dig() |
| 40 | succ() |
| 41 | potatoIndex = getItemIndex("minecraft:potato") |
| 42 | turtle.select(potatoIndex) |
| 43 | turtle.place() |
| 44 | turtle.dropDown(turtle.getItemCount(potatoIndex) - 1) |
| 45 | end |
| 46 | else |
| 47 | potatoIndex = getItemIndex("minecraft:potato") |
| 48 | turtle.place() |
| 49 | end |
| 50 | |
| 51 | |
| 52 | if (checkLeft()) |
| 53 | then |
| 54 | turtle.turnRight() |
| 55 | turtle.turnRight() |
| 56 | while(not turtle.detect()) |
| 57 | do |
| 58 | turtle.forward() |
| 59 | end |
| 60 | turtle.turnLeft() |
| 61 | end |
| 62 | end |
| 63 | |
| 64 | |
| 65 |