Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SuppressWarnings("rawtypes")
- public static EntityMetadata readMetadata(byte[] payload) {
- BinaryStream stream = new BinaryStream();
- stream.setBuffer(payload);
- long count = stream.getUnsignedVarInt();
- EntityMetadata m = new EntityMetadata();
- for (int i = 0; i < count; i++) {
- int key = (int) stream.getUnsignedVarInt();
- int type = (int) stream.getUnsignedVarInt();
- EntityData value = null;
- switch (type) {
- case Entity.DATA_TYPE_BYTE:
- value = new ByteEntityData(key, stream.getByte());
- break;
- case Entity.DATA_TYPE_SHORT:
- value = new ShortEntityData(key, stream.getLShort());
- break;
- case Entity.DATA_TYPE_INT:
- value = new IntEntityData(key, stream.getVarInt());
- break;
- case Entity.DATA_TYPE_FLOAT:
- value = new FloatEntityData(key, stream.getLFloat());
- break;
- case Entity.DATA_TYPE_STRING:
- value = new StringEntityData(key, stream.getString());
- break;
- case Entity.DATA_TYPE_SLOT:
- Item item = stream.getSlot();
- value = new SlotEntityData(key, item.getId(), item.getDamage(), item.getCount());
- break;
- case Entity.DATA_TYPE_POS:
- BlockVector3 v3 = stream.getBlockCoords();
- value = new IntPositionEntityData(key, v3.x, v3.y, v3.z);
- break;
- case Entity.DATA_TYPE_LONG:
- value = new LongEntityData(key, stream.getVarLong());
- break;
- case Entity.DATA_TYPE_VECTOR3F:
- value = new Vector3fEntityData(key, stream.getVector3f());
- break;
- }
- if (value != null) m.put(value);
- }
- return m;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement