Inventories?

Discussion in 'Plugin Development' started by Jayjay110, May 20, 2011.

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

    Jayjay110

    how would I replace items in an inventory with another item?

    say I wanted to replace all fire blocks with water blocks etc.

    On and whhats with the inventory events? non are supported?
     
  2. Offline

    Jayjay110

  3. Offline

    DreadKyller

    this should work:
    PHP:
    public void replaceInv(Player playerMaterial mat1Material mat2){
        
    ItemStack[] items player.getInventory().getContents();
        
    ItemStack[] blank={};
        for(
    ItemStack stackitems){
            if(
    stack.getType()==mat1){
                
    stack.setType(mat2);
            }
            
    blank[blank.length]=stack;
        }
        
    player.getInventory().setContents(blank);
    }
     
    Jayjay110 likes this.
  4. Offline

    Scyfi

    While on the subject of inventories. How do I get the slot index of an item in hand?
     
  5. Offline

    DreadKyller

    @Scyfi : code below, one line.
    PHP:
    int slot player.getinventory().getHeldItemSlot();
     
    Jayjay110 likes this.
  6. Offline

    Scyfi

    Thank you I completely missed the method getHeldItemslot(), was looking through the javadoc. Thanx:)
     
  7. Offline

    Jayjay110

    Thankyou, this actually helps alot :)
     
Thread Status:
Not open for further replies.

Share This Page