Question Placing a block on a block HELP

Discussion in 'Plugin Help/Development/Requests' started by Hectorg98, May 19, 2015.

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

    Hectorg98

    So basically im creating a mini game for someone and i needed some help. So I have 2 questions.
    How to add an item to someones inventory?
    And when they place this block, i need a glass block to appear on top of it.
    HELP?
     
  2. Offline

    pie_flavor

    @Hectorg98
    I am not sure what you know or don't know, so I'm going to list everything I can think of. If you don't know how to do something, say so. Don't be offended if this seems obvious, as you did not state your skill level.

    So the class that represents an item is ItemStack. It has all sorts of useful methods to mess with it. To make one, use new ItemStack(Material). You can also do new ItemStack(Material, int) where the int is the item count. Most of the information like name, lore, etc is in the ItemMeta, which is gotten by doing getItemMeta() on an ItemStack. After setting the values, take the item and do setItemMeta(ItemMeta), and give it the modified meta. If it is an item with a 'data value', such as wool, ink sack, stone, etc then use setDurability(short).

    To add the item to the player's inventory, use getInventory() on the player object, then use addItem(ItemStack). If you want to put it in a specific place, you should instead use setItem(int, ItemStack). Here are the inventory slot indexes.
     
Thread Status:
Not open for further replies.

Share This Page