All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.legendofdragoon.modloader.registries.RegistryDelegate Maven / Gradle / Ivy

There is a newer version: 3.0.4
Show newest version
package org.legendofdragoon.modloader.registries;

import org.legendofdragoon.modloader.Latch;
import org.legendofdragoon.modloader.ModNotLoadedException;

import java.util.function.Supplier;

public class RegistryDelegate {
  private final RegistryId id;
  private final Registry registry;
  private final Class> cls;
  private final Latch latch;

  RegistryDelegate(final RegistryId id, final Registry registry, final Class> cls, final Supplier supplier) {
    this.id = id;
    this.registry = registry;
    this.cls = cls;
    this.latch = new Latch<>(supplier);
  }

  public boolean isValid() {
    return this.registry.hasEntry(this.id);
  }

  public void clear() {
    this.latch.clear();
  }

  public Type get() {
    if(!this.isValid()) {
      throw new ModNotLoadedException("Mod " + this.id.modId() + " is not loaded");
    }

    return this.latch.get();
  }

  @Override
  public boolean equals(final Object obj) {
    if(obj instanceof final RegistryDelegate other) {
      return this.cls.equals(other.cls) && this.id.equals(other.id);
    }

    return false;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy