1.16.x Again NoteBlock! How to make the note block play sound with appropriate note particle?

Discussion in 'Spigot Plugin Development' started by bottomdumber, Oct 18, 2020 at 6:33 AM.

  1. I am trying to migrate my plugin from 1.12 to 1.16
    I wonder how to make note block to play sound with appropriate colored note particle as the player does it by clicking the note block.

    Here are two examples. The first one is for bukkit 1.12 and the second is my migrating for 1.16.
    Code (Java):
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;

    public class Test {

        // bukkit 1.12
        public static void play_1_12(Location location){
            Block block = location.getBlock();
            if(block.getType()== Material.NOTE_BLOCK){
                org.bukkit.block.BlockState blockState =block.getState();
                if(blockState instanceof org.bukkit.block.NoteBlock){
                    org.bukkit.block.NoteBlock noteBlock = (org.bukkit.block.NoteBlock) blockState;
                    noteBlock.play(); // play sound with particles
                }
            }
        }

        // bukkit 1.16
        public static void play_1_16(Location location){
            Block block = location.getBlock();
            if(block.getType()== Material.NOTE_BLOCK){
                org.bukkit.block.data.BlockData blockData  =block.getBlockData();
                if(blockData instanceof org.bukkit.block.data.type.NoteBlock){
                    org.bukkit.block.data.type.NoteBlock noteBlock = (org.bukkit.block.data.type.NoteBlock) blockData;
                    // noteBlock.play();
                    // what to do next? I want to make note block to play sound
                    // with appropriate colored note particle as player clicked it.
                }
            }
        }
    }
     
    I do not understand what replacement to do with "noteBlock.play();"
    Can anybody help me?
     
  2. looking through the source, using #setPowered should do what you want, though i dont know if you have to do additional things to make sure it works in the future
     
  3. Nothing happens :(
    Code (Java):
        // bukkit 1.16
        public static void play_1_16(Location location) {
            Block block = location.getBlock();
            if (block.getType() == Material.NOTE_BLOCK) {
                org.bukkit.block.data.BlockData blockData = block.getBlockData();
                if (blockData instanceof org.bukkit.block.data.type.NoteBlock) {
                    org.bukkit.block.data.type.NoteBlock noteBlock = (org.bukkit.block.data.type.NoteBlock) blockData;
                    // noteBlock.play();
                    // what to do next? I want to make note block to play sound
                    // with appropriate colored note particle as player clicked it.
                    noteBlock.setPowered(true);
                    block.setBlockData(noteBlock);
                }
            }
        }
     
    I think "setPowered" does not activate block. It only set info that block is powered.
    I can power NotweBlock with redstone + redstone torch and then click and click it by hand to make sounds while NoteBlock is still powered.
    Also, when I break redstone torch, then NoteBlock is not powered, but I can stil click and click it to make sounds. And no power is generated while I doing it (nearby comparator is not activated while I cliking it)

    There must be another method to make NoteBlock play sound without any power :(
     
    #3 bottomdumber, Oct 18, 2020 at 5:06 PM
    Last edited: Oct 18, 2020 at 5:17 PM