Java Integer to intToMCInts(int i)

Here you can find the source of intToMCInts(int i)

Description

Spilts a Java int into a so-called Minecraft int - iCrafting.sendProgressBarUpdate truncates to short.

License

Creative Commons License

Parameter

Parameter Description
i Integer to convert to two MC integers

Return

Array of two minecraft integers, 0th int holding first 16 bits

Declaration

public static int[] intToMCInts(int i) 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

public class Main {
    /**/*  w  w w  . ja v  a  2  s  .  c o  m*/
     * Spilts a Java int into a so-called Minecraft int - iCrafting.sendProgressBarUpdate truncates
     * to short. You end up being able to send 16 bits instead of full 32.
     *
     * @param i Integer to convert to two MC integers
     * @return Array of two minecraft integers, 0th int holding first 16 bits
     */
    public static int[] intToMCInts(int i) {
        byte[] bytes = intToBytes(i);

        int[] mcInts = new int[] { (int) (bytes[0] << 8 | (bytes[1] & 0xFF)),
                (int) (bytes[2] << 8 | (bytes[3] & 0xFF)) };

        return mcInts;
    }

    /**
     * Spilts an int into 4 bytes
     * @param i Integer to split
     * @return 4-byte array, 0th byte being the first byte in an integer
     */
    private static byte[] intToBytes(int i) {
        return new byte[] { (byte) (i >> 24), (byte) (i >> 16), (byte) (i >> 8), (byte) i };
    }
}

Related

  1. intToLengthHexByte(int args, int hexLength)
  2. intToLetter(int index)
  3. intToLex(int v)
  4. intToLittleEndian(int val)
  5. intToLittleEndian(int value)
  6. intToMmss(int ns)
  7. intToNetworkByteOrder(int num, byte[] buf, int start, int count)
  8. intToNetworkByteOrder(int num, int count)
  9. intToNumericFormat(int src)