示例#1
0
  public static EntityMetadata[] readEntityMetadata(NetInput in) throws IOException {
    List<EntityMetadata> ret = new ArrayList<EntityMetadata>();
    byte b;
    while ((b = in.readByte()) != 127) {
      int typeId = (b & 0xE0) >> 5;
      int id = b & 0x1F;
      MetadataType type = MagicValues.key(MetadataType.class, typeId);
      Object value;
      switch (type) {
        case BYTE:
          value = in.readByte();
          break;
        case SHORT:
          value = in.readShort();
          break;
        case INT:
          value = in.readInt();
          break;
        case FLOAT:
          value = in.readFloat();
          break;
        case STRING:
          value = in.readString();
          break;
        case ITEM:
          value = readItem(in);
          break;
        case POSITION:
          value = new Position(in.readInt(), in.readInt(), in.readInt());
          break;
        case ROTATION:
          value = new Rotation(in.readFloat(), in.readFloat(), in.readFloat());
          break;
        default:
          throw new IOException("Unknown metadata type id: " + typeId);
      }

      ret.add(new EntityMetadata(id, type, value));
    }

    return ret.toArray(new EntityMetadata[ret.size()]);
  }
 @Override
 public void read(NetInput in) throws IOException {
   this.entityId = in.readInt();
   this.attachedToId = in.readInt();
 }