Chest Interactions

Discussion in 'Plugin Development' started by ChironXII, Oct 20, 2011.

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

    ChironXII

    I have been looking for this for a while, and I can't find anything on how to do it. Basically, I want to be able to get the inventory of a chest (I have this part working) and then check if that chest contains a certain item. For example, a player right clicks a sign, and on the third line of the sign it says "cobblestone". I have the plugin getting all of the information, but I have no idea how to do anything with it. I want to check if the chest contains the item, and if so how much of it, and then be able to remove it and place it as needed. I also need to know how to do the same with a player's inventory, but I assume it is the same using a player instead of a chest. Also, how can I get an item type from text? e.g "cobblestone" would get the item type and then check the chest for it. So far I am just printing all of this info to my in game chat for checking that it is working. I have the events set up and all of that, the sign click checks if there is a chest under it, and gets the third line of the sign text for material. Any help would be much appreciated!
     
  2. Offline

    nickrak

    you can use this for to get the material:
    Code:java
    1. Material.getMaterial(String_materialName)

    or this if you want the type id:
    Code:java
    1. Material.getMaterial(String_materialName).getId()


    for getting the contents of the chest
    Code:java
    1. ItemStack[] items = Chest_chestBlockobj.getInventory().getContents()
     
  3. Offline

    ChironXII

    So, if I had item = Material.getMaterial(signLine[2]) it would give me the correct data type to interact with? (so I could then put items[1] = item ?) Also what do you use for non full stacks, like moving 32 of an item?
     
  4. Offline

    nickrak

  5. Offline

    ChironXII

    Ok got it working thanks a bunch!
     
Thread Status:
Not open for further replies.

Share This Page