Class FabricRegistryBuilder<T, R extends net.minecraft.core.WritableRegistry<T>>

java.lang.Object
net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder<T,R>
Type Parameters:
T - The type stored in the Registry
R - The registry type

public final class FabricRegistryBuilder<T, R extends net.minecraft.core.WritableRegistry<T>> extends Object
Used to create custom registries, with specified registry attributes.

See the following example for creating a Registry of String objects.


 ResourceKey<Registry<String>> key = ResourceKey.createRegistryKey(Identifier.fromNamespaceAndPath("modid", "custom_registry"));
 Registry<String> registry = FabricRegistryBuilder.createSimple(key)
													.attribute(RegistryAttribute.SYNCED)
													.buildAndRegister();
	

Tags for the entries of a custom registry must be placed in /tags/<registry namespace>/<registry path>/. For example, the tags for the example registry above would be placed in /tags/modid/registry_name/.

  • Method Details

    • from

      public static <T, R extends net.minecraft.core.WritableRegistry<T>> FabricRegistryBuilder<T,R> from(R registry)
      Create a new FabricRegistryBuilder, the registry has the RegistryAttribute.MODDED attribute by default.
      Type Parameters:
      T - The type stored in the Registry
      R - The registry type
      Parameters:
      registry - The base registry type such as MappedRegistry or DefaultedRegistry
      Returns:
      An instance of FabricRegistryBuilder
    • create

      public static <T> FabricRegistryBuilder<T, net.minecraft.core.MappedRegistry<T>> create(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> key)
      Create a new FabricRegistryBuilder using a MappedRegistry, the registry has the RegistryAttribute.MODDED attribute by default.
      Type Parameters:
      T - The type stored in the Registry
      Parameters:
      key - The registry's ResourceKey
      Returns:
      An instance of FabricRegistryBuilder
    • createDefaulted

      public static <T> FabricRegistryBuilder<T, net.minecraft.core.DefaultedMappedRegistry<T>> createDefaulted(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> key, net.minecraft.resources.Identifier defaultId)
      Create a new FabricRegistryBuilder using a DefaultedRegistry, the registry has the RegistryAttribute.MODDED attribute by default.
      Type Parameters:
      T - The type stored in the Registry
      Parameters:
      key - The registry's ResourceKey
      defaultId - The default registry id
      Returns:
      An instance of FabricRegistryBuilder
    • create

      @Deprecated public static <T> FabricRegistryBuilder<T, net.minecraft.core.MappedRegistry<T>> create(Class<T> type, net.minecraft.resources.Identifier registryId)
      Deprecated.
      Please migrate to create(ResourceKey)
      Create a new FabricRegistryBuilder using a MappedRegistry, the registry has the RegistryAttribute.MODDED attribute by default.
      Type Parameters:
      T - The type stored in the Registry
      Parameters:
      registryId - The registry Identifier used as the registry id
      Returns:
      An instance of FabricRegistryBuilder
    • createDefaulted

      @Deprecated public static <T> FabricRegistryBuilder<T, net.minecraft.core.DefaultedMappedRegistry<T>> createDefaulted(Class<T> type, net.minecraft.resources.Identifier registryId, net.minecraft.resources.Identifier defaultId)
      Deprecated.
      Create a new FabricRegistryBuilder using a DefaultedRegistry, the registry has the RegistryAttribute.MODDED attribute by default.
      Type Parameters:
      T - The type stored in the Registry
      Parameters:
      registryId - The registry Identifier used as the registry id
      defaultId - The default registry id
      Returns:
      An instance of FabricRegistryBuilder
    • attribute

      public FabricRegistryBuilder<T,R> attribute(RegistryAttribute attribute)
      Add a RegistryAttribute to the registry.
      Parameters:
      attribute - the RegistryAttribute to add to the registry
      Returns:
      the instance of FabricRegistryBuilder
    • buildAndRegister

      public R buildAndRegister()
      Applies the attributes to the registry and registers it.
      Returns:
      the registry instance with the attributes applied