Class FabricEntityDataRegistry
java.lang.Object
net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityDataRegistry
Allows registering custom
EntityDataSerializers in a reliable way.-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable net.minecraft.network.syncher.EntityDataSerializer<?> get(net.minecraft.resources.Identifier id) Retrieves the handler for the given ID, ornullif it does not exist.static @Nullable net.minecraft.resources.IdentifiergetId(net.minecraft.network.syncher.EntityDataSerializer<?> handler) Retrieves the ID for the given handler, ornullif the handler was not registered withregister(Identifier, EntityDataSerializer).static voidregister(net.minecraft.resources.Identifier id, net.minecraft.network.syncher.EntityDataSerializer<?> handler) Registers aEntityDataSerializerusing the given ID.
-
Method Details
-
register
public static void register(net.minecraft.resources.Identifier id, net.minecraft.network.syncher.EntityDataSerializer<?> handler) Registers aEntityDataSerializerusing the given ID. Use this instead ofEntityDataSerializers.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)andEntityDataSerializers.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, ornullif 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, ornullif the handler was not registered withregister(Identifier, EntityDataSerializer).
-