Vswe's Summer Courses | You're not logged in. Sign up or log in | Server time: | Donate
One can now see other persons' badge hunts. Simply head over to their profiles to access them.

Go back to course page

Bits and pieces

Bit operators and their use in modding

Changing Stacksize in creative

  • 2013-09-02 23:14:35
    Hi,
    i have been working on this assignment, and it works fine in survival mode, but in creative mode, when I try to change the stackSize, because i don't want to charge a whole stack of the Bags, it stays at the old amount.
    I change the stacksize in the method OnItemRightClick.

    I can't really post my code here, because it is assignment related, but basically what doesn't work is this:

    public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
    if (itemStack.stackSize > 1) {
    itemStack.stackSize = 1;

    //creating new Stack here

    }
    return itemStack;
    }
  • 2013-09-03 00:52:42
    why are you changing the stack size?, you are meant to be changing the damage value
  • 2013-09-03 01:16:03
    Yeah of course. I have got that working.
    The problem is that when I have a Stack of these Bags that is bigger than one, i don't want to change the damage value of all of them. Because then you could easily cheat in XP.
    Thats why I create a new Stack which is one smaller. And changing the size of the original to 1, and of course changing the Experience stored. The only problem is that in creative the stacksize stays the same.
  • 2013-09-03 05:40:22
    Why don't you just use setMaxStackSize(1)? Usually items like this don't stack anyway.
  • 2013-09-03 13:13:31
    That would work.
    But I now check if the player is in creative, and then the item doesn't do anything. Which makes sense, considering that in creative the player doesn't have an experience bar, or level. At least it's not shown.

    Thanks though.
  • 2013-09-04 07:55:43
    to check if in creative mode
    player.capabilities.isCreativeMode()
    returns a boolean, if player is of type EntityPlayer
    hope this helps
  • Log in or sign up to reply to this thread