Solved Check if some leaves are oak leaves

Discussion in 'Spigot Plugin Development' started by AsssassinJianer, Apr 13, 2017.

  1. Hey, im trying to add a features to a plugin that i will be releasing soon and i need to check just if the leaves are from an oak tree, not birch, not spruce, i'd try to check if the Block.getData() == (short) 0 but it dosnt work.

    Code (Text):


            //Apple rate bellow checking if shears are enabled or not

            if (Block.getType() == Material.LEAVES && Block.getData() == (short) 1)
            {
                if(this.plugin.getConfig().getBoolean("Features.ShearsForApples"))

                {
                    Block.setType(Material.AIR);

                    if ((r <= (this.plugin.getConfig().getDouble("Rates.Applerate")) * 0.01D))
                    {
                        Block.setType(Material.AIR);
                        Block.getWorld().dropItemNaturally(loc, new ItemStack(Material.APPLE));
                    }
                }

                else

                {
                    if ((r <= (this.plugin.getConfig().getDouble("Rates.Applerate")) * 0.01D))
                    {
                        Block.setType(Material.AIR);
                        Block.getWorld().dropItemNaturally(loc, new ItemStack(Material.APPLE));
                    }
                }

            }
     
     
  2. remove Block.getData() == (short) 1
    0 are normal oak
     
  3. If i remove the block data, all the types of Leaves drop apples, not just oak, it will include birch, spruce, jungle and oak
     
  4. NathanWolf

    Supporter

    Don't remove it, check for data == 0 instead of 1.
     
  5. already tried. doesnt work
     
  6. Leaves that are decaying have a different data value. Spawn a tree in, break the logs and use the //info worldedit tool to check the data values of the leaves. I believe from memory its 5 for oak leaves but I'm not able to get on a computer to check.
     
  7. Im not cheking it on LeafDecay, it is on BlockBreakEvent, but ima try, how do i check that with world edit?
     
  8. Use data %4 == 0, decay state values for oak are 0, 4, 8, and 12
     
    • Informative Informative x 1
  9. Nvm, already did it, data values are 4 and 12, thanks bud
     
  10. What? data %4 ==0 ? Example? I dont get it
     
  11. Code (Java):
    if (block.getData() % 4 == 0) {
        // Oak data value
    }
     
  12. Hmm, guys there's a problem, it works now, but, it works for oak and for spruce idk why, any solution just to make it works on oak and dark oak?
     
  13. NVM, I fixed it, it was something with my code. Thanks all guys
     
  14. -chuckles to self while reading about what the data values are-
    Block.getData() is deprecated because it gives 'magic' values. The correct way is to use MaterialData to get the TreeSpecies.
    Code (Java):
    MaterialData materialData = block.getState().getData();
    if(materialData instanceof Leaves){
        if(((Leaves)materialData).getSpecies()==TreeSpecies.GENERIC){
            //Leaf type is Oak
        }
    }