Skip to content

Using removeAttached on a data attachment is not synced #253

@ThePotatoArchivist

Description

@ThePotatoArchivist

Minecraft version

1.21.1

Describe the bug

When you call removeAttached for a data attachment, it is not synced to the client, making the client think the data is still attached.

Steps to reproduce

  1. Create a 1.21.1 fabric mod with the following initializer, which is intended to toggle the attachment by using a stick and print to the log every second if the client sees the data attached:
@SuppressWarnings("UnstableApiUsage")
public class AttachmentTest implements ModInitializer {
	public static final String MOD_ID = "attachmenttest";

	public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

    public static final AttachmentType<Unit> TEST = AttachmentRegistry.create(
            ResourceLocation.fromNamespaceAndPath(MOD_ID, "test"),
            builder -> builder.syncWith(StreamCodec.unit(Unit.INSTANCE), AttachmentSyncPredicate.all())
    );

	@Override
	public void onInitialize() {
        UseItemCallback.EVENT.register((player, world, hand) -> {
            var stack = player.getItemInHand(hand);
            if (!stack.is(Items.STICK)) return InteractionResultHolder.pass(stack);
            if (world.isClientSide) return InteractionResultHolder.success(stack);

            if (player.hasAttached(TEST)) {
                LOGGER.info("Removed attachment");
                player.removeAttached(TEST);
            } else {
                LOGGER.info("Set Attachment");
                player.setAttached(TEST, Unit.INSTANCE);
            }

            return InteractionResultHolder.success(stack);
        });

        ClientTickEvents.END_WORLD_TICK.register(world -> {
            if (Minecraft.getInstance().player.hasAttached(TEST) && world.getGameTime() % 20 == 0)
                LOGGER.info("Currently attached");
        });
	}
}
  1. Test the mod in fabric. The message correctly stops getting printed when the stick is used to remove the attachment.
Image
  1. Test the mod with connector & ffapi. The message keeps getting printed even after the stick is used to remove the attachment.
Image

Logs

https://mclo.gs/eHhhcNC

Additional context

Using Connector 2.0.0 beta 12, FFAPI 0.115.6+2.1.4+1.21.1, and Neoforge 21.1.216

Metadata

Metadata

Assignees

Labels

1.21.xTargets Minecraft 1.21

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions