Package net.minecraftforge.fml
Class RegistryObject<T extends IForgeRegistryEntry<? super T>>
- java.lang.Object
-
- net.minecraftforge.fml.RegistryObject<T>
-
- All Implemented Interfaces:
java.util.function.Supplier<T>
public final class RegistryObject<T extends IForgeRegistryEntry<? super T>> extends java.lang.Object implements java.util.function.Supplier<T>
-
-
Field Summary
Fields Modifier and Type Field Description private static RegistryObject<?>
EMPTY
private ResourceLocation
name
private T
value
-
Constructor Summary
Constructors Modifier Constructor Description private
RegistryObject()
private
RegistryObject(ResourceLocation name, java.lang.Class<V> baseType, java.lang.String modid)
private
RegistryObject(ResourceLocation name, java.util.function.Supplier<java.lang.Class<? super V>> registryType)
private
RegistryObject(ResourceLocation name, IForgeRegistry<V> registry)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static <T extends IForgeRegistryEntry<? super T>>
RegistryObject<T>empty()
boolean
equals(java.lang.Object obj)
RegistryObject<T>
filter(java.util.function.Predicate<? super T> predicate)
If a mod object is present, and the mod object matches the given predicate, return anRegistryObject
describing the value, otherwise return an emptyRegistryObject
.<U> java.util.Optional<U>
flatMap(java.util.function.Function<? super T,java.util.Optional<U>> mapper)
If a value is present, apply the providedOptional
-bearing mapping function to it, return that result, otherwise return an emptyOptional
.T
get()
Directly retrieves the wrapped Registry Object.ResourceLocation
getId()
int
hashCode()
void
ifPresent(java.util.function.Consumer<? super T> consumer)
If a mod object is present, invoke the specified consumer with the object, otherwise do nothing.boolean
isPresent()
Returntrue
if there is a mod object present, otherwisefalse
.<U> java.util.function.Supplier<U>
lazyMap(java.util.function.Function<? super T,? extends U> mapper)
If a mod object is present, lazily apply the provided mapping function to it, returning a supplier for the transformed result.<U> java.util.Optional<U>
map(java.util.function.Function<? super T,? extends U> mapper)
If a mod object is present, apply the provided mapping function to it, and if the result is non-null, return anOptional
describing the result.static <T extends IForgeRegistryEntry<T>,U extends T>
RegistryObject<U>of(ResourceLocation name, java.lang.Class<T> baseType, java.lang.String modid)
static <T extends IForgeRegistryEntry<T>,U extends T>
RegistryObject<U>of(ResourceLocation name, java.util.function.Supplier<java.lang.Class<? super T>> registryType)
static <T extends IForgeRegistryEntry<T>,U extends T>
RegistryObject<U>of(ResourceLocation name, IForgeRegistry<T> registry)
T
orElse(T other)
Return the mod object if present, otherwise returnother
.T
orElseGet(java.util.function.Supplier<? extends T> other)
Return the mod object if present, otherwise invokeother
and return the result of that invocation.<X extends java.lang.Throwable>
TorElseThrow(java.util.function.Supplier<? extends X> exceptionSupplier)
Return the contained mod object, if present, otherwise throw an exception to be created by the provided supplier.java.util.stream.Stream<T>
stream()
void
updateReference(IForgeRegistry<? extends T> registry)
-
-
-
Field Detail
-
name
private final ResourceLocation name
-
value
@Nullable private T extends IForgeRegistryEntry<? super T> value
-
EMPTY
private static RegistryObject<?> EMPTY
-
-
Constructor Detail
-
RegistryObject
private RegistryObject()
-
RegistryObject
private RegistryObject(ResourceLocation name, java.util.function.Supplier<java.lang.Class<? super V>> registryType)
-
RegistryObject
private RegistryObject(ResourceLocation name, IForgeRegistry<V> registry)
-
RegistryObject
private RegistryObject(ResourceLocation name, java.lang.Class<V> baseType, java.lang.String modid)
-
-
Method Detail
-
of
public static <T extends IForgeRegistryEntry<T>,U extends T> RegistryObject<U> of(ResourceLocation name, java.util.function.Supplier<java.lang.Class<? super T>> registryType)
-
of
public static <T extends IForgeRegistryEntry<T>,U extends T> RegistryObject<U> of(ResourceLocation name, IForgeRegistry<T> registry)
-
of
public static <T extends IForgeRegistryEntry<T>,U extends T> RegistryObject<U> of(ResourceLocation name, java.lang.Class<T> baseType, java.lang.String modid)
-
empty
private static <T extends IForgeRegistryEntry<? super T>> RegistryObject<T> empty()
-
get
@Nonnull public T get()
Directly retrieves the wrapped Registry Object. This value will automatically be updated when the backing registry is updated. Will throw NPE if the value is null, use isPresent to check first. Or use any of the other guarded functions.- Specified by:
get
in interfacejava.util.function.Supplier<T extends IForgeRegistryEntry<? super T>>
-
updateReference
public void updateReference(IForgeRegistry<? extends T> registry)
-
getId
public ResourceLocation getId()
-
stream
public java.util.stream.Stream<T> stream()
-
isPresent
public boolean isPresent()
Returntrue
if there is a mod object present, otherwisefalse
.- Returns:
true
if there is a mod object present, otherwisefalse
-
ifPresent
public void ifPresent(java.util.function.Consumer<? super T> consumer)
If a mod object is present, invoke the specified consumer with the object, otherwise do nothing.- Parameters:
consumer
- block to be executed if a mod object is present- Throws:
java.lang.NullPointerException
- if mod object is present andconsumer
is null
-
filter
public RegistryObject<T> filter(java.util.function.Predicate<? super T> predicate)
If a mod object is present, and the mod object matches the given predicate, return anRegistryObject
describing the value, otherwise return an emptyRegistryObject
.- Parameters:
predicate
- a predicate to apply to the mod object, if present- Returns:
- an
RegistryObject
describing the value of thisRegistryObject
if a mod object is present and the mod object matches the given predicate, otherwise an emptyRegistryObject
- Throws:
java.lang.NullPointerException
- if the predicate is null
-
map
public <U> java.util.Optional<U> map(java.util.function.Function<? super T,? extends U> mapper)
If a mod object is present, apply the provided mapping function to it, and if the result is non-null, return anOptional
describing the result. Otherwise return an emptyOptional
.- Type Parameters:
U
- The type of the result of the mapping function- Parameters:
mapper
- a mapping function to apply to the mod object, if present- Returns:
- an
Optional
describing the result of applying a mapping function to the mod object of thisRegistryObject
, if a mod object is present, otherwise an emptyOptional
- Throws:
java.lang.NullPointerException
- if the mapping function is null
-
flatMap
public <U> java.util.Optional<U> flatMap(java.util.function.Function<? super T,java.util.Optional<U>> mapper)
If a value is present, apply the providedOptional
-bearing mapping function to it, return that result, otherwise return an emptyOptional
. This method is similar tomap(Function)
, but the provided mapper is one whose result is already anOptional
, and if invoked,flatMap
does not wrap it with an additionalOptional
.- Type Parameters:
U
- The type parameter to theOptional
returned by- Parameters:
mapper
- a mapping function to apply to the mod object, if present the mapping function- Returns:
- the result of applying an
Optional
-bearing mapping function to the value of thisOptional
, if a value is present, otherwise an emptyOptional
- Throws:
java.lang.NullPointerException
- if the mapping function is null or returns a null result
-
lazyMap
public <U> java.util.function.Supplier<U> lazyMap(java.util.function.Function<? super T,? extends U> mapper)
If a mod object is present, lazily apply the provided mapping function to it, returning a supplier for the transformed result. If this object is empty, or the mapping function returnsnull
, the supplier will returnnull
.- Type Parameters:
U
- The type of the result of the mapping function- Parameters:
mapper
- A mapping function to apply to the mod object, if present- Returns:
- A
Supplier
lazily providing the result of applying a mapping function to the mod object of thisRegistryObject
, if a mod object is present, otherwise a supplier returningnull
- Throws:
java.lang.NullPointerException
- if the mapping function isnull
-
orElse
public T orElse(T other)
Return the mod object if present, otherwise returnother
.- Parameters:
other
- the mod object to be returned if there is no mod object present, may be null- Returns:
- the mod object, if present, otherwise
other
-
orElseGet
public T orElseGet(java.util.function.Supplier<? extends T> other)
Return the mod object if present, otherwise invokeother
and return the result of that invocation.- Parameters:
other
- aSupplier
whose result is returned if no mod object is present- Returns:
- the mod object if present otherwise the result of
other.get()
- Throws:
java.lang.NullPointerException
- if mod object is not present andother
is null
-
orElseThrow
public <X extends java.lang.Throwable> T orElseThrow(java.util.function.Supplier<? extends X> exceptionSupplier) throws X extends java.lang.Throwable
Return the contained mod object, if present, otherwise throw an exception to be created by the provided supplier.- Type Parameters:
X
- Type of the exception to be thrown- Parameters:
exceptionSupplier
- The supplier which will return the exception to be thrown- Returns:
- the present mod object
- Throws:
X
- if there is no mod object presentjava.lang.NullPointerException
- if no mod object is present andexceptionSupplier
is nullX extends java.lang.Throwable
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-