@@ -72,14 +72,18 @@ public class PcaSyncProtocol {
72
72
73
73
public static void init () {
74
74
//#if MC > 12004
75
+ //$$ PayloadTypeRegistry.playC2S().register(ServerboundCancelSyncBlockEntityPacket.TYPE, ServerboundCancelSyncBlockEntityPacket.CODEC);
76
+ //$$ PayloadTypeRegistry.playC2S().register(ServerboundCancelSyncEntityPacket.TYPE, ServerboundCancelSyncEntityPacket.CODEC);
77
+ //$$ PayloadTypeRegistry.playC2S().register(ServerboundSyncBlockEntityPacket.TYPE, ServerboundSyncBlockEntityPacket.CODEC);
78
+ //$$ PayloadTypeRegistry.playC2S().register(ServerboundSyncEntityPacket.TYPE, ServerboundSyncEntityPacket.CODEC);
75
79
//$$ PayloadTypeRegistry.playS2C().register(ClientboundDisablePcaSyncProtocolPacket.TYPE, ClientboundDisablePcaSyncProtocolPacket.CODEC);
76
80
//$$ PayloadTypeRegistry.playS2C().register(ClientboundEnablePcaSyncProtocolPacket.TYPE, ClientboundEnablePcaSyncProtocolPacket.CODEC);
77
81
//$$ PayloadTypeRegistry.playS2C().register(ClientboundUpdateBlockEntityPacket.TYPE, ClientboundUpdateBlockEntityPacket.CODEC);
78
82
//$$ PayloadTypeRegistry.playS2C().register(ClientboundUpdateEntityPacket.TYPE, ClientboundUpdateEntityPacket.CODEC);
79
- //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundDisablePcaSyncProtocolPacket.TYPE, ClientboundDisablePcaSyncProtocolPacket::handle );
80
- //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundEnablePcaSyncProtocolPacket.TYPE, ClientboundEnablePcaSyncProtocolPacket::handle );
81
- //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundUpdateBlockEntityPacket.TYPE, ClientboundUpdateBlockEntityPacket::handle );
82
- //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundUpdateEntityPacket.TYPE, ClientboundUpdateEntityPacket::handle );
83
+ //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundDisablePcaSyncProtocolPacket.TYPE, PcaSyncProtocol::disablePcaSyncProtocolHandler );
84
+ //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundEnablePcaSyncProtocolPacket.TYPE, PcaSyncProtocol::enablePcaSyncProtocolHandler );
85
+ //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundUpdateBlockEntityPacket.TYPE, PcaSyncProtocol::updateBlockEntityHandler );
86
+ //$$ ClientPlayNetworking.registerGlobalReceiver(ClientboundUpdateEntityPacket.TYPE, PcaSyncProtocol::updateEntityHandler );
83
87
//#else
84
88
ClientPlayNetworking .registerGlobalReceiver (ENABLE_PCA_SYNC_PROTOCOL , PcaSyncProtocol ::enablePcaSyncProtocolHandler );
85
89
ClientPlayNetworking .registerGlobalReceiver (DISABLE_PCA_SYNC_PROTOCOL , PcaSyncProtocol ::disablePcaSyncProtocolHandler );
@@ -94,25 +98,55 @@ private static void onDisconnect() {
94
98
enable = false ;
95
99
}
96
100
97
- public static void enablePcaSyncProtocolHandler (Minecraft client , ClientPacketListener handler ,
98
- FriendlyByteBuf buf , PacketSender responseSender ) {
99
- if (!client .hasSingleplayerServer ()) {
101
+ private static void enablePcaSyncProtocolHandler (
102
+ //#if MC > 12004
103
+ //$$ ClientboundEnablePcaSyncProtocolPacket packet,
104
+ //$$ ClientPlayNetworking.Context context
105
+ //#else
106
+ Minecraft client ,
107
+ ClientPacketListener handler ,
108
+ FriendlyByteBuf buf ,
109
+ PacketSender responseSender
110
+ //#endif
111
+ ) {
112
+ if (!Minecraft .getInstance ().hasSingleplayerServer ()) {
100
113
SharedConstants .getLogger ().info ("pcaSyncProtocol enable." );
101
114
enable = true ;
102
115
}
103
116
}
104
117
105
- public static void disablePcaSyncProtocolHandler (Minecraft client , ClientPacketListener handler ,
106
- FriendlyByteBuf buf , PacketSender responseSender ) {
107
- if (!client .hasSingleplayerServer ()) {
118
+ public static void disablePcaSyncProtocolHandler (
119
+ //#if MC > 12004
120
+ //$$ ClientboundDisablePcaSyncProtocolPacket packet,
121
+ //$$ ClientPlayNetworking.Context context
122
+ //#else
123
+ Minecraft client ,
124
+ ClientPacketListener handler ,
125
+ FriendlyByteBuf buf ,
126
+ PacketSender responseSender
127
+ //#endif
128
+ ) {
129
+ if (!Minecraft .getInstance ().hasSingleplayerServer ()) {
108
130
SharedConstants .getLogger ().info ("pcaSyncProtocol disable." );
109
131
enable = false ;
110
132
}
111
133
}
112
134
113
135
// 反序列化实体数据
114
- public static void updateEntityHandler (Minecraft client , ClientPacketListener handler ,
115
- FriendlyByteBuf buf , PacketSender responseSender ) {
136
+ public static void updateEntityHandler (
137
+ //#if MC > 12004
138
+ //$$ ClientboundUpdateEntityPacket packet,
139
+ //$$ ClientPlayNetworking.Context context
140
+ //#else
141
+ Minecraft client ,
142
+ ClientPacketListener handler ,
143
+ FriendlyByteBuf buf ,
144
+ PacketSender responseSender
145
+ //#endif
146
+ ) {
147
+ //#if MC > 12004
148
+ //$$ Minecraft client = context.client();
149
+ //#endif
116
150
LocalPlayer player = client .player ;
117
151
118
152
if (player == null ) {
@@ -123,12 +157,23 @@ public static void updateEntityHandler(Minecraft client, ClientPacketListener ha
123
157
LevelCompat levelCompat = playerCompat .getLevel ();
124
158
Level level = levelCompat .get ();
125
159
126
- if (!levelCompat .getDimensionLocation ().equals (buf .readResourceLocation ())) {
160
+ if (!levelCompat .getDimensionLocation ().equals (
161
+ //#if MC > 12004
162
+ //$$ packet.dimension()
163
+ //#else
164
+ buf .readResourceLocation ()
165
+ //#endif
166
+ )) {
127
167
return ;
128
168
}
129
169
170
+ //#if MC > 12004
171
+ //$$ int entityId = packet.entityId();
172
+ //$$ CompoundTag tag = packet.tag();
173
+ //#else
130
174
int entityId = buf .readInt ();
131
175
CompoundTag tag = NetworkUtil .readNbt (buf );
176
+ //#endif
132
177
Entity entity = level .getEntity (entityId );
133
178
134
179
if (entity != null ) {
@@ -166,7 +211,7 @@ public static void updateEntityHandler(Minecraft client, ClientPacketListener ha
166
211
//$$ if (tag.contains("Offers")) {
167
212
//$$ MerchantOffers.CODEC
168
213
//$$ .parse(client.level.registryAccess().createSerializationContext(NbtOps.INSTANCE),
169
- //$$ tag.getCompound("Offers"). get("Offers"))
214
+ //$$ tag.get("Offers"))
170
215
//$$ .resultOrPartial(Util.prefix("Failed to load offers: ", MagicLib.getLogger()::warn))
171
216
//$$ .ifPresent(merchantOffers -> ((AccessorAbstractVillager) entity).setOffers(merchantOffers));
172
217
//$$ }
@@ -209,8 +254,20 @@ public static void updateEntityHandler(Minecraft client, ClientPacketListener ha
209
254
}
210
255
211
256
// 反序列化 blockEntity 数据
212
- public static void updateBlockEntityHandler (Minecraft client , ClientPacketListener handler ,
213
- FriendlyByteBuf buf , PacketSender responseSender ) {
257
+ public static void updateBlockEntityHandler (
258
+ //#if MC > 12004
259
+ //$$ ClientboundUpdateBlockEntityPacket packet,
260
+ //$$ ClientPlayNetworking.Context context
261
+ //#else
262
+ Minecraft client ,
263
+ ClientPacketListener handler ,
264
+ FriendlyByteBuf buf ,
265
+ PacketSender responseSender
266
+ //#endif
267
+ ) {
268
+ //#if MC > 12004
269
+ //$$ Minecraft client = context.client();
270
+ //#endif
214
271
LocalPlayer player = client .player ;
215
272
216
273
if (player == null ) {
@@ -220,12 +277,23 @@ public static void updateBlockEntityHandler(Minecraft client, ClientPacketListen
220
277
LevelCompat levelCompat = PlayerCompat .of (player ).getLevel ();
221
278
Level level = levelCompat .get ();
222
279
223
- if (!levelCompat .getDimensionLocation ().equals (buf .readResourceLocation ())) {
280
+ if (!levelCompat .getDimensionLocation ().equals (
281
+ //#if MC > 12004
282
+ //$$ packet.dimension()
283
+ //#else
284
+ buf .readResourceLocation ()
285
+ //#endif
286
+ )) {
224
287
return ;
225
288
}
226
289
290
+ //#if MC > 12004
291
+ //$$ BlockPos pos = packet.blockPos();
292
+ //$$ CompoundTag tag = packet.tag();
293
+ //#else
227
294
BlockPos pos = buf .readBlockPos ();
228
295
CompoundTag tag = buf .readNbt ();
296
+ //#endif
229
297
BlockEntity blockEntity = level .getBlockEntity (pos );
230
298
231
299
if (Configs .saveInventoryToSchematicInServer .getBooleanValue () && pos .equals (PcaSyncUtil .lastUpdatePos )) {
@@ -252,11 +320,13 @@ public static void syncBlockEntity(BlockPos pos) {
252
320
SharedConstants .getLogger ().debug ("syncBlockEntity: {}" , pos );
253
321
lastBlockPos = pos ;
254
322
lastEntityId = -1 ;
323
+ //#if MC < 12005
255
324
FriendlyByteBuf buf = new FriendlyByteBuf (Unpooled .buffer ());
256
325
buf .writeBlockPos (pos );
326
+ //#endif
257
327
ClientPlayNetworking .send (
258
328
//#if MC > 12004
259
- //$$ new ServerboundSyncBlockEntityPacket(buf )
329
+ //$$ new ServerboundSyncBlockEntityPacket(pos )
260
330
//#else
261
331
SYNC_BLOCK_ENTITY ,
262
332
buf
@@ -272,11 +342,13 @@ public static void syncEntity(int entityId) {
272
342
SharedConstants .getLogger ().debug ("syncEntity: {}" , entityId );
273
343
lastEntityId = entityId ;
274
344
lastBlockPos = null ;
345
+ //#if MC < 12005
275
346
FriendlyByteBuf buf = new FriendlyByteBuf (Unpooled .buffer ());
276
347
buf .writeInt (entityId );
348
+ //#endif
277
349
ClientPlayNetworking .send (
278
350
//#if MC > 12004
279
- //$$ new ServerboundSyncEntityPacket(buf )
351
+ //$$ new ServerboundSyncEntityPacket(entityId )
280
352
//#else
281
353
SYNC_ENTITY ,
282
354
buf
@@ -294,7 +366,7 @@ public static void cancelSyncBlockEntity() {
294
366
FriendlyByteBuf buf = new FriendlyByteBuf (Unpooled .buffer ());
295
367
ClientPlayNetworking .send (
296
368
//#if MC > 12004
297
- //$$ new ServerboundCancelSyncBlockEntityPacket(buf )
369
+ //$$ new ServerboundCancelSyncBlockEntityPacket()
298
370
//#else
299
371
CANCEL_SYNC_REQUEST_BLOCK_ENTITY ,
300
372
buf
@@ -312,7 +384,7 @@ public static void cancelSyncEntity() {
312
384
FriendlyByteBuf buf = new FriendlyByteBuf (Unpooled .buffer ());
313
385
ClientPlayNetworking .send (
314
386
//#if MC > 12004
315
- //$$ new ServerboundCancelSyncEntityPacket(buf )
387
+ //$$ new ServerboundCancelSyncEntityPacket()
316
388
//#else
317
389
CANCEL_SYNC_ENTITY ,
318
390
buf
0 commit comments