[SOLVED] How do I get a meet in the players inventory and change it to dirt?

Discussion in 'Plugin Development' started by Luloak2, Jun 20, 2012.

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

    Luloak2

    The title says everything;)
     
  2. Offline

    Elvennomad

    You need to get the players inventory.
    Then check for the meat.
    Then in the instance of meat being found you replace it with dirt.
    You can do this by removing the meat and replacing it with a dirt block.
    I can probably help with the coding but I think it's better if you give it a shot and I help from there.
    It's how I am learning to be honest :)
     
    Luloak2 likes this.
  3. Offline

    Luloak2

    Thanks, I have already a pice of code, but it is throwing errors...
    The code is on another pc, I cannot get it right now...
    Maybe you could make the piece of code for me, it would help me. The way in general I know already;)
     
  4. Offline

    dxwarlock

    Code:java
    1.  
    2. Player p = event.getPlayer();
    3. PlayerInventory playerinvent2 = p.getInventory();
    4. ItemStack beef = new ItemStack(Material.COOKED_BEEF, 1);
    5. ItemStack dirt = new ItemStack(Material.DIRT, 1);
    6. playerinvent2.removeItem(beef);
    7. playerinvent2.addItem(dirt)
    8.  

    the basics of how to get it, remove it, and give them dirt.
    will need to put it in a loop i think, until it doesn't find anymore beef. because they might have one stack of 2 and one stack of 10..so couldn't just look for the first stack and replace it all at once by its count.

    now how to put it in the same SLOT, is beyond what I can do :)

    Im assuming it would use a 'while' statement...
    Like 'while beef exists, remove beef and count the beef" then a:
    int countofbeef=(<whatever you called it to count the beef>);
    ItemStack dirt = new ItemStack(Material.DIRT, countofbeef);
    playerinvent2.addItem(dirt)
     
    Luloak2 likes this.
  5. Offline

    Luloak2

    Thank you so much, it works great. Thx, I didn't thought about the "while" statement...
     
  6. Offline

    dxwarlock

    No problem, still learning bukkit coding myself, so I know when your 99% there and that last bit is kicking your butt, its frustrating as all hell! so try to help where I can..even if i don't know the exact code to do it :)
     
Thread Status:
Not open for further replies.

Share This Page