Allow being more flexible in registering

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2021-05-12 15:05:04 +08:00
parent 2eef26f632
commit cfef5f28b7
4 changed files with 11 additions and 11 deletions

View File

@@ -34,7 +34,7 @@ public interface ClientLifecycleEvent {
*/
@Deprecated Event<ClientState> CLIENT_STARTED = EventFactory.createLoop();
/**
* Invoked when client is initialising, not available in forge.
* Invoked when client is stopping, not available in forge.
*/
@Deprecated Event<ClientState> CLIENT_STOPPING = EventFactory.createLoop();
/**

View File

@@ -35,11 +35,11 @@ public interface Registry<T> extends Iterable<T> {
RegistrySupplier<T> delegateSupplied(ResourceLocation id);
default Supplier<T> register(ResourceLocation id, Supplier<T> supplier) {
default <E extends T> Supplier<E> register(ResourceLocation id, Supplier<E> supplier) {
return registerSupplied(id, supplier);
}
RegistrySupplier<T> registerSupplied(ResourceLocation id, Supplier<T> supplier);
<E extends T> RegistrySupplier<E> registerSupplied(ResourceLocation id, Supplier<E> supplier);
@Nullable
ResourceLocation getId(T obj);

View File

@@ -155,9 +155,9 @@ public class RegistriesImpl {
}
@Override
public @NotNull RegistrySupplier<T> registerSupplied(ResourceLocation id, Supplier<T> supplier) {
public @NotNull <E extends T> RegistrySupplier<E> registerSupplied(ResourceLocation id, Supplier<E> supplier) {
net.minecraft.core.Registry.register(delegate, id, supplier.get());
return delegateSupplied(id);
return (RegistrySupplier<E>) delegateSupplied(id);
}
@Override

View File

@@ -200,9 +200,9 @@ public class RegistriesImpl {
}
@Override
public @NotNull RegistrySupplier<T> registerSupplied(ResourceLocation id, Supplier<T> supplier) {
public @NotNull <E extends T> RegistrySupplier<E> registerSupplied(ResourceLocation id, Supplier<E> supplier) {
net.minecraft.core.Registry.register(delegate, id, supplier.get());
return delegateSupplied(id);
return (RegistrySupplier<E>) delegateSupplied(id);
}
@Override
@@ -317,10 +317,10 @@ public class RegistriesImpl {
}
@Override
public @NotNull RegistrySupplier<T> registerSupplied(ResourceLocation id, Supplier<T> supplier) {
public @NotNull <E extends T> RegistrySupplier<E> registerSupplied(ResourceLocation id, Supplier<E> supplier) {
RegistryObject registryObject = RegistryObject.of(id, delegate);
registry.put(delegate.getRegistrySuperType(), registryObject, () -> supplier.get().setRegistryName(id));
return new RegistrySupplier<T>() {
return new RegistrySupplier<E>() {
@Override
public @NotNull ResourceLocation getRegistryId() {
return delegate.getRegistryName();
@@ -337,8 +337,8 @@ public class RegistriesImpl {
}
@Override
public T get() {
return (T) registryObject.get();
public E get() {
return (E) registryObject.get();
}
@Override