Material.DYE_GREEN?

Discussion in 'Plugin Development' started by MariusAlexanderWinsjansen, Mar 21, 2012.

Thread Status:
Not open for further replies.
  1. Greetings,

    Simple question, how can I get materials like, DYE_GREEN??

    PEACE OUT!
     
  2. Offline

    Tzeentchful

    you need to be more specific about what you want. do you want a command to spawn green dye? or on a certain event?
     
  3. Offline

    mushroomhostage

    There is no Material.DYE_GREEN because Material only maps type ids -- there is one item ID for dyes (confusingly named Material.INK_SACK), and the damage value is used to store its color. The MaterialData subclasses can be used to lookup damage values. For dyes, the class is Dye, and it has a constructor and setColor() method you can use to set the DyeColor.

    That's one option, another is to lookup the data values and plugin in the numbers directly into an ItemStack, something like:
    Code:
    new ItemStack(351, 1, 2)
     
  4. I just need to get that item for different events, for example, lets say "if someone right click whit the item Gray Dye"!, usely I define which item they are clicking whit, whit "Material.ITEM", but how can I bring these items up, so I can use them in events like this?

    Thanks, this solves one of my problames!:)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  5. Is there not anyone who know how to do this?:/
     
  6. Offline

    KILL3RTACO

    i believe Player.getItemInHand().getDamage() should help
     
  7. Offline

    Taco

    To clarify what has already been said, the data value on items such as wool, dyes, etc. is stored as the item's damage and can be accessed using getData() and can be set using setData(). You can find the data values of just about everything you'll need on this page: http://www.minecraftwiki.net/wiki/Data_values

    Edit: Corrected Damage to Data, thanks to tips48 I've no clue why I was putting damage.
     
  8. Offline

    Taco

    tips48 likes this.
  9. Offline

    greg_t

    This helps me also :) will it work for monster eggs to get the different types
     
  10. Yes
     
  11. Taco tips48 , Thansk for giving me links to the different places, but, I am sorry, this doesnt help me, dont you think I have been looking after it? I totaly understand that the dyes are defined by getData(), but I still dont know how to actualy code it!

    Would it be so hard for you to just type an example code? Its just an if statment I am looking for help whit, couldt be that much of work to just show me the actualy code?

    ... and dont say that the links you have sendt clearly shows me how, becuase if it would, i would understand it, but I dont! So :)
     
  12. My link was to Taco.

    Anyway...

    Code:java
    1.  
    2. ItemStack greenWool = new ItemStack(Material.WOOL, 1, 6);
    3.  

    1 = amount, 6 = data
     
  13. Thank you for your reply!

    First off all, that code dont even work for ItemStack!

    Second off all, I am not looking after itemstack! I am looking for checking the players item in hand on the "PlayerInteractEvent"! and not wool, but dye!

    Let me make this as simple as possible, IF someone right or left click whit cocobeans, they will get the player message "I am clicking whit cocobeans"!

    So, this is my code (which is working perfectly, but is not for the right item);

    Code:
            Player player = event.getPlayer();
            Material iteminhand = player.getItemInHand().getType();
            if(iteminhand.equals(Material.WOOD_SWORD)){
                    // DO STUFF HERE!    
     
  14. Ironically, that's not extremely easy because coca beans require data. Here ya go..
    Code:java
    1.  
    2. @EventHandler
    3. public void handle(PlayerInteractEvent event) {
    4. if (!event.hasItem()) {
    5. return;
    6. }
    7. ItemStack is = event.getItem();
    8. ItemStack cocabeans = new ItemStack(Material.INK_SACK);
    9. cocabeans.setData((byte) 3);
    10. if (cocabeans.equals(is)) {
    11.  
    12. // DO STUFF HERE
    13. }
    14. }
     
  15. Code:java
    1.  
    2.  
    3. Thanks again, for replying!
    4.  
    5. This doesnt work either, but you finely understand what I am trying to do! :D
    6.  
    7. I get error that the "setData()" cant be used in ItemStacK:/
    8.  
    9. Thanks for helping me, and I hope you can get this working for me! This is VERY important for me to make possible! My plugin is done and everything, I just need to change the items it works for to dye!!
     
  16. My appologies, was using an ancient method :p
    Use
    Code:java
    1.  
    2. @EventHandler
    3. public void handle(PlayerInteractEvent event) {
    4. if (!event.hasItem()) {
    5. return;
    6. }
    7. ItemStack is = event.getItem();
    8. ItemStack beans = new MaterialData(Type.INK_SACK, (byte) 3).toItemStack();
    9. if (is.equals(beans)) {
    10. // DO SOMETHING
    11. }
    12. }
     
  17. Code:java
    1.  
    2.  
    3. "Type." didnt work, the only thing I could import on Type was effect and nothing that had whit items to do! I tryied to change to "Material.INK_SACK"which game me no errrors, but still, not working:/
     
  18. Sorry, I meant Material. It's kinda past midnight, and I'm really tired, so I'll be going to bed, but I'll look at it in the morning!
     
  19. Offline

    xGhOsTkiLLeRx

    MariusAlexanderWinsjansen

    Code:java
    1. @EventHandler
    2. public void handle(PlayerInteractEvent event) {
    3. if (!event.hasItem()) return;
    4. /* Gets the data from the item (example: BROWN DYE(3)
    5.   * Dirt would be DIRT(0), because dirt has no data like wool
    6.   */
    7. MaterialData item = event.getItem().getData();
    8. // Creates a new MaterialData (in this case brown dye: BROWN DYE(3))
    9. MaterialData beans = new MaterialData(Material.INK_SACK, (byte) 3);
    10. if (item.equals(beans)) {
    11. event.getPlayer().sendMessage("YES");
    12. }
    13. }


    I got my debug message YES. So it works.
    Enjoy :)
     
Thread Status:
Not open for further replies.

Share This Page