[HELP] When a dispenser dispenses fireworks, set that stack amount to 64?

Discussion in 'Plugin Development' started by NerdsWBNerds, Dec 31, 2012.

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

    NerdsWBNerds

    How can I, when I dispenser shoots a firework, set the stack that it took the firework from back to 64?
     
  2. Offline

    fireblast709

    • listen to the BlockDispenseEvent
    • get the block
    • get the state and check if it is an instanceof Dispenser
    • cast the state to Dispenser
    • get the Inventory
    • do whatever to it (in your case, get the stack and set the amount to 64)
    • invoke .update() in the state (you casted it somewhere, invoke .update() with that instance)
     
  3. Offline

    gamerzap

    Use this in your listener class:
    Code:java
    1.  
    2. @EventHandler
    3. public void onBlockDispense(BlockDispenseEvent evt){
    4. ItemStack item = evt.getItem();
    5. if(item.getId()==401){
    6. Block block = evt.getBlock();
    7. if(block.getState() instanceof Dispenser){
    8. Dispenser dis = (Dispenser) block.getState();
    9. dis.getInventory().addItem(new ItemStack[]{item});
    10. dis.update();
    11. }
    12. }
    13. }
    14.  

    That should work, but It might not as I haven't tested it yet and wrote it in notepad :/

    Oh yeah, forgot to invoke .update()...

    EDIT: Fixed it in the original post

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

    NerdsWBNerds

    Doesn't seem to work but I don't have any errors, it's like the DispenseEvent isn't even being called.

    EDIT: I was using an older Craftbukkit, updating now should fix the issue I was having, thanks.
     
  5. Offline

    Muddr

    one trick you can do.. which I use for unlimited potions it to set the itemstack amount to -1. it won't use the item but still dispense it.
    Code:
    Dispenser disp = (Dispenser) block.getState();
    Inventory inv = disp.getInventory();
     
    for (ItemStack item : inv) {
        if (item != null) {
            item.setAmount(-1);
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page