[Tutorial] Setting max item stacks

Discussion in 'Resources' started by CookieGamer100, Jan 2, 2014.

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

    CookieGamer100

    First you want to get..
    http://dl.bukkit.org/downloads/craftbukkit/
    http://dl.bukkit.org/downloads/bukkit/
    Added to you're Java Build Path
    These are the imports you want to make sure you have
    Code:java
    1. import net.minecraft.server.v1_7_R1.Item;
    2. import java.lang.reflect.Field;


    Then we want to make a method..
    Code:java
    1.  
    2. public void modifyMaxStack(Item item, int amount) {
    3. try {
    4. Field f = Item.class.getDeclaredField("maxStackSize");
    5. f.setAccessible(true);
    6. f.setInt(item, amount);
    7. } catch (Exception e) {
    8. e.printStackTrace();
    9. return;
    10. }
    11. }


    Then in your onEnable you want to add the main part!
    Code:java
    1. public void onEnable() {
    2. modifyMaxStack(Item.d(1), 2);
    3. //1 is the ID of Stone
    4. //2 is the max items it can stack
    5. }


    If it's not working make sure you have Bukkit and CraftBukkit in you're Build Path and the right imports! If you want any better ways of doing this comment them and I will add it! :)
     
  2. Offline

    thepaperboy99

    Pretty cool, I might use this in one of my plugins. Thanks :)
     
    CookieGamer100 likes this.
  3. CookieGamer100
    Hasn't this been done like a hundred times already? Also, your code looks oddly identical to what I showed here and here.
     
  4. Offline

    BungeeTheCookie

    No, more like 257 times already :p.
     
  5. Offline

    ccrama

    Also, what is this Item.d(1) ? I've never seen items done like that before... What does d stand for?
     
  6. Offline

    Garris0n

Thread Status:
Not open for further replies.

Share This Page