Advertisement
hevohevo

ComputerCraft: Tofu2

Jun 6th, 2016
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.39 KB | None | 0 0
  1. -- tofu2
  2. --  豆腐建築を行うプログラムです
  3. --  アイテムインベントリに適当にアイテム詰めて
  4. --  燃料はもちろんたっぷり与えておくこと
  5.  
  6. -- ####### Config ###########
  7. local haba = 15
  8. local okuyuki = 12
  9. local takasa = 5
  10. local usedBlock = 0
  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.  
  46. -- 前進しつつn個のブロックを下に設置
  47. function placeSomeBlocks(n)
  48.   if n<1 then -- 最後の真下の穴を埋める
  49.     if myPlaceDown() then
  50.       usedBlock = usedBlock+1
  51.     end
  52.     return
  53.   end
  54.  
  55.   for i=1,n do -- n個並べる
  56.     turtle.forward()
  57.     if myPlaceDown() then
  58.       usedBlock = usedBlock+1
  59.     end
  60.   end
  61. end
  62.  
  63. -- ロの字にブロックを設置
  64. function buildRonoji(okuyuki, haba)
  65.   for i=1,2 do
  66.     placeSomeBlocks(okuyuki - 1)
  67.     turtle.turnRight()
  68.     placeSomeBlocks(haba - 1)
  69.     turtle.turnRight()
  70.   end
  71. end
  72.  
  73. -- 屋根の次の位置に移動
  74. function goToRightForward()
  75.   turtle.turnRight()
  76.   turtle.forward()
  77.   turtle.turnLeft()
  78.   turtle.forward()
  79. end
  80.  
  81.  
  82.  
  83. -- ###### Main ########
  84. turtle.select(1) -- 最初の決まり文句
  85.  
  86. turtle.up()  -- 一歩上昇して、設置位置につく
  87.  
  88. -- ロの字を1段ずつ takasa まで積み上げる
  89. for ronoji=1,takasa do
  90.   buildRonoji(okuyuki, haba)
  91.   turtle.up()  -- move up
  92. end
  93.  
  94.  
  95.  
  96. -- 屋根作り
  97. -- 少しずつ小さなロの字を敷き詰める。
  98. while (okuyuki > 0) and (haba > 0) do
  99.   buildRonoji(okuyuki, haba)
  100.   goToRightForward()
  101.  
  102.   okuyuki = okuyuki - 2
  103.   haba = haba - 2
  104. end
  105.  
  106. print("Used Block:", usedBlock)
  107. -- redstone.setOutput("bottom",true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement