Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ModMessages {
- public static final String PROTOCOL_VERSION = "1";
- public static SimpleChannel INSTANCE;
- private static int packetID = 0;
- private static int id() {
- return packetID++;
- }
- public static void register() {
- SimpleChannel net = NetworkRegistry.ChannelBuilder
- .named(new ResourceLocation(Constants.MOD_ID, "messages"))
- .networkProtocolVersion(() -> "1.0")
- .clientAcceptedVersions(s -> true)
- .serverAcceptedVersions(s -> true)
- .simpleChannel();
- INSTANCE = net;
- INSTANCE.messageBuilder(PacketSyncTeleporterPosToClient.class, id(), NetworkDirection.PLAY_TO_CLIENT)
- .decoder(PacketSyncTeleporterPosToClient::new)
- .encoder(PacketSyncTeleporterPosToClient::toBytes)
- .consumer(PacketSyncTeleporterPosToClient::handle)
- .add();
- }
- public static <MSG> void sendToAllTrackingAndSelf(MSG message, Entity entity) {
- INSTANCE.send(PacketDistributor.TRACKING_ENTITY_AND_SELF.with(() -> entity), message);
- }
- // Send to the server
- public static <MSG> void sendToServer(MSG message) {
- INSTANCE.sendToServer(message);
- }
- // Send to one player
- public static <MSG> void sendToClient(MSG message, ServerPlayer player) {
- INSTANCE.send(PacketDistributor.TRACKING_ENTITY.with(() -> player), message);
- }
- // Send to all connected players
- public static <MSG> void sendToClients(MSG message) {
- INSTANCE.send(PacketDistributor.ALL.noArg(), message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement