SHARE
TWEET

ComputerCraft: Tofu1

hevohevo Jun 6th, 2016 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- tofu1
  2. --  豆腐建築を行うプログラムです
  3. --  アイテムインベントリに適当にアイテム詰めて
  4.  
  5. -- ####### Config ###########
  6. local haba = 15
  7. local okuyuki = 12
  8. local takasa = 5
  9.  
  10.  
  11. -- ####### Functions ########
  12. -- インベントリを先頭から走査し、確実にアイテムを使う
  13. function selectNextSlot()
  14.   local current = turtle.getSelectedSlot()
  15.   if current == 16 then
  16.     return false
  17.   else
  18.     turtle.select(current+1)
  19.     return true    
  20.   end
  21. end
  22.  
  23. function selectNextItemSlot()
  24.   while (turtle.getItemCount()==0) and selectNextSlot() do
  25.   end
  26. end
  27.  
  28. -- ex. myDo(turtle.place)
  29. function myDo(func)
  30.   while (turtle.getItemCount()==0) and selectNextItemSlot() do
  31.   end
  32.   return func()
  33. end
  34.  
  35. -- 建築用の関数
  36. function placeSomeBlocks(n)
  37.   if n<1 then
  38.     -- turtle.placeDown()
  39.     myDo(turtle.placeDown)
  40.    
  41.     return
  42.   end
  43.  
  44.   for i=1,n do
  45.     turtle.forward()  -- move to next position
  46.     -- turtle.placeDown()
  47.     myDo(turtle.placeDown)
  48.   end
  49. end
  50.  
  51. function placeSquare(okuyuki, haba)
  52.   for i=1,2 do
  53.     placeSomeBlocks(okuyuki - 1)
  54.     turtle.turnRight()
  55.     placeSomeBlocks(haba - 1)
  56.     turtle.turnRight()
  57.   end
  58. end
  59.  
  60. function goToRightForward()
  61.   turtle.turnRight()
  62.   turtle.forward()
  63.   turtle.turnLeft()
  64.   turtle.forward()
  65. end
  66.  
  67.  
  68.  
  69. -- ###### Main ########
  70. turtle.select(1) -- the usual phrase
  71.  
  72. turtle.up()  -- move up
  73.  
  74. -- stack six squares
  75. for ronoji=1,takasa do
  76.   -- 1st stage is made with slot 1, 2nd stage is slot 2, ...
  77.   --turtle.select(ronoji)
  78.  
  79.   -- 四角形の形にブロック配置
  80.   -- placeSquare(haba)
  81.   placeSquare(okuyuki, haba)
  82.   turtle.up()  -- move up
  83. end
  84.  
  85.  
  86.  
  87. -- 屋根作り
  88.  
  89. while (okuyuki > 0) and (haba > 0) do
  90.   print(okuyuki, haba)
  91.   placeSquare(okuyuki, haba)
  92.   goToRightForward()
  93.   okuyuki = okuyuki - 2
  94.   haba = haba - 2
  95. end
  96.  
  97. -- redstone.setOutput("bottom",true)
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top