|
1 | 1 | package net.hypixel.modapi.fabric; |
2 | 2 |
|
3 | 3 | import com.mojang.logging.LogUtils; |
| 4 | +import io.netty.buffer.ByteBuf; |
4 | 5 | import net.fabricmc.api.ClientModInitializer; |
5 | 6 | import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking; |
6 | 7 | import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; |
7 | 8 | import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; |
| 9 | +import net.fabricmc.fabric.api.gametest.v1.GameTest; |
8 | 10 | import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; |
9 | 11 | import net.fabricmc.loader.api.FabricLoader; |
10 | 12 | import net.hypixel.modapi.HypixelModAPI; |
|
16 | 18 | import net.hypixel.modapi.packet.HypixelPacket; |
17 | 19 | import net.hypixel.modapi.packet.impl.clientbound.ClientboundHelloPacket; |
18 | 20 | import net.hypixel.modapi.packet.impl.clientbound.event.ClientboundLocationPacket; |
19 | | -import net.minecraft.client.MinecraftClient; |
20 | | -import net.minecraft.network.PacketByteBuf; |
21 | | -import net.minecraft.network.codec.PacketCodec; |
22 | | -import net.minecraft.network.packet.CustomPayload; |
23 | | -import net.minecraft.test.GameTest; |
24 | | -import net.minecraft.util.Identifier; |
| 21 | +import net.minecraft.client.Minecraft; |
| 22 | +import net.minecraft.network.codec.StreamCodec; |
| 23 | +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; |
| 24 | +import net.minecraft.resources.Identifier; |
25 | 25 | import org.jetbrains.annotations.ApiStatus; |
26 | 26 | import org.slf4j.Logger; |
27 | 27 |
|
@@ -58,7 +58,7 @@ public boolean sendPacket(HypixelPacket packet) { |
58 | 58 |
|
59 | 59 | ServerboundHypixelPayload hypixelPayload = new ServerboundHypixelPayload(packet); |
60 | 60 |
|
61 | | - if (MinecraftClient.getInstance().getNetworkHandler() != null) { |
| 61 | + if (Minecraft.getInstance().getConnection() != null) { |
62 | 62 | ClientPlayNetworking.send(hypixelPayload); |
63 | 63 | return true; |
64 | 64 | } |
@@ -105,10 +105,12 @@ public static void reloadRegistrations() { |
105 | 105 |
|
106 | 106 | private static void registerClientbound(String identifier) { |
107 | 107 | try { |
108 | | - CustomPayload.Id<ClientboundHypixelPayload> clientboundId = new CustomPayload.Id<>(Identifier.of(identifier)); |
109 | | - PacketCodec<PacketByteBuf, ClientboundHypixelPayload> codec = ClientboundHypixelPayload.buildCodec(clientboundId); |
110 | | - PayloadTypeRegistry.playS2C().register(clientboundId, codec); |
111 | | - PayloadTypeRegistry.configurationS2C().register(clientboundId, codec); |
| 108 | + CustomPacketPayload.Type<ClientboundHypixelPayload> clientboundId = new CustomPacketPayload.Type<>( |
| 109 | + Identifier.parse(identifier) |
| 110 | + ); |
| 111 | + StreamCodec<ByteBuf, ClientboundHypixelPayload> codec = ClientboundHypixelPayload.buildCodec(clientboundId); |
| 112 | + PayloadTypeRegistry.clientboundPlay().register(clientboundId, codec); |
| 113 | + PayloadTypeRegistry.clientboundConfiguration().register(clientboundId, codec); |
112 | 114 |
|
113 | 115 | // Also register the global receiver for handling incoming packets during PLAY and CONFIGURATION |
114 | 116 | ClientPlayNetworking.registerGlobalReceiver(clientboundId, (payload, context) -> { |
@@ -157,10 +159,12 @@ private static void handleIncomingPayload(String identifier, ClientboundHypixelP |
157 | 159 |
|
158 | 160 | private static void registerServerbound(String identifier) { |
159 | 161 | try { |
160 | | - CustomPayload.Id<ServerboundHypixelPayload> serverboundId = new CustomPayload.Id<>(Identifier.of(identifier)); |
161 | | - PacketCodec<PacketByteBuf, ServerboundHypixelPayload> codec = ServerboundHypixelPayload.buildCodec(serverboundId); |
162 | | - PayloadTypeRegistry.playC2S().register(serverboundId, codec); |
163 | | - PayloadTypeRegistry.configurationC2S().register(serverboundId, codec); |
| 162 | + CustomPacketPayload.Type<ServerboundHypixelPayload> serverboundId = new CustomPacketPayload.Type<>( |
| 163 | + Identifier.parse(identifier) |
| 164 | + ); |
| 165 | + StreamCodec<ByteBuf, ServerboundHypixelPayload> codec = ServerboundHypixelPayload.buildCodec(); |
| 166 | + PayloadTypeRegistry.serverboundPlay().register(serverboundId, codec); |
| 167 | + PayloadTypeRegistry.serverboundConfiguration().register(serverboundId, codec); |
164 | 168 | } catch (IllegalArgumentException ignored) { |
165 | 169 | // Ignored as this is fired when we reload the registrations and the packet is already registered |
166 | 170 | } |
|
0 commit comments