类 RegistryObject<T>

java.lang.Object
net.minecraftforge.registries.RegistryObject<T>
所有已实现的接口:
Supplier<T>

public final class RegistryObject<T> extends Object implements Supplier<T>
  • 字段详细资料

    • name

      @Nullable private final @Nullable ResourceLocation name
    • key

      @Nullable private final @Nullable ResourceKey<T> key
    • optionalRegistry

      private final boolean optionalRegistry
    • value

      @Nullable private T value
    • holder

      @Nullable private @Nullable Supplier<Holder<T>> holder
    • EMPTY

      private static final RegistryObject<?> EMPTY
  • 构造器详细资料

  • 方法详细资料

    • create

      public static <T, U extends T> RegistryObject<U> create(ResourceLocation name, IForgeRegistry<T> registry)
      Factory for a RegistryObject that stores the value of an object from the provided forge registry once it is ready.
      参数:
      name - the name of the object to look up in the forge registry
      registry - the forge registry
      返回:
      a RegistryObject that stores the value of an object from the provided forge registry once it is ready
    • create

      public static <T, U extends T> RegistryObject<U> create(ResourceLocation name, ResourceKey<? extends Registry<T>> registryKey, String modid)
      Factory for a RegistryObject that stores the value of an object from a registry once it is ready based on a lookup of the provided registry key.

      If a registry with the given key cannot be found, an exception will be thrown when trying to fill this RegistryObject. Use createOptional(ResourceLocation, ResourceKey, String) for RegistryObjects of optional registries.

      参数:
      name - the name of the object to look up in a registry
      registryKey - the key of the registry. Supports lookups on BuiltInRegistries and RegistryManager.ACTIVE.
      modid - the mod id calling context
      返回:
      a RegistryObject that stores the value of an object from a registry once it is ready
      另请参阅:
    • createOptional

      public static <T, U extends T> RegistryObject<U> createOptional(ResourceLocation name, ResourceKey<? extends Registry<T>> registryKey, String modid)
      Factory for a RegistryObject that optionally stores the value of an object from a registry once it is ready if the registry exists based on a lookup of the provided registry key.

      If a registry with the given key cannot be found, it will be silently ignored and this RegistryObject will not be filled. Use create(ResourceLocation, ResourceKey, String) for RegistryObjects that should throw exceptions on missing registry.

      参数:
      name - the name of the object to look up in a registry
      registryKey - the key of the registry. Supports lookups on BuiltInRegistries and RegistryManager.ACTIVE.
      modid - the mod id calling context
      返回:
      a RegistryObject that stores the value of an object from a registry once it is ready
      另请参阅:
    • create

      public static <T, U extends T> RegistryObject<U> create(ResourceLocation name, ResourceLocation registryName, String modid)
      Factory for a RegistryObject that stores the value of an object from a registry once it is ready based on a lookup of the provided registry name.

      If a registry with the given name cannot be found, an exception will be thrown when trying to fill this RegistryObject. Use createOptional(ResourceLocation, ResourceLocation, String) for RegistryObjects of optional registries.

      参数:
      name - the name of the object to look up in a registry
      registryName - the name of the registry. Supports lookups on BuiltInRegistries and RegistryManager.ACTIVE.
      modid - the mod id calling context
      返回:
      a RegistryObject that stores the value of an object from a registry once it is ready
      另请参阅:
    • createOptional

      public static <T, U extends T> RegistryObject<U> createOptional(ResourceLocation name, ResourceLocation registryName, String modid)
      Factory for a RegistryObject that optionally stores the value of an object from a registry once it is ready if the registry exists based on a lookup of the provided registry name.

      If a registry with the given name cannot be found, it will be silently ignored and this RegistryObject will not be filled. Use create(ResourceLocation, ResourceLocation, String) for RegistryObjects that should throw exceptions on missing registry.

      参数:
      name - the name of the object to look up in a registry
      registryName - the name of the registry. Supports lookups on BuiltInRegistries and RegistryManager.ACTIVE.
      modid - the mod id calling context
      返回:
      a RegistryObject that stores the value of an object from a registry once it is ready
      另请参阅:
    • empty

      private static <T> RegistryObject<T> empty()
    • get

      @NotNull public T get()
      Retrieves the wrapped object in the registry. This value will automatically be updated when the backing registry is updated.
      指定者:
      get 在接口中 Supplier<T>
      抛出:
      NullPointerException - If the value is null. Use isPresent() to check if the value exists first.
      另请参阅:
    • updateReference

      void updateReference(IForgeRegistry<? extends T> registry)
    • updateReference

      void updateReference(Registry<? extends T> registry)
    • updateReference

      void updateReference(ResourceLocation registryName)
    • updateReference

      void updateReference(RegisterEvent event)
    • registryExists

      private static boolean registryExists(ResourceLocation registryName)
    • getId

      public ResourceLocation getId()
    • getKey

      @Nullable public @Nullable ResourceKey<T> getKey()
      Returns the resource key that points to the registry and name of this registry object. Nullable only if this RegistryObject is empty and has no name.
      返回:
      the resource key that points to the registry and name of this registry object
    • stream

      public Stream<T> stream()
    • isPresent

      public boolean isPresent()
      Return true if there is a mod object present, otherwise false.
      返回:
      true if there is a mod object present, otherwise false
    • ifPresent

      public void ifPresent(Consumer<? super T> consumer)
      If a mod object is present, invoke the specified consumer with the object, otherwise do nothing.
      参数:
      consumer - block to be executed if a mod object is present
      抛出:
      NullPointerException - if mod object is present and consumer is null
    • filter

      public RegistryObject<T> filter(Predicate<? super T> predicate)
      If a mod object is present, and the mod object matches the given predicate, return an RegistryObject describing the value, otherwise return an empty RegistryObject.
      参数:
      predicate - a predicate to apply to the mod object, if present
      返回:
      an RegistryObject describing the value of this RegistryObject if a mod object is present and the mod object matches the given predicate, otherwise an empty RegistryObject
      抛出:
      NullPointerException - if the predicate is null
    • map

      public <U> Optional<U> map(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 an Optional describing the result. Otherwise return an empty Optional.
      类型参数:
      U - The type of the result of the mapping function
      参数:
      mapper - a mapping function to apply to the mod object, if present
      返回:
      an Optional describing the result of applying a mapping function to the mod object of this RegistryObject, if a mod object is present, otherwise an empty Optional
      抛出:
      NullPointerException - if the mapping function is null
      API Note:
      This method supports post-processing on optional values, without the need to explicitly check for a return status.
    • flatMap

      public <U> Optional<U> flatMap(Function<? super T,Optional<U>> mapper)
      If a value is present, apply the provided Optional-bearing mapping function to it, return that result, otherwise return an empty Optional. This method is similar to map(Function), but the provided mapper is one whose result is already an Optional, and if invoked, flatMap does not wrap it with an additional Optional.
      类型参数:
      U - The type parameter to the Optional returned by
      参数:
      mapper - a mapping function to apply to the mod object, if present the mapping function
      返回:
      the result of applying an Optional-bearing mapping function to the value of this Optional, if a value is present, otherwise an empty Optional
      抛出:
      NullPointerException - if the mapping function is null or returns a null result
    • lazyMap

      public <U> Supplier<U> lazyMap(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 returns null, the supplier will return null.
      类型参数:
      U - The type of the result of the mapping function
      参数:
      mapper - A mapping function to apply to the mod object, if present
      返回:
      A Supplier lazily providing the result of applying a mapping function to the mod object of this RegistryObject, if a mod object is present, otherwise a supplier returning null
      抛出:
      NullPointerException - if the mapping function is null
      API Note:
      This method supports post-processing on optional values, without the need to explicitly check for a return status.
    • orElse

      public T orElse(T other)
      Return the mod object if present, otherwise return other.
      参数:
      other - the mod object to be returned if there is no mod object present, may be null
      返回:
      the mod object, if present, otherwise other
    • orElseGet

      public T orElseGet(Supplier<? extends T> other)
      Return the mod object if present, otherwise invoke other and return the result of that invocation.
      参数:
      other - a Supplier whose result is returned if no mod object is present
      返回:
      the mod object if present otherwise the result of other.get()
      抛出:
      NullPointerException - if mod object is not present and other is null
    • orElseThrow

      public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X
      Return the contained mod object, if present, otherwise throw an exception to be created by the provided supplier.
      类型参数:
      X - Type of the exception to be thrown
      参数:
      exceptionSupplier - The supplier which will return the exception to be thrown
      返回:
      the present mod object
      抛出:
      X - if there is no mod object present
      NullPointerException - if no mod object is present and exceptionSupplier is null
      API Note:
      A method reference to the exception constructor with an empty argument list can be used as the supplier. For example, IllegalStateException::new
    • getHolder

      @NotNull public @NotNull Optional<Holder<T>> getHolder()
      Returns an optional Holder instance pointing to this RegistryObject's name and value.

      This should only be used in cases where vanilla code requires passing in a Holder. Mod-written code should rely on RegistryObjects or Suppliers instead.

      The returned optional will be empty if the registry does not exist or if returns false.

      返回:
      an optional Holder instance pointing to this RegistryObject's name and value
    • equals

      public boolean equals(Object obj)
      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object