Solved Stained Clay DyeColor wrong (Blue = Yellow?)

Discussion in 'Spigot Plugin Development' started by jankingDE, May 19, 2016.

  1. Hey!

    I am using the following Code to get the DyeColor of an STAINED_CLAY Block. This works fine, but the Dye Colors are wrong. For example:

    Code (Text):

        public void on(PlayerMoveEvent e){
            Player p = e.getPlayer();
            Block block = p.getLocation().subtract(0D, 1D, 0D).getBlock();
            if(block.getType() == Material.STAINED_CLAY && block.getData() == DyeColor.RED.getDyeData()) {
                p.getWorld().playSound(p.getLocation(),Sound.valueOf("NOTE_PLING"), 0.3f, 0.3f);
                p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 2000, 2));
            } else if(block.getType() == Material.STAINED_CLAY && block.getData() == DyeColor.BLUE.getDyeData()) {
                p.getWorld().playSound(p.getLocation(),Sound.valueOf("NOTE_PLING"), 0.3f, 0.3f);
                p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 2000, 2));
    This should first give me Jump Boost on Red, and Speed on blue blocks. But I get Jump Boost on orange and Speed on yellow blocks, I don't know why.

    I mean it works for me and I will continue to use this code but I think this is a little wrong.

    If you don't know what I mean I have a video here:

    Thank you, have a nice day :D
  2. Dont use getDyeData(), use ordinal() and cast block.getData() to int.
    Or faster use switch with argument casted to int block.getData() and into case put your statements. like case 14:
    //do something....
    • Like Like x 1
  3. Alright thanks! This works, but do you have an idea why the colors are wrong? :c
  4. Cause dyecolor is unique object that holds data for blocks or dyed wolf collars etc.. and data values are not same.
    • Like Like x 1