diff --git a/fabric-registry-sync-v0/src/client/java/net/fabricmc/fabric/impl/client/registry/sync/ClientRegistrySyncHandler.java b/fabric-registry-sync-v0/src/client/java/net/fabricmc/fabric/impl/client/registry/sync/ClientRegistrySyncHandler.java index 3a172cd2fe..d821a8dee5 100644 --- a/fabric-registry-sync-v0/src/client/java/net/fabricmc/fabric/impl/client/registry/sync/ClientRegistrySyncHandler.java +++ b/fabric-registry-sync-v0/src/client/java/net/fabricmc/fabric/impl/client/registry/sync/ClientRegistrySyncHandler.java @@ -103,12 +103,11 @@ public static void apply(RegistryPacketHandler.SyncedPacketData data) throws Rem } } - if (registry instanceof RemappableRegistry remappableRegistry) { - remappableRegistry.remap(entry.getValue(), RemappableRegistry.RemapMode.REMOTE); - return; + if (!(registry instanceof RemappableRegistry remappableRegistry)) { + throw new RemapException("Registry " + registryId + " is not remappable"); } - throw new RemapException("Registry " + registryId + " is not remappable"); + remappableRegistry.remap(entry.getValue(), RemappableRegistry.RemapMode.REMOTE); } } diff --git a/fabric-registry-sync-v0/src/test/java/net/fabricmc/fabric/test/registry/sync/RegistryRemapTest.java b/fabric-registry-sync-v0/src/test/java/net/fabricmc/fabric/test/registry/sync/RegistryRemapTest.java index 0e5180d401..62511051e1 100644 --- a/fabric-registry-sync-v0/src/test/java/net/fabricmc/fabric/test/registry/sync/RegistryRemapTest.java +++ b/fabric-registry-sync-v0/src/test/java/net/fabricmc/fabric/test/registry/sync/RegistryRemapTest.java @@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import java.util.Map; import java.util.UUID; @@ -53,6 +54,7 @@ import net.fabricmc.fabric.impl.registry.sync.RemapException; import net.fabricmc.fabric.impl.registry.sync.RemappableRegistry; import net.fabricmc.fabric.impl.registry.sync.packet.DirectRegistryPacketHandler; +import net.fabricmc.fabric.impl.registry.sync.packet.RegistryPacketHandler; public class RegistryRemapTest { private RegistryKey> testRegistryKey; @@ -248,6 +250,71 @@ void missingRemoteEntries() throws RemapException { assertEquals(2, testRegistry.getRawId("two")); } + @Test + void remapRegistryFromPacketData() throws RemapException { + RemappableRegistry remappableRegistry = (RemappableRegistry) testRegistry; + + assertEquals(0, testRegistry.getRawId("zero")); + assertEquals(1, testRegistry.getRawId("one")); + assertEquals(2, testRegistry.getRawId("two")); + + ClientRegistrySyncHandler.apply(new RegistryPacketHandler.SyncedPacketData( + Map.of( + testRegistryKey.getValue(), asFastMap(Map.of( + id("zero"), 2, + id("one"), 1, + id("two"), 0 + )) + ), + Map.of() + )); + + assertEquals(2, testRegistry.getRawId("zero")); + assertEquals(1, testRegistry.getRawId("one")); + assertEquals(0, testRegistry.getRawId("two")); + + remappableRegistry.unmap(); + + assertEquals(0, testRegistry.getRawId("zero")); + assertEquals(1, testRegistry.getRawId("one")); + assertEquals(2, testRegistry.getRawId("two")); + } + + @Test + void remapRegistryFromPacketDataIgnoreOptional() throws RemapException { + RemappableRegistry remappableRegistry = (RemappableRegistry) testRegistry; + + assertEquals(0, testRegistry.getRawId("zero")); + assertEquals(1, testRegistry.getRawId("one")); + assertEquals(2, testRegistry.getRawId("two")); + + ClientRegistrySyncHandler.apply(new RegistryPacketHandler.SyncedPacketData( + Map.of( + testRegistryKey.getValue(), asFastMap(Map.of( + id("zero"), 2, + id("one"), 1, + id("two"), 0 + )), + Identifier.of("test", "optional"), asFastMap(Map.of( + id("test"), 0 + )) + ), + Map.of( + Identifier.of("test", "optional"), EnumSet.of(RegistryAttribute.OPTIONAL) + ) + )); + + assertEquals(2, testRegistry.getRawId("zero")); + assertEquals(1, testRegistry.getRawId("one")); + assertEquals(0, testRegistry.getRawId("two")); + + remappableRegistry.unmap(); + + assertEquals(0, testRegistry.getRawId("zero")); + assertEquals(1, testRegistry.getRawId("one")); + assertEquals(2, testRegistry.getRawId("two")); + } + private static List receivePayloads(List payloads) throws RemapException { var results = new ArrayList();