fix: block state id synchronization error between client and dedicated server
Fixes
@@ -7,9 +7,7 @@ import engine.enginemod.client.gui.game.GuiServerConnectingStatus;
import engine.entity.CameraEntity;
import engine.event.Listener;
import engine.game.MultiplayerGameData;
-import engine.registry.Registries;
-import engine.registry.Registry;
-import engine.registry.SynchronizableRegistry;
+import engine.registry.*;
import engine.server.event.PacketReceivedEvent;
import engine.server.network.*;
import engine.server.network.packet.PacketDisconnect;
@@ -17,8 +15,10 @@ import engine.server.network.packet.PacketSyncRegistry;
import engine.server.network.packet.c2s.PacketLoginProfile;
import engine.server.network.packet.s2c.PacketGameData;
import engine.server.network.packet.s2c.PacketLoginRequest;
-import engine.state.StateIncludedRegistry;
+import engine.state.State;
+import org.apache.commons.lang3.tuple.Pair;
+import java.util.Map;
import java.util.Objects;
public class PreGamePacketHandler {
@@ -41,15 +41,12 @@ public class PreGamePacketHandler {
}
@Listener
- public static void onRegistrySync(PacketReceivedEvent<PacketSyncRegistry> event) {
+ public static <T extends Registrable<T>> void onRegistrySync(PacketReceivedEvent<PacketSyncRegistry> event) {
+ PacketSyncRegistry packet = event.getPacket();
for (Registry<?> registry : Registries.getRegistryManager().getRegistries()) {
- if (Objects.equals(registry.getRegistryName(), event.getPacket().getRegistryName())) {
- if (registry instanceof SynchronizableRegistry) {
- ((SynchronizableRegistry<?>) registry).sync(event.getPacket().getIdMap());
- if (registry instanceof StateIncludedRegistry) {
- ((StateIncludedRegistry<?>) registry).reconstructStateId();
- }
- }
+ if (Objects.equals(registry.getRegistryName(), packet.getRegistryName())) {
+ packet.getTarget().applier.accept(registry, packet.getIdMap());
+ break;
}
}
}
