Solved Item Id's

Discussion in 'Plugin Development' started by SirMonkeyFood, Nov 21, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    SirMonkeyFood

    Hey there,
    I'm working on a plugin, that gives flowers different properties when broken. As of right now, I've got one flower down, which is the Red one. It fires tnt. Anywho, I can't seem to figure out how to differentiate between each specific type of flower. I can only make it to where if any flower is broken a piece of tnt is launched. I'd suspect it has something to do with flowers using more than one ID(38:0, 38:1, etc). How would i state that i need the tnt to go off only when the material is a flower with the id ending ':0'?

    Here are some things I've tried:
    Code:
        @EventHandler
        public void onPick(BlockBreakEvent pick){
            Player p = pick.getPlayer();
            if(pick.getBlock().getTypeId() == 38){
            Location l = pick.getBlock().getLocation();
            p.sendMessage(ChatColor.BOLD + "" + ChatColor.DARK_RED + "ITZ A TERAHP!!!");
            Entity tnt = p.getWorld().spawn(l, TNTPrimed.class);
            ((TNTPrimed)tnt).setFuseTicks(15);
            }
        }
    //This made any flower launch tnt
    Code:
        @EventHandler
        public void onPick(BlockBreakEvent pick){
            Player p = pick.getPlayer();
            if(pick.getBlock().getType().equals(Material.RED_ROSE.getNewData((byte)0))){
            Location l = pick.getBlock().getLocation();
            p.sendMessage(ChatColor.BOLD + "" + ChatColor.DARK_RED + "ITZ A TERAHP!!!");
            Entity tnt = p.getWorld().spawn(l, TNTPrimed.class);
            ((TNTPrimed)tnt).setFuseTicks(15);
            }
        }
    //This made no flower launch tnt

    Code:
        @EventHandler
        public void onPick(BlockBreakEvent pick){
            Player p = pick.getPlayer();
            if(pick.getBlock().getType().equals(Material.RED_ROSE)){
            Location l = pick.getBlock().getLocation();
            p.sendMessage(ChatColor.BOLD + "" + ChatColor.DARK_RED + "ITZ A TERAHP!!!");
            Entity tnt = p.getWorld().spawn(l, TNTPrimed.class);
            ((TNTPrimed)tnt).setFuseTicks(15);
            }
        }
    //This also made every flower launch tnt
    Thanks for any help
     
  2. Offline

    WinX64

    With the exception of Dandelion, all other flowers share the same item id. You will have to check for the extra data the blocks contain to diferentiate between the flowers.
    Although it's deprecated, you can use Block#getData to get this extra data you need(I'm not sire if there's any other way to get this data).
     
    SirMonkeyFood likes this.
  3. Offline

    SirMonkeyFood

Thread Status:
Not open for further replies.

Share This Page