Getting dispenser items.

Discussion in 'Plugin Development' started by CevinWa, Nov 5, 2012.

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


    Hello i have some problem with getting the items contained in an dispenser from the location.

    Like this i have a block that's one block above the dispenser and when the player walks over that block this will search if the dispenser has a certain item in it and do a certain thing. (Only need help with getting the data from the dispenser not the playermove event. ) I thought you maybe could do as you do with a sign when you just get the lines thrue casting but im not sure. Every of my attempts has returned nagative.
  2. Offline

    Ewe Loon

    first get the block that should be the dispenser,
    check the type to make sure irt is a dispenser
    typecase block.getState to dispenser
    then call its getInventory method

    should look something like this , note it typed it in here, could have some spelling errors

    Block blockbelow=block.getRelative(0,-1,0)
    if (blockbelow.getType()=Material.dispenser){
      Dispenser disp=(Dispenser) blockbelow.getState();
      Inventory inv=disp.getInventory()
  3. Offline


    Didn't work. And i've already tried that.

    Weird got it to work now :D Thanks

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 29, 2016
  4. Offline

    Ewe Loon

    the most common mistake is trying to typecast the block not the blockstate, which you might have done before
    but glad its working
Thread Status:
Not open for further replies.

Share This Page