Skip to content

Conversation

@DennisOchulor
Copy link
Contributor

@DennisOchulor DennisOchulor commented Jan 3, 2026

Adds to the PayloadTypeRegistry API to allow modifying and querying the max packet size for a payload type.

Adds a registerLarge overload to PayloadTypeRegistry that takes an IntSupplier, allowing mods to defer setting the max packet size.

Partially supersedes #4996

* @param maxPacketSize the maximum size of payload packet
* @param <T> the payload type
*/
<T extends CustomPacketPayload> void setMaxPacketSize(CustomPacketPayload.Type<T> type, int maxPacketSize);
Copy link
Member

Choose a reason for hiding this comment

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

I'm just thinking of alternatives to this API, it does feel a little weird to have a setter that has to be called after registering with a possibly unknown inital max size.

I was wondering if taking a ToIntFunction (T being the payload) in a registerLarge overload would be a better API. I then realised that will only work for encoding 🤔.

My only other ideas are taking an IntFunction or maven even a AtomicInteger, neither of which I love.

(Im just thinking out loud so let me know what you think).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya it does feel a bit weird, but personally I still prefer the setter. The other approaches would mean the max size could change arbitrarily, so the value would need to be revalidated each time. The max size could also be decreased from a previously set value which the current API doesn't allow (though I suppose we could just allow it? not sure if that would cause any problems).

Copy link
Member

Choose a reason for hiding this comment

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

Again thinking out loud:

It does seem wrong to allow changing this during gameplay/after packets have been sent, could it take a function to return the max size once per connection/server instance?

E.g In the constructor of FabricPacketMerger/Splitter it could compute the max packet sizes for all registered types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps a registerLarge overload that takes an IntSupplier that is called once right before the first packet of a payload type is sent/received? Should be sufficient for the data attachment API assuming no large attachments are registered after mod init.

Copy link
Contributor Author

@DennisOchulor DennisOchulor Jan 8, 2026

Choose a reason for hiding this comment

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

I've made the above change. I also removed getMaxPacketSize() as I feel the new design doesn't really need it.

@DennisOchulor DennisOchulor changed the title Allow modifying payload type max packet size after registration Allow registering large payloads with deferred max packet size Jan 8, 2026
Copy link
Member

@modmuss50 modmuss50 left a comment

Choose a reason for hiding this comment

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

I think this is good now 👍

@modmuss50 modmuss50 added enhancement New feature or request status: last call If you care, make yourself heard right away! module: networking api Pull requests and issues related to the networking api labels Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request module: networking api Pull requests and issues related to the networking api status: last call If you care, make yourself heard right away!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants