Advertisement
hevohevo

ComputerCraft: Tofu3

Jun 7th, 2016
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  1. -- tofu3
  2. --  豆腐建築を行うプログラムです
  3. --  アイテムインベントリに適当にアイテム詰めて
  4. --  燃料はもちろんたっぷり与えておくこと
  5.  
  6. -- ####### Config ###########
  7. local haba = 15
  8. local okuyuki = 12
  9. local takasa = 5
  10. local togariyane = true -- true or false
  11.  
  12. -- ####### Functions ########
  13.  
  14. -- #####
  15. -- アイテムインベントリ用の関数群
  16.  
  17. -- 次のアイテムスロットへ選択スロットを移動
  18. function selectNextSlot()
  19.   local current = turtle.getSelectedSlot()
  20.   if current == 16 then
  21.     return false
  22.   else
  23.     turtle.select(current+1)
  24.     return true    
  25.   end
  26. end
  27.  
  28. -- 選択スロットを次のアイテムのあるスロットまで移動
  29. function selectNextItemSlot()
  30.   while (turtle.getItemCount()==0) and selectNextSlot() do
  31.   end
  32. end
  33.  
  34. -- インベントリを先頭から走査し、確実にアイテムを真下設置
  35. function myPlaceDown()
  36.   while (turtle.getItemCount()==0) and selectNextItemSlot() do
  37.     print("Current slot:",turtle.getSelectedSlot())
  38.   end
  39.  
  40.   return turtle.placeDown()
  41. end
  42.  
  43. -- #####
  44. -- 建築用の関数
  45. local usedBlocks = 0
  46.  
  47. -- 前進しつつn個のブロックを下に設置
  48. function placeSomeBlocks(n)
  49.   if n<1 then -- 最後の真下の穴を埋める
  50.     if myPlaceDown() then
  51.       usedBlocks = usedBlocks+1
  52.     end
  53.     return
  54.   end
  55.  
  56.   for i=1,n do -- n個並べる
  57.     turtle.forward()
  58.     if myPlaceDown() then
  59.       usedBlocks = usedBlocks+1
  60.     end
  61.   end
  62. end
  63.  
  64. -- ロの字にブロックを設置
  65. function buildRonoji(okuyuki, haba)
  66.   for i=1,2 do
  67.     placeSomeBlocks(okuyuki - 1)
  68.     turtle.turnRight()
  69.     placeSomeBlocks(haba - 1)
  70.     turtle.turnRight()
  71.   end
  72. end
  73.  
  74. -- 屋根の次の位置に移動
  75. function goToRightForward()
  76.   turtle.turnRight()
  77.   turtle.forward()
  78.   turtle.turnLeft()
  79.   turtle.forward()
  80. end
  81.  
  82. function goToLeftBack()
  83.   turtle.turnLeft()
  84.   turtle.forward()
  85.   turtle.turnRight()
  86.   turtle.back()
  87. end
  88.  
  89. function goUp()
  90.   if togariyane then
  91.     turtle.up()
  92.   end
  93. end
  94.  
  95.  
  96. -- ###### Main ########
  97. turtle.select(1) -- 最初の決まり文句
  98.  
  99. turtle.up()  -- 一歩上昇して、設置位置につく
  100.  
  101. -- ロの字を1段ずつ takasa まで積み上げる
  102. for ronoji=1,takasa do
  103.   buildRonoji(okuyuki, haba)
  104.   turtle.up()  -- move up
  105. end
  106.  
  107. -- とがり屋根だと、ひさしを作る
  108. -- 一回り大きなロの字を作る
  109. if togariyane then
  110.   goToLeftBack()
  111.   buildRonoji(okuyuki+2, haba+2)
  112.   goToRightForward()
  113.   buildRonoji(okuyuki, haba)
  114.   turtle.up()
  115. end
  116.  
  117. -- 屋根作り
  118. -- 少しずつ小さなロの字を敷き詰める。
  119. while (okuyuki > 0) and (haba > 0) do
  120.   buildRonoji(okuyuki, haba)
  121.   goToRightForward()
  122.   goUp() -- とがり屋根だと1歩上昇
  123.   okuyuki = okuyuki - 2
  124.   haba = haba - 2
  125. end
  126.  
  127. print("Used Blocks:", usedBlock)
  128. -- redstone.setOutput("bottom",true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement