org.legendofdragoon.modloader.registries.RegistryDelegate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mod-loader Show documentation
Show all versions of mod-loader Show documentation
The mod loader used by various Severed Chains projects
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