Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 種のあるスロット番号
- firstSlot = 1
- -- 種を撒く処理
- function putSeed()
- for i=firstSlot, 16 do
- turtle.select(i)
- local data = turtle.getItemDetail(i)
- if data ~= nill and data.name == "minecraft:wheat_seeds" then
- if turtle.getItemCount(i) > 0 then
- firstSlot = i
- break
- end
- end
- end
- turtle.digDown()
- turtle.placeDown()
- end
- -- 麦を収穫する処理
- function harvest()
- local success, data = turtle.inspectDown()
- if success then
- if data.name == "minecraft:wheat" and data.metadata == 7 then
- turtle.digDown()
- putSeed()
- else
- print("Block name: ", data.name)
- print("Block metadata: ", data.metadata)
- end
- end
- end
- -- 刈り取った麦をチェストに格納する処理
- function storeWheat()
- for i=1, 16 do
- turtle.select(i)
- local data = turtle.getItemDetail(i)
- if data ~= nil and data.name == "minecraft:wheat" then
- turtle.drop(turtle.getItemCount(i))
- end
- end
- end
- -- 作業を終えて元の位置に戻る処理
- function backHome()
- if width%2 == 0 then
- turtle.turnLeft()
- for i=1, height do turtle.forward() end
- else
- turtle.forward()
- for i=1, width do turtle.forward() end
- turtle.turnRight()
- for i=1, height do turtle.forward() end
- end
- end
- -- 畑の縦横に順番にチェックし収穫と種まきを行う処理
- function plant()
- for i=1, width do
- turtle.forward()
- for j=1, height do
- if turtle.detectDown() == false then
- putSeed()
- else
- harvest()
- end
- turtle.forward()
- end
- if i%2 == 0 then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- end
- end
- -- メインの処理
- io.write("width?")
- width = io.read()
- io.write("height?")
- height = io.read()
- turtle.up()
- plant()
- backHome()
- turtle.down()
- storeWheat()
- turtle.turnRight()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement