Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static short[] getBlockArray(/*unsigned*/ long[] blockStates)
- {
- short[] retVal = new short[4096];
- //The size in bits of every block ID in the blockStates Array. Theoretical maximum is 13.
- final byte bitPerIndex = (byte) (blockStates.length * 64 / 4096);
- int curRefIndex = 0;
- for (int i = 0; i < blockStates.length; ++i)
- {
- /*unsigend*/ long cur = blockStates[i];
- //If the beginning of cur has bits from last iteration, add it to already read bits from last filled index
- int overhang = (bitPerIndex - (i * Long.SIZE /*64*/) % bitPerIndex) % bitPerIndex;
- if(overhang > 0)
- {
- retVal[curRefIndex - 1] |= Long.remainderUnsigned(cur, (1 << (overhang - 1)));
- System.out.print("(" + retVal[curRefIndex - 1] + "), ");
- }
- cur >>>= overhang;
- //Read all reamaining bits, that is ("size of Long" - "already read bits due to overhang") / bitPerIndex ceiled.
- final int remainingBitsToBeRead = Long.SIZE - overhang;
- for(int j = 0; j < (remainingBitsToBeRead + (bitPerIndex - remainingBitsToBeRead % bitPerIndex) % bitPerIndex) / bitPerIndex; ++j)
- {
- retVal[curRefIndex++] = (short) (Long.remainderUnsigned(cur, (1 << (bitPerIndex - 1))));
- cur >>>= bitPerIndex;
- }
- }
- return retVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement