private static <T> void writeEntry(PacketBuffer buf, EntityDataManager.DataEntry<T> entry)
      throws IOException {
    DataParameter<T> dataparameter = entry.getKey();
    int i = DataSerializers.getSerializerId(dataparameter.getSerializer());

    if (i < 0) {
      throw new EncoderException("Unknown serializer type " + dataparameter.getSerializer());
    } else {
      buf.writeByte(dataparameter.getId());
      buf.writeVarIntToBuffer(i);
      dataparameter.getSerializer().write(buf, entry.getValue());
    }
  }
  public <T> void register(DataParameter<T> key, T value) {
    int i = key.getId();

    if (i > 254) {
      throw new IllegalArgumentException(
          "Data value id is too big with " + i + "! (Max is " + 254 + ")");
    } else if (this.entries.containsKey(Integer.valueOf(i))) {
      throw new IllegalArgumentException("Duplicate id value for " + i + "!");
    } else if (DataSerializers.getSerializerId(key.getSerializer()) < 0) {
      throw new IllegalArgumentException(
          "Unregistered serializer " + key.getSerializer() + " for " + i + "!");
    } else {
      this.setEntry(key, value);
    }
  }
 private <T> void setEntry(DataParameter<T> key, T value) {
   EntityDataManager.DataEntry<T> dataentry = new EntityDataManager.DataEntry(key, value);
   this.lock.writeLock().lock();
   this.entries.put(Integer.valueOf(key.getId()), dataentry);
   this.empty = false;
   this.lock.writeLock().unlock();
 }
  private <T> EntityDataManager.DataEntry<T> getEntry(DataParameter<T> key) {
    this.lock.readLock().lock();
    EntityDataManager.DataEntry<T> dataentry;

    try {
      dataentry = (EntityDataManager.DataEntry) this.entries.get(Integer.valueOf(key.getId()));
    } catch (Throwable throwable) {
      CrashReport crashreport =
          CrashReport.makeCrashReport(throwable, "Getting synched entity data");
      CrashReportCategory crashreportcategory = crashreport.makeCategory("Synched entity data");
      crashreportcategory.addCrashSection("Data ID", key);
      throw new ReportedException(crashreport);
    }

    this.lock.readLock().unlock();
    return dataentry;
  }