Solved How do I give a player an item with a datatype?

Discussion in 'Plugin Development' started by Sheepii, Jan 30, 2015.

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

    Sheepii

    Code:
          
            //Doesn't seem to be temporary;
            Block block;
          
            //Sets the block to dirt;
            block.setType(Material.DIRT);
          
            //Sets the datatype to Podzol a datatype of Material.DIRT;
            block.setData((byte) 2);
          
            //Define the player (temporary);
            Player player;
          
            //ItemStack Amount;
            int amount = 5;
          
            //block.getType() returns Material.DIRT;
            player.getInventory().addItem(new ItemStack(block.getType(), amount));
    
    How do I give a player something like Podzol?

    Also, why is .setData depreciated?
     
  2. Offline

    Skionz

  3. Offline

    Sheepii

    @Skionz Thanks man. For everyone else that wanted this,

    Code:
            //Create a new ItemStack of Podzol
            ItemStack is = new ItemStack(Material.DIRT, 1, (byte) 2);
          
          
          
            //block.getType() returns Material.DIRT;
            player.getInventory().addItem(is);
    
    Quick question though,

    Why is ItemStack(int type, int amount, short damage, Byte data) depreciated? I don't quite get, "this method uses an ambiguous data byte object"
     
  4. Offline

    Skionz

    @Sheepii Something about ids and stuff getting removed. You shouldn't worry. Bukkit won't be updating any time soon.
     
Thread Status:
Not open for further replies.

Share This Page