Advertisement
DaPorkchop

Untitled

Feb 2nd, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. @SuppressWarnings("rawtypes")
  2. public static EntityMetadata readMetadata(byte[] payload) {
  3. BinaryStream stream = new BinaryStream();
  4. stream.setBuffer(payload);
  5. long count = stream.getUnsignedVarInt();
  6. EntityMetadata m = new EntityMetadata();
  7. for (int i = 0; i < count; i++) {
  8. int key = (int) stream.getUnsignedVarInt();
  9. int type = (int) stream.getUnsignedVarInt();
  10. EntityData value = null;
  11. switch (type) {
  12. case Entity.DATA_TYPE_BYTE:
  13. value = new ByteEntityData(key, stream.getByte());
  14. break;
  15. case Entity.DATA_TYPE_SHORT:
  16. value = new ShortEntityData(key, stream.getLShort());
  17. break;
  18. case Entity.DATA_TYPE_INT:
  19. value = new IntEntityData(key, stream.getVarInt());
  20. break;
  21. case Entity.DATA_TYPE_FLOAT:
  22. value = new FloatEntityData(key, stream.getLFloat());
  23. break;
  24. case Entity.DATA_TYPE_STRING:
  25. value = new StringEntityData(key, stream.getString());
  26. break;
  27. case Entity.DATA_TYPE_SLOT:
  28. Item item = stream.getSlot();
  29. value = new SlotEntityData(key, item.getId(), item.getDamage(), item.getCount());
  30. break;
  31. case Entity.DATA_TYPE_POS:
  32. BlockVector3 v3 = stream.getBlockCoords();
  33. value = new IntPositionEntityData(key, v3.x, v3.y, v3.z);
  34. break;
  35. case Entity.DATA_TYPE_LONG:
  36. value = new LongEntityData(key, stream.getVarLong());
  37. break;
  38. case Entity.DATA_TYPE_VECTOR3F:
  39. value = new Vector3fEntityData(key, stream.getVector3f());
  40. break;
  41. }
  42. if (value != null) m.put(value);
  43. }
  44. return m;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement