Advertisement
Guest User

Minecraft get ID values from blockStates-Array

a guest
Jan 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public static short[] getBlockArray(/*unsigned*/ long[] blockStates)
  2. {
  3. short[] retVal = new short[4096];
  4. //The size in bits of every block ID in the blockStates Array. Theoretical maximum is 13.
  5. final byte bitPerIndex = (byte) (blockStates.length * 64 / 4096);
  6. int curRefIndex = 0;
  7.  
  8. for (int i = 0; i < blockStates.length; ++i)
  9. {
  10. /*unsigend*/ long cur = blockStates[i];
  11.  
  12. //If the beginning of cur has bits from last iteration, add it to already read bits from last filled index
  13. int overhang = (bitPerIndex - (i * Long.SIZE /*64*/) % bitPerIndex) % bitPerIndex;
  14. if(overhang > 0)
  15. {
  16. retVal[curRefIndex - 1] |= Long.remainderUnsigned(cur, (1 << (overhang - 1)));
  17. System.out.print("(" + retVal[curRefIndex - 1] + "), ");
  18. }
  19. cur >>>= overhang;
  20.  
  21. //Read all reamaining bits, that is ("size of Long" - "already read bits due to overhang") / bitPerIndex ceiled.
  22. final int remainingBitsToBeRead = Long.SIZE - overhang;
  23. for(int j = 0; j < (remainingBitsToBeRead + (bitPerIndex - remainingBitsToBeRead % bitPerIndex) % bitPerIndex) / bitPerIndex; ++j)
  24. {
  25. retVal[curRefIndex++] = (short) (Long.remainderUnsigned(cur, (1 << (bitPerIndex - 1))));
  26. cur >>>= bitPerIndex;
  27. }
  28. }
  29.  
  30. return retVal;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement