SHOW:
|
|
- or go back to the newest paste.
| 1 | local fullstacks = true | |
| 2 | local bmcDirection = 4 --bone meal chest direction | |
| 3 | local scDirection = 3 -- seed chest direction | |
| 4 | local depositDirection = 2 -- output direction | |
| 5 | ||
| 6 | local facing = 1 | |
| 7 | local chestslot = 14 | |
| 8 | local seedslot = 15 | |
| 9 | local bonemealslot = 16 | |
| 10 | ||
| 11 | local function TurnRight() | |
| 12 | facing = facing + 1 | |
| 13 | if facing > 4 then | |
| 14 | facing = 1 | |
| 15 | end | |
| 16 | turtle.turnRight() | |
| 17 | end | |
| 18 | ||
| 19 | function FindDirt() | |
| 20 | local facingchest = true | |
| 21 | turtle.select(chestslot) | |
| 22 | facingchest = turtle.compare() | |
| 23 | while facingchest do | |
| 24 | turtle.turnRight() | |
| 25 | turtle.select(chestslot) | |
| 26 | facingchest = turtle.compare() | |
| 27 | end | |
| 28 | facing = 1 | |
| 29 | end | |
| 30 | ||
| 31 | function SelectEmptySlot() | |
| 32 | for n = 1, 13 do | |
| 33 | if turtle.getItemCount(n) == 0 then | |
| 34 | turtle.select(n) | |
| 35 | break; | |
| 36 | end | |
| 37 | end | |
| 38 | end | |
| 39 | ||
| 40 | function SelectSeedSlot() | |
| 41 | turtle.select(seedslot) | |
| 42 | end | |
| 43 | ||
| 44 | function CheckEmptySlots() | |
| 45 | local emptySlots = false | |
| 46 | for n = 1, 13 do | |
| 47 | if turtle.getItemCount(n) == 0 then | |
| 48 | emptySlots = true | |
| 49 | break; | |
| 50 | end | |
| 51 | end | |
| 52 | ||
| 53 | if not emptySlots then | |
| 54 | Deposit() | |
| 55 | end | |
| 56 | end | |
| 57 | ||
| 58 | function P(text) | |
| 59 | term.clear() | |
| 60 | term.setCursorPos(1, 1) | |
| 61 | print(text) | |
| 62 | end | |
| 63 | ||
| 64 | ||
| 65 | function GetMoreSeeds() | |
| 66 | P("Stocking seeds")
| |
| 67 | while facing ~= scDirection do | |
| 68 | TurnRight() | |
| 69 | end | |
| 70 | turtle.select(seedslot) | |
| 71 | turtle.suck() | |
| 72 | end | |
| 73 | ||
| 74 | function GetMoreBM() | |
| 75 | P("Stocking bone meal")
| |
| 76 | while facing ~= bmcDirection do | |
| 77 | TurnRight() | |
| 78 | end | |
| 79 | turtle.select(bonemealslot) | |
| 80 | if turtle.suck() then | |
| 81 | return true | |
| 82 | else | |
| 83 | return false | |
| 84 | end | |
| 85 | end | |
| 86 | ||
| 87 | function Deposit() | |
| 88 | P("Depositing yield")
| |
| 89 | while facing ~= depositDirection do | |
| 90 | TurnRight() | |
| 91 | end | |
| 92 | ||
| 93 | for n=1,13 do | |
| 94 | turtle.select(seedslot) | |
| 95 | if not turtle.compareTo(n) then | |
| 96 | turtle.select(n) | |
| 97 | turtle.drop() | |
| 98 | end | |
| 99 | end | |
| 100 | ||
| 101 | while facing ~= scDirection do | |
| 102 | TurnRight() | |
| 103 | end | |
| 104 | ||
| 105 | for n=1,13 do | |
| 106 | turtle.select(n) | |
| 107 | turtle.drop() | |
| 108 | end | |
| 109 | end | |
| 110 | ||
| 111 | function CheckSupplies() | |
| 112 | local supplies = true | |
| 113 | if turtle.getItemCount(seedslot) == 0 then | |
| 114 | GetMoreSeeds() | |
| 115 | end | |
| 116 | if turtle.getItemCount(bonemealslot) == 0 then | |
| 117 | supplies = GetMoreBM() | |
| 118 | if not supplies then | |
| 119 | waitforBM() | |
| 120 | end | |
| 121 | end | |
| 122 | end | |
| 123 | ||
| 124 | function waitforBM() | |
| 125 | P("Waiting on more bone meal")
| |
| 126 | local continue = true | |
| 127 | ||
| 128 | while facing ~= bmcDirection do | |
| 129 | TurnRight() | |
| 130 | end | |
| 131 | ||
| 132 | while continue do | |
| 133 | turtle.select(bonemealslot) | |
| 134 | if turtle.suck() then | |
| 135 | continue = false | |
| 136 | else | |
| 137 | sleep(30) | |
| 138 | end | |
| 139 | end | |
| 140 | end | |
| 141 | ||
| 142 | ||
| 143 | function Farm() | |
| 144 | local continue = true | |
| 145 | while continue do | |
| 146 | FindDirt() | |
| 147 | CheckSupplies() | |
| 148 | P("Starting farm")
| |
| 149 | FindDirt() | |
| 150 | CheckEmptySlots() | |
| 151 | FindDirt() | |
| 152 | if fullstacks then | |
| 153 | SelectSeedSlot() | |
| 154 | else | |
| 155 | SelectEmptySlot() | |
| 156 | end | |
| 157 | turtle.dig() | |
| 158 | turtle.dig() | |
| 159 | turtle.select(seedslot) | |
| 160 | turtle.place() | |
| 161 | turtle.select(bonemealslot) | |
| 162 | turtle.place() | |
| 163 | end | |
| 164 | end | |
| 165 | ||
| 166 | Farm() |