Skip to content

Expand Attachment system capabilities#3095

Draft
robotgryphon wants to merge 13 commits into
neoforged:26.1.xfrom
robotgryphon:server-attachments
Draft

Expand Attachment system capabilities#3095
robotgryphon wants to merge 13 commits into
neoforged:26.1.xfrom
robotgryphon:server-attachments

Conversation

@robotgryphon
Copy link
Copy Markdown
Contributor

@robotgryphon robotgryphon commented Apr 14, 2026

This PR lays the foundation to allow for the expansion of the attachment system to new types, without bringing along some of the hard-coded sync and data persistence code that the existing system built due to its few type requirements.

Some examples, with vanilla attachment holders. These expose the holder, data storage, data persistence, and sync systems to anyone that wishes to interact with them, via the capability system:

Usage

public static void registerVanillaAttachmentHosts(RegisterCapabilitiesEvent event) {
        event.registerAttachment(MinecraftServer.class, AttachmentCapabilities.ATTACHMENT_HOLDER, s -> s);
        event.registerAttachment(MinecraftServer.class, AttachmentCapabilities.DATA_STORAGE, s -> s);
        event.registerAttachment(MinecraftServer.class, AttachmentCapabilities.PERSISTENCE, IAttachmentHolder::attachmentPersistenceHandler);
        event.registerAttachment(MinecraftServer.class, AttachmentCapabilities.SYNC, IAttachmentHolder::attachmentSyncHandler);

        event.registerAttachment(ServerLevel.class, AttachmentCapabilities.ATTACHMENT_HOLDER, s -> s);
        event.registerAttachment(ServerLevel.class, AttachmentCapabilities.DATA_STORAGE, s -> s);
        event.registerAttachment(ServerLevel.class, AttachmentCapabilities.PERSISTENCE, IAttachmentHolder::attachmentPersistenceHandler);
        event.registerAttachment(ServerLevel.class, AttachmentCapabilities.SYNC, IAttachmentHolder::attachmentSyncHandler);
    }

Note that this is NOT required for the new sync and persistence code. It simply highlights what is now possible due to the systems moving to common, reusable interfaces.

TODOs

  • Finish off the attachment sync handlers registry and client-side data retrieval (Packet Listener + AttachmentHolderSyncHandler classes)
  • Reimplement sync game tests in a more composed manner, rather than an all-in-one megatest
  • Prove system by demoing attachments and persistence with MinecraftServer and ClientLevel classes
  • Documentation
  • Cleanup

@neoforged-automation neoforged-automation Bot added the 26.1 Targeted at Minecraft 26.1 label Apr 14, 2026
@neoforged-pr-publishing
Copy link
Copy Markdown

neoforged-pr-publishing Bot commented Apr 14, 2026

  • Publish PR to GitHub Packages

Last commit published: 4f0e1667bc60ddea2b23aa625889644d8af9ee7d - version: 26.1.2.44-beta-pr-3095-server-attachments

PR Publishing

The artifacts published by this PR:

Repository Declaration

In order to use the artifacts published by the PR, add the following repository to your buildscript:

repositories {
    maven {
        name = "Maven for PR #3095" // https://github.com/neoforged/NeoForge/pull/3095
        url = uri("https://prmaven.neoforged.net/NeoForge/pr3095")
        content {
            includeModule("net.neoforged", "neoforge")
            includeModule("net.neoforged", "testframework")
        }
    }
}

MDK installation

In order to setup a MDK using the latest PR version, run the following commands in a terminal.
The script works on both *nix and Windows as long as you have the JDK bin folder on the path.
The script will clone the MDK in a folder named NeoForge-pr3095.
On Powershell you will need to remove the -L flag from the curl invocation.

mkdir NeoForge-pr3095
cd NeoForge-pr3095
curl -L https://prmaven.neoforged.net/NeoForge/pr3095/net/neoforged/neoforge/26.1.2.44-beta-pr-3095-server-attachments/mdk-pr3095.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip

To test a production environment, you can download the installer from here.

@neoforged-compatibility-checks
Copy link
Copy Markdown

neoforged-compatibility-checks Bot commented Apr 14, 2026

@robotgryphon, this PR introduces breaking changes.
Fortunately, this project is currently accepting breaking changes, but if they are not intentional, please revert them.
Last checked commit: 4f0e1667bc60ddea2b23aa625889644d8af9ee7d.

Compatibility checks

neoforge (:neoforge)

  • net/neoforged/neoforge/network/payload/SyncAttachmentsPayload$Target
    • ❗ API class no longer exists
  • net/neoforged/neoforge/network/payload/SyncAttachmentsPayload$LevelTarget
    • ❗ API class no longer exists
  • net/minecraft/world/level/chunk/ImposterProtoChunk
    • getAttachmentHolder()Lnet/neoforged/neoforge/attachment/AttachmentHolder$AsField;: ❗ API method was removed
  • net/neoforged/neoforge/attachment/LevelAttachmentsSavedData
    • ⚠ API class no longer exists
  • net/neoforged/neoforge/attachment/AttachmentSyncHandler
    • ❗ API class no longer exists
  • net/neoforged/neoforge/attachment/AttachmentInternals
    • copyChunkAttachmentsOnPromotion(Lnet/minecraft/core/HolderLookup$Provider;Lnet/neoforged/neoforge/attachment/AttachmentHolder$AsField;Lnet/neoforged/neoforge/attachment/AttachmentHolder$AsField;)V: ⚠ API method was removed
  • net/neoforged/neoforge/network/payload/SyncAttachmentsPayload$BlockEntityTarget
    • ❗ API class no longer exists
  • net/neoforged/neoforge/attachment/AttachmentSync
    • ⚠ API class no longer exists
  • net/minecraft/world/level/Level
    • ❗ Class missing superclass of net/neoforged/neoforge/attachment/AttachmentHolder
  • net/neoforged/neoforge/network/payload/SyncAttachmentsPayload$ChunkTarget
    • ❗ API class no longer exists
  • net/neoforged/neoforge/network/payload/SyncAttachmentsPayload
    • ⚠ API class no longer exists
  • net/neoforged/neoforge/network/payload/SyncAttachmentsPayload$EntityTarget
    • ❗ API class no longer exists
  • net/minecraft/world/level/chunk/ChunkAccess
    • getAttachmentHolder()Lnet/neoforged/neoforge/attachment/AttachmentHolder$AsField;: ⚠ API method was removed
  • net/neoforged/neoforge/attachment/AttachmentType$Builder
    • sync(Lnet/neoforged/neoforge/attachment/AttachmentSyncHandler;)Lnet/neoforged/neoforge/attachment/AttachmentType$Builder;: ❗ API method was removed
  • net/neoforged/neoforge/attachment/AttachmentHolder$AsField
    • ❗ API class no longer exists

@Technici4n Technici4n self-requested a review April 14, 2026 15:12
"net/neoforged/neoforge/common/extensions/IPlayerListExtension"
],
"net/minecraft/server/MinecraftServer": [
"net/neoforged/neoforge/attachment/IForwardingAttachmentHolder"
Copy link
Copy Markdown
Member

@Technici4n Technici4n Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a more general solution such that the attachments can be synced to the client as well (and accessed from there). We brainstormed some sort of SessionData class that could be accessed from any level (including a client level) to that effect, should be findable on Discord somewhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/main/java/net/neoforged/neoforge/attachment/IForwardingAttachmentHolder.java Outdated
Comment thread src/main/java/net/neoforged/neoforge/attachment/AttachmentHolder.java Outdated
Comment thread src/main/java/net/neoforged/neoforge/attachment/IForwardingAttachmentHolder.java Outdated
Comment thread patches/net/minecraft/server/MinecraftServer.java.patch
Comment thread src/client/java/net/neoforged/neoforge/client/network/ClientPayloadHandler.java Outdated
@robotgryphon robotgryphon changed the title Add Server-level Data Attachments and Forwarding Attachment Holders Expand Attachment system capabilities Apr 30, 2026
@robotgryphon robotgryphon marked this pull request as draft April 30, 2026 06:18
@sciwhiz12 sciwhiz12 added the enhancement New (or improvement to existing) feature or request label May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

26.1 Targeted at Minecraft 26.1 enhancement New (or improvement to existing) feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants