Skip to content

Commit

Permalink
Update code for the Handled<> class to use the new interface and depr…
Browse files Browse the repository at this point in the history
…ecated the old methods as we have no way of updating them without breaking old code
  • Loading branch information
Sollace committed Sep 29, 2024
1 parent 21bad84 commit be61f70
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/main/java/com/sollace/fabwork/api/packets/Handled.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
* or if the packet class they're creating extends a pre-established
* packet from the base game.
* <p>
* Recommended approach is to use {@link HandledPacket} and override handle(sender) for server-bound
* packets and use {@link Packet} together with the receiver API
* to handle client-bound packets as this allows for better separation of client-specific code.
* Recommended approach is to use {@link Handled} and override handle(sender) for server-bound
* packets and use the receiver API to handle client-bound packets as this allows for better separation of client-specific code.
*
* @author Sollace
*/
Expand All @@ -24,7 +23,6 @@ public interface Handled<Sender> {
* Implementors may optionally override this method,
* or register handlers using the receiver().
* <p>
*
* @param sender The player who initially sent this packet.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* to handle client-bound packets as this allows for better separation of client-specific code.
*
* @author Sollace
* @deprecated The packet interface will be retired in 1.22. Use Handled<Sender> instead.
*/
@Deprecated
public interface HandledPacket<Sender> extends Packet, Handled<Sender> {
}
2 changes: 2 additions & 0 deletions src/main/java/com/sollace/fabwork/api/packets/Packet.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
* to handle client-bound packets as this allows for better separation of client-specific code.
*
* @author Sollace
* @deprecated The packet interface will be retired in 1.22. Use Handled<Sender> instead.
*/
@Deprecated
public interface Packet {
/**
* Writes this packet to the supplied buffer prior to transmission.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public interface SimpleNetworking {
*
* @return A registered PacketType
*/
@Deprecated
static <T extends Packet> C2SPacketType<T> clientToServer(Identifier id, Function<? super RegistryByteBuf, T> factory) {
return clientToServer(id, PacketCodec.of(Packet::toBuffer, factory::apply));
}
Expand Down Expand Up @@ -72,6 +73,7 @@ static <T> C2SPacketType<T> clientToServer(Identifier id, PacketCodec<? super Re
*
* @return A registered PacketType
*/
@Deprecated
static <T extends Packet> S2CPacketType<T> serverToClient(Identifier id, Function<? super RegistryByteBuf, T> factory) {
return serverToClient(id, PacketCodec.of(Packet::toBuffer, factory::apply));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public void addTemporaryListener(BiPredicate<Sender, P> callback) {
void onReceive(Sender sender, P packet) {
persistentListeners.fire(sender, packet);
listeners.fire(sender, packet);
if (packet instanceof HandledPacket) {
if (packet instanceof Handled handler) {
try {
((HandledPacket<Sender>)packet).handle(sender);
handler.handle(sender);
} catch (Exception e) {
LOGGER.error("Exception whilst handling packet callback for handled packet " + id, e);
}
Expand Down

0 comments on commit be61f70

Please sign in to comment.