drexplosionpd

createSongFromNoteBlocks

May 28th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkBlock()
  2.     local bool, data = turtle.inspect()
  3.     while not bool do
  4.         turn("r")
  5.         bool, data = turtle.inspect()
  6.     end
  7.     parseBlock(data)
  8. end
  9.  
  10. function parseNotes(data)
  11.     song = fs.open("song","a")
  12.     song.writeLine(data.state.instrument..":"..data.state.note)
  13.     turtle.dig()
  14.     turtle.forward()
  15.     turn("l")
  16.     local bool, data1 = turtle.inspect()
  17.     if (bool) then
  18.         song.writeLine(data1.state.instrument..":"..data1.state.note)
  19.     end
  20.     turn("r")
  21.     turn("r")
  22.     local bool1, data2 = turtle.inspect()
  23.     if (bool1) then
  24.         song.writeLine(data2.state.instrument..":"..data2.state.note)
  25.     end
  26.     song.close()
  27.     turn("l")
  28. end
  29.  
  30. function parseBlock(data)
  31.     if(data.name == "minecraft:repeater") then
  32.         song = fs.open("song", "a")
  33.         song.writeLine("delay:"..data.state.delay)
  34.         turtle.dig()
  35.         turtle.forward()
  36.         song.close()
  37.     elseif(data.name == "minecraft:note_block") then
  38.         parseNotes(data)
  39.     else
  40.         turtle.dig()
  41.         turtle.forward()
  42.     end
  43. end
  44.  
  45. function turn(dir)
  46.     if(dir == "r")then
  47.         turtle.turnRight()
  48.     elseif(dir == "l")then
  49.         turtle.turnLeft()
  50.     end
  51. end
  52.  
  53. while true do
  54.   checkBlock()
  55. end
Add Comment
Please, Sign In to add comment