Skip to content

Convert BedrockPacketType from enum to extensible class to support custom packet types#322

Merged
PetteriM1 merged 2 commits intoCloudburstMC:3.0from
smartcmd:feat/proposal-321
Feb 9, 2026
Merged

Convert BedrockPacketType from enum to extensible class to support custom packet types#322
PetteriM1 merged 2 commits intoCloudburstMC:3.0from
smartcmd:feat/proposal-321

Conversation

@smartcmd
Copy link
Contributor

@smartcmd smartcmd commented Jan 30, 2026

Resolves #321

@irrld
Copy link
Contributor

irrld commented Jan 30, 2026

These methods aren't only for convenience, since they are directly called by packets, it provides essentially zero overhead to find which handler to jump to (except the vtable lookup to find overrides). Changing how they are handled will add a measurable overhead to packet handling.

I see that you are trying to add custom packet support so the protocol library can be extended but we should do it another way that doesn't break existing code.

To make BedrockPacketType extendable we could make it non-enum and store each type as a statically constructed constant object. So custom packet types can be created and registered in a registry. For the handling part I think it can stay the same, since handlePacket(BedrockPacket) already exists, for custom packets that can be overridden and handled (or even cast to a custom extension handler to provide functions that are called directly).

TL;DR something like this maybe

public class BedrockPacketType {
  public static final BedrockPacketType ADD_BEHAVIOR_TREE = new BedrockPacketType(...);
  
  ...
}

public class NeteasePacketType {
  public static final BedrockPacketType NETEASE_PACKET = new BedrockPacketType(...);
}

@smartcmd smartcmd closed this Jan 30, 2026
@smartcmd smartcmd reopened this Jan 30, 2026
@smartcmd smartcmd changed the title Deprecate BedrockPacketType and packet-specific handle methods for custom packet support Convert BedrockPacketType from enum to extensible class to support custom packet types Jan 30, 2026
@smartcmd
Copy link
Contributor Author

These methods aren't only for convenience, since they are directly called by packets, it provides essentially zero overhead to find which handler to jump to (except the vtable lookup to find overrides). Changing how they are handled will add a measurable overhead to packet handling.

I see that you are trying to add custom packet support so the protocol library can be extended but we should do it another way that doesn't break existing code.

To make BedrockPacketType extendable we could make it non-enum and store each type as a statically constructed constant object. So custom packet types can be created and registered in a registry. For the handling part I think it can stay the same, since handlePacket(BedrockPacket) already exists, for custom packets that can be overridden and handled (or even cast to a custom extension handler to provide functions that are called directly).

TL;DR something like this maybe

public class BedrockPacketType {
  public static final BedrockPacketType ADD_BEHAVIOR_TREE = new BedrockPacketType(...);
  
  ...
}

public class NeteasePacketType {
  public static final BedrockPacketType NETEASE_PACKET = new BedrockPacketType(...);
}

Done, thanks for the review

@smartcmd

This comment was marked as off-topic.

@PetteriM1 PetteriM1 merged commit 57f9846 into CloudburstMC:3.0 Feb 9, 2026
1 check passed
@smartcmd smartcmd deleted the feat/proposal-321 branch February 10, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proposal: allow third-party libraries to register custom packet types at runtime

4 participants