Advertisement
yokmama

saikyo-woodchopper

Jul 29th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 KB | None | 0 0
  1. kankaku = 3
  2.  
  3. function woodplant()
  4.   -- 足元の穴を掘って土を置く
  5.   turtle.dig()
  6.   turtle.forward()
  7.   turtle.digDown()
  8.   -- slot1の土を置く
  9.   turtle.select(1)
  10.   turtle.placeDown()
  11.   -- slot2の木を植える
  12.   turtle.back()
  13.   turtle.select(2)
  14.   turtle.place()
  15. end
  16.  
  17. function storeChest()
  18.   turtle.turnLeft()
  19.   local success, check = turtle.inspect()
  20.   if success and check.name == "minecraft:chest" then
  21.     for i=3, 16 do
  22.       turtle.select(i)
  23.       turtle.drop()
  24.     end
  25.   end
  26.   turtle.turnRight()
  27. end
  28.  
  29. function woodchopper()
  30.     turtle.dig()
  31.     turtle.forward()
  32.     while turtle.detectUp() do
  33.     turtle.digUp()  
  34.     turtle.up()
  35.     end
  36.     while not turtle.detectDown() do
  37.       turtle.down()
  38.     end
  39.   -- slot2の木を植える
  40.     turtle.back()
  41.     turtle.select(2)
  42.     turtle.place()
  43. end
  44.  
  45. function turnCorner()
  46.   turtle.forward()
  47.   turtle.turnRight()
  48.   turtle.forward()
  49.   turtle.forward()
  50.   for k=1, kankaku do
  51.     turtle.forward()
  52.   end
  53.   turtle.turnRight()
  54.   turtle.forward()  
  55.  
  56.   -- チェストに木を格納する
  57.   storeChest()
  58. end
  59.  
  60. -- itemの確認
  61. slot1 = turtle.getItemDetail(1)
  62. if slot1 == nil then
  63.    print("slot1 ni tuchi wo oite kudasai")
  64.    do return end
  65. end
  66.  
  67. slot2 = turtle.getItemDetail(2)
  68. if slot2 == nil then
  69.    print("slot2 ni nae wo oite kudasai")
  70.    do return end
  71. end
  72.  
  73. -- 1列に植える数を質問
  74. io.write("ki wo ueru kazu ha?")
  75. x = io.read()
  76.  
  77. -- 燃料がある限り伐採と植樹を繰り返す
  78. while true do
  79.   for i=1, 2 do
  80.     for j = 1, x do
  81.       -- 植樹
  82.       turtle.turnRight()
  83.       -- slot3の木が育っているなら伐採する
  84.       local success, check = turtle.inspect()
  85.       if success then
  86.         -- 苗と違うものがあったら木と判断し伐採する
  87.         if slot2.name ~= check.name then
  88.           woodchopper()
  89.         end
  90.       else
  91.         woodplant()
  92.       end
  93.       turtle.turnLeft()
  94.       -- 最終でなければ間隔を空ける
  95.       if j ~= 5 then
  96.         for k=1, kankaku do
  97.           turtle.forward()
  98.         end
  99.       end
  100.     end
  101.     turnCorner()
  102.   end
  103.  
  104.   -- 30秒後に再開
  105.   os.sleep(30)
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement