How to get different colored wool?

Discussion in 'Spigot Plugin Development' started by pondamo, Jun 16, 2015.

  1. Hello, im trying to check if a player right clicks a block it will turn into wool, in this case black wool.
    However there isnt a Material called BLACK_WOOL. Theres only wool. How would I set the color of the wool?
    Code (Text):
    if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                e.getClickedBlock().setType(Material.WOOL);
     
  2. By setting the META value
     
  3. What META value do I use?
     
    • Agree Agree x 5
    • Like Like x 1
  4. just to add on a little bit ^^
    the byte number equals the number which is behind the id for example "35:4" would be "(byte) 4"
    which is equal to Material.WOOL with yellow color ^^
    if you want to know how to get the wools id in-game just press F3 + H at the same time and hover over the item ;)
     
    • Like Like x 2
  5. Well thats exactly what I though, however when I entered 15 for the byte number (black wool) it popped up with an error saying that 15 is not a valid byte number. Let me go back and re check my work, maybe I did something wrong
     
  6. I think the ID's start at 0.
     
  7. By entering the number 15 (black wool) should not give error.
     
  8. You could also try to cast the item to the Wool class. It has .getColor and .setColor which makes it a lot easier.
     
    • Agree Agree x 2
  9. Like this?
    Code (Text):
    @EventHandler
      public void onPlayerInteract(PlayerInteractEvent e)
      {
        ItemStack blackbrush = new ItemStack(Material.INK_SACK, 1, (short)DyeColor.BLACK.getData());
        ItemMeta meta = blackbrush.getItemMeta();
        if ((!meta.hasDisplayName()) || (!meta.getDisplayName().equals("Black Paintbrush"))) {
          return;
        }
        if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
            new ItemStack( Material.WOOL, 1, (byte)15);
          e.getClickedBlock().setType(Material.WOOL);
        }
      }
     
  10. Itemstack without variable? What should be the result sorry?
     
  11. sothatsit

    Patron

    Block and ItemStack data is quite different. Creating a new ItemStack and not doing anything with it is not going to do anything.

    You need to call the Block.setData(byte) method.
     
  12. #13 ExecutableFix, Jun 17, 2015
    Last edited: Jun 17, 2015
  13. you have to change the block...
    ItemStack is for example an item in the inventory
    but if you need it in the future here is an example for an ItemStack
    Code (Text):

    ItemStack blackWool = new ItemStack(Material.WOOL, 1, (byte) 15);
     
     
  14. Okay so like this...
    Code (Text):
      @EventHandler
      public void onPlayerInteract(PlayerInteractEvent e)
      {
        Wool blackw = new Wool(DyeColor.BLACK);
        if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
          e.getClickedBlock().setType(blackw);
        }
      }
     
  15. sothatsit

    Patron


    e.getClickedBlock().setData((byte) 15);

    You can find the different data values for wool here: http://minecraft.gamepedia.com/Wool
     
    • Useful Useful x 1
  16. PHP:
    @EventHandler
      public void onPlayerInteract(PlayerInteractEvent e)
      {
        Wool blackw = new Wool(DyeColor.BLACK);
        if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
          e.getClickedBlock().setType(blackw.getType());
        }
      }
    That is the code :)
     
    • Like Like x 1
  17. I get this error in eclipse: The method getType() is undefined for the type Wool
    The quick fix that eclipse gives me is to change the method to getItemType(). I tried this and tested it out and it somewhat worked. When I click a block it changes it to wool but the wool is white
     
  18. I'm still new to plugin development, but after you set the type to wool try getting the block at that location, cast it to Wool, then set the details.

    Here is some code where I set a block to a sign and write text to it. I'm sure if you swap out the sign references to Wool it should work for you.
    Code (Text):

    Block oBlock = oPlayer.getWorld().getBlockAt(X, Y, Z);
                            oBlock.setType(Material.SIGN_POST);

                            Sign oSign = (Sign) oBlock.getState();
                            oSign.setLine(0, strSignSplit[0]);
                            oSign.setLine(1, strSignSplit[1]);
                            oSign.setLine(2, strSignSplit[2]);
                            oSign.setLine(3, strSignSplit[3]);
                            oSign.update();