Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Static variables (Settings)
- safety = {"minecraft:wooden_slab"}
- turnLeft = {"minecraft:planks"}
- turnRight = {"minecraft:double_wooden_slab"}
- chest = {"minecraft:chest", "EnderStorage:enderChest"}
- inventory_size = 16
- fuel_level = 20000
- -- Crops (name of planted blocks) and seeds (name of items)
- seeds = {"minecraft:potato", "minecraft:wheat_seeds", "minecraft:carrot"}
- crops = {"minecraft:potatoes", "minecraft:wheat", "minecraft:carrots"}
- distribution = {0.5, 0.5, 0.0}
- max_metalevel = {7, 7, 7}
- cropslots = 3
- delay = 1.5
- -- Functions
- function isType(e, t)
- if e == nil then
- return false
- end
- for i = 1, #t, 1 do
- if(e.name == t[i]) then
- return i
- end
- end
- return false
- end
- function findCrop(crop)
- for i = 1, inventory_size, 1 do
- item = turtle.getItemDetail(i)
- if isType(item, seeds) and (crop == "any" or item.name == crop) then
- return i
- end
- end
- return nil
- end
- function unload(crop)
- -- Compute max of each type
- remCrops = {}
- lastSlot = {}
- for i = 1, #distribution, 1 do
- remCrops[seeds[i]] = math.ceil(cropslots * distribution[i]) * 64
- end
- -- Filter inventory
- for i = 1, inventory_size, 1 do
- item = turtle.getItemDetail(i)
- if isType(item, seeds) and remCrops[item.name] > 0 then
- if lastSlot[item.name] == nil then
- lastSlot[item.name] = i
- remCrops[item.name] = remCrops[item.name] - item.count
- else
- toMove = math.min(item.count, turtle.getItemSpace(lastSlot[item.name]))
- if toMove > 0 then
- turtle.select(i)
- remCrops[item.name] = remCrops[item.name] - toMove
- turtle.transferTo(lastSlot[item.name])
- end
- if remCrops[item.name] > 0 and turtle.getItemCount(i) > 0 then
- lastSlot[item.name] = i
- remCrops[item.name] = remCrops[item.name] - turtle.getItemCount(i)
- end
- end
- elseif item ~= nil then
- turtle.select(i)
- turtle.dropDown()
- end
- end
- end
- function refuel()
- turtle.select(inventory_size)
- turtle.drop()
- while turtle.getFuelLevel() < fuel_level do
- turtle.suckUp(1)
- turtle.refuel()
- end
- turtle.suck()
- end
- function plantCrop()
- cropId = math.random()
- for i = 1, #seeds, 1 do
- if cropId < distribution[i] then
- slot = findCrop(seeds[i])
- if slot == nil then
- slot = findCrop("any")
- end
- if slot then
- turtle.select(slot)
- return turtle.placeDown()
- end
- else
- cropId = cropId - distribution[i]
- end
- end
- return false
- end
- function checkChests()
- chests_found = false
- -- Unload
- _, block = turtle.inspectDown()
- if isType(block, chest) then
- unload()
- chests_found = true
- end
- -- Refuel
- _, block = turtle.inspectUp()
- if isType(block, chest) then
- refuel()
- chests_found = true
- end
- return chests_found
- end
- while 1 do
- os.sleep(delay)
- _, up = turtle.inspectUp()
- _, down = turtle.inspectDown()
- _, front = turtle.inspect()
- cropUnder = isType(down, crops)
- if checkChests() then
- turtle.forward()
- elseif cropUnder then
- if down.metadata == max_metalevel[cropUnder] then
- turtle.digDown()
- plantCrop()
- end
- turtle.forward()
- elseif turtle.digDown() then
- plantCrop()
- turtle.forward()
- elseif plantCrop() then
- turtle.forward()
- elseif isType(up, safety) or isType(down, safety) then
- if isType(front, turnLeft) then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- elseif isType(front, turnRight) then
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- turtle.forward()
- elseif isType(front, turnLeft) then
- turtle.turnLeft()
- elseif isType(front, turnRight) then
- turtle.turnRight()
- else
- turtle.forward()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement