Skip to content

feat: rework network system#40

Open
Jamalam360 wants to merge 1 commit into
mainfrom
feat/networking-2
Open

feat: rework network system#40
Jamalam360 wants to merge 1 commit into
mainfrom
feat/networking-2

Conversation

@Jamalam360
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reworks JamLib's networking API to be more ergonomic for packet authors. The previous model required separately defining a PayloadType<T>, a NetworkPayloadType<T> (or StreamCodecNetworkPayloadType<T>), and registering them via registerPayloadType before sending. The new model collapses these into a single PacketKind<T> (identifier + StreamCodec) plus a PacketPayload<T> interface that packet records implement directly, so Network.sendToServer/sendToClient only needs the payload instance.

The platform expect-platform layer is simplified to take a PacketKind<T> instead of a separate type/serializer pair, and per-platform NetworkContext wrappers (FabricClientNetworkContext, FabricServerNetworkContext, NeoForgeNetworkContext) replace the previous public record so NetworkContext is now an interface with getPlayer(). The internal JamLibPacket transport is unchanged in shape; its identifier field is just renamed from PayloadType<?> to PacketIdentifier.

Changes:

  • Replace PayloadType + NetworkPayloadType/StreamCodecNetworkPayloadType with PacketKind + PacketPayload, and Network.Direction with top-level PacketDirection.
  • Move registration/send/receive logic into NetworkImpl; Network becomes a thin public facade with new sendToServer(PacketPayload) / sendToClient(ServerPlayer, PacketPayload) signatures.
  • Turn NetworkContext into an interface implemented by Fabric/NeoForge wrappers, and update CapabilitiesPacket/PotatoPacket and platform entrypoints to the new API.

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated no comments.

Show a summary per file
File Description
common/.../api/network/Network.java Slim facade delegating to NetworkImpl; old registration/dispatch removed.
common/.../api/network/PacketKind.java New codec-bearing packet kind abstraction with static of(...) factories.
common/.../api/network/PacketPayload.java New interface requiring getKind()/getPayload() on payload instances.
common/.../api/network/PacketIdentifier.java New record wrapping Identifier for packet identity.
common/.../api/network/PacketDirection.java New top-level enum replacing Network.Direction.
common/.../api/network/NetworkContext.java Converted from record to interface exposing getPlayer().
common/.../api/network/NetworkCapability.java Adds canReceive(PacketKind) default plus canReceive(PacketIdentifier).
common/.../api/network/NetworkPayloadType.java Removed (superseded by PacketKind).
common/.../api/network/StreamCodecNetworkPayloadType.java Removed (superseded by PacketKindImpl).
common/.../api/network/PayloadType.java Removed (superseded by PacketIdentifier).
common/.../impl/network/NetworkImpl.java New home of handler/kind maps and send/receive dispatch.
common/.../impl/network/PacketKindImpl.java Record implementation bridging StreamCodec to Serializer/Deserializer.
common/.../impl/network/PlatformNetwork.java Expect-platform signatures now take PacketKind<T> and payload.
common/.../impl/network/JamLibPacket.java Renames payloadType to packetIdentifier; wire format unchanged.
common/.../impl/network/NetworkCapabilityImpl.java canReceive now takes a PacketIdentifier.
common/.../impl/network/NetworkCapabilitiesImpl.java Uses NetworkImpl.getRegisteredHandlerTypes and context.getPlayer().
common/.../impl/network/CapabilitiesPacket.java Converted to record implementing PacketPayload<CapabilitiesPacket>.
common/.../JamLib.java Drops registerPayloadType call; uses new PacketDirection.SERVERBOUND.
common/.../client/impl/JamLibClient.java Uses PacketDirection.CLIENTBOUND and CapabilitiesPacket.KIND.
common/.../client/impl/network/ClientNetworkCapabilitiesImpl.java Handler signature uses record CapabilitiesPacket; sends via new API.
fabric/.../impl/network/fabric/PlatformNetworkImpl.java Implements new expect-platform signatures via kind.getSerializer().
fabric/.../impl/network/fabric/FabricServerNetworkContext.java New server-side context wrapper.
fabric/.../impl/network/fabric/FabricClientNetworkContext.java New client-side context wrapper.
fabric/.../impl/fabric/JamLibFabric.java Routes serverbound receive through NetworkImpl with new context.
fabric/.../impl/fabric/JamLibClientFabric.java Routes clientbound receive through NetworkImpl with new context.
neoforge/.../impl/network/neoforge/PlatformNetworkImpl.java NeoForge counterpart of new platform send signatures.
neoforge/.../impl/network/neoforge/NeoForgeNetworkContext.java New NeoForge context wrapper around IPayloadContext.
neoforge/.../impl/neoforge/JamLibNeoForge.java Bidirectional registration now routes via NetworkImpl as serverbound.
neoforge/.../impl/neoforge/JamLibNeoForgeClient.java Client payload handler routes via NetworkImpl as clientbound.
testmod-common/.../network/PotatoPacket.java Migrated to record implementing PacketPayload<PotatoPacket>.
testmod-common/.../TestMod.java Drops registerPayloadType; uses PacketKind/PacketIdentifier in capability checks.
testmod-common/.../TestModClient.java Registers handler with PacketDirection.CLIENTBOUND and PotatoPacket.KIND.
testmod-common/.../item/PacketPotatoItem.java Sends new PotatoPacket(random) via the new sendToClient overload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants