Advertisement
xX-AAAAAAAAAA-Xx

ComputerCraft Bells

Sep 1st, 2024 (edited)
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. -- Set the time for noon (Minecraft hours)
  2. local noonHour = 12
  3.  
  4. local speakerSides = {
  5.     "top",    -- Top speaker
  6.     "left",   -- Left speaker
  7.     "bottom", -- Bottom speaker
  8.     "right"   -- Right speaker
  9. }
  10.  
  11. -- Define the notes and duration of the jingle
  12. local notes = {
  13.     {pitch = 5},  -- Start with a lower note
  14.     {pitch = 7},  -- Move up to the next note
  15.     {pitch = 9},  -- Continue ascending
  16.     {pitch = 7},  -- Return to the previous note
  17.     {pitch = 5},  -- Finish with the starting note
  18.     {pitch = 9},  -- Add a higher note for variation
  19.     {pitch = 12}, -- Ascend to a higher note
  20.     {pitch = 9},  -- Return to a previous higher note
  21.     {pitch = 7},  -- Go back down
  22.     {pitch = 5}   -- Finish the melody
  23. }
  24.  
  25. -- Function to play the jingle on the speakers
  26. local function playJingle()
  27.     -- Wrap the speakers
  28.     local speakers = {}
  29.     for _, side in ipairs(speakerSides) do
  30.         speakers[side] = peripheral.wrap(side)
  31.     end
  32.    
  33.     -- Play the jingle
  34.     for _, noteData in ipairs(notes) do
  35.         for _, side in ipairs(speakerSides) do
  36.             local speaker = speakers[side]
  37.             speaker.playNote("bell", 1, noteData.pitch)
  38.         end
  39.         os.sleep(0.5)
  40.     end
  41. end
  42.  
  43. -- Function to check the time and redstone signal, and play the jingle
  44. local function checkTimeAndPlayJingle()
  45.     while true do
  46.         -- Get the current Minecraft hour
  47.         local currentHour = os.date("*t").hour  -- Assuming os.date is used to get the hour in Minecraft time format
  48.  
  49.         -- Check if it's around noon or if there's a redstone signal on the front side
  50.         local isNoon = math.abs(currentHour - noonHour) < 0.1
  51.         local hasRedstoneSignal = redstone.getInput("front")  -- Check redstone signal on the front side
  52.  
  53.         if isNoon or hasRedstoneSignal then
  54.             playJingle()
  55.  
  56.             -- Print to indicate the jingle is playing
  57.             print("Playing jingle with bells")
  58.  
  59.             -- Wait for a bit before checking again to avoid repeated triggers
  60.             os.sleep(7)  -- Check every minute
  61.         end
  62.  
  63.         -- Yield to avoid excessive CPU usage
  64.         os.sleep(1)  -- Yield every second to reduce CPU load
  65.     end
  66. end
  67.  
  68. -- Run the function
  69. checkTimeAndPlayJingle()
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement