Skip to content

Commit

Permalink
Contains a fix for Sollace/Unicopia/#491 and fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Oct 14, 2024
1 parent be61f70 commit 5eb0ccb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/sollace/fabwork/api/packets/C2SPacketType.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public void sendToServer(T packet) {
ClientSimpleNetworkingImpl.send(new Payload<>(packet, id));
}

@Deprecated
public void sendToServer(Packet packet) {
sendToServer((T)packet);
}

/**
* Creates a single-use callback to invoke when receiving a packet from a particular client.
* The returned future will either complete successfully with the incoming packet,
Expand All @@ -60,4 +65,9 @@ public net.minecraft.network.packet.Packet<ServerCommonPacketListener> toPacket(
Objects.requireNonNull(packet, "Packet cannot be null");
return ClientSimpleNetworkingImpl.createC2SPacket(new Payload<>(packet, id));
}

@Deprecated
public net.minecraft.network.packet.Packet<ServerCommonPacketListener> toPacket(Packet packet) {
return toPacket((T)packet);
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/sollace/fabwork/api/packets/S2CPacketType.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public void sendToPlayer(T packet, ServerPlayerEntity recipient) {
ServerPlayNetworking.send(recipient, new Payload<>(packet, id));
}

@Deprecated
public void sendToPlayer(Packet packet, ServerPlayerEntity recipient) {
sendToPlayer((T)packet, recipient);
}

public void sendToAllPlayers(T packet, World world) {
Objects.requireNonNull(world, "Server world cannot be null");
var p = toPacket(packet);
Expand All @@ -36,13 +41,23 @@ public void sendToAllPlayers(T packet, World world) {
});
}

@Deprecated
public void sendToAllPlayers(Packet packet, World world) {
sendToAllPlayers((T)packet, world);
}

public void sendToSurroundingPlayers(T packet, Entity entity) {
Objects.requireNonNull(entity, "Entity cannot be null");
if (entity.getWorld() instanceof ServerWorld sw) {
sw.getChunkManager().sendToNearbyPlayers(entity, toPacket(packet));
}
}

@Deprecated
public void sendToSurroundingPlayers(Packet packet, Entity entity) {
sendToSurroundingPlayers((T)packet, entity);
}

public void sendToAllPlayers(T packet, MinecraftServer server) {
Objects.requireNonNull(server, "Server cannot be null");
var p = toPacket(packet);
Expand All @@ -51,11 +66,21 @@ public void sendToAllPlayers(T packet, MinecraftServer server) {
});
}

@Deprecated
public void sendToAllPlayers(Packet packet, MinecraftServer server) {
sendToAllPlayers((T)packet, server);
}

/**
* Repackages a fabwork packet into a normal Minecraft protocol packet suitable for sending to a connected client.
*/
public net.minecraft.network.packet.Packet<ClientCommonPacketListener> toPacket(T packet) {
Objects.requireNonNull(packet, "Packet cannot be null");
return ServerPlayNetworking.createS2CPacket(new Payload<>(packet, id));
}

@Deprecated
public net.minecraft.network.packet.Packet<ClientCommonPacketListener> toPacket(Packet packet) {
return toPacket((T)packet);
}
}

0 comments on commit 5eb0ccb

Please sign in to comment.