fabric icon indicating copy to clipboard operation
fabric copied to clipboard

Add attachment holder context to creation

Open Flemmli97 opened this issue 5 months ago • 4 comments

Currently the default initializer for attachment only accepts a supplier. it would be better if it can also accepts a function that provides the current holder of the attachment. https://github.com/FabricMC/fabric/blob/1.21.8/fabric-data-attachment-api-v1/src/main/java/net/fabricmc/fabric/api/attachment/v1/AttachmentRegistry.java#L151

This way if you e.g. wanted an attachment for an entity and provide modification access to the attachment that requires the entity too you don't need to create a method with the entity as one of the args all the time.

Flemmli97 avatar Jul 17 '25 17:07 Flemmli97

I think this was rejected due to generic problems? You can currently somewhat work around it by creating your own entity/world/block entity load event at the right spot, and using the attachment changed event to handle all further changes.

cputnam-a11y avatar Jul 17 '25 17:07 cputnam-a11y

tbh can just have Function<Object, T> and it lies on the modder to properly check. (not too sure how to handle it otherwise either)

Flemmli97 avatar Jul 17 '25 17:07 Flemmli97

I don't think they wanted that, but it's in an issue now

cputnam-a11y avatar Jul 17 '25 18:07 cputnam-a11y

It seems this is not possible with the current API design and we have to close this issue, this is done intentionally https://discord.com/channels/507304429255393322/566276937035546624/1388132874653532210

maityyy avatar Nov 09 '25 10:11 maityyy