/** * Attempt to set the empowered state of the item. * * @param stack ItemStack to set the mode on. * @param mode Desired mode. * @return TRUE if the operation was successful, FALSE if it was not. */ default boolean setMode(ItemStack stack, int mode) { if (getNumModes(stack) <= 1) { return false; } if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } if (mode < getNumModes(stack)) { stack.getTagCompound().setInteger("Mode", mode); return true; } return false; }
/** * Decrement the current mode of an item. */ default boolean decrMode(ItemStack stack) { if (getNumModes(stack) <= 1) { return false; } if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } int curMode = getMode(stack); curMode--; if (curMode <= 0) { curMode = getNumModes(stack) - 1; } stack.getTagCompound().setInteger("Mode", curMode); return true; }
/** * Increment the current mode of an item. */ default boolean incrMode(ItemStack stack) { if (getNumModes(stack) <= 1) { return false; } if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } int curMode = getMode(stack); curMode++; if (curMode >= getNumModes(stack)) { curMode = 0; } stack.getTagCompound().setInteger("Mode", curMode); return true; }