Fabric API

Fabric API

106M Downloads

Fabric auto updating tag does not work across reloads

liach opened this issue ยท 2 comments

commented

The way fabric tag extension checks if a tag reference needs an update turns out to be unreliable.

Reproduction:
Add a command that dumps a certain tag. Edit the tag in a data pack in the world. After reload, observe that the reference from tag registry still uses old value while the tag obtained from the server's tag manager real-time has the correct new values.

This problem does not exist if the player leaves the world and join again.

Code:

final class KayakCommand {

  private final Tag<EntityType<?>> actual = TagRegistry.entityType(KayakEntityTags.CARRIER_BOAT);

  KayakCommand() {}

  void register(CommandDispatcher<ServerCommandSource> dispatcher) {
    dispatcher.register(
        CommandManager.literal("kayak-test")
            .executes(this::executeKayakTest)
    );
  }

  private int executeKayakTest(CommandContext<ServerCommandSource> context) {
    ServerCommandSource source = context.getSource();
    Tag<EntityType<?>> expected = source.getMinecraftServer().getTagManager().entityTypes().getOrCreate(KayakEntityTags.CARRIER_BOAT);
    source.sendFeedback(Texts.join(expected.values(), this::idToText), false);
    source.sendFeedback(Texts.join(this.actual.values(), this::idToText), false);

    return Command.SINGLE_SUCCESS;
  }

  private Text idToText(EntityType<?> type) {
    return new LiteralText(Registry.ENTITY_TYPE.getId(type).toString());
  }

}
commented

I think this issue was solved? Some testing may be needed to validate this.

commented

Mojang fixed this on their end a while ago with the safety approach like player's.