Class FabricEntityDataRegistry

java.lang.Object
net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityDataRegistry

public final class FabricEntityDataRegistry extends Object
Allows registering custom EntityDataSerializers in a reliable way.
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable net.minecraft.network.syncher.EntityDataSerializer<?>
    get(net.minecraft.resources.Identifier id)
    Retrieves the handler for the given ID, or null if it does not exist.
    static @Nullable net.minecraft.resources.Identifier
    getId(net.minecraft.network.syncher.EntityDataSerializer<?> handler)
    Retrieves the ID for the given handler, or null if the handler was not registered with register(Identifier, EntityDataSerializer).
    static void
    register(net.minecraft.resources.Identifier id, net.minecraft.network.syncher.EntityDataSerializer<?> handler)
    Registers a EntityDataSerializer using the given ID.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • register

      public static void register(net.minecraft.resources.Identifier id, net.minecraft.network.syncher.EntityDataSerializer<?> handler)
      Registers a EntityDataSerializer using the given ID. Use this instead of EntityDataSerializers.registerSerializer(EntityDataSerializer) as the vanilla method exclusively uses integer IDs, which can result in desyncs and errors with custom handlers. This method is guaranteed to work reliably.

      Handlers registered with this method will have an associated integer ID as well, which can be used with EntityDataSerializers.getSerializer(int) and EntityDataSerializers.getSerializedId(EntityDataSerializer). However, the integer ID of a given custom handler registered through this method may change on registry sync. The integer IDs of vanilla handlers are guaranteed to remain constant.

    • get

      public static @Nullable net.minecraft.network.syncher.EntityDataSerializer<?> get(net.minecraft.resources.Identifier id)
      Retrieves the handler for the given ID, or null if it does not exist.
    • getId

      public static @Nullable net.minecraft.resources.Identifier getId(net.minecraft.network.syncher.EntityDataSerializer<?> handler)
      Retrieves the ID for the given handler, or null if the handler was not registered with register(Identifier, EntityDataSerializer).