[Tutorial] Setting max item stacks

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

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


    First you want to get..
    Added to you're Java Build Path
    These are the imports you want to make sure you have
    1. import net.minecraft.server.v1_7_R1.Item;
    2. import java.lang.reflect.Field;

    Then we want to make a method..
    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!
    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


    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


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


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


Thread Status:
Not open for further replies.

Share This Page