Is it posible to raise stack limit for specific item?

Discussion in 'Plugin Development' started by Quaro, Apr 26, 2013.

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

    Quaro

    Is it posible to rise stack limit for specific item? How?

    UP?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. Offline

    Rprrr

    Micius
    Yes, it is.

    Code:
        final Item item = Item.byId[typeid];
     
        @SuppressWarnings("rawtypes")
        Class class = item.getClass();
     
        try {
            Field maxStack = getField(class, "maxStackSize");
            maxStack.setAccessible(true);
            maxStack.setInt(item, max);
        } catch (NoSuchFieldException exc1) {
            exc1.printStackTrace();
        } catch (IllegalAccessException exc2) {
            exc1.printStackTrace();
        }
     
  3. Offline

    Quaro

    And how can i set number of max stack?
     
  4. Offline

    Cybermaxke

    Add this method in your class:
    Code:
    import java.lang.reflect.Field;
    import net.minecraft.server.v1_5_R2.Item;
    import org.bukkit.Material;
    
    public void setMaxStackSize(Material material, int size) {
        Item item = Item.byId[material.getId()];
        try {
            Field f = Item.class.getDeclaredField("maxStackSize");
            f.setAccessible(true);
            f.setInt(item, size);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
     
  5. He explained it to you... maxStack.setInt(item, max); where max is your limit.
     
  6. Offline

    Cybermaxke

  7. Offline

    Quaro

    Cybermaxke Add imports, because getting errors.
     
  8. Offline

    Cybermaxke

  9. Offline

    Quaro

    Cybermaxke what event i should choose, to make default max stack of specific item, more than 64?
     
  10. Offline

    Cybermaxke

    Micius
    Just change it in your onEnable.
     
  11. Offline

    Quaro

    Cybermaxke Doesn't working
    MyClass.setMaxStackSize(Material.EMERALD, 999999);
    still can't stack it to more than 64
    ----------EDITED-------
    Tested it more, it can be stacked only using shift (still not in same time). But you can't stack it with mouse like normally.
    ----------Edited---------
    Max stackable number can be 127, other way it will not show number
     
  12. Offline

    Cybermaxke

    You shouldhave to use InventoryClickEvents to stack them.
     
Thread Status:
Not open for further replies.

Share This Page