Advertisement
yokmama

saikyo-farmer

Jul 29th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. -- 種のあるスロット番号
  2. firstSlot = 1
  3.  
  4. -- 種を撒く処理
  5. function putSeed()
  6.     for i=firstSlot, 16 do
  7.         turtle.select(i)
  8.         local data = turtle.getItemDetail(i)
  9.         if data ~= nill and data.name == "minecraft:wheat_seeds" then
  10.             if turtle.getItemCount(i) > 0 then
  11.                 firstSlot = i
  12.                 break
  13.             end
  14.         end
  15.     end
  16.     turtle.digDown()
  17.     turtle.placeDown()
  18. end
  19.  
  20. -- 麦を収穫する処理
  21. function harvest()
  22.     local success, data = turtle.inspectDown()
  23.     if success then
  24.         if data.name == "minecraft:wheat" and data.metadata == 7 then
  25.             turtle.digDown()
  26.             putSeed()
  27.         else
  28.           print("Block name: ", data.name)
  29.           print("Block metadata: ", data.metadata)
  30.         end
  31.     end
  32. end
  33.  
  34. -- 刈り取った麦をチェストに格納する処理
  35. function storeWheat()
  36.     for i=1, 16 do
  37.         turtle.select(i)
  38.         local data = turtle.getItemDetail(i)
  39.         if data ~= nil and data.name == "minecraft:wheat" then
  40.             turtle.drop(turtle.getItemCount(i))
  41.         end
  42.     end
  43. end
  44.  
  45. -- 作業を終えて元の位置に戻る処理
  46. function backHome()
  47.     if width%2 == 0 then
  48.         turtle.turnLeft()
  49.         for i=1, height do turtle.forward() end
  50.     else
  51.         turtle.forward()
  52.         for i=1, width do turtle.forward() end
  53.         turtle.turnRight()
  54.         for i=1, height do turtle.forward() end
  55.     end
  56. end
  57.  
  58. -- 畑の縦横に順番にチェックし収穫と種まきを行う処理
  59. function plant()
  60.     for i=1, width do
  61.         turtle.forward()
  62.         for j=1, height do
  63.             if turtle.detectDown() == false then
  64.                 putSeed()
  65.             else
  66.                 harvest()
  67.             end
  68.             turtle.forward()            
  69.         end
  70.         if i%2 == 0 then
  71.             turtle.turnLeft()
  72.             turtle.forward()
  73.             turtle.turnLeft()
  74.         else
  75.             turtle.turnRight()
  76.             turtle.forward()
  77.             turtle.turnRight()
  78.         end
  79.     end
  80. end
  81.  
  82. -- メインの処理
  83. io.write("width?")
  84. width = io.read()
  85. io.write("height?")
  86. height = io.read()
  87.  
  88. turtle.up()
  89. plant()
  90. backHome()
  91. turtle.down()
  92.  
  93. storeWheat()
  94. turtle.turnRight()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement