Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("move")
- os.loadAPI("inv")
- function split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local table = {}
- i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table [i] = str
- i = i + 1
- end
- return table
- end
- function plantTile()
- if (turtle.placeDown()) then
- rednet.open("right")
- local t, d = turtle.inspectDown()
- local mes = textutils.serialize({move.getLocalCoord(), d.name})
- rednet.broadcast(mes, "farm")
- rednet.close("right")
- return true
- else
- return false
- end
- end
- function harvestAndPlant(plant)
- local t, d = turtle.inspectDown()
- if (t) then
- local p = split(split(d.name, ":")[2], "_")
- if (table.getn(p) == 2) then
- p = p[1]
- elseif (table.getn(p) == 3) then
- p = p[1] .. "_" .. p[2]
- elseif (table.getn(p) == 4) then
- p = p[1] .. "_" .. p[2] .. "_" .. p[3]
- end
- d.name = split(d.name, ":")[1] .. ":" .. p .. "_seeds"
- if (d.metadata == 7) then
- inv.selectItem(d.name)
- turtle.digDown()
- if (type(plant) == "table") then
- for i = 1, table.getn(plant), 1 do
- if (inv.selectItem(plant[i])) then
- plantTile()
- return
- end
- end
- else
- if (inv.selectItem(plant)) then
- plantTile()
- return
- end
- end
- end
- else
- if (type(plant) == "table") then
- for i = 1, table.getn(plant), 1 do
- if (inv.selectItem(plant[i])) then
- while not plantTile() do
- inv.selectItem("minecraft:diamond_hoe")
- turtle.equipLeft()
- turtle.digDown()
- inv.selectItem("minecraft:diamond_pickaxe")
- turtle.equipLeft()
- inv.selectItem(plant[i])
- end
- return
- end
- end
- else
- if (inv.selectItem(plant)) then
- print(21)
- while not plantTile() do
- inv.selectItem("minecraft:diamond_hoe")
- turtle.equipLeft()
- turtle.digDown()
- inv.selectItem("minecraft:diamond_pickaxe")
- turtle.equipLeft()
- inv.selectItem(plant[i])
- end
- return
- end
- end
- end
- end
- function farm(z, plant)
- for i = 1, 2, 1 do
- move.right()
- move.forward()
- move.right()
- for j = 1, z - 1, 1 do
- if i % 9 ~= 5 or j % 9 ~= 5 then
- print("h & p")
- harvestAndPlant(plant)
- end
- move.forward(1)
- end
- harvestAndPlant(plant)
- end
- end
- white_list = {
- "minecraft:diamond_pickaxe",
- "minecraft:diamond_hoe",
- "mysticalagriculture:tier6_inferium_seeds",
- "mysticalagriculture:tier5_inferium_seeds",
- "mysticalagriculture:tier4_inferium_seeds",
- "mysticalagriculture:tier3_inferium_seeds",
- "mysticalagriculture:tier2_inferium_seeds",
- "mysticalagriculture:tier1_inferium_seeds",
- "mysticalagriculture:coal_seeds",
- "mysticalagriculture:iron_seeds",
- "mysticalagriculture:glowstone_seeds",
- "mysticalagriculture:blaze_seeds"
- }
- move.left()
- move.left()
- move.updatePosition()
- move.updatePosition()
- move.updatePosition()
- local coord = move.getGlobalCoord()
- move.globalGoto(180, 3, coord.z)
- move.look("west")
- if (not turtle.detect()) then
- move.left()
- move.forward()
- move.right()
- end
- while true do
- for i = 1, 16, 1 do
- local in_list = false
- for j = 1, table.getn(white_list), 1 do
- if (turtle.getItemDetail(i)) then
- if (white_list[j] == turtle.getItemDetail(i).name) then
- in_list = true
- end
- end
- end
- if in_list == false then
- turtle.select(i)
- turtle.drop()
- end
- end
- rednet.open("right")
- rednet.broadcast("idle", "idle farm")
- print("idle")
- senderId, message, protocol = rednet.receive("start farm")
- rednet.broadcast("running", "farm")
- rednet.close("right")
- local data = textutils.unserialize(message)
- print("Starting farming:")
- print("\tLength: " .. data.length)
- print("\tWidth: " .. data.width)
- print("\tPriority:")
- for i = 1, table.getn(data.priority), 1 do
- print("\t\t" .. data.priority[i])
- end
- if (turtle.getFuelLevel() < (data.length * data.width + data.width - 2)) then
- while (turtle.getFuelLevel() < (data.length * data.width + data.width - 2)) do
- turtle.suckUp()
- turtle.refuel()
- end
- end
- farm(data.length, data.priority)
- end
Add Comment
Please, Sign In to add comment